% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/predict_target.R
\name{predict_target}
\alias{predict_target}
\title{Predict the target function for new study-level covariates}
\usage{
predict_target(dfspa_fit, weight_model, W_new)
}
\arguments{
\item{dfspa_fit}{A \code{"dfspa"} object produced by \code{\link[=dfspa]{dfspa()}}. Its \code{bases}
slot (\code{K}-by-\code{G_grid} matrix) provides the basis functions on the grid.}

\item{weight_model}{A \code{"metahunt_weight_model"} object produced by
\code{\link[=fit_weight_model]{fit_weight_model()}}. Must have \code{weight_model$K == nrow(dfspa_fit$bases)}.}

\item{W_new}{A matrix or data frame of study-level covariates for the new
target studies, with columns matching those used to fit \code{weight_model}.}
}
\value{
An \code{nrow(W_new)}-by-\code{G_grid} numeric matrix; row \code{j} is the
predicted target function on the grid for the \code{j}-th new study.
}
\description{
Given a fitted d-fSPA basis decomposition and a fitted weight model,
compute the predicted target function on the shared grid as
\deqn{\tilde f^{(0)}(\cdot) = \sum_{k=1}^{\hat K} \tilde\pi_{0k}\, \hat g_k(\cdot),
  \qquad \tilde\pi_0 = \widehat{\mathcal M}(\mathbf W_0).}
}
\examples{
set.seed(1)
G <- 40; m <- 60; K_true <- 3
x <- seq(0, 1, length.out = G)
basis <- rbind(sin(pi * x), cos(pi * x), x)

# generate study-level covariates and softmax weights
W <- data.frame(w1 = rnorm(m), w2 = rnorm(m))
beta <- cbind(c(1, -0.8), c(-0.5, 1.2), c(0, 0))
eta  <- as.matrix(W) \%*\% beta
pi_true <- exp(eta) / rowSums(exp(eta))
F_hat <- pi_true \%*\% basis + matrix(rnorm(m * G, sd = 0.02), m, G)

fit    <- dfspa(F_hat, K = K_true)
pi_hat <- project_to_simplex(F_hat, fit$bases)
wm     <- fit_weight_model(pi_hat, W)

W_new   <- data.frame(w1 = c(0, 1), w2 = c(0, -1))
f_pred  <- predict_target(fit, wm, W_new)
dim(f_pred)   # 2 x G

}
\seealso{
\code{\link[=apply_wrapper]{apply_wrapper()}} to reduce predicted functions to scalars.
}
