[R] comparing regression slopes
Nathan Weisz
Nathan.Weisz at uni-konstanz.de
Fri Jun 11 11:26:23 CEST 2004
Dear List,
I used rlm to calculate two regression models for two data sets (rlm
due to two outlying values in one of the data sets). Now I want to
compare the two regression slopes. I came across some R-code of Spencer
Graves in reply to a similar problem:
http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg06666.html
The code was:
> df1 <- data.frame(x=1:10, y=1:10+rnorm(10)) #3observations in
original code
> df2 <- data.frame(x=1:10, y=1:10+rnorm(10))
>
> fit1 <- lm(y~x, df1)
> s1 <- summary(fit1)$coefficients
> fit2 <- lm(y~x, df2)
> s2 <- summary(fit2)$coefficients
>
> db <- (s2[2,1]-s1[2,1])
> sd <- sqrt(s2[2,2]^2+s1[2,2]^2)
> df <- (fit1$df.residual+fit2$df.residual)
> td <- db/sd
> 2*pt(-abs(td), df)
[1] 0.9510506
However when I use rlm instead of lm I get NA for df.residual.
> fit1 <- rlm(y~x, df1)
> fit1$df.residual
[1] NA
Does this mean that I can not apply the code for values gained by rlm?
In the example above I continued by taking the df from:
> summary(fit1)$df[2]
[1] 8
Is this o.k.?
Help greatly appreciated.
Best,
Nathan Weisz
More information about the R-help
mailing list