Skip to content

Commit 7f2f42d

Browse files
committed
Added *b*dsp() terms; in C implementations of layered triadic terms, use enum for shared partner type.
1 parent 4829569 commit 7f2f42d

7 files changed

Lines changed: 443 additions & 96 deletions

R/InitErgmTerm.dgw_sp.R

Lines changed: 142 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ wrap_ergm_sp_call <- function(ergm_name, nw, a, has_base, d0 = FALSE, cache.sp =
8686

8787
.emptynwstats <-
8888
if (d0 && any(a$d == 0)) {
89-
if (is.bipartite(nw)) {
90-
nb1 <- b1.size(nw)
91-
nb2 <- network.size(nw) - nb1
92-
replace(numeric(length(a$d)), a$d == 0, choose(nb1, 2) + choose(nb2, 2))
93-
} else {
94-
replace(numeric(length(a$d)), a$d == 0, network.dyadcount(nw, FALSE))
95-
}
89+
n <-
90+
if (is.bipartite(nw))
91+
switch(type,
92+
UTP = network.size(nw),
93+
OSP = b1.size(nw),
94+
ISP = b2.size(nw))
95+
else network.size(nw)
96+
replace(dbl_along(a$d), a$d == 0,
97+
choose(n, 2L) * (is.directed(nw) + 1L))
9698
}
9799

98100
# Replace the parts that are different for the layered term.
@@ -108,6 +110,7 @@ wrap_ergm_sp_call <- function(ergm_name, nw, a, has_base, d0 = FALSE, cache.sp =
108110
else no_layer_err(ergm_name)
109111
}
110112

113+
111114
################################################################################
112115
#Term to count ESP statistics, where the shared partners may be any of
113116
#several distinct types.
@@ -413,3 +416,135 @@ InitErgmTerm.dgwnspL<-function(nw, arglist, gw.cutoff=30, ...) {
413416
#' # binary: gwnspL(decay, fixed=FALSE, cutoff=30, type="OTP", L.base=NULL,
414417
#' # Ls.path=NULL, L.in_order=FALSE)
415418
InitErgmTerm.gwnspL <- InitErgmTerm.dgwnspL
419+
420+
421+
################################################################################
422+
423+
#' @templateVar name b1dspL
424+
#' @title Dyadwise shared partners for dyads in the first bipartition on layers
425+
#' @description This term adds one
426+
#' network statistic to the model for each element in `d`; the \eqn{i}th
427+
#' such statistic equals the number of dyads in the first bipartition with exactly
428+
#' `d[i]` shared partners. (Those shared partners, of course, must be members
429+
#' of the second bipartition.) This term can only be used with bipartite networks.
430+
#'
431+
#' @usage
432+
#' # binary: b1dsp(d, Ls.path=NULL)
433+
#'
434+
#' @param d a vector of distinct integers.
435+
#' @template ergmTerm-Ls-path
436+
#'
437+
#' @template ergmTerm-cache-sp
438+
#' @template ergmTerm-general
439+
#'
440+
#' @concept bipartite
441+
#' @concept undirected
442+
#' @concept layer-aware
443+
InitErgmTerm.b1dspL <- function(nw, arglist, cache.sp=TRUE, ...){
444+
a <- check.ErgmTerm(nw, arglist, bipartite = TRUE,
445+
varnames = c("d", "Ls.path"),
446+
vartypes = c("numeric", "formula,list"),
447+
defaultvalues = list(NULL, NULL),
448+
required = c(TRUE, FALSE))
449+
450+
wrap_ergm_sp_call("b1dsp", nw, a, FALSE, TRUE, ...)
451+
}
452+
453+
################################################################################
454+
455+
#' @templateVar name gwb1dsp
456+
#' @title Geometrically weighted dyadwise shared partner distribution for dyads in the first bipartition on layers
457+
#' @description This term adds one network statistic to the model equal to the geometrically
458+
#' weighted dyadwise shared partner distribution for dyads in the first bipartition with decay parameter
459+
#' `decay` parameter, which should be non-negative. This term can only be used with bipartite networks.
460+
#'
461+
#' @usage
462+
#' # binary: gwb1dsp(decay=0, fixed=FALSE, cutoff=30, Ls.path=NULL)
463+
#'
464+
#' @templateVar multiplicand shared partner counts
465+
#' @template ergmTerm-gw-decay-fixed
466+
#' @templateVar underlying b1dsp
467+
#' @template ergmTerm-gw-cutoff
468+
#' @template ergmTerm-Ls-path
469+
#'
470+
#' @template ergmTerm-cache-sp
471+
#' @template ergmTerm-general
472+
#'
473+
#' @concept bipartite
474+
#' @concept undirected
475+
#' @concept curved
476+
#' @concept layer-aware
477+
InitErgmTerm.gwb1dspL<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
478+
a <- check.ErgmTerm(nw, arglist, bipartite = TRUE,
479+
varnames = c("decay", "fixed", "cutoff", "alpha", "Ls.path"),
480+
vartypes = c("numeric", "logical", "numeric", "numeric", "formula,list"),
481+
defaultvalues = list(NULL, FALSE, gw.cutoff, NULL, NULL),
482+
required = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE))
483+
484+
wrap_ergm_sp_call("gwb1dsp", nw, a, FALSE, ...)
485+
}
486+
487+
################################################################################
488+
489+
#' @templateVar name b2dspL
490+
#' @title Dyadwise shared partners for dyads in the second bipartition on layers
491+
#' @description This term adds one network statistic to the model for each element in `d` ; the \eqn{i} th
492+
#' such statistic equals the number of dyads in the second bipartition with exactly
493+
#' `d[i]` shared partners. (Those shared partners, of course, must be members
494+
#' of the first bipartition.) This term can only be used with bipartite networks.
495+
#'
496+
#' @usage
497+
#' # binary: b2dsp(d, Ls.path=NULL)
498+
#'
499+
#' @param d a vector of distinct integers
500+
#' @template ergmTerm-Ls-path
501+
#'
502+
#' @template ergmTerm-cache-sp
503+
#' @template ergmTerm-general
504+
#'
505+
#' @concept bipartite
506+
#' @concept undirected
507+
#' @concept layer-aware
508+
InitErgmTerm.b2dspL <- function(nw, arglist, cache.sp=TRUE, ...){
509+
a <- check.ErgmTerm(nw, arglist, bipartite = TRUE,
510+
varnames = c("d", "Ls.path"),
511+
vartypes = c("numeric", "formula,list"),
512+
defaultvalues = list(NULL, NULL),
513+
required = c(TRUE, FALSE))
514+
515+
wrap_ergm_sp_call("b2dsp", nw, a, FALSE, TRUE, ...)
516+
}
517+
518+
################################################################################
519+
520+
#' @templateVar name gwb2dspL
521+
#' @title Geometrically weighted dyadwise shared partner distribution for dyads in the second bipartition on layers
522+
#' @description This term adds one network statistic to the model equal to the geometrically
523+
#' weighted dyadwise shared partner distribution for dyads in the second bipartition with decay parameter
524+
#' `decay` parameter, which should be non-negative. This term can only be used with bipartite networks.
525+
#'
526+
#' @usage
527+
#' # binary: gwb2dsp(decay=0, fixed=FALSE, cutoff=30, Ls.path=NULL)
528+
#'
529+
#' @templateVar multiplicand shared partner counts
530+
#' @template ergmTerm-gw-decay-fixed
531+
#' @templateVar underlying b2dsp
532+
#' @template ergmTerm-gw-cutoff
533+
#' @template ergmTerm-Ls-path
534+
#'
535+
#' @template ergmTerm-cache-sp
536+
#' @template ergmTerm-general
537+
#'
538+
#' @concept bipartite
539+
#' @concept undirected
540+
#' @concept curved
541+
#' @concept layer-aware
542+
InitErgmTerm.gwb2dsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
543+
a <- check.ErgmTerm(nw, arglist, bipartite = TRUE,
544+
varnames = c("decay", "fixed", "cutoff", "alpha", "Ls.path"),
545+
vartypes = c("numeric", "logical", "numeric", "numeric", "formula,list"),
546+
defaultvalues = list(NULL, FALSE, gw.cutoff, NULL, NULL),
547+
required = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE))
548+
549+
wrap_ergm_sp_call("gwb2dsp", nw, a, FALSE, ...)
550+
}

man/b1dspL-ergmTerm-50daeb76.Rd

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/b2dspL-ergmTerm-fe3c0be7.Rd

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gwb1dsp-ergmTerm-0bf628f4.Rd

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gwb2dspL-ergmTerm-a90bec3f.Rd

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)