Hi everyone,
I am currently attempting to fit confidence interval lines to a regression model in R, but every time I try to for example add a +2 confidence interval line, I end up with two of them! I have been over my code many times and can't find any obvious mistakes. This is the code I have used:
Model21<-lm(ventral.blubber~girth+cause.of.death,data=Porpoises,na.action=na.exclude)
preddf2<-data.frame(girth=rep(3:11*10,2),cause.of.death=rep(c("Disease","Trauma"),c(18,18)))
pred.vb2<-predict(Model21,newdata=preddf2,se=TRUE)
lines(preddf2$girth[preddf2$cause.of.death=="Disease"],pred.vb2$fit[preddf2$cause.of.death=="Disease"])
lines(preddf2$girth[preddf2$cause.of.death=="Disease"],pred.vb2$fit[preddf2$cause.of.death=="Disease"]+2*pred.vb2$se.fit[preddf2$cause.of.death=="Disease"],lty="dashed")
lines(preddf2$girth[preddf2$cause.of.death=="Disease"],pred.vb2$fit[preddf2$cause.of.death=="Disease"]-2*pred.vb2$se.fit[preddf2$cause.of.death=="Disease"],lty="dashed")
Here is some information about girth, which is the explanatory variable causing the problem - all the other explanatory variables work fine using this code and produce the correct number of lines.
> summary(girth)
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
38.00 70.00 80.00 79.83 88.00 112.00 5
Does anyone know where I might have gone wrong? I would really appreciate the help!
I am currently attempting to fit confidence interval lines to a regression model in R, but every time I try to for example add a +2 confidence interval line, I end up with two of them! I have been over my code many times and can't find any obvious mistakes. This is the code I have used:
Model21<-lm(ventral.blubber~girth+cause.of.death,data=Porpoises,na.action=na.exclude)
preddf2<-data.frame(girth=rep(3:11*10,2),cause.of.death=rep(c("Disease","Trauma"),c(18,18)))
pred.vb2<-predict(Model21,newdata=preddf2,se=TRUE)
lines(preddf2$girth[preddf2$cause.of.death=="Disease"],pred.vb2$fit[preddf2$cause.of.death=="Disease"])
lines(preddf2$girth[preddf2$cause.of.death=="Disease"],pred.vb2$fit[preddf2$cause.of.death=="Disease"]+2*pred.vb2$se.fit[preddf2$cause.of.death=="Disease"],lty="dashed")
lines(preddf2$girth[preddf2$cause.of.death=="Disease"],pred.vb2$fit[preddf2$cause.of.death=="Disease"]-2*pred.vb2$se.fit[preddf2$cause.of.death=="Disease"],lty="dashed")
Here is some information about girth, which is the explanatory variable causing the problem - all the other explanatory variables work fine using this code and produce the correct number of lines.
> summary(girth)
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
38.00 70.00 80.00 79.83 88.00 112.00 5
Does anyone know where I might have gone wrong? I would really appreciate the help!