Dataset Processing

Import data and start processing the data.

dataset <- read.csv('McNab2008.csv')
# tidyverse
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.6     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
#summarize 

dataset <- dataset %>%
  mutate(log_BMR = log(BMR..kJ.h.))

mean_BMR_Climate <- dataset %>%
  group_by(Climateb) %>%
  summarize(mean_log_BMR = mean(log_BMR))

show(mean_BMR_Climate)
## # A tibble: 6 x 2
##   Climateb mean_log_BMR
##   <chr>           <dbl>
## 1 P                3.19
## 2 T                1.04
## 3 T/TR             1.45
## 4 TR               1.05
## 5 W                4.04
## 6 Y                3.41
#box plot of mammals in different climates with their logged BMR
BMR_climate <- ggplot(dataset, aes(x = Climateb, y = log_BMR, fill = Climateb)) +
 geom_boxplot(aes(fill = Climateb)) +
  stat_summary(fun = mean)

BMR_climate
## Warning: Removed 6 rows containing missing values (geom_segment).

#box plot of mammals in different climates with their logged BMR/logged mass

BMR_logged <- ggplot(dataset, aes(x = Climateb, y = log_BMR/log(Mass..g.), fill = Climateb)) +
 geom_boxplot(aes(fill = Climateb)) +
  stat_summary(fun = mean)

BMR_logged
## Warning: Removed 6 rows containing missing values (geom_segment).

#count number of species in each climate
count_number_sp <- dataset %>%
  count(Climateb)
show(count_number_sp)
##   Climateb   n
## 1        P  14
## 2        T 333
## 3     T/TR  58
## 4       TR 215
## 5        W  17
## 6        Y   1
#the simple mean BMR across all the climates, no log or anything
mean_BMR <- dataset %>%
  group_by(Climateb) %>%
  summarize (mean_BMR = mean(BMR..kJ.h.))

#no need to plot the diagram, just showing all the data should be enough
show(mean_BMR)
## # A tibble: 6 x 2
##   Climateb mean_BMR
##   <chr>       <dbl>
## 1 P           249. 
## 2 T            84.8
## 3 T/TR         31.1
## 4 TR           15.9
## 5 W           125. 
## 6 Y            30.2
# plot for the logged BMR in relation to mass for the different climates
ggplot(dataset, aes(x = Mass..g., y = log_BMR, color = Climateb)) + geom_point()+ 
  geom_smooth( method = lm) +
  xlab( 'Mass/ g') +
  ylab( 'logged BMR')
## `geom_smooth()` using formula 'y ~ x'

 # try logged BMR with logged mass
ggplot(dataset, aes(x = log(Mass..g.), y = log_BMR, color = Climateb)) +  
  geom_point() +
  geom_smooth( method = lm) +
  xlab( 'logged Mass') +
  ylab( 'logged BMR')
## `geom_smooth()` using formula 'y ~ x'

#create a dataframe of only polar climate
polar <- dataset %>%
  filter( Climateb == 'P')
#get the slope and intercept
lm_P <- lm(log_BMR ~ log(Mass..g.), polar)
summary(lm_P)
## 
## Call:
## lm(formula = log_BMR ~ log(Mass..g.), data = polar)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44954 -0.24985 -0.06274  0.25420  0.41525 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -2.02012    0.18059  -11.19 1.05e-07 ***
## log(Mass..g.)  0.69282    0.02155   32.15 5.18e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2984 on 12 degrees of freedom
## Multiple R-squared:  0.9885, Adjusted R-squared:  0.9876 
## F-statistic:  1034 on 1 and 12 DF,  p-value: 5.176e-13
#create a dataframe of only temperate climate
temperate <- dataset %>%
  filter( Climateb == 'T')
#get the slope and intercept
lm_T <- lm(log_BMR ~ log(Mass..g.), temperate)
summary(lm_T)
## 
## Call:
## lm(formula = log_BMR ~ log(Mass..g.), data = temperate)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.03790 -0.25211 -0.04813  0.23062  2.57926 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -2.656510   0.051816  -51.27   <2e-16 ***
## log(Mass..g.)  0.738188   0.009327   79.15   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4081 on 331 degrees of freedom
## Multiple R-squared:  0.9498, Adjusted R-squared:  0.9497 
## F-statistic:  6264 on 1 and 331 DF,  p-value: < 2.2e-16
#create a dataframe of only temperate/tropical climate
temperate_tropical <- dataset %>%
  filter( Climateb == 'T/TR')
#get the slope and intercept
lm_TTR <- lm(log_BMR ~ log(Mass..g.), temperate_tropical)
summary(lm_TTR)
## 
## Call:
## lm(formula = log_BMR ~ log(Mass..g.), data = temperate_tropical)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.01865 -0.20610 -0.01281  0.18431  0.93528 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -3.03781    0.11234  -27.04   <2e-16 ***
## log(Mass..g.)  0.75432    0.01737   43.44   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3379 on 56 degrees of freedom
## Multiple R-squared:  0.9712, Adjusted R-squared:  0.9707 
## F-statistic:  1887 on 1 and 56 DF,  p-value: < 2.2e-16
#create a dataframe of only tropical climate
tropical <- dataset %>%
  filter( Climateb == 'TR')
#get the slope and intercept
lm_TR <- lm(log_BMR ~ log(Mass..g.), tropical)
summary(lm_TR)
## 
## Call:
## lm(formula = log_BMR ~ log(Mass..g.), data = tropical)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.90916 -0.18727  0.00459  0.18617  0.98494 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -2.654606   0.055451  -47.87   <2e-16 ***
## log(Mass..g.)  0.692451   0.009482   73.03   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3304 on 213 degrees of freedom
## Multiple R-squared:  0.9616, Adjusted R-squared:  0.9614 
## F-statistic:  5333 on 1 and 213 DF,  p-value: < 2.2e-16
#create a dataframe of only widespread climate
widespread <- dataset %>%
  filter( Climateb == 'W')
#get the slope and intercept
lm_W <- lm(log_BMR ~ log(Mass..g.), widespread)
summary(lm_W)
## 
## Call:
## lm(formula = log_BMR ~ log(Mass..g.), data = widespread)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.46106 -0.04437  0.05586  0.11581  0.36476 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -2.4602     0.2372  -10.37 3.09e-08 ***
## log(Mass..g.)   0.7165     0.0255   28.09 2.19e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2148 on 15 degrees of freedom
## Multiple R-squared:  0.9813, Adjusted R-squared:  0.9801 
## F-statistic: 789.2 on 1 and 15 DF,  p-value: 2.191e-14