Skip to content

Commit

Permalink
Defunct-ed *degreepopularity and hammingmix terms and offset.info.for…
Browse files Browse the repository at this point in the history
…mula() after a long deprecation prediod.
  • Loading branch information
krivit committed Dec 29, 2024
1 parent 20107f8 commit 6351c44
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 206 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ export(network.list)
export(nparam)
export(nthreads)
export(nvattr.copy.network)
export(offset.info.formula)
export(param_names)
export(rank_test.ergm)
export(rlebdm)
Expand Down
144 changes: 2 additions & 142 deletions R/InitErgmTerm.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
# <b2star> <b2starmix> <b2twostar>
# <balance>
# C: <concurrent> <cycle> <ctriple>=<ctriad>
# D: <degree> <degreepopularity><density> <dsp>
# D: <degree> <density> <dsp>
# <dyadcov> <degcrossprod> <degcor>
# E: <edgecov> <edges> <esp>
# G: <gwb1degree> <gwb2degree> <gwdegree>
# <gwdsp> <gwesp> <gwidegree>
# <gwnsp> <gwodegree>
# H: <hamming>
# I: <idegree> <intransitive> <idegreepopularity>
# I: <idegree> <intransitive>
# <isolates> <istar>
# K: <kstar>
# L: <localtriangle>
Expand All @@ -40,7 +40,6 @@
# <nodemix> <nodeocov> <nodeofactor>
# <nsp>
# O: <odegree> <opentriad> <ostar>
# <odegreepopularity>
# P: <pdegcor>
# R: <receiver> <rdegcor>
# S: <sender> <simmelian> <simmelianties>
Expand Down Expand Up @@ -2290,21 +2289,6 @@ InitErgmTerm.degree1.5<-function (nw, arglist, ...) {
}


################################################################################
#' @include ergm-deprecated.R
#' @describeIn ergm-deprecated Use [`degree1.5`][degree1.5-ergmTerm] instead.
InitErgmTerm.degreepopularity<-function (nw, arglist, ...) {
.Deprecated("degree1.5")
a <- check.ErgmTerm(nw, arglist, directed=FALSE,
varnames = NULL,
vartypes = NULL,
defaultvalues = list(),
required = NULL)
list(name="degreepopularity", coef.names="degreepopularity",
minval=0, maxval=network.dyadcount(nw,FALSE)*sqrt(network.size(nw)-1), conflicts.constraints="degreedist")
}


################################################################################

#' @templateVar name density
Expand Down Expand Up @@ -2891,101 +2875,6 @@ InitErgmTerm.hamming<-function (nw, arglist, ...) {
minval = minval, maxval = maxval)
}

