Learn R Programming

gRim (version 0.1.2)

dmod: Log--linear model

Description

Specification of log--linear (graphical) model. The 'd' in the name dmod refers to that it is a (graphical) model for 'd'iscrete variables

Usage

dmod(formula, data, marginal, interactions=NULL, fit = TRUE, details=0)

Arguments

formula
Model specification in one of the following forms: 1) a right-hand sided formula, 2) as a list of generators, 3) an undirected graph (represented either as a graphNEL object or as an adjacency matrix). Notice that there are certai
data
Either a table or a dataframe. In the latter case, the dataframe will be coerced to a table. See 'details' below.
interactions
A number given the highest order interactions in the model, see Section 'details' below.
marginal
Should only a subset of the variables be used in connection with the model specification shortcuts
fit
Should the model be fitted.
details
Control the amount of output; for debugging purposes.

Value

  • An object of class dModel

Details

The independence model can be specified as ~.^1 and the saturated model as ~.^.. Setting e.g. interactions=3 implies that there will be at most three factor interactions in the model. Data can be specified as a table of counts or as a dataframe. If data is a dataframe then it will be converted to a table (using xtabs()). This means that if the dataframe contains numeric values then the you can get a very sparse and high dimensional table. When a dataframe contains numeric values it may be worthwhile to discretize data using the cut() function. The marginal argument can be used for specifying the independence or saturated models for only a subset of the variables. When marginal is given the corresponding marginal table of data is formed and used in the analysis (notice that this is different from the behaviour of loglin() which uses the full table.

See Also

cmod mmod

Examples

Run this code
## Graphical log-linear model
data(reinis)
dm1<-dmod(~.^., reinis)
dm2<-backward(dm1, k=2)
dm3<-backward(dm1, k=2, fixin=list(c("family","phys","systol")))
## At most 3-factor interactions
dm1<-dmod(~.^., data=reinis,interactions=3)

Run the code above in your browser using DataLab