cv.HDtweedie {HDtweedie} | R Documentation |
Cross-validation for HDtweedie
Description
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 |
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
|
pred.loss |
loss to use for cross-validation error. Valid options are:
Default is |
nfolds |
number of folds - default is 5. Although |
foldid |
an optional vector of values between 1 and |
... |
other arguments that can be passed to HDtweedie. |
Details
The function runs HDtweedie
nfolds
+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 |
cvm |
the mean cross-validated error - a vector of length
|
cvsd |
estimate of standard error of |
cvupper |
upper curve = |
cvlower |
lower curve = |
name |
a text string indicating type of measure (for plotting purposes). |
HDtweedie.fit |
a fitted |
lambda.min |
The optimal value of |
lambda.1se |
The largest value of |
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. (2016), “Tweedie's Compound
Poisson Model With Grouped Elastic Net,” Journal of Computational and Graphical Statistics, 25, 606-625.
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)