mcmc | R Documentation |
Generates a single Markov Chain Monte Carlo using the Metropolis-Hastings algorithm
mcmc(PDarray,
startPars,
type,
timeseries=NULL,
N=30000,
burn=2000,
thin=5,
jumps=0.02)
PDarray |
A Probability Density Array of calibrated dates, generated by |
startPars |
A vector of parameter values for the algorithm to start at. Suggest using the parameters found from a Maximum Likelihood search. Must have an odd length with values between 0 and 1 for an n-CPL model, or length 1 values between -0.1 and 0.1 for an exponential model. |
type |
Choose from the following currently available |
timeseries |
Only if 'type' = 'timeseries', a data frame should be provided containing columns x and y that define the timeseries as year and value respectively. |
N |
The total number of proposals made, before the chain is reduced for burn-in and thinning. |
burn |
The number of proposals made at the beginning of the chain to be disregarded as burn-in. |
thin |
Specifies the proportion of proposals to be disregarded (after burn-in), such that the default 5 will only keep every 5th proposal. |
jumps |
Vector that determines the size of the random jump between the last parameters and the proposed parameters. A smaller value gives a smaller jump. Different jump values can be provided for each parameter. This can be tuned by observing how well mixed each parameter is in the chain. |
Generates a single MCMC chain using the Metropolis-Hastings algorithm, printing to screen progress every 1000 proposals. An acceptance ratio of around 0.4 to 0.5 should be sought by adapting the arguments 'burn' and 'jumps'. If the acceptance ratio is too low try reducing jump. A larger dataset will typically require smaller jumps.
Returns a list including:
res |
A 2D matrix of free parameter values (between 0 and 1) in the chain, after burn-in and thinning. |
all.pars |
A 2D matrix of free parameter values (between 0 and 1) in the chain of all N proposals. |
acceptance.ratio |
The proportion of proposals (after burn-in) that are accepted. |
# randomly sample calendar dates from the toy model
set.seed(12345)
N <- 350
cal <- simulateCalendarDates(toy, N)
# Convert to 14C dates.
age <- uncalibrateCalendarDates(cal, shcal20)
data <- data.frame(age = age, sd = 50, phase = 1:N, datingType = '14C')
# Calibrate each phase, taking care to restrict to the modelled date range
CalArray <- makeCalArray(shcal20, calrange = range(toy$year), inc = 5)
PD <- phaseCalibrator(data, CalArray, remove.external = TRUE)
# Run MCMC for a 3-CPL model (5 parameters)
chain <- mcmc(PDarray = PD,
startPars = rep(0.5,5),
type='CPL',
jumps = 0.02)
# Run MCMC for a 3-CPL model with taphonomy (5 + 2 parameters)
chain <- mcmc(PDarray = PD,
startPars = c(rep(0.5,5),10000,-1.5),
type=c('CPL', 'power'),
jumps = 0.02)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.