# NOT RUN {
library(embryogrowth)
CC_AtlanticSW <- subset(DatabaseTSD, RMU=="Atlantic, SW" &
Species=="Caretta caretta" & (!is.na(Sexed) & Sexed!=0) &
!is.na(Correction.factor))
tsdL <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
temperatures=Incubation.temperature-Correction.factor,
equation="logistic", replicate.CI=NULL))
tsdH <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
temperatures=Incubation.temperature-Correction.factor,
equation="Hill", replicate.CI=NULL))
tsdR <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
temperatures=Incubation.temperature-Correction.factor,
equation="A-logistic", replicate.CI=NULL))
tsdF <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
temperatures=Incubation.temperature-Correction.factor,
equation="Flexit", replicate.CI=NULL))
tsdDR <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
temperatures=Incubation.temperature-Correction.factor,
equation="Double-A-logistic", replicate.CI=NULL))
gsd <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
temperatures=Incubation.temperature-Correction.factor,
equation="GSD", replicate.CI=NULL))
compare_AIC(Logistic_Model=tsdL, Hill_model=tsdH, Alogistic_model=tsdR,
flexit=tsdF,
DoubleAlogistic_model=tsdDR, GSD_model=gsd)
compare_AICc(Logistic_Model=tsdL, Hill_model=tsdH, Alogistic_model=tsdR,
DoubleAlogistic_model=tsdDR, GSD_model=gsd, factor.value = -1)
compare_BIC(Logistic_Model=tsdL, Hill_model=tsdH, Alogistic_model=tsdR,
DoubleAlogistic_model=tsdDR, GSD_model=gsd, factor.value = -1)
##############
eo <- subset(DatabaseTSD, Species=="Emys orbicularis", c("Males", "Females",
"Incubation.temperature"))
eo_Hill <- with(eo, tsd(males=Males, females=Females,
temperatures=Incubation.temperature,
equation="Hill"))
eo_Hill <- tsd(df=eo, equation="Hill", replicate.CI=NULL)
eo_logistic <- tsd(eo, replicate.CI=NULL)
eo_Alogistic <- with(eo, tsd(males=Males, females=Females,
temperatures=Incubation.temperature,
equation="a-logistic", replicate.CI=NULL))
### The Hulin model is a modification of A-logistic (See Hulin et al. 2009)
########## Caution
### It should not be used anymore as it can produce unexpected results
par <- eo_Alogistic$par
names(par)[which(names(par)=="K")] <- "K2"
par <- c(par, K1=0)
eo_Hulin <- with(eo, tsd(males=Males, females=Females,
parameters.initial=par,
temperatures=Incubation.temperature,
equation="Hulin", replicate.CI=NULL))
### The Double-A-logistic model is a A-logistic model with K1 and K2 using respectively
### below and above P
########## Caution
### The curve is not smooth at pivotal temperature
par <- eo_Alogistic$par
names(par)[which(names(par)=="K")] <- "K2"
par <- c(par, K1=as.numeric(par["K2"])*0.8)
par["K2"] <- par["K2"]*0.8
eo_Double_Alogistic <- with(eo, tsd(males=Males, females=Females,
parameters.initial=par,
temperatures=Incubation.temperature,
equation="Double-a-logistic", replicate.CI=NULL))
### The flexit model is modeled with K1 and K2 using respectively
### below and above P and smooth transition at P; S is the slope at P
par <- c(eo_logistic$par["P"], 1/4*eo_logistic$par["S"], K1=1, K2=1)
eo_flexit <- with(eo, tsd(males=Males, females=Females,
parameters.initial=par,
temperatures=Incubation.temperature,
equation="flexit", replicate.CI=NULL))
compare_AIC(Logistic=eo_logistic, Hill=eo_Hill, Alogistic=eo_Alogistic,
Hulin=eo_Hulin, Double_Alogistic=eo_Double_Alogistic,
flexit=eo_flexit)
## Note that SE for lower limit of TRT is wrong
plot(eo_flexit)
## To get correct confidence interval, check \code{tsd_MHmcmc()}.
### Note the asymmetry of the Double-A-logistic and flexit models
predict(eo_Double_Alogistic,
temperatures=c(eo_Double_Alogistic$par["P"]-0.2, eo_Double_Alogistic$par["P"]+0.2))
predict(eo_Double_Alogistic)
(p <- predict(eo_flexit,
temperatures=c(eo_flexit$par["P"]-0.3, eo_flexit$par["P"]+0.3)))
p["50%", 1]-0.5; 0.5-p["50%", 2]
predict(eo_flexit)
### It can be used also for incubation duration
CC_AtlanticSW <- subset(DatabaseTSD, RMU=="Atlantic, SW" &
Species=="Caretta caretta" & Sexed!=0)
tsdL_IP <- with (CC_AtlanticSW, tsd(males=Males, females=Females,
durations=IP.mean,
equation="logistic", replicate.CI=NULL))
plot(tsdL_IP, xlab="Incubation durations in days")
# Example with Chelonia mydas
cm <- subset(DatabaseTSD, Species=="Chelonia mydas" & !is.na(Sexed), c("Males", "Females",
"Incubation.temperature", "RMU"))
tsd(subset(cm, subset=RMU=="Pacific, SW"))
tsd(subset(cm, subset=RMU=="Pacific, Northwest"))
tsd(subset(cm, subset=RMU=="Atlantic, S Caribbean"))
### Eretmochelys imbricata
Ei_PacificSW <- subset(DatabaseTSD, RMU=="Pacific, SW" &
Species=="Eretmochelys imbricata")
Ei_AtlanticW <- subset(DatabaseTSD, RMU=="Atlantic, W (Caribbean and E USA)" &
Species=="Eretmochelys imbricata")
Ei_AtlanticSW <- subset(DatabaseTSD, RMU=="Atlantic, SW" &
Species=="Eretmochelys imbricata")
Ei_PacSW <- tsd(Ei_PacificSW)
Ei_AtlW <- tsd(Ei_AtlanticW)
Ei_AtlSW <- tsd(Ei_AtlanticSW)
plot(Ei_PacSW, xlim=c(27, 33), show.PTRT = FALSE, main=expression(italic("Eretmochelys imbricata")))
par(new=TRUE)
plot(Ei_AtlW, xlim=c(27, 33), col="red", xlab="", ylab="",
axes=FALSE, xaxt="n", show.PTRT = FALSE, errbar.col="red")
par(new=TRUE)
plot(Ei_AtlSW, xlim=c(27, 33), col="blue", xlab="", ylab="", axes=FALSE,
xaxt="n", show.PTRT = FALSE, errbar.col="blue")
legend("topright", legend=c("Pacific, SW", "Atlantic, W", "Atlantic, SW"), lty=1,
col=c("black", "red", "blue"))
### Chelonia mydas
Cm_PacificSW <- subset(DatabaseTSD, RMU=="Pacific, SW" & !is.na(Sexed) &
Species=="Chelonia mydas")
Cm_PacificNW <- subset(DatabaseTSD, RMU=="Pacific, NW" & !is.na(Sexed) &
Species=="Chelonia mydas")
Cm_AtlanticSC <- subset(DatabaseTSD, RMU=="Atlantic, S Caribbean" & !is.na(Sexed) &
Species=="Chelonia mydas")
Cm_IndianSE <- subset(DatabaseTSD, RMU=="Indian, SE" & !is.na(Sexed) &
Species=="Chelonia mydas")
Cm_PacSW <- tsd(Cm_PacificSW)
Cm_PacNW <- tsd(Cm_PacificNW)
Cm_IndSE <- tsd(Cm_IndianSE)
Cm_AtlSC <- tsd(Cm_AtlanticSC)
plot(Cm_PacSW, xlim=c(24, 34), show.PTRT = FALSE, main=expression(italic("Chelonia mydas")))
par(new=TRUE)
plot(Cm_PacNW, xlim=c(24, 34), col="red", xlab="", ylab="",
axes=FALSE, xaxt="n", show.PTRT = FALSE, errbar.col="red")
par(new=TRUE)
plot(Cm_IndSE, xlim=c(24, 34), col="blue", xlab="", ylab="",
axes=FALSE, xaxt="n", show.PTRT = FALSE, errbar.col="blue")
par(new=TRUE)
plot(Cm_AtlSC, xlim=c(24, 34), col="green", xlab="", ylab="",
axes=FALSE, xaxt="n", show.PTRT = FALSE, errbar.col="green")
# To fit a TSDII or FMF TSD pattern, you must indicate P_low, S_low, P_high, and S_high
# for logistic model and P_low, S_low, K1_low, K2_low, P_high, S_high, K1_high, and K2_high for
# flexit model
# The model must be 0-1 for low and 1-0 for high with P_low < P_high
Chelydra_serpentina <- subset(DatabaseTSD, !is.na(Sexed) & (Sexed != 0) &
Species=="Chelydra serpentina")
model_TSDII <- tsd(Chelydra_serpentina, males.freq=FALSE,
parameters.initial=c(P_low=21, S_low=0.3, P_high=28, S_high=-0.4),
equation="logistic")
plot(model_TSDII, lab.TRT = "TRT l = 5 %")
priors <- tsd_MHmcmc_p(result=model_TSDII, accept=TRUE)
out_mcmc <- tsd_MHmcmc(result=model_TSDII, n.iter=10000, parametersMCMC=priors)
plot(model_TSDII, resultmcmc=out_mcmc, lab.TRT = "TRT l = 5 %")
predict(model_TSDII, temperatures=25:35)
# Podocnemis expansa
Podocnemis_expansa <- subset(DatabaseTSD, !is.na(Sexed) & (Sexed != 0) &
Species=="Podocnemis expansa")
Podocnemis_expansa_Valenzuela_2001 <- subset(Podocnemis_expansa,
Reference=="Valenzuela, 2001")
PeL2001 <- tsd(df=Podocnemis_expansa_Valenzuela_2001)
# The pivotal temperature is 32.133 <U+00B0>C (CI 95% 31.495;32.766)
# In Valenzuela, 2001: "Using data from the present study alone,
# the critical temperature was 32.2 <U+00B0>C by both methods and the 95%
# confidence limits were 31.4 <U+00B0>C and 32.9 <U+00B0>C."
# Data are close but not identical to what was published.
# The pivotal temperature calculated by maximum likelihood and by inverse
# prediction from logistic regression, was 32.6<U+00B0>C using raw data from
# 1991 (N. Valenzuela, unpublished data) and from this study. The lower
# and upper 95% confidence limits of the pivotal temperature were 32.2<U+00B0>C
# and 33.2<U+00B0>C,
Podocnemis_expansa_Valenzuela_1997 <- subset(Podocnemis_expansa,
subset=(((Reference=="Lance et al., 1992; Valenzuela et al., 1997") |
(Reference=="Valenzuela, 2001")) &
(!is.na(Sexed)) & (Sexed != 0)))
PeL1997 <- tsd(df=Podocnemis_expansa_Valenzuela_1997)
# }
Run the code above in your browser using DataLab