# NOT RUN {
library(phenology)
# Example
data(MarineTurtles_2002)
ECFOCF_2002 <- TableECFOCF(MarineTurtles_2002)
# Paraetric model for clutch frequency
o_mu1p1_CFp <- fitCF(x = c(mu = 2.1653229641404539,
sd = 1.1465246643327098,
p = 0.25785366120357966),
fixed.parameters=NULL,
data=ECFOCF_2002, hessian = TRUE)
# Non parametric model for clutch frequency
o_mu1p1_CFnp <- fitCF(x = c(mu.1 = 18.246619595610383,
mu.2 = 4.2702163522832892,
mu.3 = 2.6289986859556458,
mu.4 = 3.2496360919228611,
mu.5 = 2.1602522716550943,
mu.6 = 0.68617023351032846,
mu.7 = 4.2623607001877026,
mu.8 = 1.1805600042630455,
mu.9 = 2.2786176350939731,
mu.10 = 0.47676265496204945,
mu.11 = 5.8988238539197062e-08,
mu.12 = 1.4003187851424953e-07,
mu.13 = 2.4128444894899776e-07,
mu.14 = 2.4223748020049825e-07,
p = 0.32094401970037578),
fixed.parameters=c(mu.15 = 1E-10),
data=ECFOCF_2002, hessian = TRUE)
o_mu2p1 <- fitCF(x = c(mu1 = 1.2190766766978423,
sd1 = 0.80646454821956925,
mu2 = 7.1886819592223246,
sd2 = 0.18152887523015518,
p = 0.29347220802963259,
OTN = 2.9137627675219533),
fixed.parameters=NULL,
data=ECFOCF_2002, hessian = TRUE)
o_mu1p2 <- fitCF(x = c(mu = 5.3628701816871462,
sd = 0.39390555498088764,
p1 = 0.61159637544418755,
p2 = -2.4212753004659189,
OTN = 0.31898004668901009),
data=ECFOCF_2002, hessian = TRUE)
o_mu2p2 <- fitCF(x = c(mu1 = 0.043692606004492131,
sd1 = 1.9446036983033428,
mu2 = 7.3007868915644751,
sd2 = 0.16109296152913491,
p1 = 1.6860260469536992,
p2 = -0.096816113083788985,
OTN = 2.2604431232973501),
data=ECFOCF_2002, hessian = TRUE)
compare_AIC(mu1p1=o_mu1p1_CFp,
mu2p1=o_mu2p1,
mu1p2=o_mu1p2,
mu2p2=o_mu2p2)
o_mu3p3 <- fitCF(x = c(mu1 = 0.24286312214288761,
sd1 = 0.34542255091729313,
mu2 = 5.0817174343025551,
sd2 = 1.87435099405695,
mu3 = 5.2009265101740683,
sd3 = 1.79700447678357,
p1 = 8.8961708614726156,
p2 = 0.94790116453886453,
p3 = -0.76572930634505421,
OTN1 = 1.2936848663276974,
OTN2 = 0.81164278235645926),
data=ECFOCF_2002, hessian = TRUE)
o_mu3p1 <- fitCF(x = structure(c(0.24387978183477,
1.2639261745506,
4.94288464711349,
1.945082889758,
4.9431672350811,
1.287663104591,
0.323636536050397,
1.37072039291397,
9.28055412564559e-06),
.Names = c("mu1", "sd1", "mu2",
"sd2", "mu3", "sd3",
"p", "OTN1", "OTN2")),
data=ECFOCF_2002, hessian = TRUE)
o_mu1p3 <- fitCF(x = structure(c(4.65792402108387,
1.58445909785,
-2.35414198317177,
0.623757854800649,
-3.62623634029326,
11.6950204755787,
4.05273728846523),
.Names = c("mu", "sd",
"p1", "p2", "p3",
"OTN1", "OTN2")),
data=ECFOCF_2002, hessian = TRUE)
compare_AIC(mu1p1=o_mu1p1,
mu2p1=o_mu2p1,
mu1p2=o_mu1p2,
mu2p2=o_mu2p2,
mu3p3=o_mu3p3,
mu1p3=o_mu1p3,
mu3p1=o_mu3p1)
# 3D model for (ECF, OCF, period)
ECFOCF_2002 <- TableECFOCF(MarineTurtles_2002,
date0=as.Date("2002-01-01"))
fp <- rep(0, dim(ECFOCF_2002)[3])
names(fp) <- paste0("p.", formatC(1:(dim(ECFOCF_2002)[3]), width=2, flag="0"))
par <- c(mu = 2.6404831115214353,
sd = 0.69362774786433479,
mu_season = 12.6404831115214353,
sd_season = 1.69362774786433479)
par <- c(par, fp[attributes(ECFOCF_2002)$table["begin"]:
attributes(ECFOCF_2002)$table["end"]])
# The value of p (logit -capture probability) out of the period
# of monitoring is set to +Inf (capture probability=1)
# to indicate that no turtle is nesting in the period out of
# monitoring time
# p is set to -Inf (capture probability=0) to indicate that no
# monitoring has been done but some turtles could have been present.
fixed.parameters <- c(p=+Inf)
# The fitted values are:
par <- c(mu = 2.4911638591178051,
sd = 0.96855483039640977,
mu_season = 13.836059118657793,
sd_season = 0.17440085345943984,
p.10 = 1.3348233607728222,
p.11 = 1.1960387774393837,
p.12 = 0.63025680979544774,
p.13 = 0.38648155002707452,
p.14 = 0.31547864054366048,
p.15 = 0.19720001827017075,
p.16 = 0.083199496372073328,
p.17 = 0.32969130595897905,
p.18 = 0.36582777525265819,
p.19 = 0.30301248314170637,
p.20 = 0.69993987591518514,
p.21 = 0.13642423871641118,
p.22 = -1.3949268190534629)
o_mu1p1season1 <- fitCF(x=par, data=ECFOCF_2002,
fixed.parameters=fixed.parameters)
# Same model but with two different models of capture probabilities
fp <- rep(0, dim(ECFOCF_2002)[3])
names(fp) <- paste0("p1.", formatC(1:(dim(ECFOCF_2002)[3]), width=2, flag="0"))
par <- c(mu = 2.6404831115214353,
sd = 0.69362774786433479,
mu_season = 12.6404831115214353,
sd_season = 1.69362774786433479)
par <- c(par, fp[attributes(ECFOCF_2002)$table["begin"]:
attributes(ECFOCF_2002)$table["end"]])
names(fp) <- paste0("p2.", formatC(1:(dim(ECFOCF_2002)[3]), width=2, flag="0"))
par <- c(par, fp[attributes(ECFOCF_2002)$table["begin"]:
attributes(ECFOCF_2002)$table["end"]])
fixed.parameters <- c(p1=+Inf, p2=+Inf)
o_mu1p2season1 <- fitCF(x=par, data=ECFOCF_2002,
fixed.parameters=fixed.parameters)
# Here the two different capture probabilities are different
# by a constant:
# p1=invlogit(-p) [Note that invlogit(-a1) = 1]
# p2=invlogit(-p)*invlogit(-a2)
fp <- rep(0, dim(ECFOCF_2002)[3])
names(fp) <- paste0("p.", formatC(1:(dim(ECFOCF_2002)[3]), width=2, flag="0"))
par <- c(mu = 2.6404831115214353,
sd = 0.69362774786433479,
mu_season = 12.6404831115214353,
sd_season = 1.69362774786433479,
a2=0)
par <- c(par, fp[attributes(ECFOCF_2002)$table["begin"]:
attributes(ECFOCF_2002)$table["end"]])
fixed.parameters <- c(a1=+Inf, p=+Inf)
o_mu1p1aseason1 <- fitCF(x=par, data=ECFOCF_2002,
fixed.parameters=fixed.parameters)
data=ECFOCF_2002)
# }
Run the code above in your browser using DataLab