## Not run:
# ########################################################################
# ##Example 1:
# ########################################################################
#
# rm(list=ls())
# setwd(tempdir())
# library(BGLR)
# data(wheat) #Loads the wheat dataset
#
# y=wheat.Y[,1]
# ### Creates a testing set with 100 observations
# whichNa<-sample(1:length(y),size=100,replace=FALSE)
# yNa<-y
# yNa[whichNa]<-NA
#
# ### Runs the Gibbs sampler
# fm<-BLR(y=yNa,XL=wheat.X,GF=list(ID=1:nrow(wheat.A),A=wheat.A),
# prior=list(varE=list(df=3,S=0.25),
# varU=list(df=3,S=0.63),
# lambda=list(shape=0.52,rate=1e-4,
# type='random',value=30)),
# nIter=5500,burnIn=500,thin=1)
#
# MSE.tst<-mean((fm$yHat[whichNa]-y[whichNa])^2)
# MSE.tst
# MSE.trn<-mean((fm$yHat[-whichNa]-y[-whichNa])^2)
# MSE.trn
# COR.tst<-cor(fm$yHat[whichNa],y[whichNa])
# COR.tst
# COR.trn<-cor(fm$yHat[-whichNa],y[-whichNa])
# COR.trn
#
# plot(fm$yHat~y,xlab="Phenotype",
# ylab="Pred. Gen. Value" ,cex=.8)
# points(x=y[whichNa],y=fm$yHat[whichNa],col=2,cex=.8,pch=19)
#
# x11()
# plot(scan('varE.dat'),type="o",
# ylab=expression(paste(sigma[epsilon]^2)))
#
# ########################################################################
# #Example 2: Ten fold, Cross validation, environment 1,
# ########################################################################
#
# rm(list=ls())
# setwd(tempdir())
# library(BGLR)
# data(wheat) #Loads the wheat dataset
# nIter<-1500 #For real data sets more samples are needed
# burnIn<-500
# thin<-10
# folds<-10
# y<-wheat.Y[,1]
# A<-wheat.A
#
# priorBL<-list(
# varE=list(df=3,S=2.5),
# varU=list(df=3,S=0.63),
# lambda = list(shape=0.52,rate=1e-5,value=20,type='random')
# )
#
# set.seed(123) #Set seed for the random number generator
# sets<-rep(1:10,60)[-1]
# sets<-sets[order(runif(nrow(A)))]
# COR.CV<-rep(NA,times=(folds+1))
# names(COR.CV)<-c(paste('fold=',1:folds,sep=''),'Pooled')
# w<-rep(1/nrow(A),folds) ## weights for pooled correlations and MSE
# yHatCV<-numeric()
#
# for(fold in 1:folds)
# {
# yNa<-y
# whichNa<-which(sets==fold)
# yNa[whichNa]<-NA
# prefix<-paste('PM_BL','_fold_',fold,'_',sep='')
# fm<-BLR(y=yNa,XL=wheat.X,GF=list(ID=(1:nrow(wheat.A)),A=wheat.A),prior=priorBL,
# nIter=nIter,burnIn=burnIn,thin=thin)
# yHatCV[whichNa]<-fm$yHat[fm$whichNa]
# w[fold]<-w[fold]*length(fm$whichNa)
# COR.CV[fold]<-cor(fm$yHat[fm$whichNa],y[whichNa])
# }
#
# COR.CV[11]<-mean(COR.CV[1:10])
# COR.CV
#
# ########################################################################
# ## End(Not run)
Run the code above in your browser using DataLab