Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fitEllipse

Fit a multivariate normal distribution to x and y data using jags


Description

This function contains and defines the jags model script used to fit a bivariate normal distribution to a vector of x and y data. Although not intended for direct calling by users, it presents a quick way to fit a model to a single group of data. Advanced users should be able to manipulate the contained jags model to fit more complex models using different likelihoods, such as multivariate lognormal distributions, multivariate gamma distributions etc...

Usage

fitEllipse(x, y, parms, priors, id = NULL)

Arguments

x

a vector of data representing the x-axis

y

a vector of data representing the y-axis

parms

a list containing four items providing details of the rjags run to be sampled.

  • n.iterThe number of iterations to sample

  • n.burninThe number of iterations to discard as a burnin from the start of sampling.

  • n.thinThe number of samples to thin by.

  • n.chainsThe number of chains to fit.

priors

a list of three items specifying the priors to be passed to the jags model.

  • RThe scaling vector for the diagonal of Inverse Wishart distribution prior on the covariance matrix Sigma. Typically set to a 2x2 matrix matrix(c(1, 0, 0, 1), 2, 2).

  • kThe degrees of freedom of the Inverse Wishart distribution for the covariance matrix Sigma. Typically set to the dimensionality of Sigma, which in this bivariate case is 2.

  • tauThe precision on the normal prior on the means mu.

id

a character string to prepend to the raw saved jags model output. This is typically passed on from the calling function siberMVN and identifies the community and group with an integer labelling system. Defaults to NULL which will prevent the output object being saved even if parms$save.output is set to TRUE. The file itself will be saved to the user-specified location via parms$save.dir.

Value

A mcmc.list object of posterior samples created by jags.

Examples

x <- stats::rnorm(50)
y <- stats::rnorm(50)
parms <- list()
parms$n.iter <- 2 * 10^3
parms$n.burnin <- 500
parms$n.thin <- 2     
parms$n.chains <- 2    
priors <- list()
priors$R <- 1 * diag(2)
priors$k <- 2
priors$tau.mu <- 1.0E-3
fitEllipse(x, y, parms, priors)

SIBER

Stable Isotope Bayesian Ellipses in R

v2.1.6
GPL (>= 2)
Authors
Andrew Jackson and Andrew Parnell
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.