cv.compCL: Cross-validation for compCL.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/cv.R

Description

k-fold cross-validation for compCL; produce a plot and return optimal values of lam.

Usage

1
2
cv.compCL(y, Z, Zc = NULL, intercept = FALSE, lam = NULL,
          nfolds = 10, foldid, trim = 0, keep = FALSE, ...)

Arguments

y

response vector with length n.

Z

z matrix as in compCL.

Zc

Zc matrix as in compCL. Default is NULL.

intercept

whether to include an intercept. Default is FALSE.

lam

a user supplied lambda sequence. If lam is provided as a scaler and nlam>1, lam sequence is created starting from lam. To run a single value of lam, set nlam=1. The program will sort user-defined lambda sequence in decreasing order.

nfolds

number of folds, default is 10. The smallest allowable value is nfolds=3.

foldid

an optional vector of values between 1 and the sample size n, providing the fold assignments. If supplied, nfold can be missing.

trim

percentage to be trimmed off the prediction errors from either side; default is 0.

keep

If keep=TRUE, fitted models in cross validation are reported. Default is keep=FALSE.

...

other arguments that can be passed to compCL.

Details

cross-validation and fit full data with selected model.

Value

an object of S3 class "cv.compCL" is returned, which is a list constaining:

compCL.fit

a fitted compCL object for the full data.

lam

the sequence of lam.

Ftrim

a list of cross-validation results without trimming:

  • cvm the mean cross-validated error - a vector of length length(lam).

  • cvsd standard error of cvm.

  • cvupper upper curve = cvm+cvsd.

  • cvlo lower curve = cvm-cvsd.

  • lam.min the optimal value of lam that gives minimum cross validation error.

  • lam.1se the largest value of lam such that the error is within 1 standard error of the minimum cvm.

Ttrim

a list of cross-validation result with trim*100%, The structure is the same as that for Ftrim.

foldid

the values of foldid.

Author(s)

Zhe Sun and Kun Chen

References

Lin, W., Shi, P., Peng, R. and Li, H. (2014) Variable selection in regression with compositional covariates, https://academic.oup.com/biomet/article/101/4/785/1775476. Biometrika 101 785-979

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
p = 30
n = 50
beta = c(1, -0.8, 0.6, 0, 0, -1.5, -0.5, 1.2)
beta = c(beta, rep(0, times = p - length(beta)))
Comp_data = comp_Model(n = n, p = p, beta = beta, intercept = FALSE)
cvm1 <- cv.compCL(y = Comp_data$y, Z = Comp_data$X.comp,
                  Zc = Comp_data$Zc, intercept = Comp_data$intercept)

plot(cvm1)
coef(cvm1)
## selection by "lam.min" criterion
which(abs(coef(cvm1, s = "lam.min")[1:p]) > 0)
## selection by "lam.1se" criterion
which(abs(coef(cvm1, s= "lam.1se")[1:p]) > 0)

Comp_data2 = comp_Model(n = 30, p = p, beta = Comp_data$beta, intercept = FALSE)
y_hat = predict(cvm1, Znew = Comp_data2$X.comp, Zcnew = Comp_data2$Zc)
plot(Comp_data2$y, y_hat,
     xlab = "Observed response", ylab = "Predicted response")

jiji6454/compReg documentation built on Feb. 5, 2021, 2:20 p.m.