% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/onramp.R
\name{build_grid}
\alias{build_grid}
\title{Build a shared evaluation grid from a reference dataset}
\usage{
build_grid(reference_data, n_grid = NULL, seed = NULL)
}
\arguments{
\item{reference_data}{A data frame (or matrix) of reference patient-level
covariates. May be a held-out target-population sample, the pooled
source covariates, or any plausible reference distribution.}

\item{n_grid}{Optional integer giving the desired grid size. If \code{NULL}
or \verb{>= nrow(reference_data)}, the full reference data is returned.}

\item{seed}{Optional integer seed for reproducibility (used only when
sub-sampling).}
}
\value{
A data frame of grid points.
}
\description{
Constructs a data frame of grid points suitable for \code{\link[=f_hat_from_models]{f_hat_from_models()}}
from any reference patient-level dataset. This is convenient when the
patient-level covariate space is multidimensional and there is no
obvious one-dimensional grid.
}
\details{
If \code{n_grid} is \code{NULL} or at least \code{nrow(reference_data)}, the reference
data is returned unchanged. Otherwise \code{n_grid} rows are sampled uniformly
at random (without replacement). The reference data should be on the
same scale and have the same columns as the data each centre's model
was fitted on.

The empirical distribution of the returned grid implicitly defines the
\eqn{\mu} measure used downstream. Pass uniform \code{grid_weights} (the
default) to weight each grid point equally; pass non-uniform
\code{grid_weights} to weight by an external reference distribution.
}
\examples{
set.seed(1)
ref <- data.frame(age = rnorm(500, 60, 10),
                  bp  = rnorm(500, 130, 15),
                  sex = sample(c("F", "M"), 500, replace = TRUE))
grid <- build_grid(ref, n_grid = 50, seed = 1)
nrow(grid)
head(grid)

}
