Asian shore crab (Hemigrapsus sanguineus)


Welcome to this overview of our code. I hope it helps you understand what we have been doing and how R works. Also I am a nerd, but I have no experience with Rmarkdown (the package used to make this .html) and was willing to try this out. Tell me if it’s terrible.

We have received a delightful paper about Hemigrapsus sanguineus, commonly known as the Asian shore crab. The authors have provided both their data and a README.txt file. In this we can see more detailed explanations of the variables in the data:


Variable Explanation
CrabID A unique identifier for each individual crab analyzed
Site State abbreviation where crabs were collected and measured
Temp Temperature in °C during measurements
Volume Volume of the experimental chamber in ml
Minutes Duration of each metabolic rate trial in minutes
Final oxygen concentration Percent O2 concentration at the end of each trial
Metabolic rate Metabolic rate (O2 consumption in ml/h) per crab in the experimental chamber
Sex Sex of the experimental crab
NumberLimbMissing Number of limbs missing on experimental crabs
NumberLimbRegen Number of missing limbs that were being regenerated
TotalWetMass Fresh mass of the experimental crabs in grams
PerCrabDryMass Dry mass of the experimental crabs grams

Reading the data

To get started we must first read in our data set. Remember to save the file in the directory that you will use. You can set the working directory either by clicking on Session > Set Working Directory > Choose Directory, or you can use the function setwd(). Just enter the path to the working directory in quotation marks. This helps R to understand where to retrieve the file and to save your outputs in.

You can provide the delimiter with the argument sep=. If your table has headers (variable names in the first row) than you can write header=TRUE. Use a short and logical title for your dataset. Note that it will show up in the R Environment. Clicking on this dataset will do the exact same as using the function View(). Make sure that your data looks correct.

Crab<-read.csv(file="Data_for_Dryad.csv", sep=",", header=T)

View(Crab)

Question 1

A

Three sites along the east coast of the USA were chosen for data collection. Only the most northern site (New Hampshire) is located in the Gulf of Maine. The authors do not provide reasoning for the chosen sites.

  • Authors might have chosen for these locations to include at latitudinal gradient and thus a temperature gradients.Authors said that meeting the upper limits of temperature tolerance can lead to reduced fitness in the invasive crabs, because of higher metabolic rate being mismatched to energy demand.

  • Authors might want to assess the spread northwards from New Jersey.

B

Temperature is used as a predictor variable to predict changes in metabolic rate of the crabs. We assume that the authors use temperature as a proxy for climate change. The temperature is measured in the boxes where crabs were kept during the experiment. There is no documented comparison between in situ and experimental box temperature, which could have proven similar temperature than in the experiment.

C

The dataset only shows us 181 observations. This is different from the total amount mentioned in the paper (215 individuals). An explanation for why there is a difference in the number of dataset and the number of collected crabs is that smaller crabs were pooled together.

We can look at the sample sizes per Site and Sex. The with() function allows you to specify a dataset and then use another function in it. In this case you only have to mention it once.

with(Crab, table(Site, Sex))
##     Sex
## Site Female Male Multiple
##   CT     32   16        8
##   NH     29   23        6
##   NJ     34   27        6

The samples are quite balanced over the different locations. But if we look at the different sexes, Connecticut has half as many males and females.

D

As we can see in table above the variable Sex has 3 categories, Female, Male and Multiple. The category Multiple includes the crabs that had a length of ~10 mm CW or smaller and thus have been pooled to be able to measure the metabolic rate (2-4 individuals).

The category Multiple is never mentioned in the results section of the paper. In the first paragraph they mention significant interactions between the effects of body size (PerCrabDryMass in the dataset) and Sex

E

These variables are dependent upon each other since more missing limbs means a higher probability of finding regenerating limbs on the crab. With the function cor() we can assess the dependency by testing for correlation. But first we need to check if our data is normally distributed.

shapiro.test(Crab$NumberLimbMissing)
## 
##  Shapiro-Wilk normality test
## 
## data:  Crab$NumberLimbMissing
## W = 0.72276, p-value < 2.2e-16
shapiro.test(Crab$NumberLimbRegen)
## 
##  Shapiro-Wilk normality test
## 
## data:  Crab$NumberLimbRegen
## W = 0.44434, p-value < 2.2e-16

