# fma: Fitting Factor Mixture Analysis model by the EM algorithm In FactMixtAnalysis: Factor Mixture Analysis with covariates

## Description

`fma` is used to perform Factor Mixture Analysis (with covariates) on a matrix of data by the Expectation Maximization algorithm.

## Usage

 `1` ```fma(y, k, r, x.z = NULL, x.w = NULL, it = 15, eps = 1e-04, seed = 4, scaling = FALSE, init = NULL) ```

## Arguments

 `y` A data matrix with `n` rows representing observations and `p` columns representing variables. `k` The number of the mixture components. `r` The number of factors. `x.z` A matrix of covariates with `n` rows representing observations and `q` columns representing the predictors. These covariates are assumed to linearly affect the factor means. `x.w` A matrix of covariates with `n` rows representing observations and `m` columns representing the predictors. These covariates are assumed to differently affect the a priori probability of group membership. `it` The maximum number of iterations of the EM algorithm. By default it is set to 15. `eps` The lower bound for relative variation of the likelihood. It is used as alternative stopping rule for the EM algorithm: if the relative increment of the likelihood is lower than `eps` the fitting is stopped. The default is 0.0001. `seed` Fix the seed of the running. Default is 4. `scaling` If TRUE (FALSE is default) the data are scaled before fitting the FMA model. `init` A list containing initial values for all (of some) model parameters. If `NULL` (default) the algorithm starts from random values.

## Details

Factor Mixture Analysis is a particular factor model with non Gaussian factors modelled by a multivariate Gaussian mixture. The `p` observed variables `y` are modelled in terms of the smaller set of `r` factors, `z`, and an additive specific term `u`: `y=Hz+u`, where `u` is assumed to be normally distributed with diagonal variance matrix `Psi`. `H` is the factor loading matrix. The model is fitted by the EM algorithm. The code implements also factor mixture model with covariates. Covariates may affect the observed variables into two manners: they are assumed to linearly affect the factor means (`x.z`) and \ or they can differently affect the a priori probability of group membership (`x.w`). The default is NULL which means that covariates are not incorporated in the model.

## Value

 `H` The estimated factor loading matrix. `lik` The log-likelihood computed at each iteration of the EM algorithm. `w` A matrix with the estimated weights of the mixture. `Beta` An array of dimension `k x r x (q +1)` containing the vectors of regression coefficients which are allowed to vary across the components. When no covariate is incorporated into the model, i.e. `x.z` is NULL, `Beta` has dimension `k x r` and it correponds to the estimated component means of the mixture. `phi` A matrix of dimension `k x m` which contains the coefficients of the covariates affecting the group membership. `sigma` An array of dimension `k x r x r` which contains the estimated component covariance of the mixture. `psi` The noise diagonal variance matrix. `ph.y` The posterior distribution of each mixture components. `z` The reconstructed factor scores by Thomposon method. `index` The allocation vector. `bic` The BIC value. `aic` The AIC value. `elapsed` Computational time in seconds.

Cinzia Viroli

## References

A. Montanari and C. Viroli (2010), Heteroscedastic Factor Mixture Analysis, Statistical Modelling, 10(4), 441-460.

A. Montanari and C. Viroli (2011), Dimensionally reduced mixtures of regression models, Journal of Statistical Planning and Inference, 141, 1744-1752.

C. Viroli (2011), Using factor mixture analysis to model heterogeneity, cognitive structure and determinants of dementia: an application to the Aging, Demographics, and Memory Study, Statistics in Medicine, to appear.

## Examples

 ```1 2 3 4 5 6 7``` ```data(crabs) y=as.matrix(crabs[,4:8]) fit=fma(y,k=2,r=1,it=50,eps=0.0001,scaling=TRUE) # without covariates misc(fit\$index,crabs[,1]) # compute the misclassification error sex=as.double(crabs[,2])-1 fit=fma(y,k=2,r=1,x.z=sex,x.w=sex,it=50,eps=0.0001,scaling=TRUE) # with covariates ```

### Example output

```Loading required package: MASS