muss<-read.csv(url("http://cknudson.com/data/mussels.csv"))
head(muss)
##   GroupID dry.mass count attached lipid protein carbo  ash Kcal ammonia
## 1       1     0.55    20     Rock  8.14   47.43 21.59 5.51 3.61    0.07
## 2       2     0.45    19     Rock  9.34   53.89 23.41 6.34 4.06    0.07
## 3       3     0.37    20     Rock  9.12   49.01 21.10 5.63 3.74    0.07
## 4       4     0.63    20     Rock 10.32   49.25 16.55 5.41 3.66    0.11
## 5       5     0.57    20     Rock 10.08   50.17 17.51 6.10 3.72    0.11
## 6       6     0.57    22     Rock 10.83   53.84 19.97 6.36 4.04    0.11
##     O2 AvgAmmonia   AvgO2  AvgMass
## 1 0.82 0.00350000 0.04100 0.027500
## 2 0.70 0.00368421 0.03684 0.023684
## 3 0.62 0.00350000 0.03100 0.018500
## 4 0.89 0.00550000 0.04450 0.031500
## 5 1.09 0.00550000 0.05450 0.028500
## 6 1.00 0.00500000 0.04545 0.025909
attach(muss)
summary(muss)
##     GroupID         dry.mass          count          attached 
##  Min.   : 1.00   Min.   :0.3000   Min.   :19.00   Amblema:13  
##  1st Qu.: 7.75   1st Qu.:0.4375   1st Qu.:20.00   Rock   :15  
##  Median :14.50   Median :0.5450   Median :21.50               
##  Mean   :14.93   Mean   :0.5836   Mean   :27.79               
##  3rd Qu.:22.25   3rd Qu.:0.6425   3rd Qu.:31.00               
##  Max.   :30.00   Max.   :1.1600   Max.   :72.00               
##                                                               
##      lipid           protein          carbo            ash       
##  Min.   : 6.500   Min.   :43.49   Min.   : 9.97   Min.   :4.620  
##  1st Qu.: 8.250   1st Qu.:50.05   1st Qu.:17.11   1st Qu.:5.395  
##  Median : 9.405   Median :53.94   Median :20.09   Median :5.550  
##  Mean   : 9.210   Mean   :54.91   Mean   :19.96   Mean   :5.663  
##  3rd Qu.:10.195   3rd Qu.:58.90   3rd Qu.:21.96   3rd Qu.:6.075  
##  Max.   :10.830   Max.   :71.94   Max.   :29.89   Max.   :6.570  
##                   NA's   :1       NA's   :1       NA's   :2      
##       Kcal          ammonia             O2           AvgAmmonia      
##  Min.   :3.270   Min.   :0.0500   Min.   :0.3800   Min.   :0.002500  
##  1st Qu.:3.743   1st Qu.:0.0875   1st Qu.:0.7975   1st Qu.:0.003500  
##  Median :4.005   Median :0.1100   Median :0.9250   Median :0.004749  
##  Mean   :3.955   Mean   :0.1443   Mean   :1.2157   Mean   :0.005296  
##  3rd Qu.:4.110   3rd Qu.:0.1875   3rd Qu.:1.4125   3rd Qu.:0.005647  
##  Max.   :4.610   Max.   :0.4100   Max.   :2.7700   Max.   :0.012963  
##  NA's   :2                                                           
##      AvgO2            AvgMass        
##  Min.   :0.01458   Min.   :0.006389  
##  1st Qu.:0.03100   1st Qu.:0.016885  
##  Median :0.04439   Median :0.024048  
##  Mean   :0.04564   Mean   :0.023107  
##  3rd Qu.:0.04939   3rd Qu.:0.027500  
##  Max.   :0.09571   Max.   :0.047826  
## 

We create a linear model to find the relationship that average mass and whether or not the mussel is attached to a rock have with average ammonia.

(mod <- lm(AvgAmmonia ~ AvgMass + attached))
## 
## Call:
## lm(formula = AvgAmmonia ~ AvgMass + attached)
## 
## Coefficients:
##  (Intercept)       AvgMass  attachedRock  
##     0.001140      0.239279     -0.002563

Then, our regression equation is: $$hat{AvgAmmonia}=0.001140

We can conduct a hypothesis test to determine whether average mass and average ammonia have a linear relatiohsip, regardless of if the mussel is attached to a rock or not.

summary(mod)
## 
## Call:
## lm(formula = AvgAmmonia ~ AvgMass + attached)
## 
## 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
confint(mod)
##                      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 given a constant average mass, we predict the average ammonia will increase between \(-3.372584\times 10^{-3}\) and \(-0.001753235\) if the mussel is attached to a rock.