Both variables have a p-value that is smaller than 0.05. This means we cannot assume normality. In this case we have to add the argument method="spearman" to our correlation test.

Simply fill in the two variables that you want to test.

cor(Crab$NumberLimbMissing,Crab$NumberLimbRegen, method="spearman")
## [1] 0.5157352

The correlation value represents a moderate positive correlation. We can also plot this:

## integer(0)

Note that there are a lot of 0 values. We can remove the 0’s and at the correlation once more. We can make a subset(). The != means that it includes all but the given value.

nozero<-subset(Crab, NumberLimbMissing!=0 & NumberLimbRegen!=0)

cor(nozero$NumberLimbMissing,nozero$NumberLimbRegen, method="spearman") 
## [1] 0.9256206
plot(nozero$NumberLimbMissing~nozero$NumberLimbRegen)+abline(0,1)

## integer(0)

Now we find a very strong positive correlation of 0.926. This means that the higher one of the variables, the higher the other variable will be. So they are not independent.

As we can see in the figure above, there are also some values between 0 and 1. Those are quite surprising, but can be attributed to the fact that the authors sometimes pooled the crabs and probably averaged all the measurements taken. We can look at the values for both variables.

with(Crab,table(Site, NumberLimbMissing))
##     NumberLimbMissing
## Site  0 0.5 0.67  1 1.3 1.5  2  3  4 4.5  5  6
##   CT 21   4    1 12   0   2  9  3  2   1  0  1
##   NH 42   0    1 11   0   0  2  2  0   0  0  0
##   NJ 31   1    0 17   1   1 11  3  0   0  1  1
with(Crab,table(Site, NumberLimbRegen))
##     NumberLimbRegen
## Site  0 0.3 0.5  1 1.5  2  3  4  6
##   CT 44   1   1  4   1  3  1  1  0
##   NH 56   0   0  2   0  0  0  0  0
##   NJ 47   0   1 10   0  6  2  0  1
F
summary(Crab$PerCrabDryMass) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.3772  0.7455  1.0694  1.2930  5.9711

From the summary we can tell that there is a value of 0 for PerCrabDryMass. When we look at this observation in the dataset we can see a value for TotalWetMass, it would seem logical that a crab with wet mass should have some dry mass as well.

G

The distribution of a variable can be plotted in a histogram using the hist() function.

hist(Crab$Final.oxygen.concentration)

Another option is plotting the density() which is a smoothed version of a histogram.

plot(density(Crab$Final.oxygen.concentration))+
  abline(v=mean(Crab$Final.oxygen.concentration),col="red")

The data for Final.oxygen.concentration seems to be left skewed.


Question 2

A

Step() function used by authors for model selection

summary(lm(Metabolic.rate ~
             NumberLimbMissing+NumberLimbRegen+PerCrabDryMass+Sex+Site+Temp,data=Crab))
## 
## Call:
## lm(formula = Metabolic.rate ~ NumberLimbMissing + NumberLimbRegen + 
##     PerCrabDryMass + Sex + Site + Temp, data = Crab)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40771 -0.05148 -0.01513  0.03928  0.42908 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       -0.066553   0.085399  -0.779  0.43686    
## NumberLimbMissing  0.012454   0.008146   1.529  0.12814    
## NumberLimbRegen   -0.015614   0.011690  -1.336  0.18340    
## PerCrabDryMass     0.124727   0.008351  14.935  < 2e-16 ***
## SexMale           -0.024592   0.016550  -1.486  0.13915    
## SexMultiple       -0.115506   0.026701  -4.326 2.57e-05 ***
## SiteNH             0.009466   0.024973   0.379  0.70514    
## SiteNJ            -0.022378   0.021580  -1.037  0.30122    
## Temp               0.012035   0.003982   3.023  0.00289 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1012 on 172 degrees of freedom
## Multiple R-squared:  0.6831, Adjusted R-squared:  0.6684 
## F-statistic: 46.35 on 8 and 172 DF,  p-value: < 2.2e-16
steptest<-step(lm(Metabolic.rate ~
                    (PerCrabDryMass+Sex+Site+Temp)^2,data=Crab))
