[R] Null-Hypothesis
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Wed Apr 8 14:43:45 CEST 2009
Hi Benedikt
in principle this is correct. A p-value less than a prespecified
alpha-level leads to rejection of the null hypothesis H0.
I'm a little bit puzzled about your given p-value, since actually your
slopes are the same, so H0 is valid but rejected. This might be a matter
of chance, but it is so to say against all odds (~2 out of 10 000 000)
having such a special data set.
Alternatively - and using well established estimators - you can
incorporate your factor in a joint model.
df1 <- data.frame(x=1:3, y=1:3+rnorm(3),g=0)
df2 <- data.frame(x=1:3, y=1:3+rnorm(3),g=1)
dta<-rbind(df1,df2)
dta$g<-factor(dta$g) # not really necessary for a two-group factor
ll<-lm(y~x*g,dta)
summary(ll)
This model has a varying slope and intercept term (which is the same as
fitting two separate regression lines as you did), the test for
different slopes is to test significance of x:g.
If you are in fact asking for a pure varying slope model you have to
restrict your fit1 and fit2 to have the same intercept or you use the
joint model with
ll<-lm(y~x+x:g,dta)
hth
Benedikt Niesterok schrieb:
> Hello R users,
> I've used the following help two compare two regression line slopes.
> Wanted to test if they differ significantly:
>
> Hi,
>
> I've made a research about how to compare two regression line slopes
> (of y versus x for 2 groups, "group" being a factor ) using R.
>
> I knew the method based on the following statement :
> t = (b1 - b2) / sb1,b2
> where b1 and b2 are the two slope coefficients and sb1,b2 the pooled
> standard error of the slope (b)
>
> which can be calculated in R this way:
> > df1 <- data.frame(x=1:3, y=1:3+rnorm(3))
> > df2 <- data.frame(x=1:3, y=1:3+rnorm(3))
> > 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)
>
> My value I get by running this test is :[1] 2.305553e-07
> Does it mean the two slopes differ significantly, because this value is in
> the alpha area, so that I have to reject the null- hypothesis and accept
> the alternative hypothesis?
> Is the null-hypothesis: slope1=slope2?
> Thanks for your help, Benedikt
> --
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/42803-8243
F ++49/40/42803-7790
More information about the R-help
mailing list