Hello, Is it possible to extract or compute the standard errors of model coefficients from a glm.fit object? This can be easily done from a fitted glm object, but I need glm.fit. set.seed(1) n <- 100 x <- rnorm(n) y1 <- rnorm(n) y2 <- rbinom(n, 1, .25) M1 <- glm (y1 ~ x) M2 <- glm.fit(x = x, y = y1) seCoef <- sqrt(diag(vcov(M1))) seCoef (Intercept) x 0.09698729 0.10772703 Thank you, Axel.
Dear Axel, If you look at the content of the list returned by glm.fit, you'll see that it contains almost everything in a "glm" object, and what's needed to compute the coefficient covariance matrix. Here's one way to do what you want (but note that your example was faulty in that you didn't include the regression constant in the call to glm.fit):> set.seed(1) > n <- 100 > x <- rnorm(n) > y1 <- rnorm(n) > y2 <- rbinom(n, 1, .25) # you never use this in your example > > M1 <- glm (y1 ~ x) > M2 <- glm.fit(x = cbind(1, x), y = y1) # corrected > class(M2) <- "glm" > vcov(M1)(Intercept) x (Intercept) 0.009406535 -0.00126365 x -0.001263650 0.01160511> vcov(M2)x 0.009406535 -0.00126365 x -0.001263650 0.01160511 You may have a reason to use glm.fit in preference to glm, but I'm not sure why you'd want to do that. I hope this helps, John ----------------------------------------------- John Fox, Professor McMaster University Hamilton, Ontario, Canada http://socserv.socsci.mcmaster.ca/jfox/> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Axel > Urbiz > Sent: Tuesday, December 29, 2015 9:10 AM > To: R-help at r-project.org > Subject: [R] Extract Standard Errors of Model Coefficients > > Hello, > > Is it possible to extract or compute the standard errors of model > coefficients from a glm.fit object? This can be easily done from a > fitted glm object, but I need glm.fit. > > > set.seed(1) > n <- 100 > x <- rnorm(n) > y1 <- rnorm(n) > y2 <- rbinom(n, 1, .25) > > M1 <- glm (y1 ~ x) > M2 <- glm.fit(x = x, y = y1) > seCoef <- sqrt(diag(vcov(M1))) > seCoef > > (Intercept) x > 0.09698729 0.10772703 > > Thank you, > Axel. > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Thanks a lot John. Forgot I could arbitrarily change the class of objects, which against all critics, can be very helpful at times. Best, Axel.> On Dec 29, 2015, at 9:35 AM, Fox, John <jfox at mcmaster.ca> wrote: > > Dear Axel, > > If you look at the content of the list returned by glm.fit, you'll see that it contains almost everything in a "glm" object, and what's needed to compute the coefficient covariance matrix. Here's one way to do what you want (but note that your example was faulty in that you didn't include the regression constant in the call to glm.fit): > >> set.seed(1) >> n <- 100 >> x <- rnorm(n) >> y1 <- rnorm(n) >> y2 <- rbinom(n, 1, .25) # you never use this in your example >> >> M1 <- glm (y1 ~ x) >> M2 <- glm.fit(x = cbind(1, x), y = y1) # corrected >> class(M2) <- "glm" >> vcov(M1) > (Intercept) x > (Intercept) 0.009406535 -0.00126365 > x -0.001263650 0.01160511 >> vcov(M2) > x > 0.009406535 -0.00126365 > x -0.001263650 0.01160511 > > You may have a reason to use glm.fit in preference to glm, but I'm not sure why you'd want to do that. > > I hope this helps, > John > > ----------------------------------------------- > John Fox, Professor > McMaster University > Hamilton, Ontario, Canada > http://socserv.socsci.mcmaster.ca/jfox/ > > > >> -----Original Message----- >> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Axel >> Urbiz >> Sent: Tuesday, December 29, 2015 9:10 AM >> To: R-help at r-project.org >> Subject: [R] Extract Standard Errors of Model Coefficients >> >> Hello, >> >> Is it possible to extract or compute the standard errors of model >> coefficients from a glm.fit object? This can be easily done from a >> fitted glm object, but I need glm.fit. >> >> >> set.seed(1) >> n <- 100 >> x <- rnorm(n) >> y1 <- rnorm(n) >> y2 <- rbinom(n, 1, .25) >> >> M1 <- glm (y1 ~ x) >> M2 <- glm.fit(x = x, y = y1) >> seCoef <- sqrt(diag(vcov(M1))) >> seCoef >> >> (Intercept) x >> 0.09698729 0.10772703 >> >> Thank you, >> Axel. >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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.