Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

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

mosaicCore

Common Utilities for Other MOSAIC-Family Packages

v0.9.0
GPL (>= 2)
Authors
Randall Pruim <rpruim@calvin.edu>, Daniel T. Kaplan <kaplan@macalester.edu>, Nicholas J. Horton <nhorton@amherst.edu>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.