From bcarvalh at jhsph.edu  Mon Nov 13 05:37:47 2006
From: bcarvalh at jhsph.edu (Benilton Carvalho)
Date: Sun, 12 Nov 2006 23:37:47 -0500
Subject: [Rd] inconsistency or bug in coef() (PR#9358)
In-Reply-To: <20061113042826.AED5AA1AA@slim.kubism.ku.dk>
References: <20061113042826.AED5AA1AA@slim.kubism.ku.dk>
Message-ID: <ADBEE795-50E8-42FC-AAFD-2FD419FE84A4@jhsph.edu>

it doesn't appear to be a bug for me, given that one of your  
coefficients is NA due to linear dependencies on your design matrix.

i prefer to think of it as a feature :-) (show only the coefficients  
for the variables that do not show linear dependencies).

x=1:5
y=c(1:3, 7, 6)
fit=lm(y~x)
coef(fit)
coef(summary(fit))

b

On Nov 12, 2006, at 11:28 PM, rmh at temple.edu wrote:

> tmp <- data.frame(x=c(1,1),
>                   y=c(1,2))
>
> tmp.lm <- lm(y ~ x, data=tmp)
> summary(tmp.lm)
>
> coef(summary(tmp.lm))
>
> ## I consider this to be a bug.  Since summary(tmp.lm) gives
> ## two rows for the coefficients, I believe the coef() function
> ## should also give two rows.
>
>
>
>> summary(tmp.lm)
>
> Call:
> lm(formula = y ~ x, data = tmp)
>
> Residuals:
>    1    2
> -0.5  0.5
>
> Coefficients: (1 not defined because of singularities)
>             Estimate Std. Error t value Pr(>|t|)
> (Intercept)      1.5        0.5       3    0.205
> x                 NA         NA      NA       NA
>
> Residual standard error: 0.7071 on 1 degrees of freedom
>
>> coef(summary(tmp.lm))
>             Estimate Std. Error t value  Pr(>|t|)
> (Intercept)      1.5        0.5       3 0.2048328
>>
>> version
>                _
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status
> major          2
> minor          4.0
> year           2006
> month          10
> day            03
> svn rev        39566
> language       R
> version.string R version 2.4.0 (2006-10-03)
>>
>
>
> ## this is a related problem
>
> tmp <- data.frame(x=c(1,2),
>                   y=c(1,2))
>
> tmp.lm <- lm(y ~ x, data=tmp)
> summary(tmp.lm)
>
> coef(summary(tmp.lm))
>
> ## Here the summary() give NA for the values that can't be
> ## calculated and the coef() function gives NaN.  I think both
> ## functions should return the same result.
>
>
>> summary(tmp.lm)
>
> Call:
> lm(formula = y ~ x, data = tmp)
>
> Residuals:
> ALL 2 residuals are 0: no residual degrees of freedom!
>
> Coefficients:
>             Estimate Std. Error t value Pr(>|t|)
> (Intercept)        0         NA      NA       NA
> x                  1         NA      NA       NA
>
> Residual standard error: NaN on 0 degrees of freedom
> Multiple R-Squared:     1,      Adjusted R-squared:   NaN
> F-statistic:   NaN on 1 and 0 DF,  p-value: NA
>
>>
>> coef(summary(tmp.lm))
>             Estimate Std. Error t value Pr(>|t|)
> (Intercept)        0        NaN     NaN      NaN
> x                  1        NaN     NaN      NaN
>>
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] inconsistency or bug in coef() (PR#9358)
Benilton Carvalho