[R] zigzag confidence interval in a plot

Rui Barradas ruipbarradas at sapo.pt
Fri May 17 17:28:50 CEST 2013


Hello,

Try the following.


lmR <- lm(cd$Depth ~ cd$CHAOsep12RNA)
pconfR <- predict(lmR,interval="confidence")
pcR <- pconfR[order(pconfR[, 1]), ]  # Add this line

plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab="CHAO", 
ylab="Depth", pch=15, las=2, main="Sep12-RNA", cex.main=1)
abline(lmR)
matlines(sort(cd$CHAOsep12RNA), pcR[,c("lwr", "upr")], col=1, lty=2) # 
changed


Hope this helps,

Rui Barradas

Em 17-05-2013 14:03, Ozgul Inceoglu escreveu:
> Dear All,
>
> When I plot the values and linear regression line for one data set, it is fine. But for another one I see zigzags, when I plot the confidence interval
>
>> cd
> Depth	CHAOsep12RNA
> 9,94	804
> 25,06	1476,833333
> 40,04	1540,561404
> 50,11	1575,166667
> 52,46	349,222222
> 54,92	1941,5
> 57,29	1053,507042
> 60,11	1535,1
> 70,04	2244,963303
> 79,97	1954,507042
> 100,31	2679,140625
>
>
>> plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab="CHAO", ylab="Depth", pch=15, las=2, main="Sep12-RNA", cex.main=1)
>> lmR <- lm(cd$Depth~cd$CHAOsep12RNA)
>> abline(lmR)
> pconfR <- predict(lmR,interval="confidence")
> matlines(cd$CHAOsep12RNA,pconfR[,c("lwr","upr")], col=1, lty=2)
>
> I also tried
>
>> newx <- seq(min(cd$CHAOsep12RNA), max(cd$CHAOsep12RNA), length.out=11)
>> a <- predict(lmR, newdata=data.frame(CHAO=newx), interval=c("confidence"))
>> plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab="CHAO", ylab="Depth", pch=15, las=2, main="Sep12-RNA", cex.main=1)
>> abline(lmR)
>> lines(cd$CHAOsep12RNA, a[,2], lty=2)
>
> But I see both cases kind of zigzags. What can it be the reason? thank you!
>
>
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list