[R] about the unscaled covariances from a summary.lm object

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Tue May 29 15:45:20 CEST 2007


try the following:

x1 <- rnorm(100)
x2 <- rep(0:1, each = 50)
x3 <- runif(100)
y <- drop(cbind(1, x1, x2, x3) %*% c(1, 2, -1, -3)) + rnorm(100, sd = 
2)
dat <- data.frame(y, x1, x2, x3)

######################

fit.lm <- lm(y ~ x1 + x2 + x3, dat)
summ.fit.lm <- summary(fit.lm)
X <- model.matrix(fit.lm)

all.equal(solve(crossprod(X)), summ.fit.lm$cov.unscaled)

Sigma <- summ.fit.lm$sigma^2 * solve(crossprod(X))
all.equal(sqrt(diag(Sigma)), summ.fit.lm$coefficients[, "Std. Error"])


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Martin Ivanov" <tramni at abv.bg>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, May 29, 2007 3:12 PM
Subject: [R] about the unscaled covariances from a summary.lm object


> Hello!
> I want to clarify something about the unscaled covarinces component 
> of a summary.lm object. So we have the regressor matrix X. If the 
> fitted lm object is lmobj, the inverse of the matrix t(X)%*%X is xx, 
> and the residual variance is sigma^2_e, the variance-covariance 
> matrix of the OLS estimate of the coefficients is given by:
> xx*sigma^2_e
> I saw that what the function vcov actually does is simply:
> vcov=summary(lmobj)$sigma^2 * summary(lmobj)$cov.unscaled
> So the cov.unscaled component should give the matrix xx. I am right?
> I tried inverting the matrix t(X)%*%X with solve by issuing:
> solve(t(X)%*%X), but I get a matrix quite different from the matrix 
> given by cov.unscaled. Is it just computational instability, or I am 
> missing something important?
>
> Regards,
> Martin
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list