fitPCR {gamlss.foreach} | R Documentation |
Function to fit simple Principal Component Regression.
Description
This function is a univariate (i.e. one response) version of a principal component regression. It is based on the function svdpc.fit()
of package pls but it has been generalised to take prior weights. It gets a (single) response variable y
(n x 1) and a matrix of explanatory variables of dimensions n x p and fits different principal component regressions up to principal component M. Note that M can be less or equal to p (if n > p
) or less or equal to n if n <p
, that is, when there they are less observations than variables.
The function is used by the GAMLSS additive term function pcr()
to fit a principal component regression model within gamlss()
.
Usage
fitPCR(x = NULL, y = NULL, weights = rep(1, n),
M = NULL, df = NULL, supervised = FALSE,
k = 2, r = 0.2, plot = TRUE)
Arguments
x |
a matrix of explanatory variables |
y |
the response variable |
weights |
prior weights |
M |
if set specifies the maximum number of components to be considered |
df |
if set specifies the number of components |
supervised |
whether supervised PCR should be used or not, |
k |
the penalty of GAIC |
r |
a correlation value (between zero and one) used smoothing parameter when |
plot |
Whether to plot the coefficient path |
Details
More details here
Value
It returns a object PCR
which can be used with methods print()
,
summary()
, plot()
, fitted()
and coef()
. The object has elements:
coefficients |
The beta coefficients for 1 to M principal components |
scores |
the n x M dimensional matrix T o=f scores |
loadings |
the p x M dimensional matrix P of loadings |
gamma |
the first M principal component coefficients |
se.gamma |
the standard errors of the M principal component coefficients |
center |
the location parameters used to scale the x's |
scale |
the scale parameters used to scale the x's |
fitted.values |
matrix of n x M dimensions |
Xvar |
sum of squares of the scores i.e. diag(T'T) |
gaic |
The GAIC values |
pc |
number of PC i.e. which value of GAIC has the minimum |
k |
which penalty for GAIC |
M |
the maximum of PC tried |
sigma |
The estimated sigma from the M fitted components |
residuals |
The n x M matrix of the residuals |
call |
the function call |
Author(s)
Mikis Stasinopoulos, Robert Rigby and Fernanda De Bastiani.
References
Bjorn-Helge Mevik, Ron Wehrens and Kristian Hovde Liland (2019). pls: Partial Least Squares and Principal Component Regression. R package version 2.7-2. https://CRAN.R-project.org/package=pls
Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape, (with discussion), Appl. Statist., 54, part 3, pp 507-554.
Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019) Distributions for modeling location, scale, and shape: Using GAMLSS in R, Chapman and Hall/CRC, doi:10.1201/9780429298547. An older version can be found in https://www.gamlss.com/.
Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, doi:10.18637/jss.v023.i07.
Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017) Flexible Regression and Smoothing: Using GAMLSS in R, Chapman and Hall/CRC. doi:10.1201/b21973
Stasinopoulos, M. D., Rigby, R. A., and De Bastiani F., (2018) GAMLSS: a distributional regression approach, Statistical Modelling, Vol. 18, pp, 248-273, SAGE Publications Sage India: New Delhi, India. doi:10.1177/1471082X18759144
Stasinopoulos, M. D., Rigby, R. A., Georgikopoulos N., and De Bastiani F., (2021) Principal component regression in GAMLSS applied to Greek-German government bond yield spreads, Statistical Modelling doi:10.1177/1471082X211022980.
(see also https://www.gamlss.com/).
See Also
Examples
library(glmnet)
data(QuickStartExample)
attach(QuickStartExample)
hist(y, main="(a)")
if (is.null(rownames(x))) colnames(x) <- paste0("X",
seq(1:dim(x)[2]))
############################################################
# fitPCR
############################################################
# fitting
registerDoParallel(cores = 2)
MM<- fitPCR(x,y, k=log(100))
stopImplicitCluster()
points(MM$coef[,16]~rep(16,20))
names(MM)
MM
#----------------------------------------------------------
# plotting
plot(MM)
plot(MM, "gaic")
#----------------------------------------------------------
print(MM)
#----------------------------------------------------------
coef(MM) # the gammas
coef(MM, param="beta") # the betas
coef(MM, param="beta", pc=1) # at position 1
#----------------------------------------------------------
# plotting y and and fitted balues at different points
plot(y)
points(fitted(MM, pc=3), col=2)
points(fitted(MM, pc=20), col=3)
#----------------------------------------------------------
# variance covariance
vcov(MM, type="se", pc=1)
vcov(MM, type="se", pc=2)
vcov(MM, type="se", pc=20)
# library(corrplot)
# corrplot(vcov(MM, type="cor", pc=10))
# corrplot(vcov(MM, type="cor", pc=20))
#----------------------------------------------------------
summary(MM)
summary(MM, param="beta", pc=15)
summary(MM, param ="beta", pc=3)
summary(MM, param ="beta") # at default
#----------------------------------------------------------
predict(MM, newdata= x[1:5,])
fitted(MM)[1:5]