Hi all,
I need to test the significnce of difference between slopes of two regression 
lines and regression line with theoretical line. I try to use Slope.test 
function from emu package,
but an error occured... 

library(emu)
d1<-data.frame(P1=c(1,2,3,5,7,8,9,13,14,15),
 P2=c(1,2,5,8,11,13,15,15,18,24),
 R=c(2,7,8,9,16,21,27,31,33,36)) # First data set
m1<-lm(R~P1+P2+P1*P2,data=d1) # Regr. model

d2<-data.frame(P1=c(1,5,4,7,9,1,12,4,4,5),
 P2=c(1,2,0,7,4,1,2,0,7,0),
 R=c(3,12,15,15,9,7,4,5,6,1)) # Second data set
m2<-lm(R~P1+P2+P1*P2,data=d2) # Regr. model

Slope.test(data.frame(fitted(m1),d1$R),data.frame(fitted(m2),d2$R)) #Doesn't 
work...

Is it correct to use t-test in this situation and how to compute  df  for it? 
My solution is:

s1<-coefficients(summary(lm(fitted(m1)~d1$R)))[2,1] #Slopes of regr.line
s2<-coefficients(summary(lm(fitted(m2)~d2$R)))[2,1]
se1<-coefficients(summary(lm(fitted(m1)~d1$R)))[2,2] #SE of slopes
se2<-coefficients(summary(lm(fitted(m2)~d1$R)))[2,2]
df1<-df.residual(lm(fitted(m1)~d1$R)) #D. of f.
df2<-df.residual(lm(fitted(m2)~d1$R))

kk<-function(se1,se2,df1,df2){(se1^2+se2^2)^2/(se1^4/(df1-1)+se2^4/(df2-1))} 
#D. of f. for Welsch test
tt<-function(s1,s2,se1,se2){(s1-s2)/sqrt(se1^2+se2^2)}
pp<-function(s1,s2,se1,se2,df1,df2){2*pt(-abs(tt(s1,s2,se1,se2)),df=kk(se1,se2,df1,df2))}

pp(s1,s2,se1,se2,df1,df2) # p-value

## Theoretical line

s3<-0.75
se3<-0
df3<-0

pp(s1,s3,se1,se3,df1,df3) # p-value
pp(s2,s3,se2,se3,df2,df3) # p-value


Thanks,
A.M.

______________________________________________
R-help@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.

Reply via email to