% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/metahunt.R
\name{metahunt}
\alias{metahunt}
\title{Fit the full MetaHunt pipeline}
\usage{
metahunt(
  F_hat,
  W,
  K,
  grid_weights = NULL,
  dfspa_args = list(),
  weight_model_args = list()
)
}
\arguments{
\item{F_hat}{An \code{m}-by-\code{G_grid} numeric matrix of study-level function
evaluations on a shared grid; row \code{i} is \eqn{\hat f^{(i)}}.}

\item{W}{An \code{m}-by-\code{p} matrix or data frame of study-level covariates.}

\item{K}{Integer number of basis functions.}

\item{grid_weights}{Optional length-\code{G_grid} non-negative numeric vector
defining the \eqn{L^2(\mu)} inner product; defaults to uniform.}

\item{dfspa_args}{Named list of extra arguments for \code{\link[=dfspa]{dfspa()}}.}

\item{weight_model_args}{Named list of extra arguments for
\code{\link[=fit_weight_model]{fit_weight_model()}}.}
}
\value{
An object of class \code{"metahunt"}: a list with the \code{dfspa_fit},
\code{weight_model}, training \code{pi_hat}, \code{K}, and a stored copy of
\code{grid_weights}.
}
\description{
End-to-end convenience wrapper that runs the three training-time steps
of the MetaHunt pipeline in sequence:
(1) \code{\link[=dfspa]{dfspa()}} for basis hunting,
(2) \code{\link[=project_to_simplex]{project_to_simplex()}} for per-study weight recovery, and
(3) \code{\link[=fit_weight_model]{fit_weight_model()}} for modelling the weight-to-covariate map.
The result supports \code{\link[=predict.metahunt]{predict.metahunt()}} for generating target-function
predictions on new study-level covariates.
}
\details{
For uncertainty quantification, pair a \code{"metahunt"} fit with
\code{\link[=conformal_from_fit]{conformal_from_fit()}} (requires a separate calibration set). The
high-level \code{\link[=split_conformal]{split_conformal()}} and \code{\link[=cross_conformal]{cross_conformal()}} functions
perform their own fitting and do not consume a pre-fit \code{"metahunt"}
object.
}
\examples{
set.seed(1)
G <- 40; m <- 80
x <- seq(0, 1, length.out = G)
basis <- rbind(sin(pi * x), cos(pi * x), x)
W <- data.frame(w1 = rnorm(m), w2 = rnorm(m))
eta <- as.matrix(W) \%*\% cbind(c(1, -0.8), c(-0.5, 1.2), c(0, 0))
pi_true <- exp(eta) / rowSums(exp(eta))
F_hat <- pi_true \%*\% basis + matrix(rnorm(m * G, sd = 0.05), m, G)

fit <- metahunt(F_hat, W, K = 3)
fit
f_pred <- predict(fit, newdata = W[1:3, ])
dim(f_pred)                                  # 3 x G: predicted functions
predict(fit, newdata = W[1:3, ], wrapper = mean)  # scalar summaries

}
\seealso{
\code{\link[=predict.metahunt]{predict.metahunt()}}, \code{\link[=split_conformal]{split_conformal()}},
\code{\link[=cross_conformal]{cross_conformal()}}, \code{\link[=conformal_from_fit]{conformal_from_fit()}},
\code{\link[=reconstruction_error_curve]{reconstruction_error_curve()}}, \code{\link[=cv_error_curve]{cv_error_curve()}}.
}
