help cwmglm

Title

cwmglm - Cluster Weighted Model for Generalized Linear Models

Syntax

cwmglm depvar indepvars [if] [in], posterior(stub) [ start(svmethod) k(#) iterate(#) xnormal_opts xnormal(varlist) xpoisson(varlist) xbinomial(varlist) xmultinomial(varlist) ndraw(#) iteratexnorm(#) convcrit(#) nolog noclustertable nodeviance nomarginal noregtable]

Main Options
k(#) the number of mixture components. Default is 2.

Marginalization Options
xnormal(varlist) normal covariates (marginal distribution)

xbinomial(varlist) binomial covariates (marginal distribution)

xmultinomial(varlist) multinomial covariates (marginal distribution)

xpoisson(varlist) xpoisson covariates (marginal distribution)

xnormal_opts parsimonious models for multivariate normal covariates. The possible options are eii, vii, eei, vei, evi, vvi, eee, vee, eve, vve, eev, vev, evv and vvv

Regression Options
family(familyname) Family for the GLM. The allowed families are gaussian, poisson and binomial

Initialization
start(svmethod) set the initialization method. Allowed methods are kmeans, randomid, randompr

initial(varlist) starting values of class membership. Applies only if start( custom) is specified

Maximization options
iterate(#) the number of iterations of the EM algorithm

iteratexnorm(#) the number of iterations for the maximization of parsimonious models

convcrit(#) the stopping criterion for the Aitken acceleration. (Default 1e-5)

Display options
nlog supresses iteration log

noclustertable requests cwmglm not to display the clustering table

nodeviance requests cwmglm not to display the deviance measures

nomarginal requests cwmglm not to display the parameters of the marginal distributions

noregtable requests cwmglm not to display the regression table

indepvars may contain factor variable operators; see fvvarlist.

See cwmglm postestimation for features available after estimation.

Description

cwmglm estimates mixtures of regression models with random covariates through maximum likelihood and expectation-maximization algorithm.

Options

Main options

k(#) the number of mixture components. Default is 2 , the mimimum is 1.

Marginalization options

xnormal(varlist) variables having normal distributions

xpoisson(varlist) variables having poisson distributions

xbinomial(varlist) variables having binomial distributions. This options only accepts {0,1} binary variables.

xmultinomial(varlist) variables having multinomial distributions. Factor variable syntax is not allowed. Categories are detected automatically.

xnormal_opts indicates the parsimonious model to be fitted in xnormal(varlist) (see Celeux and Govaert, 1995) . If the number of variables in xnormal(varlist) is equal to one the possibile options are eee and vvv. Default is vvv. The possible multivariate normal models are the following

eii Equal volume, spherical shape

vii Variable volume, spherical shape

eei Equal volume, equal shape, axis-aligned orientation

vei Variable volume, equal shape, axis-aligned orientation

evi Equal volume, variable shape, axis-aligned orientation

vvi Variable volume, variable shape, axis-aligned orientation

eee Equal volume, equal shape, equal orientation

vee Variable volume, equal shape, equal orientation

eve Equal volume, variable shape, equal orientation

vve Variable volume, variable shape, equal orientation

eev Equal volume, equal shape, variable orientation

vev Variable volume, equal shape, variable orientation

evv Equal volume, variable shape, variable orientation

vvv Variable volume, variable shape, variable orientation

Regression options

family(familyname) specifies the distribution of depvar for the GLM (see glm). family(gaussian) (link indentity) is the default. The other allowed distributions are family(binomial) (link logit) and family(poisson) (link log).

Initialization options

start(svmethod) Specifies the initialization procedure of the component membership probabilities or the component memberships.

ndraws(#) specifies the number of random draws for selecting the starting values if start(randompr) or start(randomid) are specified. Starting values are selected if they have the highest log-likelihood value from the EM iterations. Default is 10.

start(kmeans) specifies that starting values are computed by assigning each
observation to an initial latent class that is determined by running a kmeans cluster analysis on depvar indepvars. This is the default.

start(randomid) specifies that starting values are computed by randomly assigning
observations to initial classes.

start(randompr) specifies that starting values are computed by randomly assigning initial class probabilities.

start(custom) specifies that starting values are provided by the user.

initial(varlist) starting values of class memberhsip. varlist must contain a list of k numeric variables. This option is ignored if start(custom) is not specified.

Maximization options

iterate(#) the number of EM iterations. Default is 1200

iteratexnorm(#) the number of iterations for the parisimonious models (see xnorm(varlist) and xnormal_opts options). It affects only the estimations of vee, eve, vve, vev and vei models. Default is 200

convcrit(#) the stopping criterion for the Aitken acceleration procedure. Default threshold is 1e-5.

Display options

nlog supresses iteration log

noclustertable requests cwmglm not to display the clustering table

nodeviance requests cwmglm not to display the deviance measures

nomarginal requests cwmglm not to display the parameters of the marginal distributions

noregtable requests cwmglm not to display the regression table

Saved Results

Scalars

e(k) Number components

e(N) the number of observations

e(df_r) the number of estimated parameters

e(ll) log likelihood

e(bic) Bayesian information criterion (BIC)

e(aic) Akaike information criterion (AIC)

e(nmulti) Number of multinomial concomitant

Matrices

e(b) coefficient vector of the glm

e(V) variance-covariance matrix of the glm

e(phi0) dispersion parameter for the glm (see help glm)

e(cl_table) estimated group size

e(localdeviance) within deviance decomposition matrix for the glm

e(globaldeviance) the overall residual deviance, the overall explained deviance, the between deviance and the total deviance

e(R2) generalized coefficients of determination for the GLM

e(prior) mixture components weights

e(p_multi_#) probabilities of a each outcome for the xmultinomial variables . (returns n matrices where n is the number of multinomial variables)

e(p_binomial) probabilities of a positive outcome for the xbinomial variables

e(lambda) mean of the xpoisson variables

e(mu) mean of the xnorm variables

e(epsilon) variance-covariance matrices of the xnorm variables

e(ic) AIC and BIC

Macros

e(sample) marks estimation sample

e(depvar) the dependent variable

e(indepvars) list of covariates for the regression model

e(cmd) cwmglm

e(xnorm) the variables with normal marginalization

e(xnormodel) the parsimonious model used for the normal marginalization

e(xpoisson) the variables with poisson marginalization

e(xbinomial) the variables with binomial marginalization

e(xmultinomial) the variables with multinomial marginalization

e(glmcmd) the command used for the glm

Function

e(sample) marks estmations sample

Examples

Setup

. use covid, clear

. describe

Mixture of Poisson GLM with random covariates (k=2)

. cwmglm y x1 x2 x3 n1 female, xnormal(x1 x2 x3) vvv xpoisson(n1) xbin(female) k(2) family(poisson)

Setup

. use students, clear

. describe

Mixture of regressions with random covariates, model EEE

. cwmglm weight height heightf, k(2) xnormal(height heightf) eee

Setup

. use multinorm, clear

Preparing the loop for information criteria model selection

. local models vev evv vvv eei vei evi vvi eii vii eee vee eve vve eev

. global CWMs

Looping over different parsimonious multivariate normal models and letting k range from 2 to 5

. foreach model of local models {

. forval i=2/5 {

// note the absence of depvar indepvars

. quietly cwmglm, xnorm(x1 x2) k(`i') `model'

.if (e(converged)==1) {

.estimates store `model'`i'

.global CWMs $CWMs `model'`i'

. }

. else di in red "model `model' with `i' mixture component did not converge"

. }

. }

Model selection

. cwmcompare $CWMs

Activating the estimates from the best model

. estimates restore `r(bestAIC)'

References

Celeux, G., & Govaert, G. (1995). Gaussian parsimonious clustering models. Pattern recognition, 28(5), 781-793.

Ingrassia, S., Punzo, A., Vittadini, G., & Minotti, S. C. (2015). Erratum to: The generalized linear mixed cluster-weighted model. Journal of Classification, 32(2), 327-355.

Authors

Daniele Spinelli, corresponding author (University of Milano-Bicocca, daniele.spinelli@unimib.it)

Salvatore Ingrassia (University of Catania, s.ingrassia@unict.it)

Giorgio Vittadini (University of Milano-Bicocca, giorgio.vittadinid@unimib.it)