Learn R Programming

spcr (version 2.1.1)

cv.spcrglm: Cross-validation for spcr-glm

Description

This function performs cross-validation for SPCR-glm. cv.spcrglm enables us to determine two regularization parameters \(\lambda_\beta\) and \(\lambda_\gamma\) objectively.

Usage

cv.spcrglm(x, y, k, family=c("binomial","poisson","multinomial"), 
	w=0.1, xi=0.01, nfolds=5, adaptive=FALSE, q=1, center=TRUE, 
	scale=FALSE, lambda.B.length=10, lambda.gamma.length=10,
	lambda.B=NULL, lambda.gamma=NULL)

Value

lambda.gamma.seq

The values of lambda.gamma in the fit.

lambda.B.seq

The values of lambda.B in the fit.

CV.mat

Matrix of the mean values of cross-validation. The row shows a sequence of lambda.gamma. The column shows a sequence of lambda.B.

lambda.gamma.cv

The value of lambda.gamma selected by cross-validation.

lambda.B.cv

The value of lambda.B selected by cross-validation.

cvm

The minimum of the mean cross-validated error.

Arguments

x

A data matrix.

y

A response vector.

k

The number of principal components.

family

Response type.

w

Weight parameter with \(w \ge 0\). The default is 0.1.

xi

The elastic net mixing parameter with \(0\le \alpha \le 1\). The default is 0.01.

nfolds

The number of folds. The default is 5.

adaptive

If "TRUE", the adaptive SPCR-glm (aSPCR-glm) is used.

q

The tuning parameter that controls weights in aSPCR-glm. The default is 1.

center

If "TRUE", the data matrix is centered.

scale

If "TRUE", the data matrix is scaled.

lambda.B.length

The number of candidates for the parameter \(\lambda_\beta\). The default is 10.

lambda.gamma.length

The number of candidates for the parameter \(\lambda_\gamma\). The default is 10.

lambda.B

Optional user-supplied candidates for the parameter \(\lambda_\beta\). The default is NULL.

lambda.gamma

Optional user-supplied candidates for the parameter \(\lambda_\gamma\). The default is NULL.

Author

Shuichi Kawano
skawano@ai.lab.uec.ac.jp

References

Kawano, S., Fujisawa, H., Takada, T. and Shiroishi, T. (2018). Sparse principal component regression for generalized linear models. Compuational Statistics & Data Analysis, 124, 180--196.

See Also

spcrglm

Examples

Run this code
# binomial
n <- 100
np <- 3
nu0 <- c(-1, 1)
set.seed(4)
x <- matrix( rnorm(np*n), n, np )
y <- rbinom(n,1,1-1/(1+exp(  (nu0[1]*x[ ,1] + nu0[2]*x[ ,2]  ))))
cv.spcrglm.fit <- cv.spcrglm(x=x, y=y, k=1, family="binomial")
cv.spcrglm.fit

# Poisson
set.seed(5)
y <- rpois(n, 1)
cv.spcrglm.fit <- cv.spcrglm(x=x, y=y, k=1, family="poisson")
cv.spcrglm.fit

# multinomial
set.seed(4)
y <- sample(1:4, n, replace=TRUE)
cv.spcrglm.fit <- cv.spcrglm(x=x, y=y, k=1, family="multinomial")
cv.spcrglm.fit

Run the code above in your browser using DataLab