cglsr | R Documentation |
Conjugate gradient algorithm (CG) for the normal equations (CGLS algorithm 7.4.1, Bjorck 1996, p.289)
The code for re-orthogonalization (Hansen 1998) and filter factors (Vogel 1987, Hansen 1998) computations is a transcription (with few adaptations) of the matlab function 'cgls' (Saunders et al. https://web.stanford.edu/group/SOL/software/cgls/; Hansen 2008).
The filter factors can be used to compute the model complexity of CGLSR and PLSR models (see dfplsr_cg
).
Data X
and y
are internally centered.
cglsr(X, y, nlv, reorth = TRUE, filt = FALSE)
## S3 method for class 'Cglsr'
coef(object, ..., nlv = NULL)
## S3 method for class 'Cglsr'
predict(object, X, ..., nlv = NULL)
X |
For main function: Training X-data ( |
y |
Univariate training Y-data ( |
nlv |
The number(s) of CG iterations. |
reorth |
Logical. If |
filt |
Logical. If |
object |
A fitted model, output of a call to the main functions. |
... |
Optional arguments. Not used. |
See the examples.
Björck, A., 1996. Numerical Methods for Least Squares Problems, Other Titles in Applied Mathematics. Society for Industrial and Applied Mathematics. https://doi.org/10.1137/1.9781611971484
Hansen, P.C., 1998. Rank-Deficient and Discrete Ill-Posed Problems, Mathematical Modeling and Computation. Society for Industrial and Applied Mathematics. https://doi.org/10.1137/1.9780898719697
Hansen, P.C., 2008. Regularization Tools version 4.0 for Matlab 7.3. Numer Algor 46, 189â194. https://doi.org/10.1007/s11075-007-9136-9
Manne R. Analysis of two partial-least-squares algorithms for multivariate calibration. Chemometrics Intell. Lab. Syst. 1987; 2: 187â197.
Phatak A, De Hoog F. Exploiting the connection between PLS, Lanczos methods and conjugate gradients: alternative proofs of some properties of PLS. J. Chemometrics 2002; 16: 361â367.
Vogel, C. R., "Solving ill-conditioned linear systems using the conjugate gradient method", Report, Dept. of Mathematical Sciences, Montana State University, 1987.
z <- ozone$X
u <- which(!is.na(rowSums(z))) ## Removing rows with NAs
X <- z[u, -4]
y <- z[u, 4]
dim(X)
headm(X)
Xtest <- X[1:2, ]
ytest <- y[1:2]
nlv <- 10
fm <- cglsr(X, y, nlv = nlv)
coef(fm)
coef(fm, nlv = 1)
predict(fm, Xtest)
predict(fm, Xtest, nlv = 1:3)
pred <- predict(fm, Xtest)$pred
msep(pred, ytest)
cglsr(X, y, nlv = 5, filt = TRUE)$F
## Comparison with PLSR algorithms
nlv <- 12
fm1 <- plskern(X, y, nlv = nlv)
fm2 <- plsnipals(X, y, nlv = nlv)
cbind(coef(fm1)$B, coef(fm2)$B,
cglsr(X, y, nlv = nlv, reorth = TRUE)$B[, nlv],
cglsr(X, y, nlv = nlv, reorth = FALSE)$B[, nlv])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.