# [R] logLIk(lme(...))?

Spencer Graves @pencer@gr@ve@ @end|ng |rom e||ect|vede|en@e@org
Tue Aug 29 18:15:27 CEST 2023

```Hello, all:

I have a dataset with 2 groups.  I want to estimate 2 means and 2
standard deviations.  I naively think I should be able to use lme to do
that, e.g., lme(y~gp, random=y~1|gp, method='ML').  I think I should get
the same answer as from lm(y~1, ...) within each level of group.  I can
get the same means, but I don't know how to extract the within-gp
standard deviations, and the sum of logLik for the latter two does not
equal the former.

TOY EXAMPLE:

library(nlme)

set.seed(1)

lmePblm <- data.frame(y=c(rnorm(5, 1, 2), rnorm(5,3,5)),
gp=factor(rep(1:2, each=5)))

fit22 <- lme(y~gp, lmePblm, random=~1|gp, method='ML')

fitGp1 <- lm(y~1, lmePblm[lmePblm\$gp==1, ])

fitGp2 <- lm(y~1, lmePblm[lmePblm\$gp==2, ])

(ll22 <- logLik(fit22))

(llGp1 <- logLik(fitGp1))

(llGp2 <- logLik(fitGp2))

# Why isn't (ll22 = llGp1+llGp2)?

(ll22 - llGp1-llGp2)

# And secondarily, how can I get the residual standard deviations
# within each gp from fit22?

Thanks,
Spencer Graves

```

More information about the R-help mailing list