[R] hypothesis testing in models

Zsombor Cseres-Gergely z.cseres-gergely at ucl.ac.uk
Wed Jul 18 20:24:02 CEST 2001


Dear all,

Being an economics student, I am trying to put together a little
tutorial/FAQ/... for those who have (more) background in econometrics rather
than in statistics -- just as I have. I'v been looking for a hypothesis
testing tool in R (just linear or also nonlinear) for model parameters, but
could not find anything so far. I did find a similar but unanswered question
in the archives, but nothing apart from that. Is it there or am I missing
something? If it is not there, is there a specific reason for that?
I am aware that the required code is not special or long, but the one I could
come up with is rather ugly and a pain to use:

htest  <- function(object, resmat, target = 0, level = 0.95, n = 0) UseMethod("htest")
  # Testing liner restrictions of the form: resmat %*% cfs = target
  # resmat: matrix/vector of restriction multipliers (i x k) ARRAY!!
  # target: restriction value vector/scalar (k)

htest.lm <- function(object, resmat, target = 0, level = 0.95)
{
  tsu <- summary(object, corr=FALSE)
  cfs <- as.array(object$coefficients)
  dfr1 <- nrow(resmat)
  dfr2 <- object$df.residual
  S <- aperm(resmat %*% aperm(cfs) - target) %*% solve(resmat %*% tsu$cov.unscaled %*% aperm(resmat)) %*% (resmat %*% aperm(cfs) - target) / (nrow(resmat) * tsu$sigma^2)
  cat("  F(",dfr1,",",dfr2,") =",qf(level,dfr1,dfr2), "  vs.  S =",S,"  [ p = ",df(S,dfr1,dfr2),"]\n")
}

Thanks for any comments,
Zsombor
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list