[R] Linear Regression with slope equals 0
(Ted Harding)
Ted.Harding at manchester.ac.uk
Tue Aug 14 14:16:08 CEST 2007
On 14-Aug-07 11:36:37, E.N.D.Grew at exeter.ac.uk wrote:
>
> Hi there, am trying to run a linear regression with a slope of 0.
>
> I have a dataset as follows
>
> t d
> 1 303
> 2 302
> 3 304
> 4 306
> 5 307
> 6 303
>
> I would like to test the significance that these points would lie on a
> horizontal straight line.
>
> The standard regression lm(d~t) doesn't seem to allow the slope to be
> set.
The model d~1 will fit a constant (the mean), i.e. a regressio with
slope = 0. The model d~t will fit the usual linear regression.
The two con be compared with anova(), as well as getting the details
of the individual fits with summary().
E.g. (with your example):
d<-c(303,302,304,306,207,303)
t<-c(1,2,3,4,5,6)
lm0<-lm(u~1);lm1<-lm(u~t);anova(lm0,lm1)
##Analysis of Variance Table
##Model 1: u ~ 1
##Model 2: u ~ t
## Res.Df RSS Df Sum of Sq F Pr(>F)
##1 5 7785.5
##2 4 6641.4 1 1144.1 0.6891 0.4531
summary(lm0)
## Call: lm(formula = u ~ 1)
## Residuals:
## 1 2 3 4 5 6
## 15.5 14.5 16.5 18.5 -80.5 15.5
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 287.50 16.11 17.85 1.01e-05 ***
##Residual standard error: 39.46 on 5 degrees of freedom
mean(d)
## [1] 287.5
summary(lm1)
## Call: lm(formula = u ~ t)
## Residuals:
## 1 2 3 4 5 6
## -4.714 2.371 12.457 22.543 -68.371 35.714
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 315.800 37.934 8.325 0.00114 **
## t -8.086 9.740 -0.830 0.45314
## Residual standard error: 40.75 on 4 degrees of freedom
## Multiple R-Squared: 0.147, Adjusted R-squared: -0.0663
## F-statistic: 0.6891 on 1 and 4 DF, p-value: 0.4531
The P-value for the slope in lm1 is the same as the P-value
returned by anova().
If you want to force a particular non-zero slope (e.g. s0)
for comparison with the data, you can use
lm0 <- lm(d - s0*t ~ 1),
compared with
lm1<- lm(d- s0*t ~ t)
for instance.
Hoping this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 14-Aug-07 Time: 13:16:05
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list