Learn R Programming

mpath (version 0.1-20)

cv.glmreg_fit: Internal function of cross-validation for glmreg

Description

Internal function to conduct k-fold cross-validation for glmreg, produces a plot, and returns cross-validated log-likelihood values for lambda

Usage

cv.glmreg_fit(x, y, weights, lambda=NULL, balance=TRUE, 
family=c("gaussian", "binomial", "poisson", "negbin"), 
nfolds=10, foldid, plot.it=TRUE, se=TRUE, trace=FALSE, ...)

Arguments

x
x matrix as in glmreg.
y
response y as in glmreg.
weights
Observation weights; defaults to 1 per observation
lambda
Optional user-supplied lambda sequence; default is NULL, and glmreg chooses its own sequence
balance
for family="binomial" only
family
response variable distribution
nfolds
number of folds >=3, default is 10
foldid
an optional vector of values between 1 and nfold identifying what fold each observation is in. If supplied, nfold can be missing and will be ignored.
plot.it
a logical value, to plot the estimated log-likelihood values if TRUE.
se
a logical value, to plot with standard errors.
trace
if TRUE, shows cross-validation progress
...
Other arguments that can be passed to glmreg.

Value

  • an object of class "cv.glmreg" is returned, which is a list with the ingredients of the cross-validation fit.
  • fita fitted glmreg object for the full data.
  • residmatmatrix of log-likelihood values with row values for lambda and column values for kth cross-validation
  • bicmatrix of BIC values with row values for lambda and column values for kth cross-validation
  • cvThe mean cross-validated log-likelihood values - a vector of length length(lambda).
  • cv.errorestimate of standard error of cv.
  • foldidan optional vector of values between 1 and nfold identifying what fold each observation is in.
  • fractiona vector of lambda values with length of lambda
  • lambda.whichindex of lambda that gives maximum cv value.
  • lambda.optimvalue of lambda that gives maximum cv value.

Details

The function runs glmreg nfolds+1 times; the first to compute the lambda sequence, and then to compute the fit with each of the folds omitted. The error or the log-likelihood value is accumulated, and the average value and standard deviation over the folds is computed. Note that cv.glmreg can be used to search for values for alpha: it is required to call cv.glmreg with a fixed vector foldid for different values of alpha.

References

Zhu Wang, Shuangge Ma, Michael Zappitelli, Chirag Parikh, Ching-Yun Wang and Prasad Devarajan (2014) Penalized Count Data Regression with Application to Hospital Stay after Pediatric Cardiac Surgery, Statistical Methods in Medical Research. 2014 Apr 17. [Epub ahead of print]

See Also

glmreg and plot, predict, and coef methods for "cv.glmreg" object.