## Start:  AIC=-821.65
## Metabolic.rate ~ (PerCrabDryMass + Sex + Site + Temp)^2
## 
##                       Df Sum of Sq    RSS     AIC
## - Sex:Site             4  0.014833 1.5644 -827.93
## - Sex:Temp             2  0.013185 1.5628 -824.12
## - PerCrabDryMass:Temp  1  0.015317 1.5649 -821.87
## <none>                             1.5496 -821.65
## - PerCrabDryMass:Sex   2  0.039864 1.5894 -821.06
## - PerCrabDryMass:Site  2  0.040647 1.5902 -820.97
## - Site:Temp            2  0.108573 1.6581 -813.40
## 
## Step:  AIC=-827.93
## Metabolic.rate ~ PerCrabDryMass + Sex + Site + Temp + PerCrabDryMass:Sex + 
##     PerCrabDryMass:Site + PerCrabDryMass:Temp + Sex:Temp + Site:Temp
## 
##                       Df Sum of Sq    RSS     AIC
## - Sex:Temp             2  0.005187 1.5696 -831.33
## - PerCrabDryMass:Temp  1  0.011438 1.5758 -828.61
## <none>                             1.5644 -827.93
## - PerCrabDryMass:Site  2  0.034996 1.5994 -827.93
## - PerCrabDryMass:Sex   2  0.047472 1.6119 -826.52
## - Site:Temp            2  0.104821 1.6692 -820.19
## 
## Step:  AIC=-831.33
## Metabolic.rate ~ PerCrabDryMass + Sex + Site + Temp + PerCrabDryMass:Sex + 
##     PerCrabDryMass:Site + PerCrabDryMass:Temp + Site:Temp
## 
##                       Df Sum of Sq    RSS     AIC
## - PerCrabDryMass:Temp  1  0.013351 1.5829 -831.80
## <none>                             1.5696 -831.33
## - PerCrabDryMass:Site  2  0.035774 1.6054 -831.25
## - PerCrabDryMass:Sex   2  0.049557 1.6192 -829.70
## - Site:Temp            2  0.106393 1.6760 -823.46
## 
## Step:  AIC=-831.8
## Metabolic.rate ~ PerCrabDryMass + Sex + Site + Temp + PerCrabDryMass:Sex + 
##     PerCrabDryMass:Site + Site:Temp
## 
##                       Df Sum of Sq    RSS     AIC
## - PerCrabDryMass:Site  2  0.024345 1.6073 -833.04
## <none>                             1.5829 -831.80
## - PerCrabDryMass:Sex   2  0.046337 1.6293 -830.58
## - Site:Temp            2  0.114761 1.6977 -823.13
## 
## Step:  AIC=-833.04
## Metabolic.rate ~ PerCrabDryMass + Sex + Site + Temp + PerCrabDryMass:Sex + 
##     Site:Temp
## 
##                      Df Sum of Sq    RSS     AIC
## <none>                            1.6073 -833.04
## - PerCrabDryMass:Sex  2  0.054711 1.6620 -830.98
## - Site:Temp           2  0.119835 1.7271 -824.02
summary(steptest)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + Sex + Site + Temp + 
##     PerCrabDryMass:Sex + Site:Temp, data = Crab)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.34226 -0.05205 -0.01388  0.03472  0.45698 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 4.18368    1.44500   2.895  0.00429 ** 
## PerCrabDryMass              0.14493    0.01576   9.196  < 2e-16 ***
## SexMale                     0.01586    0.02473   0.641  0.52218    
## SexMultiple                -0.14446    0.06938  -2.082  0.03882 *  
## SiteNH                     -4.14845    1.44967  -2.862  0.00474 ** 
## SiteNJ                     -4.55717    1.45607  -3.130  0.00206 ** 
## Temp                       -0.18714    0.06745  -2.775  0.00615 ** 
## PerCrabDryMass:SexMale     -0.03440    0.01707  -2.015  0.04546 *  
## PerCrabDryMass:SexMultiple  0.28192    0.25255   1.116  0.26588    
## SiteNH:Temp                 0.19331    0.06781   2.851  0.00490 ** 
## SiteNJ:Temp                 0.21019    0.06792   3.095  0.00230 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09723 on 170 degrees of freedom
## Multiple R-squared:  0.7108, Adjusted R-squared:  0.6938 
## F-statistic: 41.79 on 10 and 170 DF,  p-value: < 2.2e-16

