mix: Estimate Parameters of Mixture Distributions

Description Usage Arguments Value References See Also Examples

View source: R/mix.R

Description

Find a set of overlapping component distributions that gives the best fit to grouped data and conditional data, using a combination of a Newton-type method and EM algorithm.

Usage

1
2
3
4
mix(mixdat, mixpar, dist = "norm", constr = list(conpi = "NONE", 
    conmu = "NONE", consigma = "NONE", fixpi = NULL, fixmu = NULL, 
    fixsigma = NULL, cov = NULL, size = NULL), emsteps = 1, 
    usecondit = FALSE, exptol = 5e-06, print.level = 0, ...) 

Arguments

mixdat

A data frame containing grouped data, whose first column should be right boundaries of grouping intervals where the first and last intervals are open-ended; whose second column should consist of the frequencies indicating numbers of observations falling into each interval. If conditional data are available, this data frame should have k + 2 columns, where k is the number of components, whose element in row j and column i + 2 is the number of observations from the jth interval belonging to the ith component.

mixpar

A data frame containing starting values for parameters of component distributions, which are, in order, the proportions, means, and standard deviations.

dist

the distribution of components, it can be one of "norm", "lnorm", "gamma", "weibull", "binom", "nbinom" and "pois".

constr

a list of constraints on parameters of component distributions. See function mixconstr.

emsteps

a non-negative integer specifying the number of EM steps to be performed.

usecondit

logical. If usecondit is TRUE and mixdat includes conditional data, then conditional data will be used with grouped data to estimate parameters of mixtures.

exptol

a positive scalar giving the tolerance at which the scaled fitted value is considered large enough to be a degree of freedom.

print.level

this argument determines the level of printing which is done during the optimization process. The default value of 0 means that no printing occurs, a value of 1 means that initial and final details are printed and a value of 2 means that full tracing information is printed.

...

additional arguments to the optimization function nlm

.

Value

A list containing the following items:

parameters

A data frame containing estimated values for parameters of component distributions, which are, in order, the proportions, means, and standard deviations.

se

A data frame containing estimated values for standard errors of parameters of component distributions.

distribution

the distribution used to fit the data.

constraint

the constraints on parameters.

chisq

the goodness-of-fit chi-square statistic.

df

degrees of freedom of the fitted mixture model.

P

a significance level (P-value) for the goodness-of-fit test.

vmat

covariance matrix for the estimated parameters.

mixdata

the original data, i.e. the argument mixdat.

usecondit

the value of the argument usecondit.

References

Macdonald, P.D.M. and Green, P.E.J. (1988) User's Guide to Program MIX: An Interactive Program for Fitting Mixtures of Distributions. ICHTHUS DATA SYSTEMS.

See Also

mixgroup for grouping data, mixparam for organizing the parameter values, mixconstr for constructing constraints. nlm for additional arguments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
data(pike65)
data(pikepar)
fitpike1 <- mix(pike65, pikepar, "lnorm", constr = mixconstr(consigma = "CCV"), emsteps = 3)
fitpike1
plot(fitpike1)
data(pike65sg)
fitpike2 <- mix(pike65sg, pikepar, "lnorm", emsteps = 3, usecondit = TRUE)
fitpike2
plot(fitpike2)
data(bindat)
data(binpar)
fitbin1 <- mix(bindat, binpar, "binom",
               constr = mixconstr(consigma = "BINOM", size = c(20, 20, 20, 20)))
plot(fitbin1)
fitbin2 <- mix(bindat, binpar, "binom", constr = mixconstr(conpi = "PFX",
               fixpi = c(TRUE, TRUE, TRUE, TRUE),
               consigma = "BINOM", size = c(20, 20, 20, 20)))
plot(fitbin2)

Example output

Parameters:
       pi    mu sigma
1 0.09967 23.07 2.372
2 0.51889 33.61 3.455
3 0.22677 41.10 4.226
4 0.10710 49.88 5.128
5 0.04757 60.47 6.217

Distribution:
[1] "lnorm"

Constraints:
   conpi    conmu consigma 
  "NONE"   "NONE"    "CCV" 

Warning message:
In mix(pike65sg, pikepar, "lnorm", emsteps = 3, usecondit = TRUE) :
  The optimization process terminated because iteration limit exceeded

Parameters:
       pi    mu sigma
1 0.10523 23.35 2.592
2 0.39080 32.78 2.991
3 0.38524 40.11 4.885
4 0.07370 51.69 4.341
5 0.04503 60.98 6.169

Distribution:
[1] "lnorm"

Constraints:
   conpi    conmu consigma 
  "NONE"   "NONE"   "NONE" 

Warning messages:
1: In sqrt(mu - mu^2/constr$size) : NaNs produced
2: In sqrt(mu - mu^2/constr$size) : NaNs produced
Warning message:
In sqrt(mu - mu^2/constr$size) : NaNs produced

mixdist documentation built on May 2, 2019, 3:34 p.m.

Related to mix in mixdist...