[statnet_help] Constraint blocks of dyads via 'constraints = ~ Dyads(vary, fix)'

Hunter, David Russell drh20 at psu.edu
Fri Dec 11 07:40:41 PST 2020


Dear Karim,

[Sorry for the resend. I was having email issues.]
Thanks for including such an easy-to-reproduce example! Let me know if this helps explain what’s going on with your code:


> table(Flomarriage %v% "group")


1 2
15 15

Your “Flomarriage" network is directed, so the output above reveals that there are (15x14) plus (15x14), or 420, different dyads that have nonzero change statistics for the nodematch(“group”) ergm model term. This is out of 30*29, or 870, total dyads in the network, leaving 450 that have zero change stats for the nodematch term.


> summary(Flomarriage ~ edges + nodematch("group"))

edges nodematch.group
40 19

The output above reveals that 19 of the 420 possible dyads that DO have nonzero change stats are edges, whereas 40–19 or 21 of the 450 possible dyads that DO NOT have nonzero change stats are edges. So we can calculate by hand the log-odds, or logit, of both 19/420 and 21/450, and these give the values of parameter estimates for the “edges” term in networks that hold fixed the dyads in one category or the other, as follows:

The “Dyads” operator with “fix” will fix the dyads with nonzero change stats, leading to the logit(21/450) answer:

> logit <- function(p) log(p/(1-p))

> logit(21/450)

[1] -3.016934

> ergm(Flomarriage~edges, constraints = ~ Dyads(fix = ~nodematch("group"), vary = NULL))$coef

edges
-3.016934

Similarly, if we use the “vary” option with the “Dyads” operator, we’ll fix the zero-change-stat dyads, which yields the logit(19/420) answer:

> logit(19/420)

[1] -3.049522

> ergm(Flomarriage~edges, constraints = ~ Dyads(vary = ~nodematch("group"), fix = NULL))$coef

edges
-3.049522

On the other hand, the “flomarriage” network is undirected with 20 edges and 16 nodes and thus (16-choose-2), or 120, dyads. This leads to an “edges” coefficient of logit(20/120):

> logit(20/120)

[1] -1.609438

> ergm(flomarriage~edges)$coef

edges
-1.609438

…and “Flomarriage” without any constraints has 40 edges out of a possible 870:

> logit(40/870)

[1] -3.032546

> ergm(Flomarriage~edges)$coef

edges
-3.032546

Hope this helps,
Dave


On Dec 10, 2020, at 6:46 PM, Karim Khader <Karim.Khader at hsc.utah.edu<mailto:Karim.Khader at hsc.utah.edu>> wrote:

All,

Does anyone have experience using the Dyad constraint (i.e. constraints = ~ Dyads(vary = ~nodematch("group"), fix = NULL)) within ‘ergm’, used to impose a block diagonal structure on the network adjacency matrix? I have recently tried implementing it but am finding that the model estimates when the constraint is used do not make sense.

