demo/SSI_CV.R

setwd(tempdir())
library(SFSI)
data(wheatHTP)
X = scale(X[1:300,])        # Subset and scale markers
G = tcrossprod(X)/ncol(X)   # Genomic relationship matrix
y = scale(Y[1:300,"YLD"])   # Subset response variable

# Predicting a testing set using training set
tst = sample(seq_along(y),ceiling(0.3*length(y)))
trn = (seq_along(y))[-tst]

# Obtain lambda from cross-validation (in traning set)
fm1 = SSI_CV(y,K=G,trn.CV=trn,nFolds=5,nCV=1)
lambda = summary(fm1)$optCOR["mean","lambda"]

# Fit the index with the obtained lambda
fm2 = SSI(y,K=G,h2=NULL,trn=trn,tst=tst,lambda=lambda)
summary(fm2)$accuracy        # Testing set accuracy

# Compare the accuracy with that of the non-sparse index
fm3 = SSI(y,K=G,h2=NULL,trn=trn,tst=tst,lambda=0)
summary(fm3)$accuracy
MarcooLopez/SFSI_data documentation built on April 15, 2021, 10:53 a.m.