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, ...)
An object of class DEFM.
The parameters of the model.
The row and column of the array to turn on for the log odds.
An object of class DEFM.
Double vector. Starting point for the MLE.
Lower and upper limits for the optimization (passed to stats4::mle.)
Further arguments passed to stats4::mle.
When TRUE
, wraps the result in a texreg object
logodds
returns a numeric vector with the log-odds for each observation in the data.
An object of class stats4::mle.
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.
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
DEFM for objects of class DEFM and loglike_defm()
for the
log-likelihood function of DEFMs.
#' 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
term_defm_logit_intercept(logit_0)
term_defm_logit_intercept(logit_0, idx = "Hispanic")
term_defm_logit_intercept(
logit_0, idx = "exposure_smoke",
vname = "Smoke Exp"
)
term_defm_logit_intercept(logit_0, idx = "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.31601852 3.869436e-01
#> Logit intercept alcohol x Hispanic 1.3351257 0.13263142 7.774442e-24
#> Logit intercept alcohol x Smoke Exp 0.6812041 0.10420837 6.278945e-11
#> Logit intercept alcohol x Grades -0.2840092 0.06962284 4.518053e-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