
Conditional Density Estimation with Homoskedasticity Assumption
Source:R/density_learners.R
lnr_homoskedastic_density.Rd
This function accepting an mean_lnr
, which it then trains on the data
and formula given. Then stats::density
is fit to the error (difference
between observed outcome and the mean_lnr
predictions).
Usage
lnr_homoskedastic_density(
data,
formula,
mean_lnr,
mean_lnr_args = NULL,
density_args = NULL
)
Arguments
- mean_lnr
should be a suitable
learner
(see?learners
) that can take in thedata
andformula
given.
Details
This returns a function that takes in newdata
and produces density
estimates according to the estimated stats::density
fit the error
from the newdata
observed outcome and the prediction from the mean_lnr
.
That is to say, this follows the following procedure (assuming \(Y\) as the outcome and \(X\) as a matrix of predictors):
$$\texttt{obtain } \hat{\mathbb E}(Y | X) \quad \mathtt{using \quad mean\_learner}$$ $$\texttt{fit } \hat{f} \gets \mathtt{density}(Y - \hat{\mathbb E}(Y | X))$$ $$\mathtt{return \quad function(newdata) \{ } \hat{f}(\mathtt{newdata\$Y} - \hat{\mathbb E}[Y | \mathtt{newdata\$X}]) \} $$
Examples
if (FALSE) { # \dontrun{
# fit a conditional density model with mean model as a randomForest
fit_density_lnr <- lnr_homoskedastic_density(
data = mtcars,
formula = mpg ~ hp,
mean_lnr = lnr_rf)
# and what we should get back should be predicted densities at the
# observed mpg given the covariates hp
fit_density_lnr(mtcars)
} # }