From ripley at stats.ox.ac.uk  Wed Dec  5 22:40:54 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 5 Dec 2007 21:40:54 +0000 (GMT)
Subject: [Rd] confint for coefficients from lm model (PR#10496)
In-Reply-To: <475718EB.2000507@biostat.ku.dk>
References: <20071205174023.1D3B92834158@mail.pubhealth.ku.dk>
	<475718EB.2000507@biostat.ku.dk>
Message-ID: <Pine.LNX.4.64.0712052138010.17391@gannet.stats.ox.ac.uk>

Yes, vcov is doing the right thing, and it does return dimnames.  (Note 
what the help page says about what parameters.)

If you do this via names not numbers it works out.  I have the .lm and 
.default cases working, but need more time to look into others.


On Wed, 5 Dec 2007, Peter Dalgaard wrote:

> Christian.Lajaunie at ensmp.fr wrote:
>> Full_Name: Christian Lajaunie
>> Version: 2.5.1
>> OS: Fedora  fc6
>> Submission from: (NULL) (193.251.63.39)
>>
>>
>> confint() does not use the appropriate variance term when the design
>> matrix contains a zero column (which of course should not happen).
>> Example:
>>
>> A 10x2 matrix with trivial column 1:
>>
>>
>>> junk <- data.frame(x=rep(0,10), u=factor(sample(c("Y", "N"), 10, replace=T)))
>>>
>>
>> The response:
>>
>>> ans <- as.integer(junk$u) + rnorm(10)
>>>
>> and the model:
>>
>>> junk.model <- lm(ans ~ junk$x + junk$u)
>>>
>>
>> 3 coefficients:
>>
>>
>>> coefficients(junk.model)
>>>
>> (Intercept)      junk$x     junk$uY
>>   0.6808802          NA   1.5912192
>>
>> and a 2x2 variance (X^tX)^-1:
>>
>>
>>> vcov(junk.model)
>>>
>>             (Intercept)     junk$uY
>> (Intercept)  0.09905378 -0.09905378
>> junk$uY     -0.09905378  0.19810756
>>
>> result in no confidence interval for the third term:
>>
>>
>>> confint(junk.model)
>>>
>>                   2.5 %   97.5 %
>> (Intercept) -0.04488412 1.406644
>> junk$x               NA       NA
>> junk$uY              NA       NA
>>
>> confint() seems to be looking for diag(vcov(junk.model))[3]
>> instead of diag(vcov(junk.model))[2]
>>
> (You should upgrade, but this is the same in 2.6.1)
>
> Yes. And confint.glm and confint.default are bad too.  The glm method
> must be a different issue, but the other two share the vcov issue.
>
> I'm a bit unsure what is the right fix, though.  Is vcov really
> returning the wrong thing? Should we rather have
>
> > vcov(junk.model)
>           [,1] [,2]       [,3]
> [1,]  0.5525259   NA -0.5525259
> [2,]         NA   NA         NA
> [3,] -0.5525259   NA  0.6906574
>
> which is not massively hard to achieve.
>
> Alternatively we could just skip the aliased coefficients. For GLMs we
> definitely do not want to profile them...
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
>

-- 
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



[Rd] confint for coefficients from lm model (PR#10496)
Prof Brian Ripley