Question 3

A

We can make a subset() of only the female crabs in New Jersey. The == means that it must be equal to the given value.

NJ_f<-subset(Crab, Site=="NJ"& Sex=="Female")

As mentioned in section 3.1 of the paper they have looked at the metabolic rate with the predictor variables dry body mass, missing limbs, regenerating limbs & the temperature with all interactions included in the (linear) model. From this I would assume that they looked at all multi-interactions as well. That would look like this.

model_njf<-lm(Metabolic.rate~PerCrabDryMass*NumberLimbMissing*NumberLimbRegen*Temp, data=NJ_f)

Then they used the step() function to select the best fitting model from all the interactions that are possible in the above model. If you assign the command to an object, it will automatically save the best model in that object. If you prefer looking at the complete output of step() just remove the object name and the arrow.

modelnjf<-step(model_njf)
summary(modelnjf) 
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + NumberLimbRegen + 
##     Temp + PerCrabDryMass:NumberLimbRegen + PerCrabDryMass:Temp + 
##     NumberLimbRegen:Temp + PerCrabDryMass:NumberLimbRegen:Temp, 
##     data = NJ_f)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.16147 -0.05648 -0.00792  0.02207  0.32320 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)   
## (Intercept)                         -2.11587    0.82142  -2.576  0.01603 * 
## PerCrabDryMass                       1.72869    0.78253   2.209  0.03618 * 
## NumberLimbRegen                      2.72191    1.56165   1.743  0.09316 . 
## Temp                                 0.09883    0.03522   2.806  0.00937 **
## PerCrabDryMass:NumberLimbRegen      -1.86696    1.24783  -1.496  0.14665   
## PerCrabDryMass:Temp                 -0.06697    0.03235  -2.070  0.04850 * 
## NumberLimbRegen:Temp                -0.11895    0.06593  -1.804  0.08277 . 
## PerCrabDryMass:NumberLimbRegen:Temp  0.07911    0.05092   1.554  0.13235   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1111 on 26 degrees of freedom
## Multiple R-squared:  0.6036, Adjusted R-squared:  0.4969 
## F-statistic: 5.656 on 7 and 26 DF,  p-value: 0.0004765

This does not seem to align with what the authors have written, so maybe it would make more sense to look at only two way interactions.

c_model_njf<-lm(Metabolic.rate~(PerCrabDryMass+NumberLimbMissing+NumberLimbRegen+Temp)^2, data=NJ_f)
cmodelnjf<-step(c_model_njf)
summary(cmodelnjf)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + NumberLimbMissing + 
##     NumberLimbRegen, data = NJ_f)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.11858 -0.06376 -0.02334  0.02580  0.41231 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        0.12306    0.04298   2.863  0.00759 ** 
## PerCrabDryMass     0.19081    0.03696   5.163 1.47e-05 ***
## NumberLimbMissing  0.07613    0.03545   2.148  0.03992 *  
## NumberLimbRegen   -0.09459    0.03847  -2.459  0.01994 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1136 on 30 degrees of freedom
## Multiple R-squared:  0.5216, Adjusted R-squared:  0.4738 
## F-statistic:  10.9 on 3 and 30 DF,  p-value: 5.226e-05

The coefficients are now similar to the ones in the paper. The 0.191 estimate means that for every 1 gram increase in mass, the metabolic rate rises with 0.191 ml O2/h-1. We can plot it similar to how it is presented in the paper.

B

Now we can subset only the male crabs in New Jersey like we did with the female crabs earlier.

NJ_m<-subset(Crab, Site=="NJ" & Sex=="Male")

As in question 3.A we can look at the model with all the two way interactions.

