Learn R Programming

embryogrowth (version 6.4)

tsd_MHmcmc: Metropolis-Hastings algorithm for Sex ratio

Description

Run the Metropolis-Hastings algorithm for tsd. Deeply modified from a MCMC script by Olivier Martin (INRA, Paris-Grignon). The number of iterations is n.iter+n.adapt+1 because the initial likelihood is also displayed. I recommend that thin=1 because the method to estimate SE uses resampling. If initial point is maximum likelihood, n.adapt = 0 is a good solution. To get the SE from result_mcmc <- tsd_MHmcmc(result=try), use: result_mcmc$BatchSE or result_mcmc$TimeSeriesSE The batch standard error procedure is usually thought to be not as accurate as the time series methods. Based on Jones, Haran, Caffo and Neath (2005), the batch size should be equal to sqrt(n.iter). Jones, G.L., Haran, M., Caffo, B.S. and Neath, R. (2006) Fixed Width Output Analysis for Markov chain Monte Carlo , Journal of the American Statistical Association, 101:1537-1547. coda package is necessary for this function. #' 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 processes at time limited.

Usage

tsd_MHmcmc(result = stop("A result of tsd() fit must be provided"), n.iter = 10000, parametersMCMC = NULL, n.chains = 1, n.adapt = 0, thin = 1, trace = FALSE, batchSize = sqrt(n.iter), 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
trace
True or False, shows progress
batchSize
Number of observations to include in each batch fo SE estimation
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.

Value

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

Details

tsd_MHmcmc runs the Metropolis-Hastings algorithm for tsd (Bayesian MCMC)

See Also

Other Functions.for.temperature.dependent.sex.determination: DatabaseTSD, TSP.list, predict.tsd, stages, tsd_MHmcmc_p, tsd

Examples

Run this code
## Not run: 
# library(embryogrowth)
# eo <- subset(DatabaseTSD, Species=="Emys orbicularis", c("Males", "Females", 
#                                        "Incubation.temperature"))
# eo_logistic <- tsd(eo)
# pMCMC <- tsd_MHmcmc_p(eo_logistic, accept=TRUE)
# # Take care, it can be very long; several days
# result_mcmc_tsd <- tsd_MHmcmc(result=eo_logistic, 
# 		parametersMCMC=pMCMC, n.iter=10000, n.chains = 1,  
# 		n.adapt = 0, thin=1, trace=TRUE)
# # summary() permits to get rapidly the standard errors for parameters
# summary(result_mcmc_tsd)
# # They are store in the result also. Two SE are estimated using or 
# # batch method or time-series SE:
# # The batch standard error procedure is usually thought to be not 
# # as accurate as the time series methods.
# se1 <- result_mcmc_tsd$BatchSE
# se2 <- result_mcmc_tsd$TimeSeriesSE
# plot(result_mcmc_tsd, parameters="S", scale.prior=TRUE, xlim=c(-3, 3), las=1)
# plot(result_mcmc_tsd, parameters="P", scale.prior=TRUE, xlim=c(25, 35), las=1)
# plot(eo_logistic, se=se2)
# ## End(Not run)

Run the code above in your browser using DataLab