constructing random effects design matrices for lassop{MMS} I'd like to use elastic net regression for coefficient estimate and parameter selection on a data set that includes nested structure. I've been experimenting with lassop{MMS} to do so. I'm not a statistician by training, and I'm having a difficult time deciphering how to translate the example provided with the documentation to a real-data context.
    require(lme4)
    require(lmerTest)
    require(MMS)
    data(grouseticks)
    ?grouseticks # sample data w/ multiple grouping levels
    n<-length(grouseticks$TICKS)
#two dummy variables for additional fixed effects that we'll assume will be selected out
    dv1<-rnorm(n, mean = 0, sd = 1)
    dv2<-rnorm(n, mean=3, sd=2)
#sample saturated ME model, two terms for random intercept. I'm trying to write this in lassop syntax. 
sat_lmm<- lmer(TICKS~YEAR+HEIGHT+YEAR+dv1+dv2+HEIGHT:dv1+(1|BROOD)+(1|LOCATION), data=grouseticks, REML=FALSE)
summary(sat_lmm)

How would set up the random effects and grouping matrices to mimic the above model formulation? Feel free to rip into this, I know my grouping and random effects matrices are desperately wrong.
x<-getME(sat_lmm,name = c( "X"))
x<-x[,c("(Intercept)" , "HEIGHT","dv1" ,"HEIGHT:dv1",  "dv2"  , "YEAR96" , "YEAR97")]
#rearrange variables so that first 3 collumns will be frozen in
y<-as.numeric(getME(sat_lmm,name = c( "y")))

# this was my naive guess at handling  random effects
zlx<-cbind( factor(grouseticks$BROOD, labels=seq(length(unique(grouseticks$BROOD)))),
            factor(grouseticks$LOCATION, labels=seq(length(unique(grouseticks$LOCATION)))))

#dummy grouping variable
gx<-rbind(rep(1, length(n)) , 
          rep(1, length(n)))

require(glmnet)
lam<-cv.glmnet(x, y, alpha=0.8, standardize=TRUE)
plot(lam)
#value of lambda that gives minimum cross-validation error
lammin<-lam$lambda.min
lamlse<-lam$lambda.lse
melasso.minlam<-lassop(data=x,
                       Y=y,
                       z=zlx, 
                       mu=lammin,
                       fix=3,
                       D=TRUE,
                       alpha=0.8,
                       showit=F)
#as this stands, it won't run.
print(melasso.minlam)

 A: I think I figured this out. For the above example, to get the model with two random intercepts above, "grp" would be a matrix of the factor levels for the two random intercept terms, and "z" would be a q x n matrix of 1.
sat_lmm <- lmer(TICKS~YEAR+HEIGHT+YEAR+dv1+dv2+HEIGHT:dv1+(1|BROOD) +(1|LOCATION), data=grouseticks, REML=FALSE)
summary(sat_lmm)

x <- getME(sat_lmm, name = c( "X"))
x <- x[,c("(Intercept)" , "HEIGHT","dv1" ,"HEIGHT:dv1",  "dv2"  , "YEAR96" , "YEAR97")]

y <- as.numeric(getME(sat_lmm,name = c( "y")))

# this was my naive guess at handling  random effects
g <- rbind( factor(grouseticks$BROOD),
            factor(grouseticks$LOCATION))

#dummy grouping variable
z <- cbind(rep(1, length(n)) , 
          rep(1, length(n)))    

melasso <- lassop(data=x,
                       Y=y,
                       z=z,
                       grp=g, 
                       mu=0.5,
                       fix=3,
                       D=TRUE,
                       alpha=0.5,
                       showit=F)

Let's say I wanted a random slope model, with a random slope for HEIGHT at BROOD level, to get the following equivalent model in lmer:
sat_lmm <- lmer(TICKS~YEAR+HEIGHT+YEAR+dv1+dv2+HEIGHT:dv1+(1+HEIGHT|BROOD)+(1|LOCATION), data=grouseticks, REML=FALSE)
    summary(sat_lmm)    

 g <- rbind( factor(grouseticks$BROOD),
                    factor(grouseticks$LOCATION))            

  z <- cbind(grouseticks$HEIGHT, 
                  rep(1, length(n)))

   melasso <- lassop(data=x,
                           Y=y,
                           z=z,
                           grp=g, 
                           mu=0.5,
                           fix=3,
                           D=TRUE,
                           alpha=0.5,
                           showit=F)

