[R] simple test on slope of lm()

Douglas Bates bates at stat.wisc.edu
Mon Nov 25 15:40:38 CET 2002


Yves Brostaux <brostaux.y at fsagx.ac.be> writes:

> To test the slope of your linear model against an arbitrary value, you
> can use lm() directly with a little trick. Let b1 be the value of the
> slope you want to test your model against, then use lm(y-b1*x~x). The
> significance test of the slope for this lm model gives the answer you
> need.
> 
> 
>  > x <- rnorm(10)
>  > y <- 2*x + rnorm(10)
>  > lm(y~x)
>  > lm(y-2*x~x)

Or you could use an offset term in the model.

 lm(y ~ x + offset(2*x))

> x <- 1:10
> y <- 2*x + rnorm(10, sd = 0.2)
> summary(lm(y ~ x))

Call:
lm(formula = y ~ x)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.324065 -0.187921  0.001240  0.183084  0.363249 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.008868   0.163598   0.054    0.958    
x           1.994596   0.026366  75.650 1.04e-12 ***
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

Residual standard error: 0.2395 on 8 degrees of freedom
Multiple R-Squared: 0.9986,	Adjusted R-squared: 0.9984 
F-statistic:  5723 on 1 and 8 DF,  p-value: 1.039e-12 

> summary(lm(y ~ x + offset(2 * x)))

Call:
lm(formula = y ~ x + offset(2 * x))

Residuals:
      Min        1Q    Median        3Q       Max 
-0.324065 -0.187921  0.001240  0.183084  0.363249 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.008868   0.163598   0.054    0.958
x           -0.005404   0.026366  -0.205    0.843

Residual standard error: 0.2395 on 8 degrees of freedom
Multiple R-Squared: 0.9986,	Adjusted R-squared: 0.9984 
F-statistic:  5723 on 1 and 8 DF,  p-value: 1.039e-12 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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