Code for a simple example that illustrates my concern is included below. In the example, I understand that e1 should be different from e2 and e3, but I would have thought that e2 and e3 should return the same estimate (since the # of possible edges and the total # of edges represented in e3 is a multiple of those represented in e2). Am I simply misunderstanding how constraints = ~ Dyads() is supposed to work?

Best,

Karim Khader
Assistant Professor
Division of Epidemiology
University of Utah
Salt Lake City, Utah


require(statnet)
require(dplyr)

data(florentine)
### Create N independent copies of 'flomarriage'
N <- 2
Florentine <- list()
for (i in 1:N){
Florentine[[i]] <- flomarriage
}

### Create new edgelist that incorporates the N independent copies,
### and assigns each node a 'group' id depending on which group they belong to
EL <- list()
for (i in 1:N){
EL[[i]] <- as.edgelist(Florentine[[i]]) + (i-1)*16
EL[[i]] <- as.data.frame(EL[[i]])%>%
mutate(group = i)%>%
rename(from = V1, to = V2)
}
EL <- do.call("rbind", EL)
NL <- rbind(EL%>%select(from, group)%>%rename(id=from),
EL%>%select(to, group)%>%rename(id=to))%>%
arrange(group, id)%>%
distinct(.keep_all = T)

### Create new Network that represents N independent copies of flomarriage
Flomarriage <- network(select(EL, from, to), vertex.attr = NL, directed = TRUE)

e1 <- ergm(Flomarriage ~ edges)
e2 <- ergm(flomarriage ~ edges)
e3 <- ergm(Flomarriage ~ edges, constraints = ~ Dyads(vary = ~nodematch("group"), fix = NULL))
_______________________________________________
statnet_help mailing list
statnet_help at u.washington.edu<mailto:statnet_help at u.washington.edu>
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmailman13.u.washington.edu%2Fmailman%2Flistinfo%2Fstatnet_help&data=04%7C01%7Cdrh20%40psu.edu%7Ccab6c82fafdc41b5b24108d89d65f6f4%7C7cf48d453ddb4389a9c1c115526eb52e%7C0%7C0%7C637432408550493476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=LVxnH42MLma9C7n8JxJcdOKAjez7lVd%2FUd3%2Bt4sM8OU%3D&reserved=0<https://nam10.safelinks.protection.outlook.com/?url=http://mailman13.u.washington.edu/mailman/listinfo/statnet_help&data=04|01|drh20@psu.edu|cab6c82fafdc41b5b24108d89d65f6f4|7cf48d453ddb4389a9c1c115526eb52e|0|0|637432408550493476|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|1000&sdata=LVxnH42MLma9C7n8JxJcdOKAjez7lVd/Ud3+t4sM8OU=&reserved=0>
On Dec 10, 2020, at 6:46 PM, Karim Khader <Karim.Khader at hsc.utah.edu<mailto:Karim.Khader at hsc.utah.edu>> wrote:

All,

Does anyone have experience using the Dyad constraint (i.e. constraints = ~ Dyads(vary = ~nodematch("group"), fix = NULL)) within ‘ergm’, used to impose a block diagonal structure on the network adjacency matrix? I have recently tried implementing it but am finding that the model estimates when the constraint is used do not make sense.

Code for a simple example that illustrates my concern is included below. In the example, I understand that e1 should be different from e2 and e3, but I would have thought that e2 and e3 should return the same estimate (since the # of possible edges and the total # of edges represented in e3 is a multiple of those represented in e2). Am I simply misunderstanding how constraints = ~ Dyads() is supposed to work?

Best,

Karim Khader
Assistant Professor
Division of Epidemiology
University of Utah
Salt Lake City, Utah


require(statnet)
require(dplyr)

data(florentine)
### Create N independent copies of 'flomarriage'
N <- 2
Florentine <- list()
for (i in 1:N){
Florentine[[i]] <- flomarriage
}

### Create new edgelist that incorporates the N independent copies,
### and assigns each node a 'group' id depending on which group they belong to
EL <- list()
for (i in 1:N){
EL[[i]] <- as.edgelist(Florentine[[i]]) + (i-1)*16
EL[[i]] <- as.data.frame(EL[[i]])%>%
mutate(group = i)%>%
rename(from = V1, to = V2)
}
EL <- do.call("rbind", EL)
NL <- rbind(EL%>%select(from, group)%>%rename(id=from),
EL%>%select(to, group)%>%rename(id=to))%>%
arrange(group, id)%>%
distinct(.keep_all = T)

### Create new Network that represents N independent copies of flomarriage
Flomarriage <- network(select(EL, from, to), vertex.attr = NL, directed = TRUE)

e1 <- ergm(Flomarriage ~ edges)
e2 <- ergm(flomarriage ~ edges)
e3 <- ergm(Flomarriage ~ edges, constraints = ~ Dyads(vary = ~nodematch("group"), fix = NULL))
_______________________________________________
statnet_help mailing list
statnet_help at u.washington.edu<mailto:statnet_help at u.washington.edu>
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmailman13.u.washington.edu%2Fmailman%2Flistinfo%2Fstatnet_help&data=04%7C01%7Cdrh20%40psu.edu%7Ccab6c82fafdc41b5b24108d89d65f6f4%7C7cf48d453ddb4389a9c1c115526eb52e%7C0%7C0%7C637432408550493476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=LVxnH42MLma9C7n8JxJcdOKAjez7lVd%2FUd3%2Bt4sM8OU%3D&reserved=0

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman13.u.washington.edu/pipermail/statnet_help/attachments/20201211/81585f87/attachment.html>


More information about the statnet_help mailing list