Skip to content

zigzag confidence interval in a plot

3 messages · Ozgul Inceoglu, Peter Ehlers, Rui Barradas

#
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
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
pconfR <- predict(lmR,interval="confidence")
matlines(cd$CHAOsep12RNA,pconfR[,c("lwr","upr")], col=1, lty=2)

I also tried
But I see both cases kind of zigzags. What can it be the reason? thank you!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zigzaging.pdf
Type: application/pdf
Size: 2111 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130517/50fd982f/attachment.pdf>
#
On 2013-05-17 06:03, Ozgul Inceoglu wrote:
Sort your dataframe by x-values (CHAOsep12RNA).

Peter Ehlers
#
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: