Learn R Programming

simukde (version 1.3.0)

find_best_fit: Find The Best Fitting Distribution

Description

It finds the best fitting distribution from supported univariate continuous distributions for given data.

Usage

find_best_fit(
  x,
  positive = FALSE,
  plot = TRUE,
  legend.pos = "topright",
  dlc = NULL,
  dlw = 1,
  ...
)

Arguments

x

a numeric vector; data.

positive

a logical constant; distribution type.

plot

a logical constant. If TRUE (default), a histogram and density lines are drawn.

legend.pos

a character string. Indicates the legend position and must be one of "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright" (default), "right" and "center".

dlc

a vector; probability density line colors for supported (up to 7) distributions. If unspecified, the rainbow color palette will be used.

dlw

a numerical constant; probability density line width.

...

Further arguments and parameters for the function hist, particularly, main title and axis labels. However, the parameter freq is not able to override.

Value

A list containing the following items:

distribution

the name of the best fitting distribution.

ks.statistic

the Kolmogorov-Smirnov test statistic for the distribution.

p.value

the p-value of the test.

summary

results similar to above for other distributions.

x

given data.

n

the sample size.

Details

This function is supported following univariate distributions:

  • for positive random variables: Log normal, Exponential, Gamma and Weibull.

  • for all random variables: Normal, Cauchy, Log normal, Exponential, Gamma, Weibull and Uniform.

Legends of the plot are ordered by p-values of the test.

References

  1. William J. Conover (1971). Practical Nonparametric Statistics. New York: John Wiley & Sons. Pages 295<U+2013>301.

  2. Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.

See Also

ks.test, fitdistr, hist

Examples

Run this code
# NOT RUN {
petal.length <- datasets::iris$Petal.Length[datasets::iris$Species == "setosa"]
simukde::find_best_fit(x = petal.length, positive = TRUE)
# }

Run the code above in your browser using DataLab