So here is the next version.

Why does the intercept needs lower.tail=TRUE to give the same result as
summary() for value=0?

# 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)
  }
}

______________________________________________
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