predict_within_cv {plmmr}R Documentation

Predict method to use in cross-validation (within cvf)

Description

Predict method to use in cross-validation (within cvf)

Usage

predict_within_cv(
  fit,
  trainX,
  trainY = NULL,
  testX,
  og_scale_beta,
  std_X_details,
  type,
  fbm = FALSE,
  idx = 1:length(fit$lambda),
  Sigma_11 = NULL,
  Sigma_21 = NULL,
  ...
)

Arguments

fit

A list with the components returned by plmm_fit.

trainX

The training data, pre-standardization and pre-rotation

trainY

The training outcome, not centered. Only needed if type = 'blup'

testX

A design matrix used for computing predicted values (i.e, the test data).

og_scale_beta

testX is on the scale of the original data, so we need the beta_vals that are untransformed to match that scale. See plmm_fit() and untransform() for details.

std_X_details

A list with 3 items:

  • 'center': the centering values for the columns of X

  • 'scale': the scaling values for the non-singular columns of X

  • 'ns': indicesof nonsingular columns in std_X

type

A character argument indicating what type of prediction should be returned. Passed from cvf(), Options are "lp," "coefficients," "vars," "nvars," and "blup." See details.

fbm

Logical: is trainX an FBM object? If so, this function expects that testX is also an FBM. The two X matrices must be stored the same way.

idx

Vector of indices of the penalty parameter lambda at which predictions are required. By default, all indices are returned.

Sigma_11

Variance-covariance matrix of the training data. Extracted from estimated_Sigma that is generated using all observations. Required if type == 'blup'.

Sigma_21

Covariance matrix between the training and the testing data. Extracted from estimated_Sigma that is generated using all observations. Required if type == 'blup'.

...

Additional optional arguments

Details

Define beta-hat as the coefficients estimated at the value of lambda that minimizes cross-validation error (CVE). Then options for type are as follows:

Note: the main difference between this function and the predict.plmm() method is that here in CV, predictions are made on the standardized scale (i.e., both the trainX and testX data come from std_X). The predict.plmm() method makes predictions on the scale of X (the original scale)

Value

A numeric vector of predicted values


[Package plmmr version 4.1.0 Index]