Learn R Programming

mpath (version 0.1-20)

cv.glmreg: Cross-validation for glmreg

Description

Does k-fold cross-validation for glmreg, produces a plot, and returns cross-validated log-likelihood values for lambda

Usage

## S3 method for class 'formula':
cv.glmreg(formula, data, weights, offset=NULL, ...)
## S3 method for class 'matrix':
cv.glmreg(x, y, weights, offset=NULL, ...)
## S3 method for class 'default':
cv.glmreg(x,  ...)
## S3 method for class 'cv.glmreg':
plot(x,se=TRUE,ylab=NULL, main=NULL, width=0.02, col="darkgrey", ...)
## S3 method for class 'cv.glmreg':
coef(object,which=object$lambda.which, ...)

Arguments

formula
symbolic description of the model, see details.
data
argument controlling formula processing via model.frame.
x
x matrix as in glmreg. It could be object of cv.glmreg.
y
response y as in glmreg.
weights
Observation weights; defaults to 1 per observation
offset
Not implemented yet
object
object of cv.glmreg
which
Indices of the penalty parameter lambda at which estimates are extracted. By default, the one which generates the optimal cross-validation value.
se
logical value, if TRUE, standard error curve is also plotted
ylab
ylab on y-axis
main
title of plot
width
width of lines
col
color of standard error curve
...
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.

Examples

Run this code
data("bioChemists", package = "pscl")
fm_pois <- cv.glmreg(art ~ ., data = bioChemists, family = "poisson")
plot(fm_pois)
title("Poisson Family",line=2.5)

Run the code above in your browser using DataLab