# Estimated Mean and Confidence Interval and Predicted Value and Prediction Interval

This question comes from Ramsey and Schafer Statistical Sleuth, Second Edition, Chapter 7:

Immediately after slaughter the pH in postmortem muscle of a steer carcass is around 7.0-7.2. For a certain kind of meat processing to take place it is necessary for pH to decrease to 6.0 so an estimate is needed of the time after slaughter at which the pH reaches 6.0. To do so, ten steer carcasses were identified to have their immediate slaughter postmortem pH level taken, and then at one of 5 times after slaughter. Time is measured in hours. There are 10 obsevations.

I am trying to do the following in R:

1. Test whether the log of time after slaughter is a statistically significant predictor of postmoterm pH levels.

2. Report the estimated mean pH at 5 hours and its confidence interval.

3. Report the predicted pH at 5 hours and its prediction interval.

4. How long after slaughter would you expect the mean pH level to be 6.0?

My data is as follows:

   TIME   PH
1     1 7.02
2     1 6.93
3     2 6.42
4     2 6.51
5     4 6.07
6     4 5.99
7     6 5.59
8     6 5.80
9     8 5.51
10    8 5.36


For 1, my code is

mod2<-lm(PH~log(TIME), data=meat)
summary(mod2)


log(TIME) has a p-value of 2.70e-08, which is statistically significant at a 5% confidence level.

However, I am confused as to how to calculate 2, 3, and 4.

For 2 and 3, I'm specifically not totally clear on the difference between what is being asked. I calculated the following:

y <- predict(mod2,newdata=data.frame(TIME=c(5)))


which, if I am not mistaken, is the predicted pH at 5 hours, right?

The prediction and confidence intervals can be calculated by some variation of the following, if I am not mistaken:

predict(..., interval = "confidence")
predict(..., interval = "prediction")


But what is the difference between, and how would one calculate, the estimated vs predicted pH at 5 hours (and their associated intervals)?

As for 4., I'm just totally unsure of how to calculate it.

I would greatly appreciate it if people could please take the time to clarify my misunderstandings and demonstrate how to calculate them using R.

## 1 Answer

you are right about the formulas for prediction and confidence intervals.

The estimated mean ph and the predicted ph value will be the same but the confidence intervals will be narrower than the prediction intervals. Confidence intervals tell us the uncertainty in estimating population mean from a sample. If the sample is larger, the confidence interval will be narrower. Prediction intervals are used for individual new observations. They have to account for the uncertainty in the mean plus the spread in the data, hence the prediction intervals are wider.

For question 4, I guess this would work:

df = data.frame(time = c(1,1,2,2,4,4,6,6,8,8),
ph = c(7.02,6.93,6.42,6.51,6.07,5.99,5.59,5.8,5.51,5.36) )

mod1 = lm(log(time)~ph, data = df)
summary(mod1)
exp(predict(mod1,newdata = data.frame(ph = c(6) ), interval = 'confidence' )
)

output (hours):
fit      lwr      upr
3.867355 3.556355 4.205552