fecr_stanSimple.Rd
Models the reduction in faecal egg counts with a simple Bayesian model formulation. The model is for paired design only, and it assumes Poisson distribution for the observed egg counts.
fecr_stanSimple(preFEC, postFEC, rawCounts = FALSE, preCF = 50, postCF = preCF, muPrior, deltaPrior, nsamples = 2000, nburnin = 1000, thinning = 1, nchain = 2, ncore = 1, adaptDelta = 0.95, saveAll = FALSE, verbose = FALSE)
preFEC | numeric vector. Pre-treatment faecal egg counts. |
---|---|
postFEC | numeric vector. Post-treatment faecal egg counts. |
rawCounts | logical. If TRUE, |
preCF | positive integer or vector of positive integers. Pre-treatment correction factor(s). |
postCF | positive integer or vector of positive integers. Post-treatment correction factor(s). |
muPrior | named list. Prior for the group mean epg parameter \(\mu\). The default prior is |
deltaPrior | named list. Prior for the reduction parameter \(\delta\). 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 the posterior summary of FECR
as the reduction, meanEPG.untreated
as the mean pre-treatment epg, and meanEPG.treated
as the mean after-treatment 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
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.
simData2s
for simulating faecal egg counts data with two samples
# \donttest{ ## load sample data data(epgs) ## apply paired model with individual efficacy model <- fecr_stanSimple(epgs$before, epgs$after, rawCounts = FALSE, preCF = 10)#> #> SAMPLING FOR MODEL 'simple' NOW (CHAIN 1). #> Chain 1: Gradient evaluation took 2.8e-05 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.28 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.060557 seconds (Warm-up) #> Chain 1: 0.042451 seconds (Sampling) #> Chain 1: 0.103008 seconds (Total) #> #> SAMPLING FOR MODEL 'simple' NOW (CHAIN 2). #> Chain 2: Gradient evaluation took 9e-06 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.09 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.04604 seconds (Warm-up) #> Chain 2: 0.042762 seconds (Sampling) #> Chain 2: 0.088802 seconds (Total) #> Model: Simple Bayesian model without zero-inflation for paired design #> Number of Samples: 2000 #> Warm-up samples: 1000 #> Thinning: 1 #> Number of Chains 2 #> mean sd 2.5% 50% 97.5% HPDLow95 #> FECR 0.9223 0.0066 0.9085 0.9225 0.9344 0.9095 #> meanEPG.untreated 1345.6952 30.2995 1288.0167 1345.0828 1405.8413 1289.2031 #> meanEPG.treated 104.5096 8.5628 87.9412 104.3059 121.3611 87.6968 #> mode HPDHigh95 #> FECR 0.9231 0.9351 #> meanEPG.untreated 1347.1312 1406.6521 #> meanEPG.treated 103.0423 121.0372 #> #> NOTE: there is no evidence of non-convergence since all parameters have potential scale reduction factors (Brooks and Gelman, 1998) less than 1.1.