simulateKvsMAD: Simulate k vs MAD

Description Usage Arguments Details Value Examples

View source: R/simulateKvsMAD.R

Description

This function simulates random variables from a (univariate) random number generator and compares the MAD absolute deviation with quantiles of the deviance. Such a comparison can provide insight into the appropriate choice of k, as k should be chosen based on which deviance values are "extreme" and which are "reasonable".

Usage

1
2
simulateKvsMAD(rand, dev, quantiles = c(0.95), nSample = 1000,
  nRuns = 100, logMAD = TRUE, ...)

Arguments

rand

The random number generator function, accepting the number of random observations to generate as well as any parameters passed in ....

dev

The deviance function, accepting the value of an observation as well as any parameters passed in ...

quantiles

The quantiles of the deviance which are desired for reporting.

nSample

The number of random samples to draw within each run.

nRuns

The number of total runs to perform.

logMAD

Logical. Should the MAD be plotted on a log scale?

...

Additional vectors of parameters. Each passed argument must be named and must be of type vector. For each run, a sample will be drawn from each vector and this value will be passed to both rand and dev. See examples.

Details

In this simulation, nSize observations are drawn from the passed distribution. From this data, the MAD and the quantile(s) of the deviance are computed. This process is repeated nRuns times to generate the expected relationship between the quantiles of the deviance and the MAD.

Value

A ggplot2 object plotting the results of the simulation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
dev = function(x, ...){-2 * dnorm(x, ..., log = TRUE)}
simulateKvsMAD(rnorm, dev, sd = 10^seq(-3, 3, .5), mean = -2:2)
simulateKvsMAD(rnorm, dev, sd = 10^seq(-3, 3, .5), mean = -2:2,
               quantiles = c(0.8, 0.9, 0.95, 0.99))
               
dev = function(x, ...){-2 * sn::dst(x, ..., log = TRUE)}
simulateKvsMAD(sn::rst, dev, xi = -5:5, omega = 10^seq(-3, 3, .5),
               alpha = -5:5, nu = 10^seq(0, 4, 1/3),
               quantiles = c(0.8, 0.9, 0.95, 0.99))

dev = function(x, ...){-2 * sn::dmst(x, ..., log = TRUE)}
simulateKvsMAD(sn::rmst, dev, xi = list(c(-1, -1), c(0, 1), c(-2, 2)),
               Omega = list(diag(2) * .1, diag(2), diag(2)*10),
               alpha = list(c(0, 1)), nu = 10^seq(0, 4, 1/3),
               quantiles = c(0.8, 0.9, 0.95, 0.99))

rockclimber112358/MCLE documentation built on May 27, 2019, 12:15 p.m.