fit_distr_fun {mosaicCore}R Documentation

Fit a distribution to data and return a function

Description

Given the name of a family of 1-dimensional distributions, this function chooses a particular member of the family that fits the data and returns a function in the selected p, d, q, or r format. When analytical solutions do not exist, MASS::fitdistr() is used to estimate the parameters by numerical maximum likelihood.

Usage

fit_distr_fun(data, formula, dist, start = NULL, ...)

Arguments

data

A data frame.

formula

A formula. A distribution will be fit to the data defined by the right side and evaluated in data.

dist

A string naming the function desired. Tyically this will be "d", "p", "q", or "r" followed by the (abbrevation for) a family of distributions such as "pnorm", "rgamma". Fitting is done use MASS::fitdistr(); see the help there for a list of distributions that are available.

start

Starting values for the numerical maximum likelihood method (passed to MASS::fitdistr).

...

Additional arguments to MASS::fitdistr()

Value

A function of one variable that acts like, say, pnorm(), dnorm(), qnorm(), or rnorm(), but with the default values of the parameters set to their maximum likelihood estimates.

Examples


fit_distr_fun( ~ cesd, data = mosaicData::HELPrct, dist = "dnorm")
fit_distr_fun( ~ cesd, data = mosaicData::HELPrct, dist = "pnorm")
fit_distr_fun( ~ cesd, data = mosaicData::HELPrct, dist = "qpois")

[Package mosaicCore version 0.9.4.0 Index]