Generate an ensemble of possible age corrected data:See www.clim-past-discuss.net/9/6077/2013/ for a detailed description of the model. The time series in X are automatically flipped to range from most recent to oldest measurements when the input t is given in increasing order.

`simulateBam(X, t, model = NULL, ageEnsOut = FALSE)`

- X
data (vector or matrix n*p)

- t
chronology for data X (n*1)

- model
a list that describes the model to use in BAM

model$ns: number of samples

model$name: 'poisson' or 'bernoulli'

model$param: probability of growth band being perturbed (default: prob of missing band = prob of doubly-counted band = 0.05)

if model$param is a single argument, then the perturbations are symmetric (prob of missing band = prob of doubly-counted band)

if model$param = [a1 a2] and a1 neq a2 the model is asymmetric

a1 = prob(missing layer) - undercounted

a2 = prob(layer counted multiple times) - overcounted

if model$param: 2xp matrix, then different miscounting prob. are defined for each time series.

model$resize: do not resize: 0 (default), resize to shortest sample: -1, resize to longest sample: 1

model$tm: if a time model is provided, the code returns the corresponding perturbed data

- ageEnsOut
TRUE or FALSE - return the ageEnsemble

res a list with

res$Xc: realizations of age-perturbed data matrix of size tn*p*ns (could be 2 or 3d)

res$tc: new chronology tn*1

res$tmc: corresponding ensemble of time-correction matrices (tn*p*ns) to map realizations in Xp back to the original data X (2=insert nan, 0=remove double band) (2 or 3d) where tn is the chronology length = n (default), shortest sample or longest sample depending on the chosen resizing option.

res$ageEnsemble (optional): Returnd the full age ensemble if desired.

Other BAM:
`bamCorrect()`

,
`runBam()`

```
if (FALSE) {
res <- simulateBam(X,t)
#will generate an ensemble of 1000 age models randomly following
#a Poisson process with rate parameter theta=0.05 used to perturb data X
res <- simulateBam(X,t,model)
#will perturb data X with the model specified in
#the model structure
}
```