####### FIRST EXAMPLE USING GRM #############
data(Phen.Data) #Phenotype data with repeated observations
data(gen.data) #GenABEL object including IDs and marker genotypes
GWAS1 <- rGLS(y ~ age + sex, genabel.data = gen.data, phenotype.data = Phen.Data)
plot(GWAS1, main="")
summary(GWAS1)
#Summary for variance component estimation without SNP effects
summary(GWAS1@call$hglm)
#The same results can be computed using the preFitModel as follows
fixed = y ~ age + sex
Mod1 <- preFitModel(fixed, random=~1|id, genabel.data = gen.data,
phenotype.data = Phen.Data, corStruc=list( id=list("GRM","Ind") ))
GWAS1b <- rGLS(fixed, genabel.data = gen.data,
phenotype.data = Phen.Data, V = Mod1$V)
plot(GWAS1b, main="Results using the preFitModel function")
####### SECOND EXAMPLE USING CAR #############
# Add a fake nest variable to the data just to run the example
#In this example there are 6 nests and 60 observations per nest
Phen.Data$nest <- rep(1:6, each=60)
#A model including polygenic effects, permanent environmental effects,
#and nest effect as random
Mod2 <- preFitModel(fixed, random=~1|id + 1|nest, genabel.data = gen.data,
phenotype.data = Phen.Data, corStruc=list( id=list("GRM","Ind"), nest=list("Ind")) )
GWAS2 <- rGLS(fixed, genabel.data = gen.data, phenotype.data = Phen.Data, V = Mod2$V)
plot(GWAS2)
#Similar to previous plot because the nest effect variance component is almost 0.
###################
#Construct a fake nighbourhood matrix
D = matrix(0,6,6)
D[1,2] = D[2,1] = 1
D[5,6] = D[6,5] = 1
D[2,4] = D[4,2] = 1
D[3,5] = D[5,3] = 1
D[1,6] = D[6,1] = 1
D[3,4] = D[4,3] = 1
#The matrix shows which pair of nests that can be considered as neighbours
image(Matrix(D), main="Neighbourhood matrix")
Mod3 <- preFitModel(fixed, random=~1|id + 1|nest, genabel.data = gen.data,
phenotype.data = Phen.Data, corStruc=list( id=list("GRM","Ind"),
nest=list("CAR")), Neighbor.Matrix=D )
GWAS2b <- rGLS(fixed, genabel.data = gen.data,
phenotype.data = Phen.Data, V = Mod3$V)
plot(GWAS2b)
Run the code above in your browser using DataLab