estim_ML: Estimate a trimmed distribution

View source: R/estimation.R

estim_MLR Documentation

Estimate a trimmed distribution

Description

Estimate the parameters of a trimmed distribution using maximum likelihood.

Usage

estim_ML(
  d,
  y,
  trim = c(-Inf, Inf),
  doTrunc = FALSE,
  par.low = rep(-Inf, nPar(d)),
  par.high = rep(Inf, nPar(d)),
  method = "Nelder-Mead",
  control = list(fnscale = -1, maxit = 10000)
)

Arguments

d

distributions3 object, assumed distribution. The parameters specified in d are interpreted as initial guesses and should be both feasible (e.g. no negative scale parameter) and data-compatible (i.e. not lead to a data point having a null pdf)

y

Numeric vector, data

trim

Numeric vector of size 2, trimming bounds.

doTrunc

Logical, do truncation? default FALSE, i.e. rectification is used.

par.low

Numeric vector of size nPar(d), lower bounds for parameters.

par.high

Numeric vector of size nPar(d), higher bounds for parameters.

method

Character string, optimization method, see ?optim.

control

List, controls for optimization algorithm, see ?optim.

Value

the estimated distribution as a distributions3 object. Note that parameters may be NA's if the estimation failed.

Examples

# EXAMPLE 1
# Define Normal distribution
norm <- Normal(mu=1,sigma=2)
# generate data and reset all negative values to zero
y <- random(norm,200); y[y<0] <- 0
# Estimate basic / rectified / truncated Gaussian distributions.
# The latter returns NA's because y=0 values occur,
# which is not compatible with a zero-truncated distribution.
estim_ML(d=norm,y=y)
estim_ML(d=norm,y=y,trim=c(0,Inf))
estim_ML(d=norm,y=y,trim=c(0,Inf),doTrunc=TRUE)

# EXAMPLE 2
# Define Normal distribution
norm <- Normal(mu=0.75,sigma=0.25)
# generate data and remove all values outside [0;1]
z <- random(norm,200); y <- z[z>0 & z<1]
# Estimate basic / rectified / truncated Gaussian distributions.
estim_ML(d=norm,y=y)
estim_ML(d=norm,y=y,trim=c(0,1))
estim_ML(d=norm,y=y,trim=c(0,1),doTrunc=TRUE)
# Good practice: explicitly set parameter bounds, here sigma>0
estim_ML(d=norm,y=y,par.low=c(-Inf,0))

benRenard/disTRIMbution documentation built on July 1, 2023, 4:24 a.m.