I am yet to see any response from the developers/maintainers of
lme4 with respect to my posting from 25
Feburary on the R-sig-mixed-models Digest, Vol 74, Issue 40
5. Re: lmer residual variance estimate with prior weights (lmer
[snip]
Sorry this slipped through the cracks. We will take a look;
if you can (re)post the query at
https://github.com/lme4/lme4/issues?state=open
(the new site for bug/feature requests) that would help us out ...
PS I looked back at your previous post, and you don't provide a
reproducible example. If you can either provide your data or (very
much preferably) a minimal reproducible example
<http://tinyurl.com/reproducible-000>, that will save us time and
greatly increase the probability that we will be able to tackle this
in the near future ...
cheers
Ben Bolker
I have set up this small simulation to compare lmer{lme4} with lme{nlme}
(with results compared also to asreml{asreml})
Note that lme and asreml give identical results for SEs of regression
parameters while lmer SEs are an order of magnitude smaller.
I also give an asreml model that teases out the lev1 and lev2 variance
components given a known lev1 variance.
## sample size weighted LMM
#
#
library(nlme)
library(lme4)
#generate some lognormal random effects (i.e. level-2)
Nsamp <- rep(0,50)
REs <- rnorm(n=50, mean=0, sd=0.3)
#generate some within residual errors (i.e. level-1)
RES <- NULL
Xf <- NULL
X <- NULL
for (i in 1:50) {
Nsamp[i] <- rpois(n=1,lambda=20)
RES <- c(RES,rep(REs[i],each=Nsamp[i]))
Xi <- as.integer(i/10)
X <- c(X,rep(Xi,each=Nsamp[i]))
Xf <- c(Xf,rep(i,each=Nsamp[i]))}
RES <- RES + rnorm(n=length(RES), mean=0, sd=0.1)
RE.Xf <- as.factor(Xf)
#set up regression model
Y <- 1 + 5*X + RES
# calculate means and fit weighted LMM with random lack-of-fit term
Ym <- as.vector(tapply(X=Y, INDEX=RE.Xf, FUN=mean))
Xm <- as.vector(tapply(X=X, INDEX=RE.Xf, FUN=mean))
Xm.f <- as.factor(Xm)
wts <- 1/Nsamp
nlme.av <- lme(fixed=Ym ~ Xm, random=~1|Xm.f, weights=varFixed(~wts))
summary(nlme.av)
lmer.av <- lmer(formula=Ym ~ Xm + (1|Xm.f), weights=Nsamp)
summary(lmer.av)
## sample size weighted LMM
#
#
library(nlme)
library(lme4)
#generate some lognormal random effects (i.e. level-2)
Nsamp <- rep(0,50)
REs <- rnorm(n=50, mean=0, sd=0.3)
#generate some within residual errors (i.e. level-1)
RES <- NULL
Xf <- NULL
X <- NULL
for (i in 1:50) {
+ Nsamp[i] <- rpois(n=1,lambda=20)
+ RES <- c(RES,rep(REs[i],each=Nsamp[i]))
+ Xi <- as.integer(i/10)
+ X <- c(X,rep(Xi,each=Nsamp[i]))
+ Xf <- c(Xf,rep(i,each=Nsamp[i]))}
RES <- RES + rnorm(n=length(RES), mean=0, sd=0.1)
RE.Xf <- as.factor(Xf)
Y <- 1 + 5*X + RES
# calculate means and fit sample size weighted LMM with random lack of
Dr Steven G. Candy
Senior Applied Statistician
Wildlife Conservation and Fisheries
Australian Antarctic Division
203 Channel Hwy, Kingston, Tasmania, 7050, Australia
ph: (+61) 3 62 323135