Consider the normal distribution \(\mathcal{N}(\mu, \sigma^2)\) defined by the density \[
f(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right),
x\in\mathbb{R},
\] where \(\mu\) is a location parameter such that \(\mu\in\mathbb{R}\), \(\sigma^2\) is a scale parameter such that \(\sigma^2>0\). Therefore when optimizing the log-likelihood or the squared differences or the GoF statistics. Setting a lower bound for the scale parameter is easy with fitdist
: just use the lower
argument.
set.seed(1234)
x <- rnorm(1000, 1, 2)
fitdist(x, "norm", lower=c(-Inf, 0))
## Fitting of the distribution ' norm ' by maximum likelihood
## Parameters:
## estimate Std. Error
## mean 0.9468056 NA
## sd 1.9936779 NA
Consider the Burr distribution \(\mathcal B(\mu, \sigma^2)\) defined by the density \[ f(x) = \frac{a b (x/s)^b}{x [1 + (x/s)^b]^{a + 1}}, x\in\mathbb{R}, \] where \(a,b\) are shape parameters such that \(a,b>0\), \(s\) is a scale parameter such that \(s>0\).
x <- rburr(1000, 1, 2, 3)
fitdist(x, "burr", lower=c(0, 0, 0), start=list(shape1 = 1, shape2 = 1,
rate = 1))
## Fitting of the distribution ' burr ' by maximum likelihood
## Parameters:
## estimate Std. Error
## shape1 0.9686565 NA
## shape2 2.0509617 NA
## rate 3.1801804 NA
Consider the geometric distribution \(\mathcal G(p)\) defined by the mass probability function \[ f(x) = p(1-p)^x, x\in\mathbb{N}, \] where \(p\) is a probability parameter such that \(p\in[0,1]\).
x <- rgeom(1000, 1/4)
fitdist(x, "geom", lower=0, upper=1)
## Fitting of the distribution ' geom ' by maximum likelihood
## Parameters:
## estimate Std. Error
## prob 0.2420136 0.00666292
Consider the shifted exponential distribution \(\mathcal E(\mu,\lambda)\) defined by the mass probability function \[ f(x) = \lambda \exp(-\lambda(x-\mu)), x>\mu, \] where \(\lambda\) is a scale parameter such that \(\lambda>0\), \(\mu\) is a boundary (or shift) parameter such that \(\mu\in\mathbb{R}\). When optimizing the log-likelihood, the boundary constraint is \[ \forall i=1,\dots,n, x_i>\mu \Rightarrow \min_{i=1,\dots,n} x_i > \mu \Leftrightarrow \mu > -\min_{i=1,\dots,n} x_i. \] When optimizing the squared differences or the GoF statistics, this constraint is not necessary. Let us do it in R.
dsexp <- function(x, rate, shift)
dexp(x-shift, rate=rate)
psexp <- function(x, rate, shift)
pexp(x-shift, rate=rate)
rsexp <- function(n, rate, shift)
rexp(n, rate=rate)+shift
x <- rsexp(1000, 1/4, 1)
constrOptim2 <- function(par, fn, gr=NULL, ui, ci, ...)
constrOptim(theta=par, f=fn, grad=gr, ui=ui, ci=ci, ...)
fitdist(x, "sexp", start=list(rate=1, shift=0), custom.optim=constrOptim2,
ui = cbind(c(1, 0), c(0, 1)), ci = c(0, -min(x)))
## Fitting of the distribution ' sexp ' by maximum likelihood
## Parameters:
## estimate Std. Error
## rate 0.2479984 NA
## shift 1.0053211 NA