statnet / ergm

Fit, Simulate and Diagnose Exponential-Family Models for Networks
Other
96 stars 37 forks source link

Implement an alias() method for ergm objects. #161

Open krivit opened 4 years ago

krivit commented 4 years ago

This could work in tandem with the existing nonidentifiability detection; in particular, the existing alias.formula() and alias.lm() methods provide more detail: not only which statistics are aliased by those before them but also how---by what linear combination of the others.

We can jury-rig the existing alias.formula() code using ergm.pl()'s outputs:

library(ergm)
data(florentine)

# edges is aliased by kstar1:
xyw <- ergmMPLE(flomarriage ~ kstar(1:2) + absdiff("wealth") + edges + triangle)
xyw <- as.data.frame(cbind(.dummy=1, xyw$predictor))
alias(.dummy~.-1, data=xyw)

gives

Model :
.dummy ~ (kstar1 + kstar2 + absdiff.wealth + edges + triangle) - 
    1

Complete :
      kstar1 kstar2 absdiff.wealth triangle
edges 1/2      0      0              0    

This could be provided as a warning after the MPLE is estimated but before MCMC-based estimation begins.

krivit commented 4 years ago

Addendum: for conciseness, we may want to only print the aliasers with nonzero coefficients. Continuing from the previous comment,

a <- alias(.dummy~.-1, data=xyw)
# Construct a matrix out of the nice fractions:
fracsm <- matrix(attr(a$Complete,"fracs"), nrow=nrow(a$Complete), ncol=ncol(a$Complete), dimnames=dimnames(a$Complete))
lcs <- apply(fracsm, 1, function(r) paste0(r[r!="0"], "*", names(r[r!="0"]), collapse=" + "))
cat(paste0(names(lcs), " = ", lcs, "\n"))

prints

edges = 1/2*kstar1
 `absdiff.-wealth` = 1*absdiff.wealth
martinamorris commented 4 years ago

just a general comment: Yay!