unimle: User-friendly univariate Maximum Likelihood Estimation

Description Usage Arguments Value Note Examples

View source: R/marginal.R

Description

Finds the MLE from a univariate sample using a parametric family of distributions built into R (or others similar to them).

Usage

1
unimle(x, ddist = dnorm, init.val = NULL, in.range = NULL)

Arguments

x

Vector of univariate sample drawn from the distribution.

ddist

A family of densities or mass functions, for example dnorm or dnbinom. Each parameter should have its own named argument.

init.val

The initial guess at parameter values for the numerical optimizer. Could be (1) a vector, in which the order provided will correspond to the order given in the R documentation for that distribution, or (2) a list with names being the parameter names, or (3) NULL in which case default parameter values are used (if there even are defaults).

in.range

The same as the argument in rnlm – a function that takes the parameter values and returns TRUE if that value of the parameter is "proper"; FALSE otherwise.

Value

A list of the parameter estimates, named according to their corresponding parameter names

Note

If you want to make your own distribution (density function), just be sure to follow R's order of arguments (x first, then named parameters).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## MLE of a Gaussian sample
unimle(rnorm(1000))
x <- rnorm(1000, 5, 100)
unimle(x)
unimle(x, init.val = list(sd = 80, mean = 10))  # Notice the order output order

## MLE of negative binomial
x <- rnbinom(1000, size = 2, mu = 10)
unimle(x, dnbinom)  # No defaults, so must specify inits
unimle(x, dnbinom, c(1, 0.3))
unimle(x, dnbinom, list(size = 1, mu = 5))

vincenzocoia/copsupp documentation built on Aug. 23, 2020, 7:37 a.m.