Functions cnmms
, cnmpl
and cnmap
can be used to compute
the maximum likelihood estimate of a semiparametric mixture model that has a
one-dimensional mixing parameter. The types of mixture models that can be
computed include finite, nonparametric and semiparametric ones.
cnmms(x, init=NULL, maxit=1000, model=c("spmle","npmle"), tol=1e-6,
grid=100, kmax=Inf, plot=c("null", "gradient", "probability"),
verbose=0)
cnmpl(x, init=NULL, tol=1e-6, tol.npmle=tol*1e-4, grid=100, maxit=1000,
plot=c("null", "gradient", "probability"), verbose=0)
cnmap(x, init=NULL, maxit=1000, tol=1e-6, grid=100, plot=c("null",
"gradient"), verbose=0)
a data object of some class that can be defined fully by the user
list of user-provided initial values for the mixing distribution
mix
and the structural parameter beta
maximum number of iterations
the type of model that is to estimated: non-parametric MLE
(npmle
) or semi-parametric MLE (spmle
).
a tolerance value that is used to terminate an algorithm.
Specifically, the algorithm is terminated, if the relative increase of the
log-likelihood value after an iteration is less than tol
. If an
algorithm converges rapidly enough, then -log10(tol)
is roughly the
number of accurate digits in log-likelihood.
number of grid points that are used by the algorithm to locate
all the local maxima of the gradient function. A larger number increases the
chance of locating all local maxima, at the expense of an increased
computational cost. The locations of the grid points are determined by the
function gridpoints
provided by each individual mixture family, and
they do not have to be equally spaced. If needed, an individual
gridpoints
function may return a different number of grid points than
specified by grid
.
upper bound on the number of support points. This is particularly useful for fitting a finite mixture model.
whether a plot is produced at each iteration. Useful for
monitoring the convergence of the algorithm. If null
, no plot is
produced. If gradient
, it plots the gradient curves and if
probability
, the plot
function defined by the user of the
class is used.
verbosity level for printing intermediate results in each iteration, including none (= 0), the log-likelihood value (= 1), the maximum gradient (= 2), the support points of the mixing distribution (= 3), the mixing proportions (= 4), and if available, the value of the structural parameter beta (= 5).
a tolerance value that is used to terminate the computing of the NPMLE internally.
the class of the mixture family that is used to fit to the data.
Number of iterations required by the algorithm
For cnmms
, it contains the values of the gradient
function at the support points and the first derivatives of the
log-likelihood with respect to theta and beta. For cnmpl
, it contains
only the first derivatives of the log-likelihood with respect to beta. For
cnmap
, it contains only the gradient of beta
.
Maximum value of the gradient function, evaluated at the
beginning of the final iteration. It is only given by function
cnmap
.
convergence code. =0
means a success, and
=1
reaching the maximum number of iterations
log-likelihood value at convergence
MLE of the mixing distribution, being an object of the class
disc
for discrete distributions
MLE of the structural parameter
Function cnmms
can also be used to compute the maximum likelihood
estimate of a finite or nonparametric mixture model.
A finite mixture model has a density of the form
$$f(x; \pi, \theta, \beta) = \sum_{j=1}^k \pi_j f(x; \theta_j, \beta).$$
where \(pi_j \ge 0\) and \(\sum_{j=1}^k pi_j \)\( =1\).
A nonparametric mixture model has a density of the form
$$f(x; G) = \int f(x; \theta) d G(\theta),$$ where \(G\) is a mixing distribution that is completely unspecified. The maximum likelihood estimate of the nonparametric \(G\), or the NPMLE of $\(G\), is known to be a discrete distribution function.
A semiparametric mixture model has a density of the form
$$f(x; G, \beta) = \int f(x; \theta, \beta) d G(\theta),$$
where \(G\) is a mixing distribution that is completely unspecified and \(\beta\) is the structural parameter.
Of the three functions, cnmms
is recommended for most problems; see
Wang (2010).
Functions cnmms
, cnmpl
and cnmap
implement the
algorithms CNM-MS, CNM-PL and CNM-AP that are described in Wang (2010).
Their implementations are generic using S3 object-oriented programming, in
the sense that they can work for an arbitrary family of mixture models that
is defined by the user. The user, however, needs to supply the
implementations of the following functions for their self-defined family of
mixture models, as they are needed internally by the functions above:
initial(x, beta, mix, kmax)
valid(x, beta)
logd(x, beta, pt, which)
gridpoints(x, beta, grid)
suppspace(x, beta)
length(x)
print(x, ...)
weight(x, ...)
While not needed by the algorithms, one may also implement
plot(x, mix, beta, ...)
so that the fitted model can be shown graphically in a way that the user desires.
For creating a new class, the user may consult the implementations of these
functions for the families of mixture models included in the package, e.g.,
cvp
and mlogit
.
Wang, Y. (2007). On fast computation of the non-parametric maximum likelihood estimate of a mixing distribution. Journal of the Royal Statistical Society, Ser. B, 69, 185-198.
Wang, Y. (2010). Maximum likelihood computation for fitting semiparametric mixture models. Statistics and Computing, 20, 75-86
# NOT RUN {
## Compute the MLE of a finite mixture
x = rnpnorm(100, disc(c(0,4), c(0.7,0.3)), sd=1)
for(k in 1:6) plot(cnmms(x, kmax=k), x, add=(k>1), comp="null", col=k+1,
main="Finite Normal Mixtures")
legend("topright", 0.3, leg=paste0("k = ",1:6), lty=1, lwd=2, col=2:7)
## Compute a semiparametric MLE
# Common variance problem
x = rcvps(k=50, ni=5:10, mu=c(0,4), pr=c(0.7,0.3), sd=3)
cnmms(x) # CNM-MS algorithm
cnmpl(x) # CNM-PL algorithm
cnmap(x) # CNM-AP algorithm
# Logistic regression with a random intercept
x = rmlogit(k=30, gi=3:5, ni=6:10, pt=c(0,4), pr=c(0.7,0.3),
beta=c(0,3))
cnmms(x)
data(toxo) # k = 136
cnmms(mlogit(toxo))
# }
Run the code above in your browser using DataLab