Does k-fold cross-validation for HDtweedie, produces a plot,
and returns a value for lambda. This function is modified based on the cv function from the glmnet package.
Usage
cv.HDtweedie(x, y, group = NULL, p, weights, lambda = NULL,
pred.loss = c("deviance", "mae", "mse"),
nfolds = 5, foldid, ...)
Arguments
x
matrix of predictors, of dimension n*p; each row is an observation vector.
y
response variable. This argument should be non-negative.
group
To apply the grouped lasso, it is a vector of consecutive integers describing the grouping of the coefficients (see example below). To apply the lasso, the user can ignore this argument, and the vector is automatically generated by treating each variable as a group.
p
the power used for variance-mean relation of Tweedie model. Default is 1.50.
weights
the observation weights. Default is equal weight.
lambda
optional user-supplied lambda sequence; default is
NULL, and HDtweedie chooses its own sequence.
pred.loss
loss to use for cross-validation error. Valid options are:
"deviance" Deviance.
"mae" Mean absolute error.
"mse" Mean square error.
Default is "deviance".
nfolds
number of folds - default is 5. Although nfolds
can be as large as the sample size (leave-one-out CV), it is not
recommended for large datasets. Smallest value allowable is nfolds=3.
foldid
an optional vector of values between 1 and nfold
identifying what fold each observation is in. If supplied,
nfold can be missing.
...
other arguments that can be passed to HDtweedie.
Details
The function runs HDtweedienfolds+1 times; the
first to get the lambda sequence, and then the remainder to
compute the fit with each of the folds omitted. The average error and standard deviation over the
folds are computed.
Value
an object of class cv.HDtweedie is returned, which is a
list with the ingredients of the cross-validation fit.
lambda
the values of lambda used in the fits.
cvm
the mean cross-validated error - a vector of length
length(lambda).
cvsd
estimate of standard error of cvm.
cvupper
upper curve = cvm+cvsd.
cvlower
lower curve = cvm-cvsd.
name
a text string indicating type of measure (for plotting
purposes).
HDtweedie.fit
a fitted HDtweedie object for the full data.
lambda.min
The optimal value of lambda that gives minimum
cross validation error cvm.
lambda.1se
The largest value of lambda such that error is
within 1 standard error of the minimum.
Author(s)
Wei Qian, Yi Yang and Hui Zou
Maintainer: Wei Qian <weiqian@stat.umn.edu>
References
Qian, W., Yang, Y., Yang, Y. and Zou, H. (2013), “Tweedie's Compound
Poisson Model With Grouped Elastic Net,” submitted to Journal of Computational and Graphical Statistics.
See Also
HDtweedie, plot.cv.HDtweedie, predict.cv.HDtweedie, and coef.cv.HDtweedie methods.
Examples
# load HDtweedie library
library(HDtweedie)
# load data set
data(auto)
# 5-fold cross validation using the lasso
cv0 <- cv.HDtweedie(x=auto$x,y=auto$y,p=1.5,nfolds=5)
# define group index
group1 <- c(rep(1,5),rep(2,7),rep(3,4),rep(4:14,each=3),15:21)
# 5-fold cross validation using the grouped lasso
cv1 <- cv.HDtweedie(x=auto$x,y=auto$y,group=group1,p=1.5,nfolds=5)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(HDtweedie)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HDtweedie/cv.HDtweedie.Rd_%03d_medium.png", width=480, height=480)
> ### Name: cv.HDtweedie
> ### Title: Cross-validation for HDtweedie
> ### Aliases: cv.HDtweedie
> ### Keywords: models regression
>
> ### ** Examples
>
> # load HDtweedie library
> library(HDtweedie)
>
> # load data set
> data(auto)
>
> # 5-fold cross validation using the lasso
> cv0 <- cv.HDtweedie(x=auto$x,y=auto$y,p=1.5,nfolds=5)
>
> # define group index
> group1 <- c(rep(1,5),rep(2,7),rep(3,4),rep(4:14,each=3),15:21)
>
> # 5-fold cross validation using the grouped lasso
> cv1 <- cv.HDtweedie(x=auto$x,y=auto$y,group=group1,p=1.5,nfolds=5)
>
>
>
>
>
> dev.off()
null device
1
>