################################################################################
#' @rdname ergm-deprecated
#' @aliases hammingmix
InitErgmTerm.hammingmix<-function (nw, arglist, ..., version=packageVersion("ergm")) {
.Deprecate_once(msg="hammingmix() has been deprecated due to disuse.")
if(version <= as.package_version("3.9.4")){
# There is no reason hammingmix should be directed-only, but for now
# the undirected version does not seem to work properly, so:
a <- check.ErgmTerm(nw, arglist, directed=TRUE,
varnames = c("attrname","x","base","contrast"),
vartypes = c("character","matrix,network","numeric","logical"),
defaultvalues = list(NULL,nw,NULL,FALSE),
required = c(TRUE,FALSE,FALSE,FALSE),
dep.inform = list(FALSE, FALSE, "levels2", FALSE))
attrarg <- a$attrname
}else{
# There is no reason hammingmix should be directed-only, but for now
# the undirected version does not seem to work properly, so:
a <- check.ErgmTerm(nw, arglist, directed=TRUE,
varnames = c("attr", "x", "base", "levels", "levels2","contrast"),
vartypes = c(ERGM_VATTR_SPEC, "matrix,network", "numeric", ERGM_LEVELS_SPEC, ERGM_LEVELS_SPEC,"logical"),
defaultvalues = list(NULL,nw,NULL,NULL,NULL,FALSE),
required = c(TRUE,FALSE,FALSE,FALSE,FALSE,FALSE),
dep.inform = list(FALSE, FALSE, "levels2", FALSE, FALSE, FALSE))
attrarg <- a$attr
}

x<-a$x

if (a$contrast) {
ergm_Init_stop("The 'contrast' argument of the hammingmix term is deprecated. Use 'levels2' instead")
}
if(is.network(x)){
xm<-as.edgelist(x)
x<-paste(quote(x))
}else if(is.character(x)){
xm<-get.network.attribute(nw,x)
xm<-as.edgelist(xm)
}else{
xm<-as.matrix(x)
x<-paste(quote(x))
}
if (is.null(xm) || ncol(xm)!=2){
ergm_Init_stop("hammingmix() requires an edgelist")
}

nodecov <- ergm_get_vattr(attrarg, nw)
attrname <- attr(nodecov, "name")

u <- ergm_attr_levels(a$levels, nodecov, nw, sort(unique(nodecov)))
namescov <- u

nr <- length(u)
nc <- length(u)

levels2.list <- transpose(expand.grid(row = u, col = u, stringsAsFactors=FALSE))
indices2.grid <- expand.grid(row = 1:nr, col = 1:nc)

levels2.sel <- if((!hasName(attr(a,"missing"), "levels2") || attr(a,"missing")["levels2"]) && any(NVL(a$base,0)!=0)) levels2.list[-a$base]
else ergm_attr_levels(a$levels2, list(row = nodecov, col = nodecov), nw, levels2.list)

rows2keep <- match(levels2.sel,levels2.list, NA)
rows2keep <- rows2keep[!is.na(rows2keep)]

u <- indices2.grid[rows2keep,]

nodecov.indices <- match(nodecov, namescov, nomatch=length(namescov) + 1)

coef.names <- paste("hammingmix",attrname,
apply(matrix(namescov[as.matrix(u)],ncol=2),1,paste,collapse="."),
sep=".")
# Number of input parameters before covariates equals twice the number
# of used matrix cells, namely 2*length(uui),
inputs=c(to_ergm_Cdouble(xm, prototype=nw), u[,1], u[,2], nodecov.indices)
attr(inputs, "ParamsBeforeCov") <- nrow(u)
# The emptynwstats code below does not work right for
# undirected networks, mostly since hammingmix doesn't work
# in this case anyway.
nw %v% "_tmp_nodecov" <- as.vector(nodecov)
if(version <= as.package_version("3.9.4")){
emptynwstats <- summary(nw ~ nodemix("_tmp_nodecov", base=a$base))
}else{
nodemix.call <- c(list(as.name("nodemix"),"_tmp_nodecov"), list(base=a$base, levels=a$levels, levels2=a$levels2)[!attr(a,"missing")[c("base","levels","levels2")]])
nodemix.call <- as.call(nodemix.call)
nodemix.form <- as.formula(call("~", nw, nodemix.call))
emptynwstats <- summary(nodemix.form)
}
list(name="hammingmix", coef.names=coef.names, inputs=inputs,
emptynwstats=emptynwstats, dependence=FALSE)
}






#=======================InitErgmTerm functions: I============================#

Expand Down Expand Up @@ -3074,21 +2963,6 @@ InitErgmTerm.idegree1.5<-function (nw, arglist, ...) {
}


################################################################################
#' @describeIn ergm-deprecated Use [`idegree1.5`][idegree1.5-ergmTerm] instead.
InitErgmTerm.idegreepopularity<-function (nw, arglist, ...) {
.Deprecated("idegree1.5")
a <- check.ErgmTerm(nw, arglist, directed=TRUE,
varnames = NULL,
vartypes = NULL,
defaultvalues = list(),
required = NULL)
list(name="idegreepopularity", coef.names="idegreepopularity",
minval=0, maxval=network.dyadcount(nw,FALSE)*sqrt(network.size(nw)-1), conflicts.constraints="idegreedist")
}



################################################################################

#' @templateVar name intransitive
Expand Down Expand Up @@ -4528,20 +4402,6 @@ InitErgmTerm.odegree1.5<-function (nw, arglist, ...) {
}


################################################################################
#' @describeIn ergm-deprecated Use [`odegree1.5`][odegree1.5-ergmTerm] instead.
InitErgmTerm.odegreepopularity<-function (nw, arglist, ...) {
.Deprecated("odegree1.5")
a <- check.ErgmTerm(nw, arglist, directed=TRUE,
varnames = NULL,
vartypes = NULL,
defaultvalues = list(),
required = NULL)
list(name="odegreepopularity", coef.names="odegreepopularity",
minval=0, maxval=network.dyadcount(nw,FALSE)*sqrt(network.size(nw)-1), conflicts.constraints="odegreedist")
}


################################################################################

