[R] Drop1 and weights

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Mar 2 18:56:59 CET 2006


On Thu, 2 Mar 2006, Yan Wong wrote:

> On 2 Mar 2006, at 13:25, Prof Brian Ripley wrote:
>
>> It looks like at some point weighted.residuals() was changed, and
>> broke this.  The models are fitted correctly, but AIC is wrong.
>> However, note that it does work correctly for a glm() fit which
>> gives you a workaround.
>
> Thank you.
>
>> You example is not reproducible, so I was unable to test the
>> workaround nor the correction which will shortly be in R-patched.
>
> Indeed, I realised this, but assumed that the problem could be
> understood even without my dataset. I'll test my data on the patched
> version when it becomes available, and re-post then.

Now I have tried a similar example, I think that the workaround is correct 
but potentially confusing due to another error elsewhere.  Using drop1 on 
a gaussian glm fit with weights gives the correct deviance and the correct 
AICs up to an additive constant.  However, AIC() on such a fit gives the 
wrong AIC, since gaussian()$aic is incorrect (or at least it treats the 
weights as case weights, which is not the interpretation everything else 
uses). (I've changed that in R-devel.)

So in 2.2.1 patched

> library(MASS)
> hills.lm <- lm(time ~ dist + climb, data=hills, weights=1/dist^2)
> drop1(hills.lm)
Single term deletions

Model:
time ~ dist + climb
        Df Sum of Sq    RSS    AIC
<none>              437.64  94.41
dist    1    164.05 601.68 103.55
climb   1      8.66 446.29  93.10
> hills.glm <- glm(time ~ dist + climb, data=hills, weights=1/dist^2)
> drop1(hills.glm)
Single term deletions

Model:
time ~ dist + climb
        Df Deviance    AIC
<none>      437.64  21.30
dist    1   601.68  30.44
climb   1   446.29  19.98

and in R-devel

> hills.glm <- glm(time ~ dist + climb, data=hills, weights=1/dist^2)
> drop1(hills.glm)
Single term deletions

Model:
time ~ dist + climb
        Df Deviance    AIC
<none>      437.64 323.87
dist    1   601.68 333.01
climb   1   446.29 322.55

(These differ only in which additive constants are included, with that in
drop1.glm in 2.2.1 patched being based on an incorrect calculation, 
which for this purpose does not matter.)

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list