[R] another question about lmer, this time involving coef()

Andrew Gelman gelman at stat.columbia.edu
Tue Jan 10 16:50:46 CET 2006


I'm having another problem with lmer(), this time something simpler (I 
think) involving the coef() function for a model with varying 
coefficients.  Here's the R code.  It's a simple model with 2 
observations per group and 10 groups:

# set up the predictors

n.groups <- 10
n.reps <- 2
n <- n.groups*n.reps
group.id <- rep (1:n.groups, each=n.reps)

# simulate the varying parameters

a.group <- rnorm (n.groups, 1, 2)

# simulate the data and print to check that i did it right

y <- rnorm (n, a.group[group.id], 1)
print (cbind (y, group.id))

# fit and summarize the model

fit.1 <- lmer (y ~ 1 + (1 | group.id))
summary (fit.1)

# coef() doesn't work!
coef (fit.1)

--

The following error message came:

Error in "rownames<-"(x, value) : attempt to set rownames on object with 
no dimensions

--

So I went into the code and the coefficient info is there.  There just 
seems to be some "bookkeeping problem" within coef().  I could kludge 
something but I'd rather work within the existing structures and use 
coef() which seems intended for this purpose.

OK, then I tried adding a predictor and it worked fine:

x <- rnorm (n)
fit.2 <- lmer (y ~ 1 + x + (1 | group.id))
summary (fit.2)
coef (fit.2)

--

Am I doing something stupid here or is it actually a (minor) bug?

Thanks
Andrew


-- 
Andrew Gelman
Professor, Department of Statistics
Professor, Department of Political Science
gelman at stat.columbia.edu
www.stat.columbia.edu/~gelman

Tues, Wed, Thurs:  
  Social Work Bldg (Amsterdam Ave at 122 St), Room 1016
  212-851-2142
Mon, Fri:
  International Affairs Bldg (Amsterdam Ave at 118 St), Room 711
  212-854-7075

Mailing address:
  1255 Amsterdam Ave, Room 1016
  Columbia University
  New York, NY 10027-5904
  212-851-2142
  (fax) 212-851-2164




More information about the R-help mailing list