densityplot.angmcmc: Density plots for angmcmc objects

View source: R/all_diagnostics.R

densityplot.angmcmcR Documentation

Density plots for angmcmc objects

Description

Plot fitted angular mixture model density surfaces or curves.

Usage

## S3 method for class 'angmcmc'
densityplot(
  x,
  data = NULL,
  fn = mean,
  type = "point-est",
  log.density = FALSE,
  xpoints = seq(0, 2 * pi, length.out = 35),
  ypoints = seq(0, 2 * pi, length.out = 35),
  plot = TRUE,
  show.hist = ifelse(log.density, FALSE, TRUE),
  xlab,
  ylab,
  zlab = ifelse(log.density, "Log Density", "Density"),
  main,
  ...
)

Arguments

x

angmcmc object.

data

unused. The parameter is already filled with results from fitted angular model. It is kept to ensure compatibility with the lattice S3 generic densityplot.

fn

function, or a single character string specifying its name, to evaluate on MCMC samples to estimate parameters. Defaults to mean, which computes the estimated posterior mean. Note that if fn = "MODE" (warning: not "mode") or fn = "MAP", then the maximum aposteriori estimate (MAP) is calculated.

type

Passed to d_fitted. Possible choices are "point-est" and "post-pred".

log.density

logical. Should log density be used for the plot?

xpoints, ypoints

Points on the x and y coordinates (if bivariate) or only x coordinate (if univariate) where the density is to be evaluated. Each defaults to seq(0, 2*pi, length.out=100).

plot

logical. Should the density surface (if the fitted data is bivariate) or the density curve (if univariate) be plotted?

show.hist

logical. Should a histogram for the data points be added to the plot, if the fitted data is univariate? Ignored if data is bivariate.

xlab, ylab, zlab, main

graphical parameters passed to lattice::wireframe (if bivariate) or plot (if univariate). If the data is univariate, zlab and ylab can be used interchangeably (both correspond to the density).

...

additional arguments passed to lattice::wireframe if fitted data is bivariate, or to hist (if (show.hist == TRUE)), if the fitted data is univariate

Details

When plot==TRUE, densityplot.angmcmc calls lattice::wireframe or plot from graphics to draw the surface or curve.

To estimate the mixture density, first the parameter vector \eta is estimated by applying fn on the MCMC samples, yielding the (consistent) Bayes estimate \hat{\eta}. Then the mixture density f(x|\eta) at any point x is (consistently) estimated by f(x|\hat{\eta}).

Note that densityplot.angmcmc does not plot the kernel densitie estimates of the MCMC parameters. (These plots can be obtained by first converting an angmcmc object to an mcmc object via as.mcmc.list, and then by using densplot from package coda on the resulting mcmc.list object. Instead, densityplot.angmcmc returns the surface (if 2-D) or the curve (if 1-D) of the fitted model density evaluated at the estimated parameter vector (obtain through pointest).

Examples

# first fit a vmsin mixture model
# illustration only - more iterations needed for convergence
fit.vmsin.20 <- fit_vmsinmix(tim8, ncomp = 3, n.iter =  20,
                             n.chains = 1)
# now create density surface with the default first 1/3 as burn-in and thin = 1
library(lattice)
densityplot(fit.vmsin.20)
# the viewing angles can be changed through the argument 'screen'
# (passed to lattice::wireframe)
densityplot(fit.vmsin.20, screen = list(z=-30, x=-60))
densityplot(fit.vmsin.20, screen = list(z=30, x=-60))
# the colors can be changed through 'col.regions'
cols <- grDevices::colorRampPalette(c("blue", "green",
                                      "yellow", "orange", "red"))(100)
densityplot(fit.vmsin.20, col.regions = cols)

# Now fit a vm mixture model
# illustration only - more iterations needed for convergence
fit.vm.20 <- fit_vmmix(wind$angle, ncomp = 3, n.iter =  20,
                             n.chains = 1)
densityplot(fit.vm.20)


BAMBI documentation built on March 31, 2023, 11:24 p.m.