Model specification for DEFM

term_defm_ones(m, idx = "", vname = "")

term_defm_fe(m, idx = "", k = 1, vname = "")

term_defm_transition(m, mat, idx = "", vname = "")

term_defm_transition_formula(m, formula, idx = "", vname = "")

term_defm_logit_intercept(m, coords = as.integer(c()), idx = "", vname = "")

rule_not_one_to_zero(m, idx)

rule_constrain_support(m, idx, lb, ub)

# S3 method for DEFM
+(e1, e2)

Arguments

m

An object of class DEFM.

idx

Character scalar. Name of the variable to include in the term.

vname

Character scalar. Name to be assigned for the new term.

k

Numeric scalar. Exponent used in the term.

mat

Integer matrix. The matrix specifies the type of motif to capture (see details.)

formula

Character scalar (see details).

coords

Integer vector with the coordinates to include in the term.

lb, ub

Numeric scalars. Lower and upper bounds.

e1, e2

e1 An object of class DEFM (e1) and a character (e2).

Value

Invisible 0.

Details

In term_defm_transition, users can specify a particular motif to model. Motifs are represented by cells with values equal to 1, for example, the matrix:

represents a transition y0 -> (y1, y2). If 0 is a motif of interest, then the matrix should include 0 to mark zero values.

The function term_defm_transition_formula, will take the formula and generate the corresponding input for defm::counter_transition(). Formulas can be specified in the following ways:

  • Intercept effect: ... No transition, only including the current state.

  • Transition effect: ... > ... Includes current and previous states.

The general notation is [0]y[column id]_[row id]. A preceeding zero means that the value of the cell is considered to be zero. The column id goes between 0 and the number of columns in the array - 1 (so it is indexed from 0,) and the row id goes from 0 to m_order.

Intercept effects

Intercept effects only involve a single set of curly brackets. Using the 'greater-than' symbol (i.e., '<') is only for transition effects. When specifying intercept effects, users can skip the row_id, e.g., y0_0 is equivalent to y0. If the passed row id is different from the Markov order, i.e., row_id != m_order, then the function returns with an error.

Examples:

  • "{y0, 0y1}" is equivalent to set a motif with the first element equal to one and the second to zero.

Transition effects

Transition effects can be specified using two sets of curly brackets and an greater-than symbol, i.e., {...} > {...}. The first set of brackets, which we call LHS, can only hold row id that are less than m_order.

The term term_defm_logit_intercept will add what is equivalent to an intercept in a logistic regression. When coords is specified, then the function will add one intercept per outcome. These can be weighted by a covariate.

The function rule_not_one_to_zero will avoid the transition one to zero in a Markov process.

The function rule_constrain_support will constrain the support of the model by specifying a lower and upper bound for a given statistic.

The + method is a shortcut for term_formula

Examples

# Loading Valtente's SNS data
data(valentesnsList)

mymodel <- new_defm(
  id    = valentesnsList$id,
  Y     = valentesnsList$Y,
  X     = valentesnsList$X,
  order = 1
)

# Adding the intercept terms and a motif from tobacco to mj
term_defm_logit_intercept(mymodel)
term_defm_transition_formula(mymodel, "{y1, 0y2} > {y1, y2}")

# Inspecting the model
mymodel
#> Num. of Arrays       : 0
#> Support size         : -
#> Support size range   : -
#> Arrays in powerset   : 0
#> Transform. Fun.      : no
#> Model terms ( 4)    :
#>  - Logit intercept alcohol
#>  - Logit intercept tobacco
#>  - Logit intercept mj
#>  - Motif {tobacco⁺, mj⁻}⇨{tobacco⁺, mj⁺}
#> Model Y variables (3):
#>   0) alcohol
#>   1) tobacco
#>   2) mj