Skip to content

Commit 193ef54

Browse files
committed
Dyads() constraint now ignores preexisting %ergmlhs% constraints and observational constraints when calling ergmMPLE(). This prevents accidental infinite recursion, at the cost of speed in some circumstances.
1 parent 2b516e7 commit 193ef54

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ergm
2-
Version: 4.13.0-8132
2+
Version: 4.13.0-8133
33
Date: 2026-04-08
44
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
55
Authors@R: c(

R/InitErgmConstraint.operator.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ InitErgmConstraint.Dyads<-function(nw, arglist, ..., verify_dind = TRUE){
5555
fd <- lapply(list(fix=fix,vary=vary),
5656
function(f){
5757
if(!is.null(f)){
58+
nw %ergmlhs% "constraints" <- nw %ergmlhs% "obs.constraints" <- NULL
5859
m <- ergmMPLE(f, basis = nw, expand.bipartite=TRUE, output="array")$predictor
5960
m <- (m != 0) %|% FALSE
6061
if(!is.directed(nw)){

tests/testthat/test-constrain-dind.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,12 @@ test_that("Dyads() operator for bipartite undirected networks", {
124124
w <- outer(wealth01[1:7],wealth01[8:16],FUN=`==`)
125125
expect_equal(fix_g,logit(sum((!w)*m)/sum(!w)),ignore_attr=TRUE)
126126
})
127+
128+
129+
test_that("Dyad-independent constraint with missing edges", {
130+
data(sampson)
131+
samplike[1, 2] <- NA
132+
truth <- coef(ergm(samplike ~ nodematch("group3")))
133+
samplike %ergmlhs% "constraints" <- ~Dyads(vary = ~nodematch("group3"))
134+
expect_equal(coef(ergm(samplike ~ edges)), truth, ignore_attr = TRUE)
135+
})

0 commit comments

Comments
 (0)