Computes a given histogram distance metric to a distribution
Source:R/metric_histogram_dist.R
metric.histogram.dist.Rd
Generally this function is used to estimate the parameters of a distribution
by minimizing the given metric. The first argument is a vector of parameters
that should match up with the arguments for dist
. For example, params = c(0, 1)
with
dist = 'norm'
refers to mean 0 and sd 1. This is so that we can use
metric.histogram.dist
in DEoptim::DEoptim
which requires the parameters to
optimize to be the first argument.
Usage
metric.histogram.dist(
params,
x,
interval_start,
interval_end,
dist = c("norm", "gamma", "gamma_flip"),
metric_func = ls(pattern = "^histogram[.].*", envir = getNamespace("HistogramZoo")),
truncated = FALSE
)
Arguments
- params
vector of parameters that should match up with the arguments for
dist
.- x
counts of the histogram
- interval_start
left endpoint of the histogram
- interval_end
right endpoint of the histogram
- dist
one of
norm
,gamma
orgamma_flip
- metric_func
one of histogram.chisq, histogram.intersection, histogram.jaccard, histogram.ks, histogram.mse
- truncated
Should distributions be truncated to the end points of the histogram?
Examples
x.hist <- observations_to_histogram(rnorm(1000))
args <- list(
x = x.hist$histogram_data,
interval_start = x.hist$interval_start,
interval_end = x.hist$interval_end,
dist = 'norm',
metric_func = 'histogram.intersection'
)
do.call(
metric.histogram.dist,
c(args, list(params = c(0, 1)))
)
#> [1] 0.02419275
do.call(
metric.histogram.dist,
c(args, list(params = c(1, 1.5)))
)
#> [1] 0.3569778