getmode {poolABC} | R Documentation |
Calculate the mode of a distribution
Description
Computes and outputs the mode of the input distribution.
Usage
getmode(x, xlim, weights = NULL, alpha = 0.7, precision = 1000)
Arguments
x |
is a numeric vector containing the values of the distribution. |
xlim |
is a vector with two entries.The first entry is the minimum of
the |
weights |
this is an optional input consisting of a vector with the prior weights for the locfit function. |
alpha |
numeric value with the alpha parameter of the locfit function. The default value is 0.7 |
precision |
value indicating the number of entries evaluated. The larger the value the higher the precision. The default value is 1000. |
Details
The locfit::locfit()
function is used to fit a local regression to the
distribution. The stats::predict()
function is then used to predict the
y-axis values of the locfit and the mode is defined as the value where that
prediction is maximized. Note that if this function is not able to fit a
local regression to the distribution, then the mode of the distribution will
be assumed to be equal to the median.
Value
a numeric value of the mode of the input distribution.
Examples
# create a random distribution
x <- rnorm(n = 100, mean = 2, sd = 25)
# compute the mode of the distribution
getmode(x = x, xlim = c(min(x), max(x)))