# NOT RUN {
library(embryogrowth)
data(nest)
formated <- FormatNests(nest)
# The initial parameters value can be:
# "T12H", "DHA", "DHH", "Rho25"
# Or
# "T12L", "DT", "DHA", "DHH", "DHL", "Rho25"
# K for Gompertz must be set as fixed parameter or being a constant K
# or relative to the hatchling size rK
x <- structure(c(105.966881676793, 613.944134764125, 306.449533440186,
118.193882815108), .Names = c("DHA", "DHH", "T12H", "Rho25"))
# pfixed <- c(K=82.33) or rK=82.33/39.33
pfixed <- c(rK=2.093313)
resultNest_4p_SSM4p <- searchR(parameters=x, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=1.7,
test=c(Mean=39.33, SD=1.92))
data(resultNest_4p_SSM4p)
plot(resultNest_4p_SSM4p, xlim=c(0,70), ylimT=c(22, 32), ylimS=c(0,45), series=1,
embryo.stages="Caretta caretta.SCL")
x <- structure(c(106.567809092008, 527.359011254683, 614.208632495199,
2720.94506457237, 306.268259715624, 120.336791245212), .Names = c("DHA",
"DHH", "DHL", "DT", "T12L", "Rho25"))
pfixed <- c(rK=2.093313)
# exemple of data.frame for test
ttest <- data.frame(Mean=rep(25.5, formated$IndiceT["NbTS"]),
SD=rep(0.75, formated$IndiceT["NbTS"]),
row.names=names(formated)[1:formated$IndiceT["NbTS"]])
resultNest_6p_SSM6p <- searchR(parameters=x, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=1.7,
test=ttest)
data(resultNest_6p_SSM6p)
pMCMC <- TRN_MHmcmc_p(resultNest_6p_SSM6p, accept=TRUE)
# Take care, it can be very long, sometimes several days
resultNest_mcmc_6p_SSM6p <- GRTRN_MHmcmc(result=resultNest_6p_SSM6p,
parametersMCMC=pMCMC, n.iter=10000, n.chains = 1, n.adapt = 0,
thin=1, trace=TRUE)
# compare_AIC() is a function from the package "HelpersMG"
compare_AIC(test1=resultNest_4p_SSM4p, test2=resultNest_6p_SSM6p)
############ with new parametrization
data(resultNest_4p_SSM4p)
x0 <- resultNest_4p_SSM4p$par
t <- hist(resultNest_4p_SSM4p, plot=FALSE)
x <- c(3.4, 3.6, 5.4, 5.6, 7.6, 7.5, 3.2)
names(x) <- seq(from=range(t$temperatures)[1], to=range(t$temperatures)[2],
length.out=7)
newx <- ChangeSSM(temperatures = (200:350)/10, parameters = x0,
initial.parameters = x,
control=list(maxit=5000))
pfixed <- c(rK=2.093313)
resultNest_newp <- searchR(parameters=newx, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=1.7,
test=c(Mean=39.33, SD=1.92))
plotR(resultNest_newp, ylim=c(0, 3), xlimR=c(23, 34), ylimH=c(0, 0.3), show.hist.TRUE)
compare_AIC(test4p=resultNest_4p_SSM4p,
test6p=resultNest_6p_SSM6p,
testAnchor=resultNest_newp)
############################################
# example with thermal reaction norm fitted from Weibull function
############################################
x <- ChangeSSM(temperatures = (200:350)/10,
parameters = resultNest_4p_SSM4p$par,
initial.parameters = structure(c(73.4009010417375, 304.142079511996,
27.4671689276281),
.Names = c("k", "lambda", "scale")),
control=list(maxit=1000))
pfixed <- c(rK=2.093313)
resultNest_3p_Weibull <- searchR(parameters=x$par, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=1.7,
test=c(Mean=39.33, SD=1.92))
plotR(list(resultNest_4p_SSM4p, resultNest_3p_Weibull), ylim=c(0,3), col=c("Black", "red"))
compare_AIC(SSM4p=resultNest_4p_SSM4p, Weibull=resultNest_3p_Weibull)
###########################################
# example with thermal reaction norm fitted from asymmetric normal function
############################################
x <- ChangeSSM(temperatures = (200:350)/10,
parameters = resultNest_4p_SSM4p$par,
initial.parameters = structure(c(3, 7, 11, 32),
.Names = c("Scale", "sdL", "sdH", "Peak")),
control=list(maxit=1000))
pfixed <- c(rK=2.093313)
resultNest_4p_normal <- searchR(parameters=x$par, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=1.7,
test=c(Mean=39.33, SD=1.92))
###########################################
# example with thermal reaction norm fitted from trigonometric model
############################################
x <- ChangeSSM(temperatures = (200:350)/10,
parameters = resultNest_4p_SSM4p$par,
initial.parameters = structure(c(3, 20, 40, 32),
.Names = c("Max", "LengthB", "LengthE", "Peak")),
control=list(maxit=1000))
pfixed <- c(rK=2.093313)
resultNest_4p_trigo <- searchR(parameters=x$par, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=1.7,
test=c(Mean=39.33, SD=1.92))
###########################################
# example with thermal reaction norm fitted from Dallwitz model
# From Girondot, M., Monsinjon, J., Guillon, J.-M., Submitted. Delimitation of the
# embryonic thermosensitive period for sex determination using an embryo growth model
# reveals a potential bias for sex ratio prediction in turtles.
# rK = 1.208968
# M0 = 0.3470893
# See the example in stages datasets
############################################
x <- structure(c(4.88677476830268, 20.4051904475743, 31.5173105860335),
.Names = c("Dallwitz_b1", "Dallwitz_b2", "Dallwitz_b3"))
pfixed <- c(rK=1.208968)
resultNest_3p_Dallwitz <- searchR(parameters=x, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=0.3470893,
test=c(Mean=39.33, SD=1.92))
plotR(resultNest_3p_Dallwitz, ylim=c(0,8))
x <- structure(c(4.91191231405918, 12.7453211281394, 31.2670410811077,
5.7449376569153, -0.825689964543813), .Names = c("Dallwitz_b1",
"Dallwitz_b2", "Dallwitz_b3", "Dallwitz_b4", "Dallwitz_b5"))
pfixed <- c(rK=1.208968)
resultNest_5p_Dallwitz <- searchR(parameters=x, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=0.3470893,
test=c(Mean=39.33, SD=1.92))
plotR(resultNest_5p_Dallwitz, ylim=c(0,8))
xp <- resultNest_6p_SSM6p$par
xp["Rho25"] <- 233
pfixed <- c(rK=1.208968)
resultNest_6p_SSM <- searchR(parameters=xp, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=0.3470893,
test=c(Mean=39.33, SD=1.92))
plotR(resultNest_6p_SSM, ylim=c(0,8))
xp <- ChangeSSM(parameters = resultNest_3p_Dallwitz$par,
initial.parameters = resultNest_4p_SSM4p$par)
pfixed <- c(rK=1.208968)
resultNest_4p_SSM <- searchR(parameters=xp$par, fixed.parameters=pfixed,
temperatures=formated, derivate=dydt.Gompertz, M0=0.3470893,
test=c(Mean=39.33, SD=1.92))
plotR(resultNest_4p_SSM, ylim=c(0,8))
compare_AIC(Dallwitz3p=resultNest_3p_Dallwitz, Dallwitz5p=resultNest_5p_Dallwitz,
SSM4p=resultNest_4p_SSM, SSM6p=resultNest_6p_SSM)
###########################################
# Example with thermal reaction norm of proportion of development
# fitted from Dallwitz model
# see Woolgar, L., Trocini, S., Mitchell, N., 2013. Key parameters describing
# temperature-dependent sex determination in the southernmost population of loggerhead
# sea turtles. Journal of Experimental Marine Biology and Ecology 449, 77-84.
############################################
x <- structure(c(1.48207559695689, 20.1100310234046, 31.5665036287242),
.Names = c("Dallwitz_b1", "Dallwitz_b2", "Dallwitz_b3"))
resultNest_PropDev_3p_Dallwitz <- searchR(parameters=x, fixed.parameters=NULL,
temperatures=formated, derivate=dydt.linear, M0=0,
test=c(Mean=1, SD=NA))
plotR(resultNest_PropDev_3p_Dallwitz, ylim=c(0, 1.5), curves="ML")
plot(x=resultNest_PropDev_3p_Dallwitz, ylimS=c(0,1), xlim=c(0,60), series=2,
embryo.stages="Generic.ProportionDevelopment")
x <- structure(c(1.48904182113431, 10.4170365155993, 31.2591665490154,
6.32355497589913, -1.07425378667104), .Names = c("Dallwitz_b1",
"Dallwitz_b2", "Dallwitz_b3", "Dallwitz_b4", "Dallwitz_b5"))
resultNest_PropDev_5p_Dallwitz <- searchR(parameters=x, fixed.parameters=NULL,
temperatures=formated, derivate=dydt.linear, M0=0,
test=c(Mean=1, SD=NA))
plotR(resultNest_PropDev_5p_Dallwitz, ylim=c(0, 1.5))
plot(x=resultNest_PropDev_5p_Dallwitz, ylimS=c(0,1), xlim=c(0,60), series=2,
embryo.stages="Generic.ProportionDevelopment")
plotR(resultNest_PropDev_3p_Dallwitz, ylim=c(0, 1.5), curves="ML")
plotR(resultNest_PropDev_5p_Dallwitz, ylim=c(0, 1.5), curves="ML", new=FALSE, col="red")
compare_AICc(Dallwitz3p=resultNest_PropDev_3p_Dallwitz,
Dallwitz5p=resultNest_PropDev_5p_Dallwitz)
# }
Run the code above in your browser using DataLab