BXC (Bendix Carstensen)
2004-Sep-27 11:57 UTC
[R] Funny behaviour of coef() and vcov() if X is singular
coef() and vcov() have different dimensions if a model contains alised parameters as the following example illustrates. A search on "alised" gave noting as far as I could see. Is this a known bug? Bendix C ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 bxc at steno.dk www.biostat.ku.dk/~bxc ----------------------> x <- rnorm(100) > y <- rnorm(100) > z <- rnorm(100) > summary( mu <- lm( y ~x + I(x-z)+z ) )Call: lm(formula = y ~ x + I(x - z) + z) Residuals: Min 1Q Median 3Q Max -1.917325 -0.633091 -0.003363 0.561464 2.473183 Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) 0.07806 0.09118 0.856 0.3940 x -0.27373 0.11415 -2.398 0.0184 I(x - z) 0.08617 0.08524 1.011 0.3146 z NA NA NA NA Residual standard error: 0.9061 on 97 degrees of freedom Multiple R-Squared: 0.05813, Adjusted R-squared: 0.03871 F-statistic: 2.993 on 2 and 97 DF, p-value: 0.05476> coef( mu )(Intercept) x I(x - z) z 0.07805884 -0.27373500 0.08617152 NA> vcov( mu )(Intercept) x I(x - z) (Intercept) 8.313341e-03 -5.702109e-05 0.0007248947 x -5.702109e-05 1.303028e-02 -0.0057006507 I(x - z) 7.248947e-04 -5.700651e-03 0.0072657814> length( coef( mu ) )[1] 4> dim( vcov( mu ) )[1] 3 3> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 9.1 year 2004 month 06 day 21 language R
Prof Brian Ripley
2004-Sep-27 12:45 UTC
[R] Funny behaviour of coef() and vcov() if X is singular
Yes, and that's intentional. You don't want non-information on unestimated parameters, do you? (What would you do with it?) BTW, you forgot the very important caveat `the "lm" methods of coef() and vcov()'. On Mon, 27 Sep 2004, BXC (Bendix Carstensen) wrote:> coef() and vcov() have different dimensions if a model contains alised > parameters > as the following example illustrates. > > A search on "alised" gave noting as far as I could see. > > Is this a known bug? > > Bendix C > ---------------------- > Bendix Carstensen > Senior Statistician > Steno Diabetes Center > Niels Steensens Vej 2 > DK-2820 Gentofte > Denmark > tel: +45 44 43 87 38 > mob: +45 30 75 87 38 > fax: +45 44 43 07 06 > bxc at steno.dk > www.biostat.ku.dk/~bxc > ---------------------- > > > x <- rnorm(100) > > y <- rnorm(100) > > z <- rnorm(100) > > summary( mu <- lm( y ~x + I(x-z)+z ) ) > > Call: > lm(formula = y ~ x + I(x - z) + z) > > Residuals: > Min 1Q Median 3Q Max > -1.917325 -0.633091 -0.003363 0.561464 2.473183 > > Coefficients: (1 not defined because of singularities) > Estimate Std. Error t value Pr(>|t|) > (Intercept) 0.07806 0.09118 0.856 0.3940 > x -0.27373 0.11415 -2.398 0.0184 > I(x - z) 0.08617 0.08524 1.011 0.3146 > z NA NA NA NA > > Residual standard error: 0.9061 on 97 degrees of freedom > Multiple R-Squared: 0.05813, Adjusted R-squared: 0.03871 > F-statistic: 2.993 on 2 and 97 DF, p-value: 0.05476 > > > coef( mu ) > (Intercept) x I(x - z) z > 0.07805884 -0.27373500 0.08617152 NA > > vcov( mu ) > (Intercept) x I(x - z) > (Intercept) 8.313341e-03 -5.702109e-05 0.0007248947 > x -5.702109e-05 1.303028e-02 -0.0057006507 > I(x - z) 7.248947e-04 -5.700651e-03 0.0072657814 > > length( coef( mu ) ) > [1] 4 > > dim( vcov( mu ) ) > [1] 3 3 > > version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 1 > minor 9.1 > year 2004 > month 06 > day 21 > language R > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- 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