[R-sig-ME] getting between groups variance when using (1|x:y)in the formula
Hans Ekbrand
hans at sociologi.cjb.net
Mon Jun 4 23:30:34 CEST 2012
On 2012-06-01 13:53, Ben Bolker wrote:
> Hans Ekbrand<hans at ...> writes:
>
>
>> On 2012-05-31 17:35, Hans Ekbrand wrote:
>>
>>> Let's say I have a formula like this
>>>
>>> my.fit<- glmer(w ~ 1 + y + (1|x) + (1|x:y) + z)
>>>
>>> Then the summary() output gives information about variance and std.dev
>>> for the random term x:y
>>>
>>> and ranef(my.fit, postVar = TRUE) gives estimates and standard
>>> deviations for x and each value of x:y.
>>>
>>> Is there a way to get a single measure of the variance of y within x?
>>>
>> I meant to say "a singe measure of the variance of y within x, for each
>> level of y".
>>
>>
> I don't think that's something that glmer() estimates -- it
> assumes that the variance is equal for every y-within-x combination.
> I suppose you could just compute the variance of each group of
> conditional modes, i.e. if xyests are your x:y conditional modes
> and xests are your x conditional modes then you could
> tapply(xyests,list(xests),var) ... someone may suggest something
> better ...
>
Thanks for your suggestion, Ben. I ended up doing like this.:
my.df <- ranef(my.fit, postVar = TRUE, whichel = "x:y")$x
my.var <- as.numeric(attr(my.df, "postVar"))
foo <- strsplit(rownames(my.df), ":")
the.names <- unique(sapply(1:nrow(my.df), function(x) {foo[[x]][2] }))
the.sd <- sapply(the.names, function(x) {
these <- grep(paste(":", x, "$", sep = ""), rownames(my.df))
sqrt(sum(my.var[these])/length(these))
})
I am not really sure about the meaningfulness of this measure, but it
varied over the levels of y in the way I expected.
More information about the R-sig-mixed-models
mailing list