Tuning the number of principal components in the generalised linear models.
glmpcr.tune(y, x, M = 10, maxk = 10,
mat = NULL, ncores = 1, graph = TRUE)
A real valued vector.
A matrix with the predictor variables, they have to be continuous.
The number of folds in the cross validation.
The maximum number of principal components to check.
You can specify your own folds by giving a mat, where each column is a fold. Each column contains indices of the observations. You can also leave it NULL and it will create folds.
The number of cores to use. If more than 1, parallel computing will take place. It is advisable to use it if you have many observations and or many variables, otherwise it will slow down th process.
If graph is TRUE a plot of the performance for each fold along the values of \(\alpha\) will appear.
If graph is TRUE a plot of the performance versus the number of principal components will appear. A list including:
A matrix with the mean squared error of prediction (MSPE) for every fold.
A vector with the mean squared error of prediction (MSPE), each value corresponds to a number of principal components.
The number of principal components which minimizes the MSPE.
The lowest value of the MSPE.
The time required by the cross-validation procedure.
Cross validation is performed to select the optimal number of principal components in the GLM. This is used by alfapcr.tune
.
Aguilera A.M., Escabias M. and Valderrama M.J. (2006). Using principal components for estimating logistic regression with high-dimensional multicollinear data. Computational Statistics & Data Analysis 50(8): 1905-1924.
Jolliffe I.T. (2002). Principal Component Analysis.
# NOT RUN {
library(MASS)
x <- as.matrix(fgl[, 2:9])
y <- rpois(214, 10)
glmpcr.tune(y, x, M=10, maxk = 20, mat = NULL, ncores = 1)
# }
Run the code above in your browser using DataLab