require(fence)
#### Example 1 #####
data(iris)
full = Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + (1|Species)
test_af = fence.lmer(full, iris)
plot(test_af)
test_af$sel_model
#### Example 2 #####
r =1234; set.seed(r)
p=8; n=150; rho = 0.6
id = rep(1:50,each=3)
R = diag(p)
for(i in 1:p){
for(j in 1:p){
R[i,j] = rho^(abs(i-j))
}
}
R = 1*R
x=mvrnorm(n, rep(0, p), R) # all x's are time-varying dependence #
colnames(x)=paste('x',1:p, sep='')
tbetas = c(0,0.5,1,0,0.5,1,0,0.5) # non-zero beta 2,3,5,6,8
epsilon = rnorm(150)
y = x%*%tbetas + epsilon
colnames(y) = 'y'
data = data.frame(cbind(x,y,id))
full = y ~ x1+x2+x3+x4+x5+x6+x7+x8+(1|id)
#X = paste('x',1:p, sep='', collapse='+')
#full = as.formula(paste('y~',X,'+(1|id)', sep="")) #same as previous one
fence_obj = fence.lmer(full,data) # it takes 3-5 min #
plot(fence_obj)
fence_obj$sel_model
Run the code above in your browser using DataLab