Learn R Programming

mosaicCore (version 0.9.0)

fit_distr_fun: 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, ...)

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.

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()

Examples

Run this code

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")

Run the code above in your browser using DataLab