Skip to content

Commit

Permalink
is.dyad.independent.ergm_model() now has an additional argument, igno…
Browse files Browse the repository at this point in the history
…re_aux=, controlling whether a dyad-dependent auxiliary in an otherwise dyad-independent model will make the whole model dyad-dependent. wrap.ergm_model() uses this option to propoagate an auxiliary's dyadic dependence only in auxiliary-only submodels.
  • Loading branch information
krivit committed Feb 19, 2024
1 parent acfa597 commit a24923f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ergm
Version: 4.6-7346
Date: 2024-02-06
Version: 4.6-7340
Date: 2024-02-19
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
person(c("Mark", "S."), "Handcock", role=c("aut"), email="[email protected]"),
Expand Down
10 changes: 9 additions & 1 deletion R/InitErgmTerm.operator.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#' with the `params` element; wrap empty network statistics; wrap
#' indicator of dyadic independence; and wrap offset indicators.
#'
#' `namewrap` also controls how dyadic dependence flag is propagated
#' for auxiliaries. If `NULL`, it is propagated; if not, the
#' auxiliaries are ignored and only terms's dyadic dependence is
#' propagated.
#'
#' @param m An `ergm_model` object.
#' @param nw A `network` object.
#' @param namewrap An optional function taking a character vector and
Expand Down Expand Up @@ -53,11 +58,14 @@ wrap.ergm_model <- function(m, nw, namewrap = identity){
names(params) <- namewrap(param_names(m, canonical=FALSE))
## names(params)[offsettheta] <- paste0("offset(", names(params)[offsettheta], ")")
}else map <- gradient <- params <- NULL

dependence <- !is.dyad.independent(m, ignore_aux=TRUE)
}else{
minpar <- maxpar <- offsettheta <- coef.names <- emptynwstats <- map <- gradient <- params <- NULL
dependence <- !is.dyad.independent(m, ignore_aux=FALSE)
}

list(map=map, gradient=gradient, params=params, minpar=minpar, maxpar=maxpar, coef.names=coef.names, emptynwstats=emptynwstats, dependence=!is.dyad.independent(m), offset=offsettheta)
list(map=map, gradient=gradient, params=params, minpar=minpar, maxpar=maxpar, coef.names=coef.names, emptynwstats=emptynwstats, dependence=dependence, offset=offsettheta)
}

ergm_rename_terms <- function(model, namewrap){
Expand Down
9 changes: 6 additions & 3 deletions R/is.dyad.independent.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ is.dyad.independent<-function(object,...) UseMethod("is.dyad.independent")
is.dyad.independent.NULL <- function(object, ...) TRUE # By convention.

#' @describeIn ergm_model Tests whether the model is dyad-independent.
#' @param ignore_aux A flag to specify whether a dyad-dependent
#' auxiliary should make the model dyad-dependent or should be
#' ignored.
#' @export
is.dyad.independent.ergm_model <- function(object, ...){
is.dyad.independent.ergm_model <- function(object, ..., ignore_aux=TRUE){
## NB: Auxiliaries (i.e., terms without statistics) do not affect dyadic dependence.
! any(sapply(object$terms, function(term) length(term$coef.name) && (is.null(term$dependence) || term$dependence)))
! any(sapply(object$terms, function(term) (!ignore_aux || length(term$coef.names)) && (is.null(term$dependence) || term$dependence)))
}

#' @rdname is.dyad.independent
Expand All @@ -63,7 +66,7 @@ is.dyad.independent.formula<-function(object,response=NULL,basis=NULL,...){

ergm_preprocess_response(nw, response)
m<-ergm_model(object, nw, ...)
is.dyad.independent(m)
is.dyad.independent(m, ...)
}

#' @rdname is.dyad.independent
Expand Down
6 changes: 5 additions & 1 deletion man/ergm_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/wrap.ergm_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a24923f

Please sign in to comment.