Type: | Package |
Title: | Flexible Cluster-Weighted Modeling |
Version: | 1.92 |
Date: | 2020-03-27 |
Author: | Mazza A., Punzo A., Ingrassia S. |
Maintainer: | Angelo Mazza <a.mazza@unict.it> |
Description: | Allows maximum likelihood fitting of cluster-weighted models, a class of mixtures of regression models with random covariates. Methods are described in Angelo Mazza, Antonio Punzo, Salvatore Ingrassia (2018) <doi:10.18637/jss.v086.i02>. |
License: | GPL-2 |
LazyLoad: | yes |
Depends: | R (≥ 3.0.0) |
Imports: | stats,graphics,parallel,numDeriv,mclust,statmod,ContaminatedMixt |
NeedsCompilation: | no |
Packaged: | 2020-03-27 17:01:35 UTC; angel |
Repository: | CRAN |
Date/Publication: | 2020-03-27 22:30:02 UTC |
flexCWM - Flexible Cluster Weighted Modeling
Description
Allows for maximum likelihood fitting of cluster-weighted models, a class of mixtures of regression models with random covariates.
Details
Package: | CWM |
Type: | Package |
Version: | 1.7 |
Date: | 2017-02-14 |
License: | GNU-2 |
Author(s)
Mazza A., Punzo A., Ingrassia S.
Maintainer: Mazza Angelo <a.mazza@unict.it>
References
Mazza, A., Ingrassia, S., and Punzo, A. (2018). flexCWM: A Flexible Framework for Cluster-Weighted Models. Journal of Statistical Software, 86(2), 1-30.
Ingrassia, S., Minotti, S. C., and Vittadini, G. (2012). Local Statistical Modeling via the Cluster-Weighted Approach with Elliptical Distributions. Journal of Classification, 29(3), 363-401.
Ingrassia, S., Minotti, S. C., and Punzo, A. (2014). Model-based clustering via linear cluster-weighted models. Computational Statistics and Data Analysis, 71, 159-182.
Ingrassia, S., Punzo, A., and Vittadini, G. (2015). The Generalized Linear Mixed Cluster-Weighted Model. Journal of Classification, 32(forthcoming)
Punzo, A. (2014). Flexible Mixture Modeling with the Polynomial Gaussian Cluster-Weighted Model. Statistical Modelling, 14(3), 257-291.
See Also
dataset ExCWM
Description
An artificial data set, with 200 observations, generated by a CWM with 2 mixture components of different size, one binomial response variable, and four covariates with bivariate Gaussian, Poisson and Binomial distribution, respectively.
Usage
data(ExCWM)
Format
A dataset
See Also
Examples
data("ExCWM")
attach(ExCWM)
str(ExCWM)
# mixtures of binomial distributions
resXbin <- cwm(Xbin = Xbin, k = 1:2, initialization = "kmeans")
getParXbin(resXbin)
# Mixtures of Poisson distributions
resXpois <- cwm(Xpois = Xpois, k = 1:2, initialization = "kmeans")
getParXpois(resXpois)
# parsimonious mixtures of multivariate normal distributions
resXnorm <- cwm(Xnorm = cbind(Xnorm1,Xnorm2), k = 1:2, initialization = "kmeans")
getParXnorm(resXnorm)
Extractors for cwm
class objects.
Description
These functions extract values from cwm
class objects.
Usage
getBestModel(object, criterion = "BIC", k = NULL, modelXnorm = NULL, familyY = NULL)
getPosterior(object, ...)
getSize(object, ...)
getCluster(object, ...)
getParGLM(object, ...)
getParConcomitant(object, name = NULL, ...)
getPar(object, ...)
getParPrior(object, ...)
getParXnorm(object, ...)
getParXbin(object, ...)
getParXpois(object, ...)
getParXmult(object, ...)
getIC(object,criteria)
whichBest(object, criteria = NULL, k = NULL, modelXnorm = NULL, familyY = NULL)
## S3 method for class 'cwm'
summary(object, criterion = "BIC", concomitant = FALSE,
digits = getOption("digits")-2, ...)
## S3 method for class 'cwm'
print(x, ...)
Arguments
object , x |
a class |
criterion |
a string with the information criterion to consider; supported values are: |
criteria |
a vector of strings with the names of information criteria to consider. If |
k |
an optional vector containing the numbers of mixture components to consider. If not specified, all the estimated models are considered. |
modelXnorm |
an optional vector of character strings indicating the parsimonious models to consider for |
familyY |
an optional vector of character strings indicating the conditional distribution of |
name |
an optional vector of strings specifing the names of distribution families of concomitant variables; if |
concomitant |
When |
digits |
integer used for number formatting. |
... |
additional arguments to be passed to |
Details
When several models have been estimated, these functions consider the best model according to the information criterion in criterion
, among the estimated models having a number of components among those in k
an error distribution among those in familyY
and a parsimonious model among those in modelXnorm
.
getIC
provides values for the information criteria in criteria
.
The getBestModel
method returns a cwm
object containing the best model only, selected as described above.
Examples
#res <- cwm(Y=Y,Xcont=X,k=1:4,seed=1)
#summary(res)
#plot(res)
Fit for the CWM
Description
Maximum likelihood fitting of the cluster-weighted model by the EM algorithm.
Usage
cwm(formulaY = NULL, familyY = gaussian, data, Xnorm = NULL, Xbin = NULL,
Xpois = NULL, Xmult = NULL, modelXnorm = NULL, Xbtrials = NULL, k = 1:3,
initialization = c("random.soft", "random.hard", "kmeans", "mclust", "manual"),
start.z = NULL, seed = NULL, maxR = 1, iter.max = 1000, threshold = 1.0e-04,
eps = 1e-100, parallel = FALSE, pwarning = FALSE)
Arguments
formulaY |
an optional object of class " |
familyY |
a description of the error distribution and link function to be used for the conditional distribution of
Default value is |
data |
an optional |
Xnorm , Xbin , Xpois , Xmult |
an optional matrix containing variables to be used for marginalization having normal, binomial, Poisson and multinomial distributions. |
modelXnorm |
an optional vector of character strings indicating the parsimonious models to be fitted for variables in |
Xbtrials |
an optional vector containing the number of trials for each column in |
k |
an optional vector containing the numbers of mixture components to be tried. Default value is |
initialization |
an optional character string. It sets the initialization strategy for the EM-algorithm. It can be:
Default value is |
start.z |
matrix of soft or hard classification: it is used only if |
seed |
an optional scalar. It sets the seed for the random number generator, when random initializations are used; if |
maxR |
number of initializations to be tried. Default value is 1. |
iter.max |
an optional scalar. It sets the maximum number of iterations in the EM-algorithm. Default value is 200. |
threshold |
an optional scalar. It sets the threshold for the Aitken acceleration procedure. Default value is 1.0e-04. |
eps |
an optional scalar. It sets the smallest value for eigenvalues of covariance matrices for |
parallel |
When |
pwarning |
When |
Details
When familyY = binomial
, the response variable must be a matrix with two columns, where the first column is the number of "successes" and the second column is the number of "failures".
When several models have been estimated, methods summary
and print
consider the best model according to the information criterion in criterion
, among the estimated models having a number of components among those in k
an error distribution among those in familyY
and a parsimonious model among those in modelXnorm
.
Value
This function returns a class cwm
object, which is a list of values related to the model selected. It contains:
call |
an object of class |
formulaY |
an object of class |
familyY |
the distribution used for the conditional distribution of |
data |
a |
concomitant |
a list containing |
Xbtrials |
number of trials used for |
models |
a list; each element is related to one of the models fitted. Each element is a list and contains: |
posterior
posterior probabilitiesiter
number of iterations performed in EM algorithmk
number of (fitted) mixture components.size
estimated size of the groups.cluster
classification vectorloglik
final log-likelihood valuedf
overall number of estimated parametersprior
weights for the mixture componentsIC
list containing values of the information criteriaconverged
logical;TRUE
if EM algorithm convergedGLModels
a list; each element is related to a mixture component and contains:model
a "glm
" class object.sigma
estimated local scale parameters of the conditional distribution ofY
, whenfamilyY
isgaussian
orstudent.t
t_df
estimated degrees of freedom of the t distribution, whenfamilyY
isstudent.t
nuY
estimated shape parameter, whenfamilyY
isGamma
. The gamma distribution is parameterized according to McCullagh & Nelder (1989, p. 30)
concomitant
a list with estimated concomitant variables parameters for each mixture componentnormal.d, multinomial.d, poisson.d, binomial.d
marginal distribution of concomitant variablesnormal.mu
mixture component means forXnorm
normal.Sigma
mixture component covariance matrices forXnorm
normal.model
models fitted forXnorm
multinomial.probs
multinomial distribution probabilities forXmult
poisson.lambda
lambda parameters forXpois
binomial.p
binomial probabilities forXbin
Author(s)
Mazza A., Punzo A., Ingrassia S.
References
Mazza, A., Ingrassia, S., and Punzo, A. (2018). flexCWM: A Flexible Framework for Cluster-Weighted Models. Journal of Statistical Software, 86(2), 1-30.
Ingrassia, S., Minotti, S. C., and Vittadini, G. (2012). Local Statistical Modeling via the Cluster-Weighted Approach with Elliptical Distributions. Journal of Classification, 29(3), 363-401.
Ingrassia, S., Minotti, S. C., and Punzo, A. (2014). Model-based clustering via linear cluster-weighted models. Computational Statistics and Data Analysis, 71, 159-182.
Ingrassia, S., Punzo, A., and Vittadini, G. (2015). The Generalized Linear Mixed Cluster-Weighted Model. Journal of Classification, 32(forthcoming)
McCullagh, P. and Nelder, J. (1989). Generalized Linear Models. Chapman & Hall, Boca Raton, 2nd edition
Punzo, A. (2014). Flexible Mixture Modeling with the Polynomial Gaussian Cluster-Weighted Model. Statistical Modelling, 14(3), 257-291.
See Also
Examples
## an exemple with artificial data
data("ExCWM")
attach(ExCWM)
str(ExCWM)
# mixtures of binomial distributions
resXbin <- cwm(Xbin = Xbin, k = 1:2, initialization = "kmeans")
getParXbin(resXbin)
# Mixtures of Poisson distributions
resXpois <- cwm(Xpois = Xpois, k = 1:2, initialization = "kmeans")
getParXpois(resXpois)
# parsimonious mixtures of multivariate normal distributions
resXnorm <- cwm(Xnorm = cbind(Xnorm1,Xnorm2), k = 1:2, initialization = "kmeans")
getParXnorm(resXnorm)
## an exemple with real data
data("students")
attach(students)
str(students)
# CWM
fit2 <- cwm(WEIGHT ~ HEIGHT + HEIGHT.F , Xnorm = cbind(HEIGHT, HEIGHT.F),
k = 2, initialization = "kmeans", modelXnorm = "EEE")
summary(fit2, concomitant = TRUE)
plot(fit2)
Plot for CWMs
Description
Plot method for cwm class objects.
Usage
## S3 method for class 'cwm'
plot(x, regr = TRUE, ctype = c("Xnorm","Xbin","Xpois",
"Xmult"), which = NULL, criterion = "BIC", k = NULL,
modelXnorm = NULL, familyY = NULL,histargs=list(breaks=31),...)
Arguments
x |
An object of class |
regr |
boolean, allows for bivariate regression plot. |
ctype |
a vector with concomitant variables types to plot. |
which |
a vector with columns number to plot, or "all" for all the columns |
criterion |
a string with the information criterion to consider; supported values are: |
k |
an optional vector containing the numbers of mixture components to consider. If not specified, all the estimated models are considered. |
modelXnorm |
an optional vector of character strings indicating the parsimonious models to consider for |
familyY |
an optional vector of character strings indicating the conditional distribution of |
histargs |
an optional list with |
... |
further arguments for |
Examples
data("students")
attach(students)
str(students)
fit2 <- cwm(WEIGHT ~ HEIGHT + HEIGHT.F , Xnorm = cbind(HEIGHT, HEIGHT.F), k = 2,
initialization = "kmeans", modelXnorm = "EEE")
summary(fit2, concomitant = TRUE)
plot(fit2)
dataset students
Description
A dataframe with data from a survey of 270 students attending a statistics course at the Department of Economics and Business of the University of Catania in the academic year 2011/2012. It contains the following variables:
-
GENDER
gender of the respondent; -
HEIGHT
height of the respondent, measured in centimeters; -
WEIGHT
weight of the respondent, measured in kilograms; -
HEIGHT.F
height of respondent's father, measured in centimeters.
Usage
data(students)
Format
A dataset
Source
http://www.economia.unict.it/punzo/
References
Ingrassia, S., Minotti, S. C., and Punzo, A. (2014). Model-based clustering via linear cluster-weighted models. Computational Statistics and Data Analysis, 71, 159-182.
See Also
Examples
data("students")
attach(students)
str(students)
fit2 <- cwm(WEIGHT ~ HEIGHT + HEIGHT.F , Xnorm = cbind(HEIGHT, HEIGHT.F), k = 2,
initialization = "kmeans", modelXnorm = "EEE")
summary(fit2, concomitant = TRUE)
plot(fit2)