mix2exp.RdEstimates the three parameters of a mixture of two exponential distributions by maximum likelihood estimation.
mix2exp(lphi = "logitlink", llambda = "loglink", iphi = 0.5,
il1 = NULL, il2 = NULL, qmu = c(0.8, 0.2), nsimEIM = 100,
zero = "phi")Link functions for the parameters \(\phi\)
and \(\lambda\). The latter is the rate parameter
and note that the mean of an ordinary exponential distribution is
\(1 / \lambda\).
See Links for more choices.
Initial value for \(\phi\), and
optional initial value for \(\lambda_1\) and
\(\lambda_2\).
The last two have values that must be positive.
The default is to compute initial values internally using
the argument qmu.
Vector with two values giving the probabilities relating to the
sample quantiles for obtaining initial values for
\(\lambda_1\) and \(\lambda_2\). The two
values are fed in as the probs argument into
quantile.
The probability density function can be loosely written as $$f(y) = \phi\,Exponential(\lambda_1) + (1-\phi)\,Exponential(\lambda_2)$$ where \(\phi\) is the probability an observation belongs to the first group, and \(y>0\). The parameter \(\phi\) satisfies \(0 < \phi < 1\). The mean of \(Y\) is \(\phi / \lambda_1 + (1-\phi) / \lambda_2\) and this is returned as the fitted values. By default, the three linear/additive predictors are \((logit(\phi), \log(\lambda_1), \log(\lambda_2))^T\).
An object of class "vglmff"
(see vglmff-class).
The object is used by modelling functions
such as vglm
and vgam.
This VGAM family function requires care for a successful
application.
In particular, good initial values are required because
of the presence of local solutions. Therefore running
this function with several different combinations of
arguments such as iphi, il1, il2,
qmu is highly recommended. Graphical methods such
as hist can be used as an aid.
This VGAM family function is experimental and should be used with care.
Fitting this model successfully to data can be
difficult due to local solutions, uniqueness problems
and ill-conditioned data. It pays to fit the model
several times with different initial values and check
that the best fit looks reasonable. Plotting the
results is recommended. This function works better as
\(\lambda_1\) and \(\lambda_2\)
become more different. The default control argument
trace = TRUE is to encourage monitoring convergence.
if (FALSE) lambda1 <- exp(1); lambda2 <- exp(3)
(phi <- logitlink(-1, inverse = TRUE))
#> [1] 0.2689414
mdata <- data.frame(y1 = rexp(nn <- 1000, lambda1))
#> Error: object 'lambda1' not found
mdata <- transform(mdata, y2 = rexp(nn, lambda2))
#> Error: object 'mdata' not found
mdata <- transform(mdata, Y = ifelse(runif(nn) < phi, y1, y2))
#> Error: object 'mdata' not found
fit <- vglm(Y ~ 1, mix2exp, data = mdata, trace = TRUE)
#> Error in eval(mf, parent.frame()): object 'mdata' not found
coef(fit, matrix = TRUE)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'coef': object 'fit' not found
# Compare the results with the truth
round(rbind('Estimated' = Coef(fit),
'Truth' = c(phi, lambda1, lambda2)), digits = 2)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'Coef': object 'fit' not found
with(mdata, hist(Y, prob = TRUE, main = "Orange=estimate, blue=truth"))
#> Error: object 'mdata' not found
abline(v = 1 / Coef(fit)[c(2, 3)], lty = 2, col = "orange", lwd = 2)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'Coef': object 'fit' not found
abline(v = 1 / c(lambda1, lambda2), lty = 2, col = "blue", lwd = 2)
#> Error: object 'lambda1' not found
# \dontrun{}