% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/conformal.R
\name{conformal_from_fit}
\alias{conformal_from_fit}
\title{Split conformal intervals from a pre-fit MetaHunt pipeline}
\usage{
conformal_from_fit(
  dfspa_fit,
  weight_model,
  F_cal,
  W_cal,
  W_new,
  alpha = 0.05,
  wrapper = NULL,
  grid_weights = NULL
)
}
\arguments{
\item{dfspa_fit}{A \code{"dfspa"} object from \code{\link[=dfspa]{dfspa()}}.}

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

\item{F_cal}{An \code{n_cal}-by-\code{G_grid} numeric matrix of observed study-level
function evaluations for the calibration set. Calibration studies must
be independent of both \code{dfspa_fit} and \code{weight_model} for valid
coverage.}

\item{W_cal}{A matrix or data frame of study-level covariates for the
calibration set, with the same columns used to fit \code{weight_model}.}

\item{W_new}{A matrix or data frame of study-level covariates for new
target studies.}

\item{alpha}{Miscoverage level; default \code{0.05}.}

\item{wrapper}{Optional reduction function (see \code{\link[=apply_wrapper]{apply_wrapper()}}). If
\code{NULL}, intervals are pointwise at every grid point.}

\item{grid_weights}{Optional length-\code{G_grid} non-negative numeric vector
used for the default wrapper and for weighted inner products.}
}
\value{
An object of class \code{"metahunt_conformal"}; see \code{\link[=split_conformal]{split_conformal()}}
for a description of its fields.
}
\description{
Lower-level entry point that builds split conformal intervals for new
target covariates using an already-fitted d-fSPA basis decomposition,
an already-fitted weight model, and a user-supplied calibration set.
Use this when you have independently tuned \code{K} or want to reuse a
pipeline fit; otherwise the high-level \code{\link[=split_conformal]{split_conformal()}} is usually
more convenient.
}
\examples{
set.seed(1)
G <- 30; m <- 80
x <- seq(0, 1, length.out = G)
basis <- rbind(sin(pi * x), cos(pi * x), x)
W <- data.frame(w1 = rnorm(m))
eta <- cbind(0.8 * W$w1, -0.4 * W$w1, rep(0, m))
pi_true <- exp(eta) / rowSums(exp(eta))
F_hat <- pi_true \%*\% basis + matrix(rnorm(m * G, sd = 0.05), m, G)

# user-controlled split and fit
tr  <- 1:50; cal <- 51:70; new <- 71:80
fit <- dfspa(F_hat[tr, ], K = 3)
pih <- project_to_simplex(F_hat[tr, ], fit$bases)
wm  <- fit_weight_model(pih, W[tr, , drop = FALSE])

res <- conformal_from_fit(
  fit, wm,
  F_cal = F_hat[cal, ], W_cal = W[cal, , drop = FALSE],
  W_new = W[new, , drop = FALSE],
  wrapper = mean
)
res

}
\seealso{
\code{\link[=split_conformal]{split_conformal()}} for the high-level version that splits and
fits internally, \code{\link[=cross_conformal]{cross_conformal()}} for the K-fold variant.
}
