[R-sig-ME] Weights

Markus Jäntti markus.jantti at iki.fi
Thu Jun 28 13:31:59 CEST 2012


On 06/28/2012 12:36 PM, Ben Bolker wrote:
> Francois Maurice <maurice.francois at ...> writes:
>
>>
>> Hi,
>>
>> I have a variable that gives weights to each case.
>> Is there a way with lme() to specify weights ? I tried the
>> "weights" argument but I think it is not the write place.
>> The argument ask me for a varFunc object, which I
>> don't know what it is!!
>>
>> I know that the "weights" argument works well with lmer()
>> but lmer() doesn't give the p-values for fixed
>> effects, or at least I don't know how to get it from lmer().
>
>    Maybe not exactly what you want, but if you know the variances
> corresponding to the weights you want to impose (say they are a variable
> 'estvars' in your data frame) I think you could
> use
>
> lme(..., weights=varFixed(~estvars), ...)
>
>
> in particular, to use wts 'wts' you probably want to use
>
> lme(..., weights=varFixed(~I(1/wts)), ...)
>
>    To make sure that I'm not crazy I would suggest that you try
> some simple cases using this approach with lme and lmer, using
> explicit weights in the lmer case, and see if you get the same
> answers ...
>
>    (If anyone has a better idea or knows this to be wrong,
> please speak up !)

Hi -- this seems to work (since the fixed variance function is the default, it 
can be omitted in the weights= argument to lme). In lmer, the weight that has 
the mean standardized to one produces different results from the one that does 
not, but in lme they both produce the same results. It might be useful to 
explore that a little further.

<code>

## example data
td <- data.frame(y=1:100,
                  g=factor(rep(1:20, 5)),
                  f=factor(rep(1:5, 20)),
                  wgt=100:1)
td$relwgt <- td$wgt/mean(td$wgt)
## replicate the data by the number of weights
ltd <- td[rep(rownames(td), td$wgt),]

library(nlme)
summary(lme(y ~ 1, random= ~1|g, data=td))
summary(lme(y ~ 1, random= ~1|g, data=td, weights=~1/wgt))
summary(lme(y ~ 1, random= ~1|g, data=td, weights=~1/relwgt))
## without weights on the replicated data
summary(lme(y ~ 1, random= ~1|g, data=ltd)
detach(package:nlme)
library(lme4)
summary(lmer(y ~ 1 + (1|g), data=td))
summary(lmer(y ~ 1 + (1|g), data=td, weights=wgt))
summary(lmer(y ~ 1 + (1|g), data=td, weights=relwgt))
## without weights on the replicated data
summary(lmer(y ~ 1 + (1|g), data=ltd))
detach(package:lme4)


</code>

HTH,

Markus



-- 
Markus Jantti
Professor of Economics
Swedish Institute for Social Research
Stockholm University



More information about the R-sig-mixed-models mailing list