[R] Regression slopes
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Thu Jun 5 15:13:24 CEST 2003
Martin Biuw wrote:
> Hi,
> Sorry if this is an obvious one, but is there a simple way to modify the lm
> function to test whether a slope coefficient is significantly different
> from 1 instead of different from 0?
>
> Thanks,
>
There might be an easier way, but the brute force method would be:
R> set.seed(1)
R> x <- data.frame(x = 1:10, y = 1:10 + rnorm(10))
R> lm.x <- lm(y ~ x, data = x)
R> coef.x <- summary(lm.x)$coef
R> # t-statistic comparing slope to 1
R> t.x <- (coef.x["x","Estimate"]-1)/coef.x["x","Std. Error"]
R> # p-value
R> 2 * pt(abs(t.x), lm.x$df, lower = FALSE)
[1] 0.5559868
Hope this helps,
Sundar
More information about the R-help
mailing list