Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

proj-pred

Extract draws of the linear predictor and draw from the predictive distribution of the projected submodel


Description

proj_linpred extracts draws of the linear predictor and proj_predict draws from the predictive distribution of the projected submodel or submodels. If the projection has not been performed, the functions also perform the projection.

Usage

proj_linpred(
  object,
  newdata,
  offsetnew = NULL,
  weightsnew = NULL,
  nterms = NULL,
  transform = FALSE,
  integrated = FALSE,
  seed = NULL,
  ...
)

proj_predict(
  object,
  newdata,
  offsetnew = NULL,
  weightsnew = NULL,
  nterms = NULL,
  ndraws = 1000,
  seed = NULL,
  ...
)

Arguments

object

Either an object returned by varsel, cv_varsel or init_refmodel, or alternatively any object that can be converted to a reference model.

newdata

The predictor values used in the prediction. If solution_terms is specified, then newdata should either be a dataframe containing column names that correspond to solution_terms or a matrix with the number and order of columns corresponding to solution_terms. If solution_terms is unspecified, then newdata must either be a dataframe containing all the column names as in the original data or a matrix with the same columns at the same positions as in the original data.

offsetnew

Offsets for the new observations. By default a vector of zeros. By default we take the weights from newdata as in the original model. Either NULL or right hand side formula.

weightsnew

Weights for the new observations. For binomial model, corresponds to the number trials per observation. For proj_linpred, this argument matters only if newdata is specified. By default we take the weights from newdata as in the original model. Either NULL or right hand side formula.

nterms

Number of terms in the submodel (the variable combination is taken from the variable selection information). If a vector with several values, then results for all specified model sizes are returned. Ignored if solution_terms is specified. By default use the automatically suggested model size.

transform

Should the linear predictor be transformed using the inverse-link function? Default is FALSE. For proj_linpred only.

integrated

If TRUE, the output is averaged over the parameters. Default is FALSE. For proj_linpred only.

seed

An optional seed to use for drawing from the projection. For proj_predict only.

...

Additional argument passed to project if object is an object returned by varsel or cv_varsel.

ndraws

Number of draws to return from the predictive distribution of the projection. The default is 1000. For proj_predict only.

Value

If the prediction is done for one submodel only (nterms has length one or solution_terms is specified) and newdata is unspecified, a matrix or vector of predictions (depending on the value of integrated). If newdata is specified, returns a list with elements pred (predictions) and lpd (log predictive densities). If the predictions are done for several submodel sizes, returns a list with one element for each submodel.

Examples

if (requireNamespace('rstanarm', quietly=TRUE)) {
  ### Usage with stanreg objects
  n <- 30
  d <- 5
  x <- matrix(rnorm(n*d), nrow=n)
  y <- x[,1] + 0.5*rnorm(n)
  data <- data.frame(x,y)
  
  fit <- rstanarm::stan_glm(y ~ X1 + X2 + X3 + X4 + X5, gaussian(), data=data, chains=2, iter=500)
  vs <- varsel(fit)
  
  # compute predictions with 4 variables at the training points
  pred <- proj_linpred(vs, newdata = data, nv = 4)
  pred <- proj_predict(vs, newdata = data, nv = 4)
}

projpred

Projection Predictive Feature Selection

v2.0.2
GPL-3
Authors
Juho Piironen [aut], Markus Paasiniemi [aut], Alejandro Catalina [cre, aut], Aki Vehtari [aut], Jonah Gabry [ctb], Marco Colombo [ctb], Paul-Christian Bürkner [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.