# Re: [R] regression slope

From: Corey Moffet <cmoffet_at_nwrc.ars.usda.gov>
Date: Wed 21 Jul 2004 - 04:26:10 EST

At 06:44 PM 7/20/2004 +0100, Adaikalavan Ramasamy wrote:
>I would try to construct the confidence intervals and compare them to
>the value that you want
>> x <- rnorm(20)
>> y <- 2*x + rnorm(20)
>> summary( m1 <- lm(y~x) )
>
><snip>
>Coefficients:
> Estimate Std. Error t value Pr(>|t|)
>(Intercept) 0.1418 0.1294 1.095 0.288
>x 2.2058 0.1289 17.108 1.4e-12 ***
><snip>
>
>That says that the slope estimate is 2.2058 with standard error of
>0.1289. So the approximate 99% CI is 2.2058 +/- 3*0.1289 = (1.819,
>2.593) which is clearly greater than 1.

Another method which gives the p value etc. was shared with this list by Prof. Ripley several years ago:

set.seed(1)
x <- rnorm(20)
x.hypoth <- 1 # i.e., Null hypothesis is that x != 1 y <- 2*x + rnorm(20)
summary( m1 <- lm(y - x.hypoth*x~x) )

Produces:

Call:
lm(formula = y - x.hypoth * x ~ x)

Residuals:

Coefficients:

Estimate Std. Error t value Pr(>|t|) (Intercept) 0.03307 0.19981 0.166 0.870 x 0.79245 0.21951 3.610 0.002 **

```---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Residual standard error: 0.8738 on 18 degrees of freedom
Multiple R-Squared:  0.42,      Adjusted R-squared: 0.3878
F-statistic: 13.03 on 1 and 18 DF,  p-value: 0.002001

>
>> summary(m1)[][2,1] + 3* summary(m1)[][2,2]

> 2.592629
>> summary(m1)[][2,1] - 3* summary(m1)[][2,2]
> 1.819026
>
>For your next question, you simply compare the CI of one slope to
>another and see if they overlap.
>
>There is probably a way to construct proper significance testing to get
>p-values and such. You can try reading MASS4 or hopefully someone in the
>list might provide with a neater answer.
>
>
>On Tue, 2004-07-20 at 17:02, Avril Coghlan wrote:
>> Hello,
>>
>>   I'm a newcomer to R so please
>> forgive me if this is a silly question.
>>
>> It's that I have a linear regression:
>> fm <- lm (x ~ y)
>> and I want to test whether the
>> slope of the regression is significantly
>> less than 1. How can I do this in R?
>>
>> I'm also interested in comparing the
>> slopes of two regressions:
>> fm1 <- lm (x ~ y)
>> fm2 <- lm (a ~ b)
>> and asking if the slope of fm1 is
>> less than the slope of fm2. Is this
>> easy to do in R?
>>
>>
>> I will be very grateful for any help.
>>
>> regards,
>> Avril Coghlan
>> (University College Dublin, Ireland)
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
http://www.R-project.org/posting-guide.html

>>
>
>______________________________________________

>R-help@stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
With best wishes and kind regards I am

Sincerely,

Corey A. Moffet
Rangeland Scientist

##################################################################
####
USDA-ARS                                        #
Northwest Watershed Research Center             #
800 Park Blvd, Plaza IV, Suite 105          ###########   ####
Boise, ID 83712-7716                       #    #      # #
Voice: (208) 422-0718                      #    #  ####   ####
FAX:   (208) 334-1502                      #    # #           #
####   ###########
##################################################################

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help