fec_stan {eggCounts}R Documentation

Modelling of faecal egg count data (one-sample case)


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)



numeric vector. Faecal egg counts.


logical. If TRUE, preFEC and postFEC correspond to raw counts (as counted on equipment). Otherwise they correspond to calculated epgs (raw counts times correction factor). Defaults to FALSE.


a positive integer or a vector of positive integers. Correction factor(s).


logical. If true, uses the model with zero-inflation. Otherwise uses the model without zero-inflation


named list. Prior for the group mean epg parameter \mu. The default prior is list(priorDist = "gamma",hyperpars=c(1,0.001)), i.e. a gamma distribution with shape 1 and rate 0.001, its 90% probability mass lies between 51 and 2996.


named list. Prior for the group dispersion parameter \kappa. The default prior is list(priorDist = "gamma",hyperpars=c(1,0.7)), i.e. a gamma distribution with shape 1 and rate 0.7, its 90% probability mass lies between 0.1 and 4.3 with a median of 1.


named list. Prior for the zero-inflation parameter \phi. The default prior is list(priorDist = "beta",hyperpars=c(1,1)), i.e. a uniform prior between 0 and 1.


a positive integer. Number of samples for each chain (including burn-in samples).


a positive integer. Number of burn-in samples.


a positive integer. Thinning parameter, i.e. the period for saving samples.


a positive integer. Number of chains.


a positive integer. Number of cores to use when executing the chains in parallel.


numeric. The target acceptance rate, a numeric value between 0 and 1.


logical. If TRUE, posterior samples for all parameters are saved in the stanfit object. If FALSE, only samples for \mu, \kappa and \phi are saved. Default to FALSE.


logical. If true, prints progress and debugging information.


List of built-in models

Note that this function only models the mean of egg counts, see fecr_stan() for modelling the reduction.

Other information

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 User Guide.

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.


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


Craig Wang

See Also

simData1s for simulating faecal egg count data with one sample


## load the sample data

## apply zero-infation model
model <- fec_stan(epgs$before, rawCounts = FALSE, CF = 50)

[Package eggCounts version 2.3-2 Index]