This function is a wrapper over different methods of density estimation. By
default, it uses the base R density
with by default uses a different smoothing
bandwidth ("SJ"
) from the legacy default implemented the base R density
function ("nrd0"
). However, Deng and Wickham suggest that method = "KernSmooth"
is the fastest and the most accurate.
estimate_density(x, ...)# S3 method for data.frame
estimate_density(
x,
method = "kernel",
precision = 2^10,
extend = FALSE,
extend_scale = 0.1,
bw = "SJ",
ci = NULL,
select = NULL,
by = NULL,
at = NULL,
rvar_col = NULL,
...
)
Vector representing a posterior distribution, or a data frame of such
vectors. Can also be a Bayesian model. bayestestR supports a wide range
of models (see, for example, methods("hdi")
) and not all of those are
documented in the 'Usage' section, because methods for other classes mostly
resemble the arguments of the .numeric
or .data.frame
methods.
Currently not used.
Density estimation method. Can be "kernel"
(default), "logspline"
or "KernSmooth"
.
Number of points of density data. See the n
parameter in density
.
Extend the range of the x axis by a factor of extend_scale
.
Ratio of range by which to extend the x axis. A value of 0.1
means that the x axis will be extended by 1/10
of the range of the data.
See the eponymous argument in density
. Here, the default has been
changed for "SJ"
, which is recommended.
The confidence interval threshold. Only used when method = "kernel"
.
This feature is experimental, use with caution.
Character vector of column names. If NULL
(the default), all
numeric variables will be selected. Other arguments from
datawizard::extract_column_names()
(such as exclude
) can also be used.
Optional character vector. If not NULL
and input is a data frame,
density estimation is performed for each group (subsets) indicated by by
.
See examples.
Deprecated in favour of by
.
A single character - the name of an rvar
column in the data
frame to be processed. See example in p_direction()
.
Deng, H., & Wickham, H. (2011). Density estimation in R. Electronic publication.