`R/mx_mixture.R`

`mixture_starts.Rd`

Automatically set starting values for an OpenMx mixture model. This function
was designed to work with mixture models created using `tidySEM`

functions like `mx_mixture`

, and may not work with other
`mxModel`

s.

mixture_starts(model, splits, ...)

model | A mixture model of class |
---|---|

splits | Optional. A numeric vector of length equal to the number of
rows in the |

... | Additional arguments, passed to functions. |

Returns an `mxModel`

with starting values.

Starting values are derived by the following procedure:

The mixture model is converted to a multi-group model.

The data are split along

`splits`

, and assigned to the corresponding groups of the multi-group model.The multi-group model is run, and the final values of each group are assigned to the corresponding mixture component as starting values.

The mixture model is returned with these starting values.

If the argument `splits`

is not provided, the function will call
`cutree(hclust(dist(data)), k = classes))`

, where `data`

is
extracted from the `model`

argument.

Other sensible ways to split the data include:

Using K-means clustering:

`kmeans`

`(x = data, centers = classes)$cluster`

Using agglomerative hierarchical clustering:

`hclass(`

`hc`

`(data = data), G = classes)[, 1]`

Using a random split:

`sample.int`

`(n = classes, size = nrow(data), replace = TRUE)`

if (FALSE) { df <- iris[, 1, drop = FALSE] names(df) <- "x" mod <- mx_mixture(model = "x ~ m{C}*1 x ~~ v{C}*x", classes = 2, data = df, run = FALSE) mod <- mixture_starts(mod) }