[R] Calculation of VCV matrix of estimated coefficient
Ben Bolker
bbo|ker @end|ng |rom gm@||@com
Wed Sep 4 22:14:09 CEST 2024
The number you need for MSE is
sum(residuals(model)^2)/df.residual(model)
On Wed, Sep 4, 2024 at 3:34 PM Daniel Lobo <danielobo9976 using gmail.com> wrote:
>
> Hi,
>
> I am trying to replicate the R's result for VCV matrix of estimated
> coefficients from linear model as below
>
> data(mtcars)
> model <- lm(mpg~disp+hp, data=mtcars)
> model_summ <-summary(model)
> MSE = mean(model_summ$residuals^2)
> vcov(model)
>
> Now I want to calculate the same thing manually,
>
> library(dplyr)
> X = as.matrix(mtcars[, c('disp', 'hp')] %>% mutate(Intercept = 1));
> solve(t(X) %*% X) * MSE
>
> Unfortunately they do not match.
>
> Could you please help where I made mistake, if any.
>
> Thanks
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list