% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/interface_to_interface.R
\name{formula_to_matrix}
\alias{formula_to_matrix}
\title{Convert a formula-based model to a matrix interface}
\usage{
formula_to_matrix(fit_func, predict_func = stats::predict)
}
\arguments{
\item{fit_func}{A model-fitting function whose first two arguments are
\code{formula} and \code{data} (e.g. \code{lm}, \code{glm}).}

\item{predict_func}{A prediction function with signature
\code{function(model, newdata, ...)}. Defaults to \code{stats::predict}.}
}
\value{
A named list with two elements:
\describe{
\item{\code{fit(X, y, weights, ...)}}{Fits the model. \code{X} is a
data.frame (or coercible matrix), \code{y} is the response vector.
Extra arguments are forwarded to \code{fit_func}.}
\item{\code{predict(model, newdata, ...)}}{Generates predictions.
\code{newdata} must have the same columns as the \code{X} used in
\code{fit}. Extra arguments are forwarded to \code{predict_func}.}
}
}
\description{
Wraps a model function that expects \code{formula + data} so it can be called
with a plain \code{X} (data.frame or matrix) and \code{y} (vector).
Factors in \code{X} are preserved; special column names are safely backtick-quoted
in the generated formula so they survive the formula parser.
}
\examples{
lm_matrix <- formula_to_matrix(lm)
X <- data.frame(wt = mtcars$wt, hp = mtcars$hp, cyl = factor(mtcars$cyl))
y <- mtcars$mpg
model <- lm_matrix$fit(X, y)
lm_matrix$predict(model, X[1:5, ])

}
