[R] df.residual for rlm()

Jan jrheinlaender at gmx.de
Tue Mar 1 11:58:06 CET 2011


Hello,

for testing coefficients of lm(), I wrote the following function (with
the kind support of this mailing list):

# 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
  2 * pt(-abs(t),n) # times two because problem is two-sided
}

This works fine for lm() objects, but fails for rlm() because
df.residual() is NA. 

Can I get the degrees of freedom by calculating 

n = length(lm.result) - length(coefficients(lm.result))

Thanks for any help!
	Jan



More information about the R-help mailing list