R Under development (unstable) (2025-06-14 r88315 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # File tests/degree.mean.age.R in package tergm, part of the Statnet suite of > # packages for network analysis, https://statnet.org . > # > # This software is distributed under the GPL-3 license. It is free, open > # source, and has the attribution requirements (GPL Section 7) at > # https://statnet.org/attribution . > # > # Copyright 2008-2025 Statnet Commons > ################################################################################ > library(statnet.common) Attaching package: 'statnet.common' The following objects are masked from 'package:base': attr, order, replace > #opttest({ > library(tergm) Loading required package: ergm Loading required package: network 'network' 1.19.0 (2024-12-08), part of the Statnet Project * 'news(package="network")' for changes since last version * 'citation("network")' for citation information * 'https://statnet.org' for help, support, and other information 'ergm' 4.9.0 (2025-06-09), part of the Statnet Project * 'news(package="ergm")' for changes since last version * 'citation("ergm")' for citation information * 'https://statnet.org' for help, support, and other information 'ergm' 4 is a major update that introduces some backwards-incompatible changes. Please type 'news(package="ergm")' for a list of major changes. Attaching package: 'ergm' The following object is masked from 'package:statnet.common': snctrl Loading required package: networkDynamic 'networkDynamic' 0.11.5 (2024-11-21), part of the Statnet Project * 'news(package="networkDynamic")' for changes since last version * 'citation("networkDynamic")' for citation information * 'https://statnet.org' for help, support, and other information Registered S3 method overwritten by 'tergm': method from simulate_formula.network ergm 'tergm' 4.2.2 (2025-06-15), part of the Statnet Project * 'news(package="tergm")' for changes since last version * 'citation("tergm")' for citation information * 'https://statnet.org' for help, support, and other information Attaching package: 'tergm' The following object is masked from 'package:ergm': snctrl The following object is masked from 'package:statnet.common': snctrl > set.seed(0) > logit<-function(p)log(p/(1-p)) > > coef.form.f<-function(coef.diss,density) -log(((1+exp(coef.diss))/(density/(1-density)))-1) > > S<-300 > > n<-40 > target.stats<-edges<-40 > duration<-12 > coef.diss<-logit(1-1/duration) > > ### Undirected > > dyads<-n*(n-1)/2 > density<-edges/dyads > coef.form<-coef.form.f(coef.diss,density) > > cat("\nUndirected:\n") Undirected: > > g0<-network.initialize(n,dir=FALSE) > > g0 %v% "a" <- rep(1:2, c(1,3)/4*n) > > print(coef.form) [1] -5.398163 > print(coef.diss) [1] 2.397895 > > # Simulate from the fit. > dynsim<-simulate(g0 ~ Form(~edges) + Persist(~edges),coef=c(coef.form,coef.diss),time.burnin=S, time.slices=S,verbose=TRUE,output="stats", + monitor=~edges+mean.age + +degree.mean.age(1:3)+degrange.mean.age(1:2,3:4)+degrange.mean.age(1:2) + +degree.mean.age(1:3,"a")+degrange.mean.age(1:2,3:4,"a")+degrange.mean.age(1:2,by="a"), dynamic=TRUE, + constraints=~. + ) Returned from STERGM burnin > > dynsim.dup <- duplicated(as.data.frame(t(dynsim))) > dynsim <- dynsim[,!dynsim.dup] > > targets <- c(edges,rep(12, ncol(dynsim)-1)) > test <- approx.hotelling.diff.test(dynsim,mu0=targets) > if(test$p.value < 0.001){ + print(test) + stop("At least one statistic differs from target.") + } > > > #dynsim<-simulate(g0,formation=~edges,dissolution=~edges+edges.ageinterval(7),coef.form=coef.form,coef.diss=c(logit(0.8),logit(0.8)-logit(0.7)),time.slices=S,verbose=TRUE,statsonly=TRUE,monitor=~edges+edges.ageinterval(1:40,2:41)) > > > #print.sim.stats(dynsim,target.stats,duration) > #dynsim<-simulate(g0,formation=~edges,dissolution=~edges,coef.form=coef.form,coef.diss=coef.diss,time.slices=S,verbose=TRUE,statsonly=TRUE,monitor=~degrange(0:2,2:4,"a")) > #}, "degree mean age terms simulation") > > proc.time() user system elapsed 6.23 0.45 6.68