Why are my confidence and prediction intervals not plotting?
05:42 25 Nov 2025

I'm trying to create a model for a data set from a paper about tooth wear, and I was able to create linear models with prediction and confidence intervals for three of the four teeth we're looking at, but I can't seem to get the final model to show prediction and confidence intervals. I'm not the best at coding, so I'm not sure if it's me or if it's the data or if it's the linear model. Any assistance or advice would be appreciated!

Data set available here: https://deepblue.lib.umich.edu/data/downloads/qz20ss512

This is my code:

dev.off()
plot(M2_present$M2_av,M2_present$Age_Mid, xlim=c(0,2), ylim=c(5,20), main= "Linear Relationship betweeen Permanent Molar 2 and Age-at-Death of Individual", xlab="M2 Wear Score",ylab="Age (in years)",pch=20)
legend("topleft",inset=c(0.,0),legend=c("Fitted Model","Confidence Interval","Prediction Interval"),lty=c(1,2,1),col=c("red","red","blue"))
par(xpd=FALSE)
abline(testLM_M2,col="red")
newrepM2=data.frame(M2_av=c(min(M2_present$M2_av):max(M2_present$M2_av)))
confM2=predict(testLM_M2,newdata=newrepM2,interval="confidence")
predM2=predict(testLM_M2,newdata=newrepM2,interval="prediction")
confM2=as.data.frame(confM2)
predM2=as.data.frame(predM2)
lines(newrepM2$M2_av,confM2$lwr,col="red",lty=2)
lines(newrepM2$M2_av,confM2$upr,col="red",lty=2)
lines(newrepM2$M2_av,predM2$lwr,col="blue")
lines(newrepM2$M2_av,predM2$upr,col="blue")
text(M2_present$M2_av,M2_present$Age_Mid,labels=M2namebank,pos = 4, offset = 0.5, cex = 0.7)

This the plot that is created, with no lines for confidence and prediction.

rstudio