| pred-projection {projpred} | R Documentation |
After the projection of the reference model onto a submodel, proj_linpred()
gives the linear predictor (possibly transformed to response scale) for all
projected draws of such a submodel. proj_predict() draws from the
predictive distribution of such a submodel. If the projection has not been
performed, both functions also perform the projection. Both functions can
also handle multiple submodels at once (if the input object is of class
vsel).
proj_linpred( object, newdata = NULL, offsetnew = NULL, weightsnew = NULL, filter_nterms = NULL, transform = FALSE, integrated = FALSE, .seed = sample.int(.Machine$integer.max, 1), ... ) proj_predict( object, newdata = NULL, offsetnew = NULL, weightsnew = NULL, filter_nterms = NULL, nresample_clusters = 1000, .seed = sample.int(.Machine$integer.max, 1), ... )
object |
An object returned by |
newdata |
Passed to argument |
offsetnew |
Passed to argument |
weightsnew |
Passed to argument |
filter_nterms |
Only applies if |
transform |
For |
integrated |
For |
.seed |
Pseudorandom number generation (PRNG) seed by which the same
results can be obtained again if needed. If |
... |
Arguments passed to |
nresample_clusters |
For |
Let S_prj denote the number of (possibly
clustered) projected posterior draws (short: the number of projected draws)
and N the number of observations. Then, if the prediction is done for
one submodel only (i.e., length(nterms) == 1 || !is.null(solution_terms)
in the call to project()):
proj_linpred() returns a list with elements pred (predictions) and
lpd (log predictive densities). Both elements are S_prj x N matrices.
proj_predict() returns an S_prj x N
matrix of predictions where S_prj denotes
nresample_clusters in case of clustered projection.
If the prediction is done for more than one submodel, the output from above
is returned for each submodel, giving a named list with one element for
each submodel (the names of this list being the numbers of solutions
terms of the submodels when counting the intercept, too).
if (requireNamespace("rstanarm", quietly = TRUE)) {
# Data:
dat_gauss <- data.frame(y = df_gaussian$y, df_gaussian$x)
# The "stanreg" fit which will be used as the reference model (with small
# values for `chains` and `iter`, but only for technical reasons in this
# example; this is not recommended in general):
fit <- rstanarm::stan_glm(
y ~ X1 + X2 + X3 + X4 + X5, family = gaussian(), data = dat_gauss,
QR = TRUE, chains = 2, iter = 500, refresh = 0, seed = 9876
)
# Projection onto an arbitrary combination of predictor terms (with a small
# value for `nclusters`, but only for the sake of speed in this example;
# this is not recommended in general):
prj <- project(fit, solution_terms = c("X1", "X3", "X5"), nclusters = 10,
seed = 9182)
# Predictions (at the training points) from the submodel onto which the
# reference model was projected:
prjl <- proj_linpred(prj)
prjp <- proj_predict(prj, .seed = 7364)
}