-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
Discussed in #623
Originally posted by martinamorris July 15, 2025
Context: Hoping to use the summary() function to calculate mean degree by group.
The term operators in ergm 4 include an "interaction" operator (demonstrated in the Advanced ERGM workshop, section 4.4).
I was hoping to use this to calculate the mean degree by group in a summary call: summary(nw ~ meandeg*nodefactor("Attribute", levels=T). But this doesn't produce the expected result. Reprex below.
library(ergm)
data("faux.mesa.high")
mesa <- faux.mesa.high
# meandeg, overall (works as expected)
## using direct calculation
2*network.edgecount(mesa) / network.size(mesa)
## using summary
summary(mesa ~ meandeg)
# meandeg by grade (not as expected)
## nodes by grade
nodes.by.grade <- table(mesa %v% "Grade")
## edges by grade (note, sums to 406, so is actually "stubs" by grade)
stubs.by.grade <- summary(mesa ~ nodefactor("Grade", levels=T))
## meandeg by grade using stubs/nodes calculation
stubs.by.grade/nodes.by.grade
### using summary and interaction term operator with ":"
summary(mesa ~ meandeg:nodefactor("Grade", levels=TRUE))
Metadata
Metadata
Assignees
Labels
No labels