if (FALSE) {
set.seed(3222)
# lapprox both for quantitative and binary phenotypes
# input:
# Z: covariate matrix including the intercept
# X: matrix for joint GxE interaction effects (marginal effect must be represented by the intercept)
# y: phenotype vector (0/1 code needed for binary phenotype)
n = 400 # sample size
q = 2 # number of covariates
Z = matrix(rnorm(n*q),n,q) # covariates, the first component is used as the environment variable
mu = -1.5 + Z[,1]
y = mu + rnorm(n) # quantitative phenotype
Y = rbinom(n,size=1,prob=1/(1+exp(-mu*5))) # binary phenotype
#Example usage for quantitative trait
# lapprox for joint GxE interaction test (correctly specified)
# y ~ b0*1 + b1*Z[,1] + b2*Z[,2] + b3*G*1 + b4*G*Z[,1]
# H0: b3 = b4 = 0 is tested
lapprox(Z=cbind(1,Z),X=cbind(1,Z[,1]),y=y)
# [1] 1.012104
# lapprox for joint GxE interaction test (misspecified)
# y ~ b0*1 + b1*Z[,1]*Z[,1] + b2*Z[,2]*Z[,2] + b3*G*1 + b4*G*Z[,1]*Z[,1]
# H0: b3 = b4 = 0 is tested
lapprox(Z=cbind(1,Z*Z),X=cbind(1,Z[,1]*Z[,1]),y=y)
# [1] 1.969929
# lapprox for marginal association test
# y ~ b0*1 + b1*Z[,1] + b2*Z[,2] + b3*G*1
# H0: b3 = 0 is tested is tested
lapprox(Z=cbind(1,Z),X=matrix(1,nrow(Z),1),y=y)
# [1] 1.010101
#Example usage for binary trait
# lapprox for joint GxE interaction test (correctly specified)
# y ~ b0*1 + b1*Z[,1] + b2*Z[,2] + b3*G*1 + b4*G*Z[,1]
# H0: b3 = b4 = 0 is testedd
lapprox(Z=cbind(1,Z),X=cbind(1,Z[,1]),y=Y)
# [1] 0.9388417
# lapprox for joint GxE interaction test (misspecified)
# y ~ b0*1 + b1*Z[,1]*Z[,1] + b2*Z[,2]*Z[,2] + b3*G*1 + b4*G*Z[,1]*Z[,1]
# H0: b3 = b4 = 0 is tested
lapprox(Z=cbind(1,Z*Z),X=cbind(1,Z[,1]*Z[,1]),y=Y)
# [1] 1.150531
# lapprox for marginal association test
# y ~ b0*1 + b1*Z[,1] + b2*Z[,2] + b3*G*1
# H0: b3 = 0 is tested
lapprox(Z=cbind(1,Z),X=matrix(1,nrow(Z),1),y=Y)
# [1] 1.078894
}
Run the code above in your browser using DataLab