fec_stan.Rd
Models the mean of faecal egg counts with Bayesian hierarchical models. See Details for a list of model choices.
fec_stan(fec, rawCounts = FALSE, CF = 50, zeroInflation = TRUE, muPrior, kappaPrior, phiPrior, nsamples = 2000, nburnin = 1000, thinning = 1, nchain = 2, ncore = 1, adaptDelta = 0.95, saveAll = FALSE, verbose = FALSE)
fec | numeric vector. Faecal egg counts. |
---|---|
rawCounts | logical. If TRUE, |
CF | a positive integer or a vector of positive integers. Correction factor(s). |
zeroInflation | logical. If true, uses the model with zero-inflation. Otherwise uses the model without zero-inflation |
muPrior | named list. Prior for the group mean epg parameter \(\mu\). The default prior is |
kappaPrior | named list. Prior for the group dispersion parameter \(\kappa\). The default prior is |
phiPrior | named list. Prior for the zero-inflation parameter \(\phi\). The default prior is |
nsamples | a positive integer. Number of samples for each chain (including burn-in samples). |
nburnin | a positive integer. Number of burn-in samples. |
thinning | a positive integer. Thinning parameter, i.e. the period for saving samples. |
nchain | a positive integer. Number of chains. |
ncore | a positive integer. Number of cores to use when executing the chains in parallel. |
adaptDelta | numeric. The target acceptance rate, a numeric value between 0 and 1. |
saveAll | logical. If TRUE, posterior samples for all parameters are saved in the |
verbose | logical. If true, prints progress and debugging information. |
Prints out summary of meanEPG
as the posterior mean epg. The posterior summary contains the mean, standard deviation (sd), 2.5%, 50% and 97.5% percentiles, the 95% highest posterior density interval (HPDLow95 and HPDHigh95) and the posterior mode. NOTE: we recommend to use the 95% HPD interval and the mode for further statistical analysis.
The returned value is a list that consists of:
an object of S4 class stanfit
representing the fitted results
a data.frame that is the same as the printed posterior summary
without zero-inflation: set zeroInflation = FALSE
with zero-inflation: set zeroInflation = TRUE
Note that this function only models the mean of egg counts, see fecr_stan()
for modelling the reduction.
The first time each model with non-default priors is applied, it can take up to 20 seconds to compile the model. Currently the function only support prior distributions with two parameters. For a complete list of supported priors and their parameterization, please consult the list of distributions in Stan.
The default number of samples per chain is 2000, with 1000 burn-in samples. Normally this is sufficient in Stan. If the chains do not converge, one should tune the MCMC parameters until convergence is reached to ensure reliable results.
simData1s
for simulating faecal egg count data with one sample
## load the sample data data(epgs) ## apply zero-infation model model <- fec_stan(epgs$before, rawCounts = FALSE, CF = 50)#> #> SAMPLING FOR MODEL 'zinb' NOW (CHAIN 1). #> Chain 1: Gradient evaluation took 4.2e-05 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.42 seconds. #> Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup) #> Chain 1: Iteration: 500 / 2000 [ 25%] (Warmup) #> Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup) #> Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling) #> Chain 1: Iteration: 1500 / 2000 [ 75%] (Sampling) #> Chain 1: Iteration: 2000 / 2000 [100%] (Sampling) #> Chain 1: Elapsed Time: 0.706259 seconds (Warm-up) #> Chain 1: 0.618353 seconds (Sampling) #> Chain 1: 1.32461 seconds (Total) #> #> SAMPLING FOR MODEL 'zinb' NOW (CHAIN 2). #> Chain 2: Gradient evaluation took 1.5e-05 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.15 seconds. #> Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup) #> Chain 2: Iteration: 500 / 2000 [ 25%] (Warmup) #> Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup) #> Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling) #> Chain 2: Iteration: 1500 / 2000 [ 75%] (Sampling) #> Chain 2: Iteration: 2000 / 2000 [100%] (Sampling) #> Chain 2: Elapsed Time: 0.563578 seconds (Warm-up) #> Chain 2: 0.655911 seconds (Sampling) #> Chain 2: 1.21949 seconds (Total) #> Model: Zero-inflated Bayesian model #> Number of Samples: 2000 #> Warm-up Samples: 1000 #> Thinning: 1 #> Number of Chains 2 #> mean sd 2.5% 50% 97.5% HPDLow95 mode HPDHigh95 #> meanEPG 1238.757 589.3419 461.5077 1123.219 2626.891 363.1545 876.223 2314.627 #> #> NOTE: there is no evidence of non-convergence since all parameters have potential scale reduction factors (Brooks and Gelman, 1998) less than 1.1.