fmtab: Finite Mixture of Contingency Table Analysis (fmtab) Object

fmtabR Documentation

Finite Mixture of Contingency Table Analysis (fmtab) Object

Description

A finite mixture of models related to contingency table analysis

Value

Returns R6 object of class fmtab.

Super class

fmmr6::fmmr6 -> fmtab

Public fields

data_model

(DataModel())
The DataModel Object that stores the data using in the fmmr6.

family

(character(1)|character())
The distribution family which can be either a string like "gaussian" or a vector like c("gaussian", "gaussian").

latent

(integer(1))
The number of latent classes.

method

(character(1))
The estimation method to fit the fmglm.

start

(matrix())
The starting values for the fmglm.

constraint

(matrix())
The constraint matrix.

concomitant

(formula(1))
The formula to model the concomitant model. The default value is NULL.

optim_method

(character(1))
The optimization method to use to fit the model.

Methods

Public methods

Inherited methods

Method new()

Create a new instance of this R6 R6::R6Class class.

Usage
fmtab$new(
  formula,
  data,
  data_str = "longc",
  data_var = NULL,
  model = "loglinear",
  latent = 2,
  method = "em",
  start = NULL,
  optim_method = "base",
  concomitant = NULL,
  constraint = matrix(1)
)
Arguments
formula

(formula(1))
The formula/expression of the model to fit in the fmglm.

data

(data.frame())
The Data used in the fmglm.

data_str

(character(1))
Desired data structure. Available data structure are listed as follows:

default: Default data structure, the DataModel object will identify the dependent variable Y and the independent variable X based on the provided formula.

freq_tab: the frequency table. The data must contain a freq variable.

long: Data in the long format. Normally used for a longitudinal/panel data. The data must contain a variable to identify the changes within observation, e.g. the observations made at different time t. One should also define a variable for identifying each observation, e.g. obs.

wide: Data in the wide format. This data format collapses a longitudinal data into one row for one observation.

longc: Data in the long format used in a choice model. Variable alt represents the alternative for each individual. Variable chosen shows which alt is chosen.

widec Data in the wide format used in a choice model.

latent

(integer(1))
The number of latent classes.

method

(character(1))
The estimation method to fit the fmglm.

start

(matrix())
The starting values for the fmglm.

optim_method

(character(1))
The optimization method to use to fit the model. The default is base.

concomitant

(formula(1))
The formula for the concomitant model. E.g. ~ z1 + z2 + z3.

constraint

(matrix())
The constraint matrix.

use_llc

(boolean(1))
Whether to use the complete log-likelihood or the normal log-likelihood. The default is TRUE.

Returns

Return a R6 object of class fmglm


Method fit()

Fit the fmglm model

Usage
fmtab$fit(algo = "em", max_iter = 500, start = "random", rep = 1)
Arguments
algo

(character(1))
The algorithm used in fitting the fmglm model. The default algorithm is em standing for the normal EM algorithm. One can choose from c("em", "cem", "sem"). cem is the classification EM algorithm. sem is the stochastic EM algorithm.

max_iter

(integer(1))
Specify the maximum number of iterations for the E-step-M-step loop. The default number is 500.

start

(character(1))
Specify the starting method of the EM algorithm. Can either start from kmeans or random. kmeans use the K-mean methods to put samples into latent classes. random randomly assigns samples into latent classes. The default method is kmeans.

rep

(integer(1))
Specify the number of reps EM-algorithm runs. This parameter is designed for preventing the local maximum. Each rep, the EM_algorithm generates a start. It is only useful when start is random. After all reps, the algorithm will pick the rep with maximum log likelihood. The default value is 1


Method summarize()

Generate a summary for the result.

Usage
fmtab$summarize(digits = 3)
Arguments
digits

(integer(1))
Determine how many digits presented in the output.


Method clone()

The objects of this class are cloneable with this method.

Usage
fmtab$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Author(s)

Dongjie Wu


wudongjie/fmmr6 documentation built on June 24, 2022, 2:48 p.m.