#' @templateVar name opentriad
Expand Down
16 changes: 15 additions & 1 deletion R/ergm-defunct.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
#'
#' as.rlebdm.ergm(...)
#'
#' offset.info.formula(...)
#'
#' InitErgmTerm.degreepopularity(...)
#'
#' InitErgmTerm.idegreepopularity(...)
#'
#' InitErgmTerm.odegreepopularity(...)
#'
#' @description Functions that have been removed after a period of deprecation.
#' @param ... Arguments to defunct functions.
#' @details
Expand Down Expand Up @@ -140,7 +148,13 @@
#'
#' `as.rlebdm.ergm()`: no longer used
#'
#' @aliases robust.inverse plot.network.ergm ergm.getterms plot.mcmc.list.ergm plot.ergm summary.statistics ergm.checkargs ergm.checkbipartite ergm.checkdirected summary.gof ergm.getMCMCsample ergm.MHP.table MHproposal MHproposal.character MHproposal.ergm MHproposal.formula ergm.init.methods ergm.ConstraintImplications ergm.mcmcslave ergm.update.formula remove.offset.formula network.update ergm.getmodel ergm.getglobalstats as.edgelist.compressed as.network.uncompressed standardize.network newnw.extract san.ergm is.inCH as.rlebdm.ergm
#' `offset.info.formula()`: no longer used
#'
#' `degreepopularity`, `odegreepopularity`, `idegreepopularity`: use the corresponding `degree1.5` term
#'
#' `hammingmix`: use `hamming(...):nodemix(...)` for example
#'
#' @aliases robust.inverse plot.network.ergm ergm.getterms plot.mcmc.list.ergm plot.ergm summary.statistics ergm.checkargs ergm.checkbipartite ergm.checkdirected summary.gof ergm.getMCMCsample ergm.MHP.table MHproposal MHproposal.character MHproposal.ergm MHproposal.formula ergm.init.methods ergm.ConstraintImplications ergm.mcmcslave ergm.update.formula remove.offset.formula network.update ergm.getmodel ergm.getglobalstats as.edgelist.compressed as.network.uncompressed standardize.network newnw.extract san.ergm is.inCH as.rlebdm.ergm degreepopularity-ergmTerm odegreepopularity-ergmTerm idegreepopularity-ergmTerm hammingmix-ergmTerm offset.info.formula
#'
#' @keywords internal
NULL
10 changes: 0 additions & 10 deletions R/formula.utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,3 @@ enformulate.curved.formula <- function(object, theta, ...){

model.transform.formula(object, theta, recipes, ...)
}

#' @describeIn ergm-deprecated \code{offset.info.formula} returns the offset
#' vectors associated with a formula.
#' @export offset.info.formula
offset.info.formula <- function(object, ...){
.Deprecated()
nw <- ergm.getnetwork(object)
m<-ergm_model(object, nw, ...)
with(m$etamap, list(term=offset, theta=offsettheta,eta=offsetmap))
}
17 changes: 17 additions & 0 deletions man/ergm-defunct.Rd

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

28 changes: 1 addition & 27 deletions man/ergm-deprecated.Rd

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

25 changes: 0 additions & 25 deletions src/changestats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2036,31 +2036,6 @@ C_CHANGESTAT_FN(c_hamming) {

}

/*****************
changestat: d_hammingmix
*****************/
C_CHANGESTAT_FN(c_hammingmix) {

Edge nhedge = INPUT_PARAM[0];
/* Rprintf("nstats %d nhedge %d i0 %f i1 %f i2 %f i3 %f\n",nstats, nhedge, INPUT_PARAM[0],
INPUT_PARAM[1],
INPUT_PARAM[2],
INPUT_PARAM[3]
); */


/* *** don't forget tail -> head */
int matchvaltail = INPUT_PARAM[tail+2*N_CHANGE_STATS+2*nhedge];
int matchvalhead = INPUT_PARAM[head+2*N_CHANGE_STATS+2*nhedge];
unsigned int discord = XOR(dEdgeListSearch(tail, head, INPUT_PARAM), edgestate);
for (unsigned int j=0; j<N_CHANGE_STATS; j++){
if(matchvaltail==INPUT_PARAM[2*nhedge+1+j] &&
matchvalhead==INPUT_PARAM[2*nhedge+1+N_CHANGE_STATS+j]){
CHANGE_STAT[j] += (discord ? -1.0 : 1.0);
}
}
}

/******************** changestats: I ***********/

// A macro indicating whether x is in [from,to)
Expand Down

0 comments on commit 6351c44

Please sign in to comment.