[R] yet another lmer question
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Sat Jan 28 20:52:25 CET 2006
Andrew Gelman <gelman at stat.columbia.edu> writes:
> I've been trying to keep track with lmer, and now I have a couple of
> questions with the latest version of Matrix (0.995-4). I fit 2 very
> similar models, and the results are severely rounded in one case and
> rounded not at all in the other.
>
> > y <- 1:10
> > group <- rep (c(1,2), c(5,5))
> > M1 <- lmer (y ~ 1 + (1 | group))
> > coef(M1)
> $group
> (Intercept)
> 1 3.1
> 2 7.9
>
> > x <- rep (c(1,2), c(3,7))
> > M2 <- lmer (y ~ 1 + x + (1 + x | group))
> > coef(M2)
> $group
> (Intercept) x
> 1 -0.755102 2.755102
> 2 0.616483 3.640738
>
> I can't figure out why everything is rounded for the first model but not
> for the second. Also, mcmcsamp() works for M1 but not for M2:
Well,
> dput(coef(M1)[[1]])
structure(list("(Intercept)" = c(3.10000000006436, 7.89999999993564
)), .Names = "(Intercept)", row.names = c("1", "2"), class =
"data.frame")
> c(3.10000000006436, 7.89999999993564)
[1] 3.1 7.9
I.e., if you pass fake data, sometimes you get *results* that can be
rounded to a few significant digits. R tries to get rid of trailing
zeros in its print routines.
> > mcmcsamp(M1)
> (Intercept) log(sigma^2) log(grop.(In))
> [1,] 9.099073 0.5711817 3.246981
> attr(,"mcpar")
> [1] 1 1 1
> attr(,"class")
> [1] "mcmc"
>
> > mcmcsamp(M2)
> Error: inconsistent degrees of freedom and dimension
> Error in t(.Call("mer_MCMCsamp", object, saveb, n, trans, PACKAGE =
> "Matrix")) :
> unable to find the argument 'x' in selecting a method for
> function 't'
Looks like a buglet, but
> x
[1] 1 1 1 2 2 2 2 2 2 2
> group
[1] 1 1 1 1 1 2 2 2 2 2
Effects of x can (seemingly?) only be detected within group 1. I.e.
the random variation of the effect of x is based on a sample of size
1, so I'm actually more surprised that you get a fit at all...
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list