简体   繁体   中英

R: Partial least square regression

How to obtain the X and Y matrices being used in each steps for calculating pls components in R?

I know the below command will give k pls components,

library(pls)
plsr(Y ~ ., ncomp=k,   data=as.data.frame(X), scale=TRUE, validation="LOO")

but is there a way to recover k pls components by k times using the following command?

plsr(Y ~ ., ncomp=1,   data=as.data.frame(X), scale=TRUE, validation="LOO")   

According to the updating rules on each step for partial least square based on the score and loading vectors, one can try to generate the pls components one at the time.'trainx' is the matrix containing the covariates and 'trainy' is the matrix of response variables.

require("pls")
require('chemometrics')    

pls_s1<-pls1_nipals(trainx,trainy,a=1,scale=TRUE)
pls_s11<-plsr(trainy~., data=as.data.frame(trainx),ncomp=1,scale=TRUE)
yscores[,kk]<-Yscores(pls_s11)
yloadings[kk]<-Yloadings(pls_s11)
T[,kk]<-pls_s1$T
P[,kk]<-pls_s1$P
X=scale(trainx)-T[,kk]%*%t(P[,kk])
Y=scale(trainy)-nn1$predictions%*%t(yloadings[kk])
pls_rs<-pls1_nipals(X,Y,a=1,scale=FALSE)
pls_rs1<-plsr(Y~., data=as.data.frame(X),ncomp=1,scale=TRUE)
yscores[,kk]<-Yscores(pls_rs1)
yloadings[kk]<-Yloadings(pls_rs1)
T[,kk]<-pls_rs$T
P[,kk]<-pls_rs$P
X=scale(X,scale=FALSE)-T[,kk]%*%t(P[,kk])
Y=scale(Y,scale=FALSE)-nnrs1$predictions%*%t(yloadings[kk])

and it continues in a same fashion...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM