plot.arbutus: Plot the simulated test statistics versus observed test...

View source: R/plotting-fxns.R

plot.arbutusR Documentation

Plot the simulated test statistics versus observed test statistics

Description

Plots a histogram of the simulated values along with the observed values for a single test statistic. Either a point estimate or distribution of observed values may be used. Is the generic plot function for objects of class arbutus.

Usage

## S3 method for class 'arbutus'
plot(
  x,
  xlab = NA,
  ylab = "Counts",
  col = NA,
  breaks = NA,
  las = 1,
  lwd = 3,
  legend = TRUE,
  legend.pos = "topright",
  cex = 1,
  n.row = 2,
  n.col = NA,
  mar = c(5, 4, 2, 2),
  ...
)

Arguments

x

an arbutus object inherited from compare_pic_stat

xlab

x-axis label. Defaults to stat.

ylab

y-axis label. Defaults to "Counts".

col

colours used in plot. The first colour corresponds to the histogram of simulated test statistics. The second colour to the line, or histogram, representing the observed value of the test statistic. If no argument is supplied, the function uses the default colours.

breaks

the number of breaks in the histogram. Defaults to 20.

las

plot parameter (see par).

lwd

plot parameter (see par).

legend

logical, specifying whether a legend should be included (see details).

legend.pos

postiion of the legend (see legend).

cex

plot parameter for legend (see par).

n.row

number of rows to plot when plotting multiple test statistics. Defaults to 2.

n.col

number of columns to plot when plotting multiple test statistics. Defaults to ncol(obs)/2.

mar

margins for each plot. Defaults to 5,4,2,2.

...

additional arguments to be passed to plot

Details

This function is designed to give researchers a quick visual inspection of model adequacy by plotting the simulated distribution of all test statistics versus the emprical values.

This function is a simply a wrapper for the functions arbutus_plot_point and arbutus_plot_dist. It creates plots for all test statistics used in arbutus and compare_pic_stat. The function can be supplied either a point estimate for the observed test statistics or a distribution of estimates.

If the empirical estimate lies in the tails of the distribution of simulated test statistics, the model can be rejected as inadequate.

The p-values corresponding to this plot can be obtained with the function pvalue_arbutus.

We are still working on a general function for plotting legends. For the time being, if legend=TRUE, a legend will appear with each test statistic. This is obviously not ideal, but we are working on it.

If users wish to create their own plots, all of the information is stored in the arbutus object. x$obs contains a data.frame of observed test statistics and x$sim, a data.frame of simulated test statistics.

See Also

arbutus, compare_pic_stat, arbutus_plot_point, arbutus_plot_dist

Examples

## finch data
data(finch)
phy <- finch$phy
data <- finch$data[,1]

## pretend that the tree has already been rescaled
modelad <- arbutus(phy, data=data, nsim=20)
plot(modelad)


## Not run: 
## use diversitree to fit a BM model with ML
require(diversitree)
lik <- make.bm(phy, data)
f <- find.mle(lik, x.init=1)
modelad.bm.ml <- arbutus(f)
plot(modelad.bm.ml, legend=FALSE)

## use diversitree to fit a BM model with MCMC
m <- mcmc(lik, x.init=1, nsteps=1000, w=1, print.every=0)
modelad.bm.mcmc <- arbutus(m, sample=100)
plot(modelad.bm.mcmc)

## End(Not run)


mwpennell/arbutus documentation built on Oct. 6, 2022, 10 a.m.