Continuing with the Mussels data, I will explain the method of interpreting linear regression by individual regression coefficients.

muss <- read.csv(url("http://cknudson.com/data/mussels.csv"))
mussModel <- lm(AvgAmmonia ~ AvgMass + attached, muss)
summary(mussModel)
## 
## Call:
## lm(formula = AvgAmmonia ~ AvgMass + attached, data = muss)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -2.019e-03 -5.240e-04 -5.959e-05  3.429e-04  2.526e-03 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.0011398  0.0005533   2.060     0.05 *  
## AvgMass       0.2392793  0.0215863  11.085 3.86e-11 ***
## attachedRock -0.0025629  0.0003931  -6.519 7.91e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.00103 on 25 degrees of freedom
## Multiple R-squared:  0.8574, Adjusted R-squared:  0.846 
## F-statistic: 75.18 on 2 and 25 DF,  p-value: 2.66e-11

The hypothesis tested is that after accounting for one predictor, the relationship between the other variable and the response variable will not follow a linear relationship. Both AvgMass and attachedRock had t-values that yielded low p-values. Because the p-values are low, we can reject the respective hypothesis and make the following statements:

Whether the mussel is attached to a rock or Amblema, we predict that the ammonia output will be 0.2392793 higher for every increase of one in average mass.

For any given average mass, we predict that the ammonia output will be 0.0025629 lower if the mussel is attached to a rock.

The R output also reveals some more interesting data to us. We have our two variables used to predict the ammonia output and these two variables yield an r-squared value of 0.8574. About 85% of our data can be explained by these two variables!

confint(mussModel)
##                      2.5 %       97.5 %
## (Intercept)   1.999745e-07  0.002279427
## AvgMass       1.948215e-01  0.283737200
## attachedRock -3.372584e-03 -0.001753235

We are 95% confident that for any given average mass, the ammonia output will be between (0.001753, 0.003370) lower if the mussel is attached to a rock. We are also 95% confident that whether the mussel is attached to a rock or Amblema, the ammonia output will be between (0.1948, 0.2837) higher for every increase of one in average mass.

If we select values for average mass and the attached variables, we can create a confidence interval for the mean ammonia output given those parameters.

Zebra <- data.frame(AvgMass = 0.028500, attached = "Rock")
ZebraConfy <- predict(mussModel, Zebra , interval = "confidence", level=0.95)
ZebraConfy
##           fit         lwr         upr
## 1 0.005396366 0.004814794 0.005977937

We are 95% confident that the mean average ammonia output for all Zebra mussels that are attached to rocks with masses of 0.0285 will lie between (0.004814, 0.005978).

If we would like to see the prediction interval (a confidence interval, but for only one Zebra mussel attached to a rock with mass 0.0285), we repeat these steps but swap the interval command to “prediction”.

ZebraPredy <- predict(mussModel, Zebra , interval = "prediction", level=0.95)
ZebraPredy
##           fit         lwr         upr
## 1 0.005396366 0.003196409 0.007596322

As expected, the prediction interval is wider.