if (FALSE) {
library(phenology)
data(Gratiot)
# Generate a formatted list named data_Gratiot
data_Gratiot <- add_phenology(Gratiot, name="Complete",
reference=as.Date("2001-01-01"), format="%d/%m/%Y")
# Generate initial points for the optimisation
parg <- par_init(data_Gratiot, fixed.parameters=NULL)
# Run the optimisation
result_Gratiot <- fit_phenology(data=data_Gratiot,
fitted.parameters=parg, fixed.parameters=NULL)
# Generate set of priors for Bayesian analysis
pmcmc <- phenology_MHmcmc_p(result_Gratiot, accept = TRUE)
# Here no WAIC data
result_Gratiot_mcmc <- phenology_MHmcmc(result = result_Gratiot, n.iter = 10000,
parametersMCMC = pmcmc, n.chains = 1,
n.adapt = 0, thin = 10, trace = FALSE,
WAIC=FALSE)
# Here the WAIC is at the level of the beaches
result_Gratiot_mcmc <- phenology_MHmcmc(result = result_Gratiot, n.iter = 10000,
parametersMCMC = pmcmc, n.chains = 1,
n.adapt = 0, thin = 10, trace = FALSE,
WAIC=TRUE, WAIC.bybeach=TRUE)
# Here the WAIC is at the level of the counts
result_Gratiot_mcmc <- phenology_MHmcmc(result = result_Gratiot, n.iter = 10000,
parametersMCMC = pmcmc, n.chains = 1,
n.adapt = 0, thin = 10, trace = FALSE,
WAIC=TRUE, WAIC.bybeach=FALSE)
loo::loo(result_Gratiot_mcmc$WAIC)
loo::waic(result_Gratiot_mcmc$WAIC)
# Get standard error of parameters
summary(result_Gratiot_mcmc)
# Make diagnostics of the mcmc results using coda package
mcmc <- as.mcmc(result_Gratiot_mcmc)
require(coda)
heidel.diag(mcmc)
raftery.diag(mcmc)
autocorr.diag(mcmc)
acf(mcmc[[1]][,"LengthB"], lag.max=200, bty="n", las=1)
acf(mcmc[[1]][,"Max_Complete"], lag.max=50, bty="n", las=1)
batchSE(mcmc, batchSize=100)
# The batch standard error procedure is usually thought to
# be not as accurate as the time series methods used in summary
summary(mcmc)$statistics[,"Time-series SE"]
plot(result_Gratiot_mcmc, parameters="Max_Complete", las=1, xlim=c(-10, 210))
plot(result_Gratiot_mcmc, what="MarkovChain", ylim=c(20, 40))
plot(result_Gratiot_mcmc, what="LnL")
}
Run the code above in your browser using DataLab