Learn R Programming

flexmix (version 0.9-0)

stepFlexmix: Run FlexMix Repeatedly

Description

Runs flexmix repeatedly for different numbers of components and return the maximum likelihood solution for each.

Usage

stepFlexmix(..., K, nrep=3)

Arguments

...
passed to flexmix
K
A vector of integers passed in turn to the k argument of flexmix
nrep
For each value of k run flexmix nrep times and keep only the solution with maximum likelihood.

Value

  • A list of objects of class "flexmix" if length(K)>1, else directly an object of class "flexmix".

Examples

Run this code
data(NPreg)

## try 5 times for k=2
ex1 <- stepFlexmix(yn~x+I(x^2), data=NPreg, K=2, nrep=5)
ex1

## now for k=2,3,4,5
## low nrep to have reasonable execution time of example
## even on slow systems
ex2 <- stepFlexmix(yn~x+I(x^2), data=NPreg, K=2:5, nrep=2)
ex2
sapply(ex2, logLik)

## model selection:
sapply(ex2, AIC)

Run the code above in your browser using DataLab