#create a data matrix
t <- seq(0,4*pi,len=50)
X <- matrix(cbind(cos(t),sin(2*t)),length(t),2) %*%
matrix(rnorm(20),2,10)
#add some normal errors
X <- X + .25*rnorm(length(X))
#and mark some data as missing
X[runif(length(X))<.25] <- NA
#compute cross-validation for 1 to 4 basis functions
res.cv <- SVD.smooth.cv(X, n.basis=1:4, niter=100)
#plot cross-validation statistics
par(mfcol=c(2,2),mar=c(4,4,.5,.5))
plot(res.cv$CV.stat$RMSE,type="l",ylab="RMSE")
plot(res.cv$CV.stat$R2,type="l",ylab="R2")
plot(res.cv$CV.stat$BIC,type="l",ylab="BIC")
#plot the BIC for each column, illustrates how many columns that
#improve and how many that worsen when increasing the number of
#basis functions.
pairs(res.cv$BIC.all,panel=function(x,y){points(x,y);abline(0,1)})
Run the code above in your browser using DataLab