Learning Log 6

This learning log will include the test, confidence interval, and prediction interval for the mussels data.

Zebra<-read.csv((url("http://cknudson.com/data/mussels.csv")))
attach(Zebra)

Test

H0:Bj=0 HA:Bj= not 0

The null hypothesis H0= 0, which means that the relationship between the predictor variable,AvgAmmonia, and the response variables, AvgMass and attachedRock, is not significant, and the alternative hypothesis HA is not equal to 0, which means that the relationship between the predictor variable and the response variables is significant.

model1 <-  lm(AvgAmmonia ~ AvgMass + attached)
model1
## 
## Call:
## lm(formula = AvgAmmonia ~ AvgMass + attached)
## 
## Coefficients:
##  (Intercept)       AvgMass  attachedRock  
##     0.001140      0.239279     -0.002563
summary(model1)
## 
## 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

The summary() command showed us that the p values for AvgMass and attachedRock both have p values less then .05 so we would reject the null hypothesis and accept the alternative hypothesis that the relationship between the Avg Ammonia produced by a zebra mussel does have a significant relationship with the Avg mass of the mussel and whether it is attached to a rock or an amblema mussel.

This same command tells us that the Multiple R-squared is .8574 which means that the two predictor variables can explain 85.74% of the Avg Ammonia produced by a zebra mussel.

The model1 gives us the linear eq that the AvgAmmonia= .001140+.239279AvgMass-.002563attachedRock. The response variable is the AvgAmmonia which is the average ammonia (mg/h) released by zebra mussels. The predict variables are AvgMass, the average mass of the zebra mussel in grams, and attached, which is if the mussel is attached to a rock or not. This equation means that if the AvgMass remains the same that the AvgAmmonia would decrease by .002563 mg/h if attached to a rock. It also means that if the variable attached remains the same the AvgAmmonia would increase by .239279 mg/h per gram of zebra mussel.

Confidence Interval

The following command will give the confidence interval for the liner regression model AvgAmmonia= AvgMass + attached.

confint(model1)
##                      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 if the AvgMass remains the same that the AvgAmmonia decrease between 3.372584e^-03 mg/h to .00175 mg/h if attached to a rock. We are also 95% confident that if the variable attached remains the same that the AvgAmmonia would increase by .1948 mg/h to .2837 mg/h per gram of zebra mussel.

We can estimate the avg ammonia produced by a zebra mussel at a certain mass and if it is attached to a rock or not by using a confidence interval.

newdata <- data.frame( AvgMass=.10 , attached="Rock")
conf<- predict(model1,newdata,interval = "confidence")
conf
##          fit        lwr      upr
## 1 0.02250484 0.01908667 0.025923

The command newdata tells the code that we want to use a mussel that is .1 grams big and is attached to a rock. The command predy tells the code to find the prediction interval for this newdata.

With the results from this we are 95% confident that for any given zebra mussel that is .1 grams and attach to a rock that it will produce an average amount of ammonia between .019 mg/h and .0259 mg/h.

Prediction Interval

We can also estimate the avg ammonia produced by a zebra mussel at a certain mass and if it is attached to a rock or not.

newdata <- data.frame( AvgMass=.10 , attached="Rock")
predy<- predict(model1,newdata,interval = "predict")
predy
##          fit        lwr        upr
## 1 0.02250484 0.01848172 0.02652795

With the results from this we are 95% confident that for any given zebra mussel that is .1 grams and attach to a rock that it will produce an average amount of ammonia between .0185 mg/h and .0265 mg/h.

As we can clearly see the prediction interval is wider than the confidence interval.