### load dual.spls library
library(dual.spls)
### constructing the simulated example
oldpar <- par(no.readonly = TRUE)
n <- 100
p <- 50
nondes <- 20
sigmaondes <- 0.5
data=d.spls.simulate(n=n,p=p,nondes=nondes,sigmaondes=sigmaondes)
X <- data$X
y <- data$y
#fitting the model
mod.dspls <- d.spls.pls(X=X,y=y,ncp=10,verbose=TRUE)
str(mod.dspls)
### plotting the observed values VS predicted values for 6 components
plot(y,mod.dspls$fitted.values[,6], xlab="Observed values", ylab="Predicted values",
main="Observed VS Predicted for 6 components")
points(-1000:1000,-1000:1000,type='l')
### plotting the regression coefficients
par(mfrow=c(3,1))
i=6
plot(1:dim(X)[2],mod.dspls$Bhat[,i],type='l',
main=paste(" PLS , ncp =", i),
ylab='',xlab='' )
par(oldpar)
Run the code above in your browser using DataLab