Title: | Finite Mixture Modeling of Generalized Nonlinear Models |
---|---|
Description: | The fitting of mixtures of generalized nonlinear models is implemented as an extension of the existing package 'flexmix'. |
Authors: | Sanela Omerovic [aut, cre], Herwig Friedl [ths] |
Maintainer: | Sanela Omerovic <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 0.0.1 |
Built: | 2024-11-11 07:05:48 UTC |
Source: | CRAN |
Extension of package flexmix
for fitting mixtures of
Generalized Nonlinear Models.
The package flexmixNL
implements an extension for the package
flexmix
for fitting mixtures of Generalized Nonlinear Models
(GNMs). The package provides a specified M-step for the EM-algorithm within the
FlexMix framework (see also flexmix
) for fitting
GNMs for the normal and gamma distribution.
The mixture model is specified by the function FLXMRnlm
.
Sanela Omerovic
See also flexmix
for finite mixtures of regression models and
gnm
for the fitting of Generalized Nonlinear Models (GNMs) for
further information.
# example 1. data("NReg", package = "flexmixNL") # mixture of two nonlinear regression models (normal distribution). start1 <- list(a = 170, b = 5) start2 <- list(a = 130, b = 5) model <- flexmix(yn ~ x, k = 2, data = NReg, model = list(FLXMRnlm(formula = yn ~ a*x / (b+x), family = "gaussian", start = list(start1, start2)))) # final cluster assignments. plot(yn ~ x, col = clusters(model), data = NReg) # example 2. data("GReg", package = "flexmixNL") # mixture of two nonlinear regression models (gamma distribution). exp.1 = function(x,predictors){ list(predictors = list(a = 1, b = 1), variables = list(substitute(x)), term = function(predictors, variables){ sprintf("exp( %s + %s * %s)", predictors[1], predictors[2], variables) }) } class(exp.1) = "nonlin" start1 <- list(a = -0.4, b = 0.3) start2 <- list(a = -0.1, b = 0.4) model2 <- flexmix(yg ~ x, k = 2, data = GReg, model = list(FLXMRnlm(formula = yg ~ -1 + exp.1(x), family = "Gamma", start = list(start1, start2)))) # final cluster assignments. plot(yg ~ x, col = clusters(model2), data = GReg)
# example 1. data("NReg", package = "flexmixNL") # mixture of two nonlinear regression models (normal distribution). start1 <- list(a = 170, b = 5) start2 <- list(a = 130, b = 5) model <- flexmix(yn ~ x, k = 2, data = NReg, model = list(FLXMRnlm(formula = yn ~ a*x / (b+x), family = "gaussian", start = list(start1, start2)))) # final cluster assignments. plot(yn ~ x, col = clusters(model), data = NReg) # example 2. data("GReg", package = "flexmixNL") # mixture of two nonlinear regression models (gamma distribution). exp.1 = function(x,predictors){ list(predictors = list(a = 1, b = 1), variables = list(substitute(x)), term = function(predictors, variables){ sprintf("exp( %s + %s * %s)", predictors[1], predictors[2], variables) }) } class(exp.1) = "nonlin" start1 <- list(a = -0.4, b = 0.3) start2 <- list(a = -0.1, b = 0.4) model2 <- flexmix(yg ~ x, k = 2, data = GReg, model = list(FLXMRnlm(formula = yg ~ -1 + exp.1(x), family = "Gamma", start = list(start1, start2)))) # final cluster assignments. plot(yg ~ x, col = clusters(model2), data = GReg)
This is the main driver for flexmixNL
interfacing the
family of Generalized Nonlinear Models.
FLXMRnlm(formula = . ~ ., family = c("gaussian", "Gamma"), start = list(), offset = NULL)
FLXMRnlm(formula = . ~ ., family = c("gaussian", "Gamma"), start = list(), offset = NULL)
formula |
A model |
family |
A character string naming a family function
( |
start |
A list of starting values for the regression parameters. |
offset |
Specification of an a priori known component to be included in the nonlinear predictor during fitting. |
Models for FLXMRnlm
are specified by a model formula
(formula
argument) relating the response to a
nonlinear predictor.
When fitting normal mixture models (family="gaussian"
) the nonlinear
predictor is explicitely formulated (see also nls
).
When fitting gamma mixture models (family="Gamma"
) the nonlinear
predictor is specified by a symbolic description (see also gnm
).
Variables not included in the data frame (see also flexmix
)
are identified as the regression parameters. Starting values are required for
every regression parameter.
See flexmixNL
for examples.
Returns an object of class FLXMRnlm
.
Sanela Omerovic
A simple artificial regression example containing 200 data points
with two latent classes. The data set includes one independent variable
(uniform on ) and one dependent variable with gamma distribution.
data("GReg")
data("GReg")
This data frame contains the following columns:
a numeric vector giving the independent variable.
a numeric vector giving the dependent variable with gamma distribution.
a numeric vector indicating the labeling of the data points to two distinct classes.
data("GReg", package = "flexmixNL") plot(yg ~ x, col = class, data = GReg)
data("GReg", package = "flexmixNL") plot(yg ~ x, col = class, data = GReg)
A simple artificial regression example containing 200 data points
with two latent classes. The data set includes one independent variable
(uniform on ) and one dependent variable with normal
distribution.
data("NReg")
data("NReg")
This data frame contains the following columns:
a numeric vector giving the independent variable.
a numeric vector giving the dependent variable with normal distribution.
a numeric vector indicating the labeling of the data points to distinct classes.
data("NReg", package = "flexmixNL") plot(yn ~ x, col = class, data = NReg)
data("NReg", package = "flexmixNL") plot(yn ~ x, col = class, data = NReg)