Fits a Discrete Exponential-Family Model using Maximum Likelihood.

logodds(m, par, i, j)

defm_mle(object, start, lower, upper, ...)

summary_table(object, as_texreg = FALSE, ...)

texreg_fancy(fits, fun, skip_intercept = FALSE, ...)

Arguments

m

An object of class DEFM.

par

The parameters of the model.

i, j

The row and column of the array to turn on for the log odds.

object

An object of class DEFM.

start

Double vector. Starting point for the MLE.

lower, upper

Lower and upper limits for the optimization (passed to stats4::mle.)

...

Further arguments passed to summary_table (with the exception of as_texreg, which is set to TRUE).

as_texreg

When TRUE, wraps the result in a texreg object

fits

Either a single or a list of defm fit objects.

fun

Function to be called from the texreg package, e.g., texreg::screenreg.

skip_intercept

Whether or not to skip the intercept (logit) terms when printing the table

Value

  • logodds returns a numeric vector with the log-odds for each observation in the data.

An object of class stats4::mle.

An object of class texreg with additional attributes: custom.coef.map, reorder.coef, and groups.

Details

The likelihood function of the DEFM is closely-related to the Exponential-Family Random Graph Model [ERGM]. Furthermore, the DEFM can be treated as a generalization of the ERGM. The model implemented here can be viewed as an ERGM for a bipartite network, where the actors are individuals and the events are the binary outputs.

If the model features no markov terms, i.e., terms that depend on more than one output, then the model is equivalent to a logistic regression. The example below shows this equivalence.

The function summary_table computes pvalues and returns a table with the estimates, se, and pvalues. If as_texreg = TRUE, then it will return a texreg object.

References

Vega Yon, G. G., Pugh, M. J., & Valente, T. W. (2022). Discrete Exponential-Family Models for Multivariate Binary Outcomes (arXiv:2211.00627). arXiv. https://arxiv.org/abs/2211.00627

See also

DEFM for objects of class DEFM and loglike_defm() for the log-likelihood function of DEFMs.

Examples

#' Using Valente's SNS data
data(valentesnsList)

# Creating the DEFM object
logit_0 <- new_defm(
  id = valentesnsList$id,
  X = valentesnsList$X,
  Y = valentesnsList$Y[,1,drop=FALSE],
  order = 0
)

# Building the model
td_logit_intercept(logit_0)
td_logit_intercept(logit_0, covar = "Hispanic")
td_logit_intercept(
  logit_0,
  covar = "exposure_smoke"
)
td_logit_intercept(logit_0, covar = "Grades")
init_defm(logit_0) # Needs to be initialized

# Fitting the model
res_0 <- defm_mle(logit_0)

# Refitting the model using GLM
res_glm <- with(
  valentesnsList,
  glm(Y[,1] ~ X[,1] + X[,3] + X[,7], family = binomial())
  )

# Comparing results
summary_table(res_0)
#>                                                coef         se      pvalues
#> Logit intercept alcohol                  -0.2734108 0.31601060 3.869317e-01
#> Logit intercept alcohol x Hispanic        1.3351257 0.13263089 7.771238e-24
#> Logit intercept alcohol x exposure_smoke  0.6812041 0.10420832 6.278809e-11
#> Logit intercept alcohol x Grades         -0.2840092 0.06962101 4.515969e-05
summary(res_glm)
#> 
#> Call:
#> glm(formula = Y[, 1] ~ X[, 1] + X[, 3] + X[, 7], family = binomial())
#> 
#> Coefficients:
#>             Estimate Std. Error z value Pr(>|z|)    
#> (Intercept) -0.27338    0.31600  -0.865    0.387    
#> X[, 1]       1.33511    0.13262  10.067  < 2e-16 ***
#> X[, 3]       0.68121    0.10421   6.537 6.27e-11 ***
#> X[, 7]      -0.28401    0.06962  -4.080 4.51e-05 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 2294.3  on 1729  degrees of freedom
#> Residual deviance: 2050.2  on 1726  degrees of freedom
#> AIC: 2058.2
#> 
#> Number of Fisher Scoring iterations: 3
#> 

# Comparing the logodds
head(logodds(logit_0, par = coef(res_0), i = 0, j = 0))
#> [1] -2.3746611 -1.4094478 -1.5514524 -0.3295123  1.3169051 -0.3295123