data(NPreg)
## mixture of two linear regression models. Note that control parameters
## can be specified as named list and abbreviated if unique.
ex1 <- flexmix(yn~x+I(x^2), data=NPreg, k=2,
control=list(verb=5, iter=100))
ex1
summary(ex1)
## now we fit a model with one Gaussian response and one Poisson
## response. Note that the formulas inside the call to FLXglm are
## relative to the overall model formula.
ex2 <- flexmix(yn~x, data=NPreg, k=2,
model=list(FLXglm(yn~.+I(x^2)),
FLXglm(yp~., family="poisson")))
ex2
table(ex2@cluster, NPreg$class)
## for Gaussian responses we get coefficients and standard deviation
parameters(ex2, component=1, model=1)
## for Poisson response we get only coefficients
parameters(ex2, component=1, model=2)
## fitting a model only to the Poisson response is of course
## done like this
ex3 <- flexmix(yp~x, data=NPreg, k=2, model=FLXglm(family="poisson"))
## if observations are grouped, i.e., we have several observations per
## individual, fitting is usually much faster:
ex4 <- flexmix(yp~x|id1, data=NPreg, k=2, model=FLXglm(family="poisson"))
Run the code above in your browser using DataLab