Package 'flexmixNL'

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

Help Index


Mixtures of Generalized Nonlinear Models

Description

Extension of package flexmix for fitting mixtures of Generalized Nonlinear Models.

Details

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.

Author(s)

Sanela Omerovic

See Also

See also flexmix for finite mixtures of regression models and gnm for the fitting of Generalized Nonlinear Models (GNMs) for further information.

Examples

# 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)

flexmixNL Interface for Generalized Nonlinear Models

Description

This is the main driver for flexmixNL interfacing the family of Generalized Nonlinear Models.

Usage

FLXMRnlm(formula = . ~ ., 
         family = c("gaussian", "Gamma"), 
         start = list(), 
         offset = NULL)

Arguments

formula

A model formula decribing the nonlinear predictor and including variables and regression parameters.

family

A character string naming a family function (family="gaussian" or family="Gamma" available).

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.

Details

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.

Value

Returns an object of class FLXMRnlm.

Author(s)

Sanela Omerovic

See Also

flexmixNL, formula, gnm, nls


Artificial Example for Gamma Regression

Description

A simple artificial regression example containing 200 data points with two latent classes. The data set includes one independent variable (uniform on [0,10][0,10]) and one dependent variable with gamma distribution.

Usage

data("GReg")

Format

This data frame contains the following columns:

x

a numeric vector giving the independent variable.

yg

a numeric vector giving the dependent variable with gamma distribution.

class

a numeric vector indicating the labeling of the data points to two distinct classes.

Examples

data("GReg", package = "flexmixNL")
plot(yg ~ x, col = class, data = GReg)

Artificial Example for Normal Regression

Description

A simple artificial regression example containing 200 data points with two latent classes. The data set includes one independent variable (uniform on [0,10][0,10]) and one dependent variable with normal distribution.

Usage

data("NReg")

Format

This data frame contains the following columns:

x

a numeric vector giving the independent variable.

yn

a numeric vector giving the dependent variable with normal distribution.

class

a numeric vector indicating the labeling of the data points to distinct classes.

Examples

data("NReg", package = "flexmixNL")
plot(yn ~ x, col = class, data = NReg)