c_model_njm<-lm(Metabolic.rate~(PerCrabDryMass+NumberLimbMissing+NumberLimbRegen+Temp)^2, data=NJ_m)
modelnjm<-step(c_model_njm)
summary(modelnjm)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + Temp + PerCrabDryMass:Temp, 
##     data = NJ_m)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.176900 -0.054090  0.006392  0.036417  0.135822 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         -1.76797    0.35502  -4.980 4.90e-05 ***
## PerCrabDryMass       1.10595    0.27623   4.004 0.000557 ***
## Temp                 0.08223    0.01477   5.567 1.16e-05 ***
## PerCrabDryMass:Temp -0.04019    0.01091  -3.682 0.001235 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07191 on 23 degrees of freedom
## Multiple R-squared:  0.8721, Adjusted R-squared:  0.8554 
## F-statistic: 52.26 on 3 and 23 DF,  p-value: 1.994e-10

The 1.106 estimate means that for every 1 gram increase in mass, the metabolic rate rises with 1.106 ml O2/h-1. This corresponds to what is written in the paper.

The coefficient of the male crabs is almost tenfold larger than the coefficient of the female crabs.

C

In question A I think I already did this. But I might not completely understand the question that they ask. Maybe in A it was just supposed to use only the text as an indication of what they have put in the model.

To use the dredge() function, we must load the package MuMIn again.

Now we will simply use the same lm() formula as in question 3.A and add it into the dredge() function.

library(MuMIn)
## Warning: package 'MuMIn' was built under R version 4.2.2
dredge(lm(Metabolic.rate~(PerCrabDryMass+NumberLimbMissing+NumberLimbRegen+Temp)^2, data=NJ_f, na.action=na.fail))
## Fixed term is "(Intercept)"

The lowest AIC score is not the model they used, but the model that was used is within the delta 2 from the top ranked model. The logical thing to do would be to select the simplest model, which would include only the dry mass & temperature. So why did it not get selected by the step function. I do not know the answer yet.


Question 4

A

We subset only the female crabs in New Hampshire

NH_f<-subset(Crab, Site=="NH" & Sex=="Female")

In the text they mention predictors dry mass, missing limbs, interaction missing limbs & temperature and the separate effect (non-significant) of temperature for female crabs is mentioned. So this is what we will include in the model.

modelnhf<-lm(Metabolic.rate~PerCrabDryMass+NumberLimbMissing+NumberLimbMissing:Temp+Temp, data=NH_f)

summary(modelnhf)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + NumberLimbMissing + 
##     NumberLimbMissing:Temp + Temp, data = NH_f)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.13087 -0.04556 -0.00802  0.04133  0.18771 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            -0.036752   0.125205  -0.294   0.7716    
## PerCrabDryMass          0.171574   0.018348   9.351 1.79e-09 ***
## NumberLimbMissing       0.479449   0.196058   2.445   0.0222 *  
## Temp                    0.008534   0.006879   1.241   0.2267    
## NumberLimbMissing:Temp -0.029082   0.011830  -2.458   0.0216 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.08027 on 24 degrees of freedom
## Multiple R-squared:  0.7881, Adjusted R-squared:  0.7528 
## F-statistic: 22.32 on 4 and 24 DF,  p-value: 8.563e-08

The coefficients can be interpreted as followed; for every 1 gram increase in dry mass, the metabolic rate rises with 0.172 ml O2/h-1 and for every 1 degrees increase in temperature the metabolic rate rises with 0.009 ml O2/h-1.

Now we are sub-setting only the male crabs in New Hampshire.

NH_m<-subset(Crab, Site=="NH" & Sex=="Male")

In the text the mention dry mass and dry mass:temperature interaction only for male crabs.

modelnhm<-lm(Metabolic.rate~PerCrabDryMass+PerCrabDryMass:Temp, data=NH_m)

summary(modelnhm)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + PerCrabDryMass:Temp, 
##     data = NH_m)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.21076 -0.08372 -0.03482  0.07306  0.36087 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          0.172285   0.044031   3.913 0.000863 ***
## PerCrabDryMass      -0.258947   0.156633  -1.653 0.113901    
## PerCrabDryMass:Temp  0.020031   0.008368   2.394 0.026594 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1391 on 20 degrees of freedom
## Multiple R-squared:  0.7321, Adjusted R-squared:  0.7053 
## F-statistic: 27.32 on 2 and 20 DF,  p-value: 1.907e-06

This does not show the same results so I assumed that they must have included the separate effect of temperature once again. Even though it is not stated.

