Introduction

An explanation is needed from Ellie regarding the underlying logic of this function and a citation. I haven’t looked at the derivation in detail.

Loading some packages and data

library(ggplot2)
library(knitr)
theme_set(theme_bw())
library(plotly)
library(mgcv)
library(dplyr)
load("/home/rstudio/myscripts/morph2/data/test.rob")
opts_chunk$set(messages = FALSE, warning = FALSE)

The climate data set is from NOAA and contains the maximum and minimum daily temperatures multiplied by 10 (to turn them from floating point to integer values) and the average windspeed also multiplied by 10.

clim$temperature<-(clim$tmin+clim$tmax)/20
clim$windspeed<-clim$avwind/10
clim$year<-as.numeric(format(clim$date,"%Y"))
clim$month<-as.numeric(format(clim$date,"%m"))

The function

FBMR<-function(ftemperature=-10,fwindspeed=2,fmass=1500)
{
TBrant<-7.5
ftemperature[ftemperature>TBrant]<-TBrant
fwindspeed[fwindspeed<0.5]<-1
DeltaT<-TBrant-ftemperature
b<-0.0092*fmass^0.66*DeltaT^0.32
a<-4.15-b*sqrt(0.06)
a+b+sqrt(fwindspeed)
}
## For example
FBMR(10,3,fmass=1500)
## [1] 5.882051

The equation assumes no additional maintenance cost when the temperature is above 7.5 degrees. The function therefore sets all values above this to 7.5. So there is a conditional statement here. Also if the windspeed is precisely zero the equation does not produce a result, so a very slight wind movement is assumed if the data set throws up a zero (which is probably an error anyway)

DeltaT is simply the difference in temperature from the baseline. There are two sub equations that produce the parameters a and b that are then combined in the final equation.

clim$bmr<-FBMR(clim$temperature,clim$windspeed,1500)
g0<-ggplot(filter(clim,year==2015),aes(x=date,y=bmr)) %>%
+ geom_point() +geom_smooth(method = "loess") +ylab("Basal metabolic rate (Watts)") +xlab("Date")
g0

clim %>% group_by(year,month) %>% summarise(avg=mean(bmr))->monthly
monthly$period<-cut(monthly$year,c(1940,2000,2016))
levels(monthly$period)<-c("1982-1999","2000-2016")
g1<-ggplot(monthly,aes(x=month,y=avg,col=period)) %>%
+ geom_point() %>%
+ geom_smooth(method = "loess") + ylab("Mean monthly BMR (Watts)") + scale_x_continuous("Month",breaks=1:12)
g1

tmp<-monthly 
tmp$month<-as.factor(tmp$month)
tmp$period<-as.factor(tmp$period)


g2<-ggplot(tmp,aes(x=month,y=avg,group=period,col=period))%>%
  + stat_summary(fun.y=mean,geom="point") %>%
  + stat_summary(fun.data=mean_cl_normal,geom="errorbar") %>%
  +  scale_x_discrete(name ="Month", limits=1:12) %>%
  + scale_color_grey() + theme_classic() + ylab("Mean monthly BMR (Watts)")
 g2

Interactive plots

ggplotly(g0)
ggplotly(g1)
ggplotly(g2)