Yes, that's what I was looking for.
Many thanks,

Samuel

-----Original Message-----
From: S Ellison [mailto:s.elli...@lgcgroup.com]
Sent: 01 August 2011 15:16
To: Samuel Le; r-h...@stat.math.ethz.ch
Subject: RE: formula used by R to compute the t-values in a linear regression



> -----Original Message-----
> [mailto:r-help-boun...@r-project.org] On Behalf Of Samuel Le
> Subject: [R] formula used by R to compute the t-values in a
> linear regression
> I was wondering if someone knows the formula used by the
> function lm to compute the t-values.

Typing
summary.lm

I found the standard error and t calculation (for around line 58-62 of the 
resulting listing.
    resvar <- rss/rdf
    R <- chol2inv(Qr$qr[p1, p1, drop = FALSE])
    se <- sqrt(diag(R) * resvar)
    est <- z$coefficients[Qr$pivot[p1]]
    tval <- est/se

You can also find (rather further up) that the degrees of freedom df used are 
taken directly from the linear model $df (z$df in the function). Others noted 
that incorrect df often cause problems, so checking that you're using the 
correct df is possible by inspecting the lm summary.

The standard errors are apparently (as is usual for a least squares problem, I 
think) taken from the diagonal of  the inverse of the hessian, multiplied by 
the residual variance. Unfortunately I could not get at the hessian calculation 
quite as easily (it looks like it uses a function that's not exported from 
stats) so that's left as an exercise in browsing source code ...

S Ellison


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:25}}

______________________________________________
R-help@r-project.org 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.

Reply via email to