On 10/17/2010 11:25 AM, Jan private wrote: > So here is the next version. > > Why does the intercept needs lower.tail=TRUE to give the same result as > summary() for value=0?
It doesn't. Or rather: For all coefficients, lower/upper tail depends on the _sign_ of t, so presumably you have a negative intercept in this particular data set. The more traditional way is 2*pt(-abs(t), n). > > # See Verzani, simpleR (pdf), p. 80 > coeff.test <- function(lm.result, idx, value) { > # idx = 1 is the intercept, idx>1 the other coefficients > # null hypothesis: coeff = value > # alternative hypothesis: coeff != value > coeff <- coefficients(lm.result)[idx] > SE <- coefficients(summary(lm.result))[idx,"Std. Error"] > n <- df.residual(lm.result) > t <- (coeff - value )/SE > if (idx == 1) { > 2 * pt(t,n,lower.tail=TRUE) # times two because problem is two-sided > } else { > 2 * pt(t,n,lower.tail=FALSE) > } > } > > -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ 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.