data(ozone2)
ind = which(apply(is.na(ozone2$y),2,sum)==0)
X = ozone2$y[,ind]
n = nrow(X)
p = ncol(X)
#Generalizing Operators - Spatio-Temporal Smoothers
R = Exp.cov(ozone2$lon.lat[ind,],theta=5)
er = eigen(R,only.values=TRUE);
R = R/max(er$values)
Q = Exp.cov(c(1:n),c(1:n),theta=3)
eq = eigen(Q,only.values=TRUE)
Q = Q/max(eq$values)
#Sparse GPCA
fit = sgpca(X,Q,R,K=1,lamu=0,lamvs=c(.5,1))
fit$prop.var #proportion of variance explained
fit$optlams #optimal regularization param chosen by BIC
fit$bics #BIC values for each lambda
#Sparse Non-negative GPCA
fit = sgpca(X,Q,R,K=1,lamu=0,lamvs=1,posv=TRUE)
#Two-way Sparse GPCA
fit = sgpca(X,Q,R,K=1,lamu=1,lamvs=1)
#Two-way Sparse Non-negative GPCA
fit = sgpca(X,Q,R,K=1,lamu=1,lamvs=1,posu=TRUE,posv=TRUE)
#Return full regularization paths for inputted lambda values
fit = sgpca(X,Q,R,K=1,lamu=0,lamvs=c(.1,.5,1),full.path=TRUE)
Run the code above in your browser using DataLab