modelnhm2<-lm(Metabolic.rate~PerCrabDryMass+PerCrabDryMass:Temp+Temp, data=NH_m)

summary(modelnhm2)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + PerCrabDryMass:Temp + 
##     Temp, data = NH_m)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.23989 -0.07997 -0.00350  0.05187  0.33983 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)   
## (Intercept)          0.75760    0.36941   2.051  0.05433 . 
## PerCrabDryMass      -0.50236    0.21463  -2.341  0.03031 * 
## Temp                -0.03118    0.01955  -1.595  0.12721   
## PerCrabDryMass:Temp  0.03300    0.01145   2.882  0.00955 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.134 on 19 degrees of freedom
## Multiple R-squared:  0.7637, Adjusted R-squared:  0.7264 
## F-statistic: 20.47 on 3 and 19 DF,  p-value: 3.577e-06

The coefficients can be interpreted as followed; for every 1 gram increase in dry mass, the metabolic rate decreases with 0.502 ml O2/h-1 and for every 1 degrees increase in temperature the metabolic rate decreases with 0.031 ml O2/h-1.

B

We can either look at the paper and compare, but we can also look at the coefficients produced by the models used in the paper. We already have those for NJ and NH, but we can make them quite quick for CT as well.

CT_f<-subset(Crab, Site=="CT" & Sex=="Female")

CT_m<-subset(Crab, Site=="CT" & Sex=="Male")

They only included dry mass in the model for female crabs in CT.

modelctf<-lm(Metabolic.rate~PerCrabDryMass, data=CT_f)

summary(modelctf)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass, data = CT_f)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.09825 -0.04067 -0.02108  0.03573  0.25182 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.15130    0.03149   4.804 4.05e-05 ***
## PerCrabDryMass  0.18433    0.04473   4.121 0.000273 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07957 on 30 degrees of freedom
## Multiple R-squared:  0.3615, Adjusted R-squared:  0.3402 
## F-statistic: 16.99 on 1 and 30 DF,  p-value: 0.0002733

For the male crabs they included dry mass, and both regenerating and missing limbs.

modelctm<-lm(Metabolic.rate~PerCrabDryMass+NumberLimbMissing+NumberLimbRegen, data=CT_m)

summary(modelctm)
## 
## Call:
## lm(formula = Metabolic.rate ~ PerCrabDryMass + NumberLimbMissing + 
##     NumberLimbRegen, data = CT_m)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.061718 -0.033085 -0.023215  0.003821  0.189733 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        0.05924    0.04994   1.186 0.258464    
## PerCrabDryMass     0.32404    0.06063   5.345 0.000175 ***
## NumberLimbMissing  0.03759    0.02795   1.345 0.203589    
## NumberLimbRegen   -0.10118    0.04190  -2.415 0.032641 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07669 on 12 degrees of freedom
## Multiple R-squared:   0.71,  Adjusted R-squared:  0.6375 
## F-statistic: 9.792 on 3 and 12 DF,  p-value: 0.001513

Now we can put all these estimate for the different sites and sexes in a little table and maybe plot it so it is easier to compare them.

## Warning: package 'knitr' was built under R version 4.2.2
Site Sex Estimate
NJ Female 0.191
NJ Male 1.106
NH Female 0.172
NH Male -0.502
CT Female 0.184
CT Male 0.324

From this we can see that the female crabs have similar increase in metabolic rate as a function of mass over the different locations. Male crabs show much higher variability.

C

Question 5

A

Now we have to combine New Jersey and New Hampshire in a dataset. And then we can plot it as follows.

ECT<-subset(Crab, Site=="NJ"|Site=="NH")

plot(ECT$Metabolic.rate, ECT$Temp,
     xlab="Metabolic rate (ml O2-1 h-1)", ylab= "Temperature")+
  abline(lm(ECT$Metabolic.rate~ECT$Temp))

## integer(0)

As we can see, the data does not look linear at all. We can look at the residual plots for this model.

par(mfrow=c(2,2))

plot(glm(Metabolic.rate~Temp, data=ECT))

We can approach this non-linearity by doing a logistic regression maybe.

B

Question 6


Welcome to the end of the document, glad you made it here.