Skip to content
Prev 397325 / 398500 Next

Extract estimate of error variance from glm() object

?s 23:29 de 24/12/2024, Bert Gunter escreveu:
Hello,

In case of doubt, program a residual standard error function and compare 
the results.



rse <- function(object)  {
   rss <- resid(object)^2
   sum(rss / object[["df.residual"]]) |> sqrt()
}

clotting <- data.frame(
   u = c(5,10,15,20,30,40,60,80,100),
   lot1 = c(118,58,42,35,27,25,21,19,18),
   lot2 = c(69,35,26,21,18,16,13,12,12))

fit1 <- glm(lot1 ~ log(u), data = clotting, family = gaussian)
fit2 <- lm(lot1 ~ log(u), data = clotting)

# all of the results below are identically equal
sigma(fit1)
rse(fit1)

sigma(fit2)
rse(fit2)



Hope this helps,

Rui Barradas