fitCF_MHmcmc: Run the Metropolis-Hastings algorithm for ECFOCF data

View source: R/fitCF_MHmcmc.R

fitCF_MHmcmcR Documentation

Run the Metropolis-Hastings algorithm for ECFOCF data

Description

Run the Metropolis-Hastings algorithm for RMU.data.
The number of iterations is n.iter+n.adapt+1 because the initial likelihood is also displayed.
I recommend thin=1 because the method to estimate SE uses resampling.
As initial point is maximum likelihood, n.adapt = 0 is a good solution.
The parameters intermediate and filename are used to save intermediate results every 'intermediate' iterations (for example 1000). Results are saved in a file of name filename.
The parameter previous is used to indicate the list that has been save using the parameters intermediate and filename. It permits to continue a mcmc search.
These options are used to prevent the consequences of computer crash or if the run is very very long and computer processes at time limited.

Usage

fitCF_MHmcmc(
  result = stop("An output from fitCF() must be provided"),
  n.iter = 10000,
  parametersMCMC = stop("A parameter set from fitCF_MHmcmc_p() must be provided"),
  n.chains = 1,
  n.adapt = 0,
  thin = 1,
  adaptive = FALSE,
  adaptive.lag = 500,
  adaptive.fun = function(x) {
     ifelse(x > 0.234, 1.3, 0.7)
 },
  trace = FALSE,
  traceML = FALSE,
  intermediate = NULL,
  filename = "intermediate.Rdata",
  previous = NULL
)

Arguments

result

An object obtained after a SearchR fit

n.iter

Number of iterations for each step

parametersMCMC

A set of parameters used as initial point for searching with information on priors

n.chains

Number of replicates

n.adapt

Number of iterations before to store outputs

thin

Number of iterations between each stored output

adaptive

Should an adaptive process for SDProp be used

adaptive.lag

Lag to analyze the SDProp value in an adaptive content

adaptive.fun

Function used to change the SDProp

trace

TRUE or FALSE or period, shows progress

traceML

TRUE or FALSE to show ML

intermediate

Period for saving intermediate result, NULL for no save

filename

If intermediate is not NULL, save intermediate result in this file

previous

Previous result to be continued. Can be the filename in which intermediate results are saved.

Details

fitCF_MHmcmc runs the Metropolis-Hastings algorithm for ECFOCF (Bayesian MCMC)

Value

A list with resultMCMC being mcmc.list object, resultLnL being likelihoods and parametersMCMC being the parameters used

Author(s)

Marc Girondot marc.girondot@gmail.com

See Also

Other Model of Clutch Frequency: ECFOCF_f(), ECFOCF_full(), TableECFOCF(), fitCF(), fitCF_MHmcmc_p(), generateCF(), lnLCF(), logLik.ECFOCF(), plot.ECFOCF(), plot.TableECFOCF()

Examples

## Not run: 
library("phenology")
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)
                           
pMCMC <- fitCF_MHmcmc_p(result=o_mu1p1_CFp, accept=TRUE)
fitCF_MCMC <- fitCF_MHmcmc(result = o_mu1p1_CFp, n.iter = 1000, 
                           parametersMCMC = pMCMC, n.chains = 1, n.adapt = 0, 
                           adaptive=TRUE, 
                           thin = 1, trace = TRUE)
                           
plot(fitCF_MCMC, parameters="mu")
plot(fitCF_MCMC, parameters="sd")
plot(fitCF_MCMC, parameters="p", xlim=c(0, 0.5), breaks=seq(from=0, to=0.5, by=0.05))
plot(fitCF_MCMC, parameters="p", transform = invlogit, xlim=c(0, 1), 
     breaks=c(seq(from=0, to=1, by=0.05)))


## End(Not run)

phenology documentation built on Sept. 11, 2024, 6:07 p.m.