├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── ChangeLog ├── DESCRIPTION ├── NAMESPACE ├── R ├── access.R ├── age.at.R ├── as.networkDynamic.siena.R ├── assignment.R ├── duration.matrix.R ├── extract.R ├── get.dyads.active.R ├── import.R ├── reconcile.activity.R ├── tea_utils.R ├── utilities.R ├── vertexpid.R ├── when.R └── zzz.R ├── README.md ├── data ├── McFarland_cls33_10_16_96.rda ├── nd_test_nets.rda ├── newcomb.RData ├── windsurferPanels.rda └── windsurfers.rda ├── inst ├── doc │ └── networkDynamic.pdf └── extdata │ ├── alphaIdTest.son │ ├── cls33_10_16_96.son │ ├── cls33_10_16_96_edges.tsv │ ├── cls33_10_16_96_vertices.tsv │ └── extraVarTest.son ├── man ├── Newcomb.Rd ├── activate.Rd ├── activity.attribute.Rd ├── add.active.Rd ├── add.methods.networkDynamic.Rd ├── adjust.activity.Rd ├── age.at.Rd ├── as.data.frame.networkDynamic.Rd ├── as.network.networkDynamic.Rd ├── as.networkDynamic.Rd ├── classrooms.Rd ├── delete.activity.Rd ├── duration.matrix.Rd ├── get.dyads.active.Rd ├── get.networks.Rd ├── get.timing.info.Rd ├── is.active.Rd ├── nd_test_nets.Rd ├── net.obs.period.Rd ├── network.collapse.Rd ├── network.dynamic.check.Rd ├── network.extensions.Rd ├── network.extract.Rd ├── networkDynamic-internal.Rd ├── networkDynamic-package.Rd ├── networkDynamic.Rd ├── persistent_ids.Rd ├── print.networkDynamic.Rd ├── read.son.Rd ├── reconcile.activity.Rd ├── spell_comparisons.Rd ├── tea_functions.Rd ├── when.attrs.match.Rd └── windsurfers.Rd ├── nonsource ├── README ├── build_to_Rlib ├── docs.und.specifications │ ├── implementation_draft_specs.txt │ ├── network.dynamic.txt │ └── temporally.extended.attributes.txt ├── networkDynamic.TODO.txt ├── relatedCode │ ├── UsefulCodeSnips │ ├── mcfarlandDataFormat.R │ ├── networkTets.R │ ├── speedTests.R │ ├── tea_rprof │ ├── tea_timings.pdf │ ├── test_network_generator.R │ ├── transExample.R │ └── windsurfer.R ├── simSpeedTesting.R └── update_DESCRIPTION ├── src ├── Rinit.c ├── diagnostics.c ├── diagnostics.h ├── edgetree.c ├── edgetree.h ├── infection.c ├── infection.h ├── is.active.c ├── is.active.h ├── spellfunctions.h ├── wtedgetree.c └── wtedgetree.h ├── tests ├── activate_tests.R ├── age.at_tests.R ├── classTests.R ├── converter_tests.R ├── get_tests.R ├── import_tests.R ├── network_tests.R ├── pid_tests.R ├── query_tests.R ├── reconcile.activityTests.R ├── tea_tests.R ├── utils_tests.R └── when_tests.R └── vignettes ├── networkDynamic.Rnw └── networkDynamic.pdf /.Rbuildignore: -------------------------------------------------------------------------------- 1 | nonsource 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | .travis.yml 5 | .RSession 6 | appveyor.yml 7 | ^CRAN-RELEASE$ 8 | ^cran-comments\.md$ 9 | ^CODE_OF_CONDUCT\.md$ 10 | ^\.github$ 11 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | .RSession 8 | 9 | # Example code in package build process 10 | *-Ex.R 11 | 12 | # Output files from R CMD build 13 | /*.tar.gz 14 | 15 | # Output files from R CMD check 16 | /*.Rcheck/ 17 | 18 | # RStudio files 19 | .Rproj.user/ 20 | *.Rproj 21 | 22 | # produced vignettes 23 | vignettes/*.html 24 | vignettes/*.pdf 25 | 26 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 27 | .httr-oauth 28 | 29 | # knitr and R markdown default cache directories 30 | /*_cache/ 31 | /cache/ 32 | 33 | # Temporary files created by R markdown 34 | *.utf8.md 35 | *.knit.md 36 | # Prerequisites 37 | *.d 38 | 39 | # Object files 40 | *.o 41 | *.ko 42 | *.obj 43 | *.elf 44 | 45 | # Linker output 46 | *.ilk 47 | *.map 48 | *.exp 49 | 50 | # Precompiled Headers 51 | *.gch 52 | *.pch 53 | 54 | # Libraries 55 | *.lib 56 | *.a 57 | *.la 58 | *.lo 59 | 60 | # Shared objects (inc. Windows DLLs) 61 | *.dll 62 | *.so 63 | *.so.* 64 | *.dylib 65 | 66 | # Executables 67 | *.exe 68 | *.out 69 | *.app 70 | *.i*86 71 | *.x86_64 72 | *.hex 73 | 74 | # Debug files 75 | *.dSYM/ 76 | *.su 77 | *.idb 78 | *.pdb 79 | 80 | # Kernel Module Compile Results 81 | *.mod* 82 | *.cmd 83 | modules.order 84 | Module.symvers 85 | Mkfile.old 86 | dkms.conf 87 | 88 | # Backup files 89 | *~ 90 | *.bak 91 | .Rproj.user 92 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at contact@statnet.org. 63 | All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.1, available at 118 | . 119 | 120 | Community Impact Guidelines were inspired by 121 | [Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. 122 | 123 | For answers to common questions about this code of conduct, see the FAQ at 124 | . Translations are available at . 125 | 126 | [homepage]: https://www.contributor-covenant.org 127 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: networkDynamic 2 | Version: 0.11.5 3 | Date: 2024-11-21 4 | Title: Dynamic Extensions for Network Objects 5 | Type: Package 6 | Depends: R (>= 3.0.0), network (>= 1.17.0) 7 | Imports: statnet.common, methods, networkLite 8 | Suggests: testthat 9 | LinkingTo: network 10 | Authors@R: c( 11 | person("Carter T.", "Butts", role=c("aut"), email="buttsc@uci.edu"), 12 | person("Ayn", "Leslie-Cook", role=c("aut"), email="aynlc3@uw.edu"), 13 | person("Pavel N.", "Krivitsky", role=c("aut"), email="pavel@uow.edu.au"), 14 | person("Skye", "Bender-deMoll", role=c("aut","cre"), email="skyebend@uw.edu"), 15 | person("Zack", "Almquist", role=c("ctb"), email="almquist@uci.edu"), 16 | person("David R.", "Hunter", role=c("ctb"), email="dhunter@stat.psu.edu"), 17 | person("Li","Wang",role=c("ctb"),email="lxwang@gmail.com"), 18 | person("Kirk","Li",role=c("ctb"),email="kirkli@uw.edu"), 19 | person("Steven M.","Goodreau",role=c("ctb"),email="goodreau@uw.edu"), 20 | person("Jeffrey", "Horner", role=c("ctb"), email="jeffrey.horner@gmail.com"), 21 | person("Martina", "Morris", role=c("ctb"), email="morrism@u.washington.edu")) 22 | Description: Simple interface routines to facilitate the handling of network objects with complex intertemporal data. This is a part of the "statnet" suite of packages for network analysis. 23 | License: GPL-3 24 | LazyLoad: yes 25 | URL: https://statnet.org/ 26 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(networkDynamic, .registration = TRUE) 2 | 3 | import(statnet.common, network, networkLite) 4 | importFrom("methods", "el") 5 | importFrom("methods", "is") 6 | importFrom("stats", "na.omit") 7 | importFrom("utils", "read.table", "tail") 8 | 9 | export( 10 | networkDynamic, 11 | print.networkDynamic, 12 | as.data.frame.networkDynamic, 13 | is.networkDynamic, 14 | as.networkDynamic, 15 | as.network.networkDynamic, 16 | as.networkDynamic.networkDynamic, 17 | as.networkDynamic.network, 18 | read.son, 19 | "%t%", 20 | network.extract, 21 | "%k%", 22 | network.collapse, 23 | get.networks, 24 | network.dynamic.check, 25 | activate.edges, 26 | activate.vertices, 27 | add.edges.active, 28 | add.vertices.active, 29 | deactivate.edges, 30 | deactivate.vertices, 31 | delete.edge.activity, 32 | delete.vertex.activity, 33 | get.change.times, 34 | get.edgeIDs.active, 35 | get.edges.active, 36 | get.neighborhood.active, 37 | get.edge.activity, 38 | get.vertex.activity, 39 | is.active, 40 | is.adjacent.active, 41 | network.dyadcount.active, 42 | network.edgecount.active, 43 | network.naedgecount.active, 44 | network.size.active, 45 | activate.network.attribute, 46 | get.network.attribute.active, 47 | activate.vertex.attribute, 48 | get.vertex.attribute.active, 49 | activate.edge.attribute, 50 | activate.edge.value, 51 | get.edge.attribute.active, 52 | deactivate.edge.attribute, 53 | deactivate.vertex.attribute, 54 | deactivate.network.attribute, 55 | list.vertex.attributes.active, 56 | list.edge.attributes.active, 57 | list.network.attributes.active, 58 | get.edge.value.active, 59 | spells.overlap, 60 | spells.hit, 61 | search.spell, 62 | get.vertex.id, 63 | vertex.pid.check, 64 | get.vertex.pid, 65 | initialize.pids, 66 | get.edge.id, 67 | get.edge.pid, 68 | edge.pid.check, 69 | add.vertices.networkDynamic, 70 | add.edges.networkDynamic, 71 | add.edge.networkDynamic, 72 | reconcile.vertex.activity, 73 | reconcile.edge.activity, 74 | adjust.activity, 75 | get.dyads.active, 76 | when.vertex.attrs.match, 77 | when.edge.attrs.match, 78 | edges.age.at, 79 | dyads.age.at, 80 | vertices.age.at 81 | #when.next.edge.change 82 | ) 83 | 84 | # register S3 methods 85 | S3method(add.edge,networkDynamic) 86 | S3method(add.edges,networkDynamic) 87 | S3method(add.vertices,networkDynamic) 88 | S3method(as.data.frame,networkDynamic) 89 | S3method(as.network,networkDynamic) 90 | S3method(as.networkDynamic,network) 91 | S3method(as.networkDynamic,networkDynamic) 92 | S3method(print,networkDynamic) 93 | S3method(as.networkDynamic,networkLite) 94 | S3method(as.networkDynamic,siena) 95 | 96 | # these are NOT S3 methods, but are included here because its the 97 | # only way to quiet the warning 98 | S3method(add.edges,active) 99 | S3method(add.vertices,active) 100 | S3method(network.dyadcount,active) 101 | S3method(network.edgecount,active) 102 | S3method(network.naedgecount,active) 103 | S3method(network.size,active) 104 | S3method(get.vertex.attribute,active) 105 | S3method(list.vertex.attributes,active) 106 | S3method(get.edge.attribute,active) 107 | S3method(get.edge.value,active) 108 | S3method(list.edge.attributes,active) 109 | S3method(get.network.attribute,active) 110 | S3method(list.network.attributes,active) 111 | -------------------------------------------------------------------------------- /R/age.at.R: -------------------------------------------------------------------------------- 1 | # functions to return the duration of edge and vertex activity with respect to a query time point 2 | 3 | 4 | # return the ages of edges activity spell intersecting with at 5 | edges.age.at <-function(nD,at,e=seq_along(nD$mel),active.default=TRUE){ 6 | if (length(nD$mel) > 0) { 7 | if ((min(e) < 1) || (max(e) > nD%n% "mnext" - 1)) { 8 | stop("Illegal edge id in edge.age.at.\n") 9 | } 10 | } 11 | ages<-rep(NA,length(e)) 12 | # find which e are non-deleted edges 13 | ePresent<-!sapply(nD$mel[e],is.null) 14 | # restrict to only those present edges that will be active 15 | ePresent[ePresent]<-is.active(nD,e=e[ePresent],at=at,active.default=active.default) 16 | # get the spell matrices for those e that are present and active 17 | activity<-get.edge.activity(nD,e=e[ePresent],active.default=active.default) 18 | # update age coresponding edges present and active 19 | ages[ePresent]<-sapply(activity,function(spls){ 20 | index<-spells.hit(c(at,at),spls) # get the index of matching spell 21 | return(at-spls[index,1]) # return difference between 'at' query and onset of matching spell 22 | }) 23 | return(ages) 24 | } 25 | 26 | # return the ages of activity spell of edges specified by edge id dyads 27 | dyads.age.at <-function(nD,at,tails,heads,active.default=TRUE,format.out=c('vector','edgelist','matrix')){ 28 | if(is.hyper(nD)){ 29 | stop('dyad.age.at does not support hypergrahic networks') 30 | } 31 | if(is.multiplex(nD)){ 32 | stop('dyad.age.at does not support multiplex networks because vertex id dyads may not uniquely specify edges') 33 | } 34 | 35 | format.out<-match.arg(format.out) 36 | 37 | # if heads and tails both missing, assume dyads wanted for all existing edges (existing at any time point) 38 | if(missing(tails) & missing(heads)){ 39 | dyads<-as.matrix.network.edgelist(nD,) 40 | tails<-dyads[,1] 41 | heads<-dyads[,2] 42 | } else { 43 | if (length(tails)!=length(heads)){ 44 | stop('vectors of vertices for heads and tails of edges must be the same length') 45 | } 46 | 47 | } 48 | 49 | 50 | ages<-rep(NA,length(tails)) 51 | # find the set of edges corresponding to elements in tail and head 52 | e<-lapply(seq_along(tails),function(i){ 53 | get.edgeIDs.active(nD,v=tails[i],alter=heads[i],at=at,active.default = active.default) 54 | }) 55 | ePresent<-sapply(e,length)>0 56 | #if there is at least one active edge.. 57 | if(sum(ePresent)>0){ 58 | activity<-get.edge.activity(nD,e=unlist(e[ePresent]),active.default=active.default) 59 | # update age coresponding edges present and active 60 | ages[ePresent]<-sapply(activity,function(spls){ 61 | index<-spells.hit(c(at,at),spls) # get the index of matching spell 62 | return(at-spls[index,1]) # return difference between 'at' query and onset of matching spell 63 | }) 64 | } 65 | if(format.out=='edgelist'){ 66 | out<-cbind(tails,heads,ages) #todo: should we force tail head ordering for undirected nets? 67 | } else if(format.out=='matrix'){ 68 | out<-matrix(NA,nrow=network.size(nD),ncol=network.size(nD)) 69 | 70 | #I'm not sure why this is the inexing form but, out[tails,heads] doesn't work 71 | out[tails+(heads-1)*network.size(nD)]<-ages 72 | # if it is undirected, also set the other dimension 73 | if(!is.directed(nD)){ 74 | out[heads+(tails-1)*network.size(nD)]<-ages 75 | } 76 | 77 | } else { # return as a vector 78 | out<-ages 79 | } 80 | 81 | return(out) 82 | 83 | 84 | } 85 | 86 | 87 | 88 | vertices.age.at <-function(nD,at,v=seq_len(network.size(nD)),active.default=TRUE){ 89 | ages<-rep(NA,length(v)) 90 | vActive<-is.active(nD,v=v,at=at,active.default=active.default) 91 | activity<-get.vertex.activity(nD,v=v[vActive],active.default=active.default) 92 | # update age coresponding to vertices active 93 | ages[vActive]<-sapply(activity,function(spls){ 94 | index<-spells.hit(c(at,at),spls) # get the index of matching spell 95 | return(at-spls[index,1]) # return difference between 'at' query and onset of matching spell 96 | }) 97 | return(ages) 98 | } -------------------------------------------------------------------------------- /R/as.networkDynamic.siena.R: -------------------------------------------------------------------------------- 1 | 2 | # nodeSets: List of node sets involved 3 | # observations: Integer indicating number of waves of data 4 | # depvars: List of networks and behavior variables 5 | # cCovars: List of constant covariates associated with nodeSets, should be mapped to static vertex attributes 6 | # vCovars: List of changing covariates associated with nodeSets, should be mapped to TEA attributes 7 | # dycCovars: List of constant dyadic covariates, should be mapped to static edge attributes 8 | # dyvCovars: List of changing dyadic covariates, should be mapped to dynamic edge attributes 9 | # compositionChange: List of composition change objects corresponding to the node sets These are lists of intervals and should be mapped to vertex activity 10 | 11 | 12 | as.networkDynamic.siena<-function(object, verbose=FALSE,...){ 13 | 14 | if(!'siena'%in%class(object)){ 15 | stop("as.networkDynamic.siena can only be applied to objects of class 'siena' as produced by RSiena::sienaDataCreate") 16 | } 17 | sienaData<-object 18 | waves<-list() # will be a list of networks for the time points 19 | behaviorVars<-list() # will be list of behavior variables 20 | 21 | for (edgeType in names(sienaData$depvars)){ 22 | # need to change parsing behavior depending on how it is coded in the depvar 23 | if(attributes(sienaData$depvars[[edgeType]])$type=='oneMode'){ 24 | # this is the edge data 25 | # expect that the matrices are listed by (row, col, wave] 26 | waves<-lapply(1:sienaData$observations,function(t){ 27 | #TODO: should be more efficient do to this via edgelist .. 28 | arraymat<-sienaData$depvars[[edgeType]][,,t,drop=FALSE] 29 | # need to convert the array into a matrix 30 | # TODO: double check if it is by row 31 | mat<-matrix(sienaData$depvars[[edgeType]][,,t,drop=FALSE],nrow=dim(arraymat)[1],ncol=dim(arraymat)[2],byrow = TRUE) 32 | as.network.matrix(mat,matrix.type='adjacency') 33 | }) 34 | } else if(attributes(sienaData$depvars[[edgeType]])$type=='behavior'){ 35 | # this is dynamic vertex data 36 | behaviorVars[[edgeType]]<-lapply(1:sienaData$observations,function(t){ 37 | sienaData$depvars[[edgeType]][,1,t] 38 | }) 39 | } else { 40 | warning( 'processing depvar type ',attributes(sienaData$depvars[[edgeType]])$type, ' not yet implemented and was skipped') 41 | } 42 | } 43 | 44 | # activate any of the behavior vars onto the static networks 45 | # they will be converted to dynamic later 46 | if(length(behaviorVars)>0){ 47 | for(var in names(behaviorVars)){ 48 | for(t in 1:sienaData$observations){ 49 | set.vertex.attribute(waves[[t]],var,behaviorVars[[var]][[t]]) 50 | } 51 | } 52 | } 53 | 54 | # convert the list of networks 55 | dyn<-networkDynamic(network.list=waves,create.TEAs = TRUE) 56 | 57 | 58 | # TODO: it is called nodesets, so probably there can be more than one? need example and produce in loop 59 | if(length(sienaData$nodeSets)>1){ 60 | stop('multiple nodeSets found in siena data object, not sure how to process') 61 | } else { 62 | set.vertex.attribute(dyn,names(sienaData$nodeSets)[1],as.vector(sienaData$nodeSets[[1]])) 63 | if (verbose) message('mapped nodeSet ',names(sienaData$nodeSets)[1], ' as vertex attribute') 64 | } 65 | 66 | # apply the compositionChange (vertex dynamics) 67 | # I don't see an example of a compositionChange object with more than one spell per vertex 68 | # so I'm not clear how these are represented and should be interpreted 69 | if(length(sienaData$compositionChange)>0){ 70 | # if any of the vectors are longer than 2, I don't know how to interpret them 71 | if(any(sapply(sienaData$compositionChange$composition,length)!=2)){ 72 | stop('unsure how to process composition change vectors with more than two elements') 73 | } 74 | # have to remove existing vertex activity 75 | delete.vertex.activity(dyn) 76 | # because the mapping is from a semi-discrete time units with right-closed intervals 77 | # we will subtract one unit from the onset 78 | spells<-do.call('rbind',sienaData$compositionChange$composition) 79 | spells[,1]<-spells[,1]-1 80 | activate.vertices(dyn,onset=spells[,1],terminus=spells[,2]) 81 | if(verbose) message('mapped compositionChange to vertex activity ') 82 | } 83 | 84 | # copy constant vertex covariates 85 | if(length(sienaData$cCovars)>0){ 86 | for(covar in names(sienaData$cCovars)){ 87 | #TODO: these need to be matched to associated nodeSet? 88 | # need to reconstruct these as they have been recentered, add the mean back in 89 | values<-as.vector(sienaData$cCovars[[covar]]) 90 | valMean<-attr(sienaData$cCovars[[covar]],'mean') 91 | set.vertex.attribute(dyn,covar,values+valMean) 92 | if (verbose) message('mapped constant covariate ',covar, ' as vertex attribute') 93 | } 94 | } 95 | 96 | # copy constant dyadic covariates 97 | if(length(sienaData$dycCovars)>0){ 98 | for(dyadvar in names(sienaData$dycCovars)){ 99 | #TODO: these need to be matched to associated nodeSet? 100 | set.edge.value(dyn,dyadvar,as.vector(sienaData$dycCovars[[dyadvar]])) 101 | if (verbose) message('mapped constant covariate ',dyadvar, ' as edge attribute') 102 | } 103 | message('NOTE: dyadic covariates that do not correspond to existing edges are not copied') 104 | } 105 | 106 | return(dyn) 107 | } 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /R/assignment.R: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # 3 | # File networkDynamic/R/assignment.R 4 | # Part of the statnet package, http://statnetproject.org 5 | # 6 | # This software is distributed under the GPL-3 license. It is free, 7 | # open source, and has the attribution requirements (GPL Section 7) in 8 | # http://statnetproject.org/attribution 9 | # 10 | # Copyright 2012 the statnet development team 11 | ###################################################################### 12 | # 13 | # This file contains various routines for the assignment of network objects 14 | # into calling environments. These are internal functions and not to be used 15 | # by the package users. 16 | # 17 | # Contents: 18 | # 19 | # .findNameInSubsetExpr 20 | # .validLHS 21 | # 22 | ###################################################################### 23 | 24 | 25 | # Recursively traverse the parse tree of the expression x, ensuring that it is 26 | # a valid subset expresssion, and return the name associated with the expression. 27 | # 28 | .findNameInSubsetExpr <- function(x){ 29 | if (is(x,'call')){ 30 | # Ensure call is a subset function, one of $, [, or [[ 31 | if(!(deparse(x[[1]]) %in% c('$','[','[['))) return(NA) 32 | 33 | # Make sure arguments are clean 34 | xns <- lapply(x[2:length(x)],.findNameInSubsetExpr) 35 | if (any(is.na(xns))) return(NA) 36 | 37 | # Possible name found 38 | return(xns[[1]]) 39 | } 40 | else if (is(x,'name')) 41 | return(deparse(x)) 42 | 43 | NULL 44 | } 45 | 46 | # Return TRUE if x is a valid left-hand-side object that can take a value 47 | 48 | .validLHS <- function(x,ev){ 49 | xn <- .findNameInSubsetExpr(x) 50 | # There are valid expressions for which we don't want to assign into the caller's env. 51 | # For instance, when a user executes z<-add.edges(x+y), then the user obviously 52 | # doesn't want x+y to be assigned. Rather he's using them as temporaries to obtain 53 | # z. OTOH we don't want someone doing something obtuse like add.edges(x[sample(...)]) 54 | # In the first case, it's not wrong to end up here, but in the second case we would 55 | # like to warn the user. But we're not going to at this point. 56 | #warning('Cannot make assignment into ',deparse(x)) 57 | if (!is.null(xn) && !is.na(xn) && exists(xn,envir=ev)) 58 | return(TRUE) 59 | else 60 | return(FALSE) 61 | } 62 | -------------------------------------------------------------------------------- /R/duration.matrix.R: -------------------------------------------------------------------------------- 1 | # File networkDynamic/R/duration.matrix.R 2 | # Part of the statnet package, http://statnetproject.org 3 | # 4 | # This software is distributed under the GPL-3 license. It is free, 5 | # open source, and has the attribution requirements (GPL Section 7) in 6 | # http://statnetproject.org/attribution 7 | # 8 | # Copyright 2012 the statnet development team 9 | ###################################################################### 10 | 11 | # turns a network and toggle list into a list of edge spells 12 | # usage 13 | 14 | # nw0: network object, with vertices and edges specified 15 | # changes: toggle list of the form 16 | # time(integer) tail(vertex.id) head(vertex.id) 17 | # start: start time of the network (integer) 18 | # end: end time of the network (integer) 19 | # returns a data.frame of the format: 20 | # c("start", "end", "tail", "head", "left.censored", "right.censored", "duration") 21 | 22 | duration.matrix <- function(nw0, changes, start, end) { 23 | if (!("network" %in% class(nw0))) stop("nw0 must be a network object") 24 | if (ncol(changes) < 3) stop("changes must provide a list of toggle time, tail, and head") 25 | edges <- as.edgelist(nw0) 26 | if(!is.directed(nw0)){ 27 | # The following shouldn't be necessary, but just to be safe: 28 | changes[,2:3] <- cbind(pmin(changes[,2,drop=FALSE],changes[,3,drop=FALSE]),pmax(changes[,2,drop=FALSE],changes[,3,drop=FALSE])) 29 | } 30 | 31 | allties <- .C("DurationMatrix", as.integer(network.size(nw0)), 32 | as.integer(nrow(edges)), 33 | as.integer(edges), 34 | as.integer(start), as.integer(end), 35 | as.integer(nrow(changes)), as.integer(as.matrix(changes)), 36 | duration = as.integer(rep(0,6*(nrow(edges)+nrow(changes)))), 37 | PACKAGE = "networkDynamic")$duration 38 | allties <- as.data.frame(matrix(allties, ncol=6)) 39 | names(allties) <- c("start", "end", "tail", "head", "left.censored", "right.censored") 40 | allties <- allties[allties[,3]!=0,] # Get rid of unused rows 41 | allties$left.censored <- as.logical(allties$left.censored) 42 | allties$right.censored <- as.logical(allties$right.censored) 43 | allties$duration <- with(allties, end-start) 44 | allties 45 | } 46 | -------------------------------------------------------------------------------- /R/get.dyads.active.R: -------------------------------------------------------------------------------- 1 | # File networkDynamic/R/extract.R 2 | # Part of the statnet package, http://statnetproject.org 3 | # 4 | # This software is distributed under the GPL-3 license. It is free, 5 | # open source, and has the attribution requirements (GPL Section 7) in 6 | # http://statnetproject.org/attribution 7 | # 8 | # Copyright 2012,2013 the statnet development team 9 | ###################################################################### 10 | 11 | # function to return the set of vertex dyads corresponding to active edges in a network 12 | get.dyads.active<-function(nD, onset = NULL, terminus = NULL, length = NULL, at = NULL, rule = c("any", "all","earliest","latest"), active.default = TRUE){ 13 | 14 | if(is.hyper(nD)){ 15 | stop("get.dyads.active does not currently support hypergraphic networks") 16 | } 17 | rule<-match.arg(rule) 18 | goodIds<-valid.eids(nD) 19 | activeEids<-goodIds[is.active(nD,onset=onset,terminus=terminus,length=length,at=at,rule=rule,active.default=active.default,e=goodIds)] 20 | return(cbind(sapply(nD$mel[activeEids],'[[','outl'),sapply(nD$mel[activeEids],'[[','inl'))) 21 | } 22 | 23 | 24 | #dyadVersion<-function(nw,at){ 25 | # return(get.dyads.active(nw,at=at)) 26 | #} 27 | 28 | #dfVersion<-function(nw,at){ 29 | # df<-as.data.frame(nw) 30 | # active<-(df$onset <= at) & (df$terminus >= at) 31 | # return(cbind(df$tail[active],df$head[active])) 32 | #} 33 | 34 | #times<-microbenchmark(dyadVersion(nw,1),dfVersion(nw,1),times=1000) -------------------------------------------------------------------------------- /R/when.R: -------------------------------------------------------------------------------- 1 | # functions for determining when network elements take specific values 2 | 3 | 4 | # internal function to determine the first / earliest time point at which a tea attribute matches using the specified operation 5 | whenMatchEarliest<-function(tea,value,match.op='==',no.match=Inf){ 6 | sapply(tea,function(val){ 7 | if (length(val)==1 && is.na(val) | is.null(val)){ 8 | return(NA) 9 | } else { 10 | #value list 11 | comparisons<-sapply(val[[1]],match.op,value) 12 | if(!is.logical(comparisons)){ 13 | stop("the comparison function provided by the 'match.op' argument must provide Logical results for every attribute value") 14 | } 15 | matches<-which(comparisons) 16 | if(length(matches)<1){ 17 | return(no.match) 18 | } 19 | return(val[[2]][min(matches),1]) 20 | } 21 | }) 22 | } 23 | 24 | # internal function to determine the last / latest time point at which a tea attribute matches using the specified operation 25 | whenMatchLatest<-function(tea,value,match.op='==',no.match=Inf){ 26 | sapply(tea,function(val){ 27 | if (length(val)==1 && is.na(val) | is.null(val)){ 28 | return(NA) 29 | } else { 30 | #value list 31 | comparisons<-sapply(val[[1]],match.op,value) 32 | if(!is.logical(comparisons)){ 33 | stop("the comparison function provided by the 'match.op' argument must provide Logical results for every attribute value") 34 | } 35 | matches<-which(comparisons) 36 | if(length(matches)<1){ 37 | return(no.match) 38 | } 39 | return(val[[2]][max(matches),2]) 40 | } 41 | }) 42 | } 43 | 44 | # function to determine when a TEA vertex attribute takes on a specific value 45 | 46 | when.vertex.attrs.match<-function(nd,attrname,value,match.op='==',rule='earliest',no.match=Inf,v=seq_len(network.size(nd))){ 47 | if(missing(nd) || !is.networkDynamic(nd)){ 48 | stop('when.vertex.attrs.match requires its first argument to be a networkDynamic object') 49 | } 50 | if(missing(value)){ 51 | stop("when.vertex.attrs.match requires providing a 'value' argument for comparison") 52 | } 53 | if(missing(attrname)){ 54 | stop("when.vertex.attrs.match requires providing an 'attrname' argument giving the name of the vertex attribute to be compared") 55 | } 56 | 57 | # search for the .active version of the name 58 | searchAttr<-paste(attrname,"active",sep='.') 59 | tea<-get.vertex.attribute(nd,searchAttr,unlist=FALSE)[v] 60 | # use different method depending on rule 61 | if (rule=='earliest'){ 62 | return(whenMatchEarliest(tea=tea,value=value,match.op=match.op,no.match=no.match)) 63 | } else if (rule=='latest'){ 64 | return(whenMatchLatest(tea=tea,value=value,match.op=match.op,no.match=no.match)) 65 | } else { 66 | stop("no matching methods implemented for rule '",rule,"'") 67 | } 68 | 69 | } 70 | 71 | 72 | # function to determine when a TEA edge attribute takes on a specific value 73 | 74 | when.edge.attrs.match<-function(nd,attrname,value,match.op='==',rule='earliest',no.match=Inf,e=seq_along(nd$mel)){ 75 | if(missing(nd) || !is.networkDynamic(nd)){ 76 | stop('when.vedge.attrs.match requires its first argument to be a networkDynamic object') 77 | } 78 | if(missing(value)){ 79 | stop("when.edge.attrs.match requires providing a 'value' argument for comparison") 80 | } 81 | if(missing(attrname)){ 82 | stop("when.edge.attrs.match requires providing an 'attrname' argument giving the name of the edge attribute to be compared") 83 | } 84 | 85 | # search for the .active version of the name 86 | searchAttr<-paste(attrname,"active",sep='.') 87 | tea<-get.edge.attribute(nd,searchAttr,unlist=FALSE)[e] 88 | # use different method depending on rule 89 | if (rule=='earliest'){ 90 | return(whenMatchEarliest(tea=tea,value=value,match.op=match.op,no.match=no.match)) 91 | } else if (rule=='latest'){ 92 | return(whenMatchLatest(tea=tea,value=value,match.op=match.op,no.match=no.match)) 93 | } else { 94 | stop("no matching methods implemented for rule '",rule,"'") 95 | } 96 | } 97 | 98 | 99 | # function to find the next time at which an edge involving the specified subset of vertices is activated or deactivated 100 | when.next.edge.change<-function(nd,at, v=seq_len(network.size(nd)),neighborhood = c("out", "in", "combined")){ 101 | # find ids of the set of edges we need to check 102 | eids<-unique(unlist(sapply(v,function(v){ 103 | get.edgeIDs(nd,v=v,neighborhood=neighborhood) 104 | }))) 105 | # find which ones are currently active 106 | nextTimes<-sapply(eids,function(e){ 107 | # if no activitey return inf 108 | spls<-nd$mel[[e]]$atl$active 109 | if (is.null(spls)){ 110 | return(Inf) 111 | } 112 | splIndex<-spells.hit(needle=c(at,Inf),haystack=spls) 113 | if (splIndex<0){ 114 | return(Inf) 115 | } 116 | # if the spell is active, return its terminus 117 | if(spls[splIndex,1]<=at){ 118 | return(spls[splIndex,2]) 119 | } else { 120 | # otherwise return its onset 121 | return(spls[splIndex,1]) 122 | } 123 | }) 124 | return(min(nextTimes)) 125 | } -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | # File networkDynamic/R/zzz.R 2 | # Part of the statnet package, http://statnetproject.org 3 | # 4 | # This software is distributed under the GPL-3 license. It is free, 5 | # open source, and has the attribution requirements (GPL Section 7) in 6 | # http://statnetproject.org/attribution 7 | # 8 | # Copyright 2012 the statnet development team 9 | ###################################################################### 10 | # .onLoad is run when the package is loaded with library(networkDynamic) 11 | # 12 | ###################################################################### 13 | 14 | .onAttach<- function(lib, pkg){ 15 | sm <- statnetStartupMessage("networkDynamic",c('statnet'),TRUE) 16 | if(!is.null(sm)) packageStartupMessage(sm) 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `networkDynamic`: Dynamic Extensions for Network Objects 2 | 3 | [![R build status](https://github.com/statnet/networkDynamic/workflows/R-CMD-check/badge.svg)](https://github.com/statnet/networkDynamic/actions) 4 | 5 | [![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/networkDynamic?color=2ED968)](https://cranlogs.r-pkg.org/) 6 | [![cran version](https://www.r-pkg.org/badges/version/networkDynamic)](https://cran.r-project.org/package=networkDynamic) 7 | 8 | `networkDynamic` is a network data management package that provides tools to import, transform and extract relational data with timing information from various data structures (matrices, spell lists, toggles, etc). The software manages temporal information for both vertices and edges, including presence/absence (which allows for changes in network size) and discrete or continuous attributes. Both directed and undirected networks are supported. 9 | 10 | This package is a part of the [Statnet](https://statnet.org) suite of packages for network analysis, so it is designed to work seamlessly with all of the packages in that suite. `networkDynamic` extends the capability of Statnet's `network` package to handle temporal information, and it is the data management foundation used by the higher level packages: 11 | * [`tsna`](https://github.com/statnet/tsna) Exploratory data analysis and summary statistics for temporal networks 12 | * [`ndtv`](https://github.com/statnet/ndtv) Temporal network graphics and animation 13 | * [`tergm`](https://github.com/statnet/tergm) Statistical analysis and simulation of temporal networks with TERGMs 14 | * [`ergmgp`](https://github.com/statnet/ergmgp) Modeling continuous time graph processes with ERGM equilibria 15 | * [`EpiModel`](https://www.epimodel.org/) Epidemic modeling on dynamic networks 16 | 17 | ## Docs and Examples 18 | 19 | `networkDynamic` [package vignette](https://CRAN.R-project.org/package=networkDynamic/vignettes/networkDynamic.pdf) [reference manual](https://CRAN.R-project.org/package=networkDynamic/networkDynamic.pdf) 20 | 21 | Tutorials on using `networkDynamic` in data analysis workflows include the Statnet workshops [Temporal network tools in statnet: networkDynamic, ndtv and tsna](https://statnet.org/workshop-ndtv/ndtv_workshop.html) [Temporal Exponential Random Graph Models (TERGMs) for dynamic networks](https://statnet.org/workshop-tergm/) 22 | 23 | Self-guided training materials for all of the Statnet packages can be found on the [statnet workshop page](https://statnet.org/workshops/) . For `EpiModel` please see the [EpiModel organization site](https://www.epimodel.org/) 24 | 25 | 26 | 27 | ## Citation and License 28 | 29 | This software is distributed under the GPL-3 license. It is free, open source, and has the attribution requirements (GPL Section 7) at 30 | http://statnet.org/attribution 31 | 32 | To cite the package ‘networkDynamic’ in publications use: 33 | 34 | Butts C, Leslie-Cook A, Krivitsky P, Bender-deMoll S 35 | (2023). _networkDynamic: Dynamic Extensions for Network Objects_. R package version 0.11.3, 36 | 37 | 38 | This work was supported by grant R01HD68395 from the National Institute of Health. 39 | 40 | 41 | ## Code of Conduct 42 | 43 | Please note that the `networkDynamic` project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. 44 | 45 | -------------------------------------------------------------------------------- /data/McFarland_cls33_10_16_96.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/data/McFarland_cls33_10_16_96.rda -------------------------------------------------------------------------------- /data/nd_test_nets.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/data/nd_test_nets.rda -------------------------------------------------------------------------------- /data/newcomb.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/data/newcomb.RData -------------------------------------------------------------------------------- /data/windsurferPanels.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/data/windsurferPanels.rda -------------------------------------------------------------------------------- /data/windsurfers.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/data/windsurfers.rda -------------------------------------------------------------------------------- /inst/doc/networkDynamic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/inst/doc/networkDynamic.pdf -------------------------------------------------------------------------------- /inst/extdata/alphaIdTest.son: -------------------------------------------------------------------------------- 1 | //test file for parsing alpha ids and clusters 2 | AlphaId Label StartTime 3 | 1 1 0 4 | 2 2 0 5 | three 3 0 6 | FromId ToId StartTime 7 | 1 2 0 8 | three 2 0 9 | ClusterId NodeIds StartTime 10 | A {1} 0 11 | -------------------------------------------------------------------------------- /inst/extdata/cls33_10_16_96_vertices.tsv: -------------------------------------------------------------------------------- 1 | vertex_id data_id start_minute end_minute sex role 2 | 1 122658 0 49 F grade_11 3 | 2 129047 0 49 M grade_11 4 | 3 129340 0 49 M grade_11 5 | 4 119263 0 49 M grade_12 6 | 5 122631 0 49 F grade_12 7 | 6 144843 0 49 M grade_11 8 | 7 1003 0 49 M instructor 9 | 8 113433 0 49 M grade_11 10 | 9 131642 0 49 M grade_12 11 | 10 139722 0 49 F grade_11 12 | 11 139195 0 49 F grade_12 13 | 12 133105 0 49 M grade_11 14 | 13 116749 0 49 M grade_12 15 | 14 3 0 49 M instructor 16 | 15 146757 0 49 F grade_11 17 | 16 121402 0 49 M grade_11 18 | 17 127265 0 49 F grade_11 19 | 18 121829 0 49 F grade_11 20 | 19 113140 0 49 M grade_11 21 | 20 128065 0 49 F grade_11 22 | 23 | -------------------------------------------------------------------------------- /man/Newcomb.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/Newcomb.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{Newcomb} 11 | \title{Newcomb's Fraternity Networks} 12 | \alias{Newcomb} 13 | \alias{newcomb} 14 | \alias{newcomb.rank} 15 | \alias{Newcomb.rank} 16 | \description{ 17 | These 14 networks record weekly sociometric preference rankings 18 | from 17 men attending the University of Michigan in the fall 19 | of 1956; Data were collected longitudinally over 15 weeks, 20 | although data from week 9 are missing. 21 | 22 | The men were recruited to live in off-campus (fraternity) 23 | housing, rented for them as part of the Michigan Group Study 24 | Project supervised by Theodore Newcomb from 1953 to 1956. All 25 | were incoming transfer students with no prior acquaintance of 26 | one another. 27 | 28 | The data set contains two longitudinal networks as \code{network.list}. 29 | 30 | \code{newcomb.rank} is a 31 | \code{network.list} object with 14 networks. Each network is complete and the 32 | edge value \code{rank} is the preference of the \eqn{i}th men for the \eqn{j}th 33 | man from \code{1} through \code{16}. A \code{1} indicates first 34 | preference, and no ties were allowed. 35 | 36 | \code{newcomb} is a \code{network.list} object that has binary 37 | edge values but is similar in structure to \code{newcomb.rank} 38 | and derived from it. Each network has a tie from the \eqn{i}th 39 | men to the \eqn{j}th man if \eqn{i} had a preference for 40 | \eqn{j} of 8 or less. Otherwise there is not tie from \eqn{i} 41 | to \eqn{j}. Note that since these are ranks, the degree of each vertex (and the total number of edges) does not vary over time 42 | } 43 | \usage{data(newcomb)} 44 | \source{\url{https://github.com/bavla/Nets/tree/master/data/Pajek/ucinet#-newcomb-fraternity}} 45 | \references{See the link above. 46 | Newcomb T. (1961). The acquaintance process. New York: Holt, Reinhard and Winston.\\ 47 | Nordlie P. (1958). A longitudinal study of interpersonal attraction in a natural group setting. Unpublished doctoral dissertation, University of Michigan.\\ 48 | White H., Boorman S. and Breiger R. (1977). Social structure from multiple networks, I. Blockmodels of roles and positions. American Journal of Sociology, 81, 730-780. 49 | } 50 | \details{Use \code{data(package="netdata")} to get a full list of networks.} 51 | \seealso{network, sna} 52 | \keyword{datasets} 53 | \section{Licenses and Citation}{ 54 | If the source of the data set does not specified otherwise, 55 | this data set is protected by the Creative Commons License 56 | \url{https://creativecommons.org/licenses/by-nc-nd/2.5/}. 57 | 58 | When publishing results obtained using this data set the original authors 59 | should be cited. In addition this package should be cited as: 60 | 61 | Mark S. Handcock, David Hunter, Carter T. Butts, Steven M. Goodreau, 62 | and Martina Morris. 2003 63 | \emph{statnet: An R package for the Statistical Modeling of Social Networks} 64 | \cr 65 | \url{https://statnet.org/} 66 | and the source should be cited as: 67 | 68 | Vladimir Batagelj and Andrej Mrvar (2006): \emph{Pajek datasets} 69 | \cr 70 | \url{https://github.com/bavla/Nets/tree/master/data/Pajek/} 71 | } 72 | \examples{ 73 | data(newcomb) 74 | } -------------------------------------------------------------------------------- /man/activity.attribute.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/activity.attribute.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{activity.attribute} 11 | \alias{activity.attribute} 12 | %- Also NEED an '\alias' for EACH other topic documented here. 13 | \title{ Activity Attributes for Dynamically Extended Networks } 14 | \description{ 15 | Dynamically extended networks are \code{networkDynamic} class objects (extensions of \link[network]{network} objects) whose vertex and edge elements include timing information. This page describes the types of timing information currently available, and the general syntax for setting or querying this information. 16 | } 17 | %\usage{ 18 | %} 19 | %- maybe also 'usage' for other objects documented here. 20 | %\arguments{ 21 | % \item{x}{ ~~Describe \code{x} here~~ } 22 | %} 23 | \details{ 24 | Currently, each edge and vertex in a dynamically extended network is presumed to be in one of two states at any given point in time: (\dQuote{active} or \dQuote{inactive}). The state of a network element (i.e., edge or vertex) is governed by an attribute with the name \dQuote{active}, which is considered a reserved term for purposes of this package. 25 | 26 | The activity attribute consists of a two-column numeric matrix. Each 27 | row contains an activity spell, and the two columns 28 | encode onset and terminus times respectively. Elements are presumed 29 | inactive until the onset of their first activity spell, and are 30 | likewise presumed inactive after the termination of their last active spell. 31 | 32 | Spells are taken to span the period from the onset 33 | (inclusive) to the terminus (exclusive), so [onset,terminus). 34 | They must be consecutive, ordered forward in time, and strictly 35 | non-overlapping. 36 | 37 | The syntax for defining or querying spells can specify either an instantaneous time point or an interval. The commands for this include \code{at=}, \code{onset=}, \code{terminus=} and \code{length=}. Any numeric values may be used in the interval specifications, including \code{Inf} and \code{-Inf}, (with some restrictions, see below). A spell with \code{onset=-Inf} represents onset censoring. A spell with \code{terminus=Inf} represents terminus censoring. \code{Inf} and \code{-Inf} cannot be used with the \code{at} specification. Similarly, \code{onset} can not be \code{Inf} and \code{terminus} can not be \code{-Inf}. 38 | 39 | The general syntax rules for specifying spells are as follows: 40 | 41 | To specify a spell as a single time point: 42 | \itemize{ 43 | \item{ use the \code{at} argument, or} 44 | \item{ use \code{onset=terminus}. } 45 | } 46 | To specify a spell as a particular interval, one of the following combinations of \code{onset}, \code{terminus} and \code{length} is required: 47 | \itemize{ 48 | \item{ \code{onset} and \code{terminus} } 49 | \item{ \code{onset} and \code{length} } 50 | \item{ \code{terminus} and \code{length} } 51 | } 52 | The special \dQuote{null} spell is used to designate elements that are never active (i.e., have no valid activity spells). These can only be set by the \code{deactivate} function (see \code{\link{activity.attribute}}) and by convention are stored as \code{c(Inf,Inf)}. \dQuote{Null} spells are incompatible with other spells, and should be replaced whenever an activation enters the element's event history. 53 | 54 | Although it is possible to access and modify the activity spells using \link[network]{network} attribute methods (e.g., \code{\link[network:attribute.methods]{get.edge.attribute}}) it is not recommended, and extreme care should be taken to preserve the structure of the spell matrix. The preferred way to modify the spells of a network element is with the \code{\link{activate}} related methods. Vertices and edges with specific activity ranges can be selected using \code{\link{network.extensions}}. 55 | 56 | In addition, a number of special functions are also provided to simplify common tasks related to the \code{active} attribute (noted below). 57 | 58 | } 59 | 60 | %\references{ ~put references to the literature/web site here ~ } 61 | \author{ Ayn Leslie-Cook \email{aynlc3@uw.edu}, Carter T. Butts \email{buttsc@uci.edu} } 62 | %\note{ ~~further notes~~ 63 | % 64 | % ~Make other sections like Warning with \section{Warning 5}{....} ~ 65 | %} 66 | \seealso{ \code{\link{is.active}}, \code{\link{activate}}, \code{\link{activate.vertices}},\code{\link{activate.edges}}, \code{\link{deactivate.vertices}},\code{\link{deactivate.edges}},\code{\link{network.extensions}}} 67 | \examples{ 68 | triangle <- network.initialize(3) # create a toy network 69 | 70 | activate.vertices(triangle,onset=1,terminus=5,v=1) 71 | activate.vertices(triangle,onset=1,terminus=10,v=2) 72 | activate.vertices(triangle,onset=4,terminus=10,v=3) 73 | deactivate.vertices(triangle,onset=2, length=2, v=1) 74 | 75 | get.vertex.activity(triangle) # vertex spells 76 | } 77 | % Add one or more standard keywords, see file 'KEYWORDS' in the 78 | % R documentation directory. 79 | \keyword{ manip } 80 | \keyword{ graphs }% __ONLY ONE__ keyword per line 81 | -------------------------------------------------------------------------------- /man/add.active.Rd: -------------------------------------------------------------------------------- 1 | % Part of the statnet package, http://statnetproject.org 2 | % 3 | % This software is distributed under the GPL-3 license. It is free, 4 | % open source, and has the attribution requirements (GPL Section 7) in 5 | % http://statnetproject.org/attribution 6 | % 7 | % Copyright 2013 the statnet development team 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | \name{add.vertices.active} 10 | \alias{add.vertices.active} 11 | \alias{add.edges.active} 12 | \title{ 13 | add.verticies.active, add.edges.active 14 | } 15 | \description{ 16 | Convenience functions for adding a set of verticies (or edges) and setting them to be active in a single call 17 | } 18 | 19 | \usage{ 20 | \method{add.vertices}{active}(x, nv, vattr = NULL, last.mode = TRUE, 21 | onset = NULL, terminus = NULL, length = NULL, at = NULL, ...) 22 | 23 | \method{add.edges}{active}(x, tail, head, names.eval = NULL, vals.eval = NULL, 24 | onset = NULL, terminus = NULL, length = NULL, at = NULL, ...) 25 | } 26 | \arguments{ 27 | \item{x}{ an object of class \code{\link[network]{network}} or \code{\link{networkDynamic}}. } 28 | \item{nv}{the number of vertices to add} 29 | \item{tail}{a vector of vertex IDs corresponding to the tail (source, ego) of each edge to be added} 30 | \item{head}{a vector of vertex IDs corresponding to the head (target, alter) of each edge to be added} 31 | 32 | \item{onset}{ an optional vector of time points that specifies the starts of the interval(s). This must be accompanied by one of \code{terminus} or \code{length}. } 33 | \item{terminus}{ an optional vector of time points that specifies the ends of the interval(s). This must be accompanied by one of \code{onset} or \code{length}. } 34 | \item{length}{ an optional vector of interval lengths for the interval(s). This must be accompanied by one of \code{onset} or \code{terminus}. } 35 | \item{at}{ optional, one or more time points to be activated. } 36 | \item{names.eval}{optional list of length equal to the number of edges, with each element containing a list of names for the attributes of the corresponding edge. not currently interpreted in a dynamic context, but passed directly to \code{\link[network]{add.edges}}} 37 | \item{vals.eval}{an optional list of lists of edge attribute values (matching \code{names.eval}). Not currently interpreted in a dynamic context, but passed directly to \code{\link[network]{add.edges}}} 38 | \item{vattr}{optionally, a list of attributes with one entry per new vertex. not currently interpreted in a dynamic context, but passed directly to \code{\link[network]{add.vertices}}} 39 | \item{last.mode}{logical; should the new vertices be added to the last (rather than the first) mode of a bipartite network?} 40 | \item{...}{possible future additional arguments} 41 | } 42 | \details{ 43 | Essentially a wrapper for a call to \code{\link[network]{add.vertices}} and \code{\link{activate.vertices}} or \code{\link[network]{add.edges}} and \code{\link{activate.edges}} when setting up a network object. These are not the S3 methods that their name appears to imply, since there is no "active" class. See \code{\link{add.edges.networkDynamic}}, etc. 44 | } 45 | \value{ 46 | The passed in network object with class set to \code{\link{networkDynamic}} and the specified number of new vertices or edges added and activated 47 | } 48 | 49 | \author{ 50 | Ayn Leslie-Cook \email{aynlc3@uw.edu}} 51 | 52 | \note{Order of arguments was changed in version 1.9 for S3 method consistency. Does not currently support the multiple-vertex head- and tail-sets of \code{add.edges} or \code{add.edge}.} 53 | 54 | 55 | \seealso{ 56 | See Also as \code{\link{activate.vertices}}, \code{\link{activate.edges}},\code{\link[network]{add.vertices}},\code{\link[network]{add.edges}} 57 | } 58 | \examples{ 59 | nw <- network.initialize(5) 60 | activate.vertices(nw,onset=0,terminus=10) 61 | network.size(nw) # just 5 nodes 62 | # add some new nodes with times 63 | add.vertices.active(nw,2,onset=10,terminus=12) 64 | network.size(nw) # now we have 7 nodes 65 | 66 | # add 2 edges edges, and activate them 67 | add.edges(nw, tail=c(1,2),head=c(2,3)) 68 | activate.edges(nw,onset=0,terminus=10,e=1:2) 69 | 70 | # instead add and activate at the same time 71 | add.edges.active(nw, tail=c(3,4),head=c(4,5),onset=10,terminus=12) 72 | } 73 | 74 | -------------------------------------------------------------------------------- /man/add.methods.networkDynamic.Rd: -------------------------------------------------------------------------------- 1 | \name{add.methods} 2 | \alias{add.edges.networkDynamic} 3 | \alias{add.vertices.networkDynamic} 4 | \alias{add.edge.networkDynamic} 5 | %- Also NEED an '\alias' for EACH other topic documented here. 6 | \title{ 7 | PID-aware versions of functions for adding edges and vertices to networkDynamic objects 8 | } 9 | \description{ 10 | The methods (\code{add.vertices.networkDynamic}, \code{add.edge.networkDynamic}, \code{add.edges.networkDynamic}) override their network-package counterparts in order to permit assigning \link{persistent.ids} to newly-added elements if the pid is defined. They can be defined by the user with the \code{vertex.pids} argument, or, if not specified, a unique random id will be generated. (Note that any new values added by default to a \code{vertex.names} pid will not be numeric.) 11 | } 12 | \usage{ 13 | \method{add.vertices}{networkDynamic}(x, nv, vattr = NULL, last.mode = TRUE, 14 | vertex.pid = NULL, ...) 15 | 16 | \method{add.edges}{networkDynamic}(x, tail, head, names.eval = NULL, vals.eval = NULL, 17 | edge.pid = NULL, ...) 18 | 19 | \method{add.edge}{networkDynamic}(x, tail, head, names.eval = NULL, vals.eval = NULL, 20 | edge.check = FALSE, edge.pid = NULL, ...) 21 | 22 | } 23 | 24 | %- maybe also 'usage' for other objects documented here. 25 | \arguments{ 26 | \item{x}{an object of class \code{network} or \code{networkDynamic} (see \code{\link[network:add.vertices]{add.vertices}} in network)} 27 | \item{nv}{number of vertices to be added. (see \code{\link[network:add.vertices]{add.vertices}} in network)} 28 | \item{vattr}{optionally, a list of attributes with one entry per new vertex. (see \code{\link[network:add.vertices]{add.vertices}} in network), not interpreted as a dynamic attribute} 29 | \item{last.mode}{logical; should the new vertices be added to the last (rather than the first) mode of a bipartite network? (see \code{\link[network:add.vertices]{add.vertices}} in network)} 30 | \item{vertex.pid}{a vector of vertex.pids to be assigned to the newly-added vertices} 31 | \item{edge.pid}{a vector of edge.pids to be assigned to the newly-added edges} 32 | \item{names.eval}{see \code{\link[network:add.edges]{add.edges}} in network), not interpreted as a dynamic attribute} 33 | \item{vals.eval}{see \code{\link[network:add.edges]{add.edges}} in network), not interpreted as a dynamic attribute} 34 | \item{edge.check}{see \code{\link[network:add.edges]{add.edges}} in network)} 35 | \item{head}{see \code{\link[network:add.edges]{add.edges}} in network)} 36 | \item{tail}{see \code{\link[network:add.edges]{add.edges}} in network)} 37 | \item{...}{possible additional arguments} 38 | } 39 | \details{ 40 | The networkDynamic versions of these methods call the network versions internally. See \link{persistent.ids} for additional details about the PID mechanism. 41 | } 42 | \value{ 43 | \itemize{ 44 | \item{\code{add.verticies} (invisibly) returns a reference to the network with the new vertices added. Pids will be added/created if a \code{vertex.pid} attribute is set.} 45 | \item{\code{add.edge} and \code{add.edges} (invisibly) return a reference to the network with the new edges added. Pids will be added/created if a \code{vertex.pid} attribute is set.} 46 | } 47 | } 48 | %\references{ 49 | %A specification document: \url{https://statnet.csde.washington.edu/trac/wiki/PersistentIdProposal} 50 | %} 51 | \author{ 52 | lxwang, skyebend, the statnet team 53 | } 54 | \note{ 55 | Adding edges via the extraction/replacement operators \code{[,]} bypasses the pid code and will break the edge pids defined for the network. Similarly, \code{\link{add.vertices.active}} and \code{\link{add.edges.active}} do not yet support including pids. 56 | } 57 | 58 | 59 | \seealso{ 60 | See also \code{\link{persistent.ids}}, \code{\link[network:add.vertices]{add.vertices}}, \code{\link[network:add.edges]{add.edge}}, \code{\link[network:add.edges]{add.edges}} in network. 61 | } 62 | \examples{ 63 | # add vertices while using vertex.names as pids 64 | nd <- as.networkDynamic(network.initialize(3)) 65 | set.network.attribute(nd,"vertex.pid","vertex.names") 66 | add.vertices(nd,nv=2,vertex.pid=c(4,5)) # specify pids for two new vertices 67 | network.vertex.names(nd) # peek at pids 68 | 69 | # add vertices and edges w/ auto-generated pids 70 | nd <- as.networkDynamic(network.initialize(3)) 71 | initialize.pids(nd) 72 | get.vertex.attribute(nd,'vertex.pid') # peek at pids 73 | add.vertices(nd,nv=2) # silently generate pids for vertices 74 | get.vertex.attribute(nd,'vertex.pid') # peek at pids 75 | add.edges(nd,1,2) # silently generate a pid for the edge 76 | get.edge.attribute(nd,'edge.pid') 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /man/adjust.activity.Rd: -------------------------------------------------------------------------------- 1 | \name{adjust.activity} 2 | \alias{adjust.activity} 3 | \title{ 4 | Adjust the activity ranges in all of the spells of a networkDynamic object 5 | } 6 | \description{ 7 | Transforms the values of all the activity spells of vertices and edges, as well as spells of dynamic TEA attributes (and the \code{net.obs.period} if it exists). 8 | } 9 | \usage{ 10 | adjust.activity(nd, offset = 0, factor = 1) 11 | } 12 | %- maybe also 'usage' for other objects documented here. 13 | \arguments{ 14 | \item{nd}{ 15 | networkDynamic object to be modified 16 | } 17 | \item{offset}{ 18 | numeric value to be added (or subtracted) to all spell values 19 | } 20 | \item{factor}{ 21 | numeric factor for multiplying all spell values 22 | } 23 | } 24 | \details{ 25 | Spell values are modified by first adding the value of \code{offset} and then multiplying by \code{factor}. If a \code{\link{net.obs.period}} attribute exists, it's observation spell values are transformed, and the \code{time.increment} value is multiplied by \code{factor}. 26 | } 27 | \value{ 28 | The \code{nd} argument is modified in place and returned invisibly. 29 | } 30 | 31 | 32 | \author{ 33 | skyebend@uw.edu 34 | } 35 | 36 | 37 | \seealso{ 38 | See also \code{\link{activity.attribute}}, \code{\link{attribute.activity.functions}} and \code{\link{net.obs.period}} 39 | } 40 | \examples{ 41 | # convert steps of an imaginary discrete sim 42 | # with each steps corresponding to 1 day 43 | # into decimal 'years' since 1990 44 | sim<-network.initialize(5) 45 | activate.vertices(sim,onset=0,terminus=2546) 46 | add.edges.active(sim,head=1:4,tail=2:5,onset=0,terminus=2546) 47 | set.network.attribute(sim,'net.obs.period',list( 48 | observations=list(c(0,2546)),mode="discrete", 49 | time.increment=1,time.unit="step")) 50 | 51 | # do the transformation 52 | adjust.activity(sim,offset=1990*365.25,factor=1/365.25) 53 | 54 | # modify the 'units' of net.obs.period 55 | obs <-get.network.attribute(sim,'net.obs.period') 56 | obs$time.unit<-'year' 57 | set.network.attribute(sim,'net.obs.period',obs) 58 | 59 | # peek at the new values 60 | as.data.frame(sim) 61 | get.network.attribute(sim,'net.obs.period') 62 | } -------------------------------------------------------------------------------- /man/age.at.Rd: -------------------------------------------------------------------------------- 1 | \name{age.at} 2 | \alias{edges.age.at} 3 | \alias{dyads.age.at} 4 | \alias{vertices.age.at} 5 | %- Also NEED an '\alias' for EACH other topic documented here. 6 | \title{ 7 | Age of active edges or vertices at a query time point 8 | } 9 | \description{ 10 | Reports the age of edges or vertices at a specific time point. More precisely, the duration of time between the query time point and the onset of the activity spell active at that point. 11 | } 12 | \usage{ 13 | edges.age.at(nD, at, e = seq_along(nD$mel), active.default = TRUE) 14 | dyads.age.at(nD, at, tails, heads, active.default=TRUE, 15 | format.out = c("vector", "edgelist", "matrix")) 16 | vertices.age.at(nD, at, v=seq_len(network.size(nD)), active.default=TRUE) 17 | } 18 | %- maybe also 'usage' for other objects documented here. 19 | \arguments{ 20 | \item{nD}{ 21 | a \code{\link{networkDynamic}} object to be evaluated 22 | } 23 | \item{at}{ 24 | numeric query time point which edge or vertex ages should be evaluated at 25 | } 26 | \item{e}{ 27 | numeric vector of edges ids for which ages / durations should be reported 28 | } 29 | 30 | \item{v}{ 31 | numeric vector of vertex ids for which ages / durations should be reported 32 | } 33 | 34 | \item{tails}{ 35 | numeric vector of vertex ids incident on the 'tail' of edges for which ages / durations should be reported 36 | } 37 | 38 | \item{heads}{ 39 | numeric vector of vertex ids incident on the 'head' of edges for which ages / durations should be reported 40 | } 41 | 42 | 43 | \item{active.default}{ 44 | logical, if \code{TRUE} edges or vertices with no activity specified will be considered always active (see \code{\link{is.active}}) 45 | } 46 | 47 | \item{format.out}{ 48 | character value indicating out the output should be structured. \code{vector} returns output as a vector, \code{edgelist} returns a 3-column matrix in which the first columns are the tail and head vertex ids of the edge and the 3rd column is the age, \code{matrix} returns an adjacency matrix with the edge ages as values. 49 | } 50 | } 51 | \details{ 52 | Edges or vertices that are not active at time \code{at} will return \code{NA}. For edges or vertices with multiple activity spells, this function \emph{does not} report the total duration of activity across all spells, only the duration from the start of the spell with which the \code{at} point intersects. 53 | 54 | \code{dyads.age.at} reports the age of edges corresponding to each dyad (tail,head). It cannot be used with hypergraphic or multiplex networks because a pair of vertex ids may not uniquely correspond to an edge. If \code{tails} and \code{heads} are not specified, they will default to the tails and heads of all existing (but not necessarily active) edges in the network. Ordering and index position should correspond to \code{\link[network]{valid.eids}}. 55 | } 56 | \value{ 57 | By default, a numeric vector indicating the age of the network element at the query time point, or NA if the element is not active or (in the case of edges) deleted. Elements of the vector return correspond to the values of \code{e} or \code{v} or \code{(tails,heads)} respectively. 58 | } 59 | 60 | \author{ 61 | skyebend 62 | } 63 | 64 | 65 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 66 | 67 | \seealso{ 68 | See also \code{\link{get.edge.activity}}, \code{\link{is.active}} 69 | } 70 | \examples{ 71 | # set up an example network for testing 72 | test<-network.initialize(5) 73 | add.edges(test,tail = 1:4,head=2:5 ) 74 | activate.edges(test,onset=0:2,terminus=c(2,3,3),e=1:3) 75 | activate.vertices(test,v = 1:4,onset=-3:0,terminus=5:8) 76 | 77 | # how old are each of the edges at time point 2.0 ? 78 | edges.age.at(test,at=2.0) 79 | 80 | # how old is vertex id 2 time point 3 81 | vertices.age.at(test,at=3, v=2) 82 | 83 | # how old are the edges [1,2] and [3,4] at time point 2 84 | dyads.age.at(test,at=2,tails=c(1,3),heads=c(2,4)) 85 | 86 | dyads.age.at(test,at=2,format.out='matrix') 87 | 88 | } -------------------------------------------------------------------------------- /man/as.data.frame.networkDynamic.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/as.data.frame.networkDynamic.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{as.data.frame.networkDynamic} 11 | \alias{as.data.frame.networkDynamic} 12 | %- Also NEED an '\alias' for EACH other topic documented here. 13 | \title{ 14 | Extracts the edge timing information from a networkDynamic object and represent as a data.frame. 15 | } 16 | \description{ 17 | Creates a data.frame giving lists of edges and their activity spells corresponding to the \code{\link{networkDynamic}} object. An observation window may be specified, and edge spells with values outside the window will be omitted or truncated/censored to the observation window bounds. 18 | } 19 | \usage{ 20 | \method{as.data.frame}{networkDynamic}(x, row.names = NULL, optional = FALSE, e =seq_along(x$mel), 21 | start = NULL, end = NULL, active.default=TRUE,...) 22 | } 23 | %- maybe also 'usage' for other objects documented here. 24 | \arguments{ 25 | \item{x}{a networkDynamic object} 26 | \item{row.names}{ignored} 27 | \item{optional}{ignored} 28 | \item{e}{vector of edge ids that should be included in the output.} 29 | \item{start}{optional, numeric onset-censoring time: time at which the network was first 30 | observed. Edge spells with earlier onset times are given this 31 | as their onset time (and marked as left censored). See Details for 32 | the default values.} 33 | \item{end}{optional right-censoring time: time at which the network was last 34 | observed. Edge spells with larger terminus are given this 35 | as their terminus time (and marked as right censored). See Details for 36 | the default values.} 37 | \item{active.default}{logical indicating if edges with no defined activity spells should be considered active by default (and appear as a row in output)} 38 | \item{\dots}{possible additional arguments} 39 | } 40 | \details{ 41 | Exports the edge dynamics of a \code{\link{networkDynamic}} object as a \code{\link{data.frame}} giving a table of edges with their activity spells, including whether an activity spell was ``censored'' (onset or termination was not observed within the observation window). 42 | If a \code{\link{net.obs.period}} attribute exists, the maximal and minimal values will be used as censoring times by default. Censoring times can also be provided using the \code{start} and \code{end} arguments (which will override \code{net.obs.period}), and censoring can be prevented by setting \code{start=-Inf, end=Inf}. Edge spells that exceed the censoring bounds will have their onset and/or terminus time appropriately truncated to match and will be marked as censored. Spells which are fully outside the censoring bounds will be deleted and the corresponding rows will not be returned. 43 | 44 | Note that the spell overlap rules mean that when edge spells are modeled as momentary events (onset==terminus), any events have onset==terminus==end of the the observation window will not be returned. This will likely be the case for networks created by the \code{\link{networkDynamic}} converter function. 45 | } 46 | \value{ 47 | A \code{\link{data.frame}} containing timed relational information 48 | describing the networkDynamic object, having the following columns: 49 | \item{onset, terminus}{Onset and terminus times of an edge, respectively, if 50 | not censored, and left and right censoring times, if censored.} 51 | \item{tail, head}{Tail and head of the edge.} 52 | \item{onset.censored, terminus.censored}{TRUE if onset/terminus time is censored.} 53 | \item{duration}{the duration (terminus-onset) of each spell, evaluated after censoring} 54 | \item{edge.id}{the id of the edge the row corresponds to} 55 | The output \code{data.frame} will be sorted by edge.id, onset,terminus. This means that for most (non-multiplex) networks the group of spells for a specific edge will appear in sequential lines of output, but the overall output is not in a temporal order. 56 | } 57 | 58 | \note{ 59 | Vertex and attribute activity are not included in the returned data.frame. If an edge has multiple activity spells, it will have multiple rows in the output. When output in censored, it may not match values returned by \code{\link{get.edge.activity}} 60 | } 61 | 62 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 63 | \seealso{ 64 | See Also as \code{\link{get.edge.activity}},\code{\link{get.vertex.activity}} 65 | } 66 | 67 | 68 | 69 | \examples{ 70 | net <-network.initialize(3) 71 | net[1,2]<-1; 72 | net[2,3]<-1; 73 | ## censoring 74 | activate.edges(net,onset=1,terminus=Inf,e=1) 75 | activate.edges(net,onset=2,terminus=3,e=2) 76 | activate.vertices(net, onset=1, terminus=Inf, v=1) 77 | as.data.frame(net) 78 | } 79 | % Add one or more standard keywords, see file 'KEYWORDS' in the 80 | % R documentation directory. 81 | 82 | -------------------------------------------------------------------------------- /man/as.network.networkDynamic.Rd: -------------------------------------------------------------------------------- 1 | % Part of the statnet package, http://statnetproject.org 2 | % 3 | % This software is distributed under the GPL-3 license. It is free, 4 | % open source, and has the attribution requirements (GPL Section 7) in 5 | % http://statnetproject.org/attribution 6 | % 7 | % Copyright 2013 the statnet development team 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | \name{as.network.networkDynamic} 10 | \alias{as.network.networkDynamic} 11 | 12 | \title{ 13 | Remove `networkDynamic' class name from networkDynamic object. 14 | } 15 | \description{ 16 | Changes the class of a \code{networkDynamic} object to a plain \code{network} object while leaving all attributes (including dynamic attributes) intact. 17 | } 18 | \usage{ 19 | \method{as.network}{networkDynamic}(x, ...) 20 | } 21 | 22 | \arguments{ 23 | \item{x}{ 24 | A \code{networkDynamic} object that will have its class name stripped. 25 | } 26 | \item{\dots}{ 27 | Possible additional arguments 28 | } 29 | } 30 | \details{ 31 | The primary use-case for this method is to force some other S3 method (like \code{simulate} in the \code{tergm} package, plot, or print) to use 'network' instead of 'networkDynamic' in method dispatching. Dynamic features data structures be left intact but not recognized by corresponding methods, so effectively broken. 32 | } 33 | \value{ 34 | Returns the original network with the \code{networkDynamic} class name removed but all other attributes unchanged 35 | } 36 | 37 | \author{ 38 | Skye Bender-deMoll 39 | } 40 | 41 | 42 | \seealso{ 43 | See Also as \code{\link{network.extract}} for extracting parts of a networkDynamic, and \code{\link{network.collapse}} for extracting part of a networkDynamic as a static network. \code{\link{as.networkDynamic}} for the inverse operation (adding the networkDynamic class to a static network). 44 | } 45 | \examples{ 46 | test<-network.initialize(2) 47 | add.edges.active(test,tail=1,head=2,onset=1,terminus=2) 48 | is.networkDynamic(test) 49 | test<-as.network(test) 50 | is.networkDynamic(test) 51 | 52 | } -------------------------------------------------------------------------------- /man/as.networkDynamic.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/as.networkDynamic.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{as.networkDynamic} 11 | \alias{as.networkDynamic} 12 | \alias{as.networkDynamic.network} 13 | \alias{as.networkDynamic.networkDynamic} 14 | \alias{as.networkDynamic.networkLite} 15 | 16 | \title{ 17 | as.networkDynamic 18 | } 19 | 20 | \description{ 21 | The \code{as.networkDynamic} generic provides a very basic conversion to 22 | \code{networkDynamic} from other network types. It is generally recommended 23 | to use the \code{\link{networkDynamic}} function instead of 24 | \code{as.networkDynamic}, because \code{\link{networkDynamic}} provides a 25 | number of additional features for handling temporal information. 26 | } 27 | 28 | \usage{ 29 | 30 | \method{as.networkDynamic}{networkDynamic}(object,...) 31 | 32 | \method{as.networkDynamic}{network}(object,...) 33 | 34 | \method{as.networkDynamic}{networkLite}(object,...) 35 | } 36 | %- maybe also 'usage' for other objects documented here. 37 | \arguments{ 38 | \item{object}{a \code{network}, \code{networkLite}, or \code{networkDynamic} object} 39 | 40 | \item{\dots}{ignored} 41 | 42 | } 43 | \details{ 44 | \code{as.networkDynamic.network} converts a \code{network} object into 45 | a \code{networkDynamic} object by adding a \code{networkDynamic} class. 46 | 47 | \code{as.networkDynamic.networkLite} converts a \code{networkLite} object into 48 | a \code{networkDynamic} object by first converting it to a \code{network} 49 | object and then adding a \code{networkDynamic} class. (\code{networkLite}s are 50 | a backend data structure used in some \code{EpiModel} and \code{statnet} 51 | packages, providing improved performance for certain applications, especially 52 | when working with vertex and edge attributes that can be stored as atomic 53 | vectors. Currently, \code{networkLite}s come with the restriction that the 54 | network attributes \code{hyper}, \code{multiple}, and \code{loops} must be 55 | \code{FALSE}. See \code{\link[networkLite]{networkLite-package}} for more information.) 56 | 57 | Such conversions between network types are used when starting a dynamic 58 | simulation from a cross-sectional network and returning the simulation history 59 | as a dynamic network, as done in the \code{tergm} package for example. 60 | } 61 | 62 | \value{ 63 | For \code{as.networkDynamic.network} the input object is returned with a 64 | \code{networkDynamic} class added. For \code{as.networkDynamic.networkLite}, 65 | the input object is converted to a \code{network} object and then the 66 | \code{networkDynamic} class is added. For 67 | \code{as.networkDynamic.networkDynamic} the input object is returned 68 | unchanged. 69 | } 70 | 71 | \author{ 72 | Pavel, Zack W Almquist 73 | } 74 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 75 | \seealso{ 76 | For the inverse (removing the \code{networkDynamic} class) see 77 | \code{\link{as.network.networkDynamic}} and 78 | \code{\link[networkLite]{as.networkLite.network}} (which applies to \code{networkDynamic}s). 79 | For extracting cross-sectional information from a \code{networkDynamic} (which 80 | is often more appropriate than simply removing the \code{networkDynamic} 81 | class), see \code{\link{network.collapse}} and \code{\link{network.extract}}. 82 | For more general construction of \code{networkDynamic}s, see 83 | \code{\link{networkDynamic}}. 84 | } 85 | 86 | \examples{ 87 | nd <- as.networkDynamic(network.initialize(3)) 88 | class(nd) 89 | is.networkDynamic(nd) 90 | 91 | nwL <- networkLite::networkLite(3) 92 | nwD <- as.networkDynamic(nwL) 93 | class(nwD) 94 | is.networkDynamic(nwD) 95 | } 96 | -------------------------------------------------------------------------------- /man/classrooms.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/classrooms.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{cls33_10_16_96} 11 | \alias{cls33_10_16_96} 12 | \alias{McFarland_cls33_10_16_96} 13 | \docType{data} 14 | \title{ 15 | Daniel McFarland's Streaming Classroom Interactions Dataset 16 | } 17 | \description{ 18 | A dynamic network object describing continuous time streams of social interactions between teachers and students in a classroom observed by Daniel McFarland in 1996. 19 | } 20 | \usage{data(McFarland_cls33_10_16_96)} 21 | \format{ 22 | The format is is a \link{networkDynamic} object named \code{cls33_10_16_96} with node and edge \link{activity.attribute}s defined by spell matricies and associated vertex attributes and dynamic edge attributes. 23 | } 24 | \details{ 25 | The dynamic network object has 20 vertices and directed edges and covers a time range of 0.0 to 49.0 minutes of class time. The vertex attribute \code{gender} gives gender ('M' or 'F') of each person and \code{type} gives a crude role ('grade11','grade12','instructor'). The original dataset id for the vertices is included as \code{data_id} and defined as a persistent.id. The edges include a dynamic attribute (TEA) \code{interaction_type} with values 'saction', 'social' and 'task' (see explanation below) and a \code{weight} assigned by the reacher to that interaction (direct comunication is given more weight than indirect 'broadcast' communication). 26 | 27 | A .son formatted input file with the same data as well as seperate tsv files for vertices and edges are located in the /inst/extdata directory. 28 | 29 | The data for these classroom interactions consists of streaming observations of conversation turns. The conversation turns were recorded as pairs of senders and receivers and for types of content. Speakers were viewed as directing their communication in one of two fashions: (1) indirect soundings, such as lectures (where a teacher addresses all students); and (2) direct interactions that are focused on particular others. Each type of directional speech is viewed as having different forms of network reception - indirect speech reaches all bystanders as passive hearers and directed speech reaches the focal person as an active co-author of the conversation (Goffman 1981). 30 | 31 | Two types of interaction are found to prevail in classroom contexts: task and sociable (McFarland, in press). Task interactions are those behaviors that pertain to the ongoing teacher prescribed task (content is academic). In contrast, sociable interactions concern everyday concerns of adolescents' social lives, such as parties, dating, social outings, plans, etc. While the content is the key distinction, it is often the case that these speech acts are distinguishable in style as well, where sociable behaviors are more play-like, fast-paced, and free than the more constrained academic styles of speech during lessons (Cazden 1988). Last, observations also recorded when task and sociable forms of interaction were laminated with evaluative meaning. Such evaluations were seen as being either positive or negative - either giving praise or attempting a reprimand (Ridgeway and Johnson). 32 | 33 | The class (#33) is an economics class composed of 11th and 12th graders at a magnet high school. On this day, economics has two teachers. The first is the usual teacher and the second is a businessman who donates his time a couple days a month to assist the class with their lesson on stock investments. After a minute of undefined class time, the two teachers prescribe collaborative group work and assist students in conducting it. The students are assigned groups within which they are to study the stock market and make mock investments they can follow over time. The groups compete with each other over the course of the semester to see who can make the greatest profit. 34 | 35 | The network narrative for the class opens with the teacher trying to focus student attention and then lecturing while the visiting professional assists each group. The teacher prescribes group work but continues to lecture, thereby preventing the desired social routine from fully taking effect. Eventually the students are doing group projects while the adults move from group to group, facilitating their progress, and stabilizing interaction patterns. The routine of group work is basically characterized by dyadic task and social interactions that persist in multiple clusters. Not all persons engage in these groups, and a couple students sit quietly by themselves. The group work routine breaks down as social activity increases within the groups', and then the teacher emits broadcast sanctions in an effort to redirect student attention back on task (16 minutes). The task breaks down again at the end of class, but this time because the adults make closing announcements. 36 | 37 | So the network illustrates that teachers are involved in this task engaging their students as they monitor interaction. When students become too social, a teacher usually arrives, disperses the group, and then reforms it via task interactions (revolution in type of behavior, McFarland 2004). Hence, the ``dance'' here entails relatively bounded groups of individuals that free-associate over tasks and drift into social affairs, and teachers who refocus affairs by indirect means of broadcasts or by direct means of directed speech. 38 | } 39 | 40 | \source{ 41 | Dr. Daniel McFarland, Stanford University \url{https://ed.stanford.edu/faculty/mcfarland} 42 | } 43 | 44 | \references{ 45 | McFarland, Daniel A. 2005. ``Why Work When You Can Play? Dynamics of Formal and Informal Organization in Classrooms.'' Chapter 8 in The Social Organization of Schooling, edited by Larry Hedges and Barbara Schneider (pp. 147-174). New York: Russell Sage Foundation. 46 | 47 | McFarland, Daniel A. 2004. ``Resistance as a Social Drama - A Study of Change-Oriented Encounters.'' American Journal of Sociology 109 (6): 1249-1318. 48 | 49 | McFarland, Daniel A. 2001. ``Student Resistance: How the Formal and Informal Organization of Classrooms Facilitate Everyday Forms of Student Defiance.'' American Journal of Sociology 107 (3): 612-78. 50 | 51 | McFarland, Daniel A. and Skye Bender-deMoll. 2003. ``Classroom Structuration: A Study of Network Stabilization.'' Working paper, Stanford University. 52 | } 53 | \examples{ 54 | data(McFarland_cls33_10_16_96) 55 | } 56 | 57 | \keyword{datasets} 58 | -------------------------------------------------------------------------------- /man/delete.activity.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/delete.activity.matrices.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{delete.activity} 11 | \alias{delete.edge.activity} 12 | \alias{delete.vertex.activity} 13 | \title{ Remove Timing Information in a Dynamically Extended Network Object } 14 | \description{ 15 | Removes the activity spells of a given set of vertices or edges. 16 | } 17 | \usage{ 18 | delete.edge.activity(x, e=seq_along(x$mel)) 19 | 20 | delete.vertex.activity(x, v=seq_len(network.size(x))) 21 | } 22 | \arguments{ 23 | \item{x}{ an object, of class \code{network} or \code{networkDynamic}. } 24 | \item{e}{ the edges of \code{x} that will have their timing information 25 | deleted; default = all. } 26 | \item{v}{ the vertices of \code{x} that will have their timing information 27 | deleted; default = all. } 28 | } 29 | \details{ 30 | Though the timing information of the edges and/or vertices may be 31 | removed, other networkDynamic methods will assume activity or 32 | inactivity across all time points, based on the argument 33 | \code{active.default}. 34 | } 35 | \value{ 36 | An object with the same class as \code{x}, equivalent to \code{x} without the 37 | activity spells of the edges \code{e} or the vertices \code{v}. 38 | } 39 | %\references{ ~put references to the literature/web site here ~ } 40 | \author{ Ayn Leslie-Cook \email{aynlc3@uw.edu}, Carter T. Butts \email{buttsc@uci.edu} } 41 | %\note{ ~~further notes~~ 42 | % 43 | % ~Make other sections like Warning with \section{Warning }{....} ~ 44 | %} 45 | \seealso{ \code{\link{activate}} } 46 | \examples{ 47 | library(networkDynamic) 48 | data(flo) 49 | net1 <- network(flo) 50 | activate.edges(net1) 51 | activate.vertices(net1) 52 | net2 <- net1 53 | delete.edge.activity(net1, e=seq(2,40,2)) 54 | delete.edge.activity(net2) 55 | delete.vertex.activity(net2) 56 | is.active(net1, at=0, e=c(1,2), active.default=FALSE) 57 | is.active(net1, at=0, e=c(1,2), active.default=TRUE) 58 | is.active(net2, at=0, e=1:16, active.default=FALSE) 59 | is.active(net2, at=0, e=1:16, active.default=TRUE) 60 | } 61 | % Add one or more standard keywords, see file 'KEYWORDS' in the 62 | % R documentation directory. 63 | \keyword{ manip } 64 | \keyword{ graphs }% __ONLY ONE__ keyword per line 65 | -------------------------------------------------------------------------------- /man/duration.matrix.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/duration.matrix.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{duration.matrix} 11 | \alias{duration.matrix} 12 | 13 | \title{ Construct a edge spells list from base network and toggle list. } 14 | \description{ 15 | Given a network object and a toggle list, it will construct a list of edges and activity spells and return that as a data frame. The network object does not need to have edges; it only needs to have enough vertices to cover all the edges specified in the toggle list. 16 | 17 | The toggle list should be a three column matrix or data frame, where the first column is the toggle time, the second column is the tail vertex id of the edge, and the third column is the head vertex id of the edge. A toggle represents a switch from active state to inactive, or vice-versa. 18 | 19 | 20 | } 21 | \usage{ 22 | duration.matrix(nw0, changes, start, end) 23 | } 24 | \arguments{ 25 | \item{nw0}{ an object of class \code{network} } 26 | \item{changes}{ a matrix or data frame, listing the toggles for edges as specified in the above description } 27 | \item{start}{ integer, specifies the starting time of the network's dynamic activity } 28 | \item{end}{ integer, specifies the ending time of the network's dynamic activity } 29 | } 30 | \value{ 31 | Returns a data frame that lists the edge spells specified by the toggles. The columns in the data frame are 32 | \code{start end tail head left.censored right.censored duration}. Left and right censoring and duration are calculated 33 | automatically from the toggle list and the start and end times. 34 | } 35 | 36 | %\references{ ~put references to the literature/web site here ~ } 37 | \author{ Ayn Leslie-Cook \email{aynlc3@uw.edu}, Carter T. Butts \email{buttsc@uci.edu} } 38 | %\note{ ~~further notes~~ 39 | % 40 | % ~Make other sections like Warning with \section{Warning }{....} ~ 41 | %} 42 | \seealso{ \code{\link{as.networkDynamic}} } 43 | \examples{ 44 | library(networkDynamic) 45 | # duration matrix test 46 | net <-network.initialize(3) 47 | net[1,2]<-1; 48 | net[2,3]<-1; 49 | net[1,3]<-1; 50 | class(net) 51 | # toggle list: time, tail, head 52 | tog=matrix(c(1,1,2, 1,2,3, 2,1,2, 4,1,3, 4,1,2), ncol=3, byrow=TRUE) 53 | networkDynamic:::duration.matrix(net, tog, 0, 5) 54 | } 55 | % Add one or more standard keywords, see file 'KEYWORDS' in the 56 | % R documentation directory. 57 | %\keyword{ ~kwd1 } 58 | %\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 59 | -------------------------------------------------------------------------------- /man/get.dyads.active.Rd: -------------------------------------------------------------------------------- 1 | \name{get.dyads.active} 2 | \alias{get.dyads.active} 3 | \title{ 4 | Return the set of vertex ids of edges active at a given time 5 | } 6 | \description{ 7 | Constructs a matrix, essentially an edgelist, of the pairs of vertices connected by edges active within the query spell. 8 | } 9 | \usage{ 10 | get.dyads.active(nD, onset = NULL, terminus = NULL, length = NULL, at = NULL, 11 | rule = c("any", "all", "earliest", "latest"), active.default = TRUE) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{nD}{ 16 | networkDynamic object to be queried 17 | } 18 | \item{onset}{ 19 | optional numeric value giving onset time of query spell 20 | } 21 | \item{terminus}{ 22 | optional numeric value giving terminus time of query spell 23 | } 24 | \item{length}{ 25 | optional numeric value giving length (duration) of query spell 26 | } 27 | \item{at}{ 28 | optional numeric value giving single time point to query 29 | } 30 | \item{rule}{ 31 | a character string indicating the definition of "active" for this query: \code{any} (default) to define active as any active spell during the interval, or \code{all} to define active as being active over the entire interval. For this functions, the values of \code{earliest} and \code{latest} are equivalent to \code{any} and are only included for consistency. 32 | } 33 | \item{active.default}{ 34 | logical; should elements without an activity attribute be regarded as active by default? Default to \code{TRUE} 35 | } 36 | } 37 | \details{ 38 | Uses \code{\link{is.active}} internally. The ordering of matrix rows is arbitrary. The ordering of vertices in non-directed networks corresponds to how they were set in the data structure (i.e. does not enforce i > j) If no edges are active or exist, a matrix with zero rows will be returned. 39 | } 40 | \value{ 41 | Returns a two-column numeric matrix in which the first column gives a tail vertex.id and the second column gives the head vertex.id and each row corresponds to the existence of an active relationship between the vertices for the given query spell. 42 | } 43 | 44 | \author{ 45 | skyebend 46 | } 47 | \note{ 48 | This function does not support hypergraphic networks. 49 | } 50 | 51 | 52 | \seealso{ 53 | See also \code{\link{is.active}} 54 | } 55 | \examples{ 56 | data(windsurfers) 57 | get.dyads.active(windsurfers,onset=2,terminus=3) 58 | } 59 | -------------------------------------------------------------------------------- /man/get.networks.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/get.slices.networkDynamic.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2013 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{get.networks} 11 | \alias{get.networks} 12 | %- Also NEED an '\alias' for EACH other topic documented here. 13 | \title{Obtain a list of collapsed networks sampled periodically from a networkDynamic object} 14 | \description{ 15 | Given a start time, end time, and increment (or vectors of onsets and termini) to express sampling intervals, return a list of collapsed networks from a networkDynamic object. 16 | } 17 | \usage{ 18 | get.networks(dnet, start = NULL, end = NULL, time.increment = NULL, 19 | onsets=NULL, termini=NULL,...) 20 | } 21 | %- maybe also 'usage' for other objects documented here. 22 | \arguments{ 23 | \item{dnet}{ 24 | A \code{networkDynamic} object with possible vertex, edge, network, and attribute spell information. 25 | } 26 | \item{start}{ numeric value giving the start of the sampling interval} 27 | \item{end}{ numeric value giving the end of the sampling interval} 28 | \item{time.increment}{value for the offset (and duration) between sucessive samples. Will default to 1 if not otherwise specified} 29 | 30 | \item{onsets}{ A numeric vector containing the onset times of the networks to be extracted. This must be accompanied by \code{termini} of the same length. 31 | } 32 | \item{termini}{ A numeric vector containing the terminus times of the networks to be extracted. This must be accompanied by \code{onsets} of the same length. 33 | } 34 | 35 | \item{\dots}{ Additional arguments to \code{\link{network.collapse}} (such as \code{rule},\code{active.default},\code{retain.all.vertices}) } 36 | } 37 | 38 | 39 | 40 | \details{ 41 | The sampling ("slicing") intervals may be defined using either the \code{start}, \code{end}, and \code{time.increment} parameters, or by providing parallel vectors of \code{onsets} and \code{termini}. If values are not specefied but a \code{\link{net.obs.period}} attribute exists to describe the 'natural' sampling parameters, \code{start} and \code{end} will defult to the max an min of the observations element, with \code{time.increment} set to its corresponding value in the \code{net.obs.period}. 42 | } 43 | \value{ 44 | A \code{list} of static \code{network} objects corresponding to the specified sampling intervals of the \code{networkDynamic} 45 | } 46 | 47 | \author{ 48 | Kirk Li, Skye Bender-deMoll 49 | } 50 | \note{ 51 | See Note in \code{\link{network.collapse}}. 52 | } 53 | 54 | 55 | \seealso{ 56 | See Also as \code{\link{network.collapse}} for obtaining a slice of static network, \code{\link{network.extract}} for extracting sub-ranges of a networkDynamic, \code{\link{get.vertex.attribute.active}} for more on TEA attributes, and \code{\link{as.network.networkDynamic}} for stripping the the networkDynamic class from an object. 57 | } 58 | \examples{ 59 | # create a networkDynamic with some basic activity and time extended attributes (TEA) 60 | test <- network.initialize(5) 61 | add.edges.active(test, tail=c(1,2,3), head=c(2,3,4),onset=0,terminus=1) 62 | activate.edges(test,onset=3,terminus=5) 63 | activate.edges(test,onset=-2,terminus=-1) 64 | activate.edge.attribute(test,'weight',5,onset=3,terminus=4) 65 | activate.edge.attribute(test,'weight',3,onset=4,terminus=5,e=1:2) 66 | 67 | # obtain the list of networks 68 | list <- get.networks(test,start=0, end=5) 69 | 70 | # aggregate over a longer time period with specified rule 71 | list <- get.networks(test,start=0, end=6,time.increment=2,rule='latest') 72 | 73 | # use 'at' style extraction of momentary slices via onsets & termini 74 | list <- get.networks(test,onsets=0:5,termini=0:5) 75 | 76 | # ensure that all networks returned will be the same size 77 | list <- get.networks(test,onsets=0:5,termini=0:5,retain.all.vertices=TRUE) 78 | 79 | 80 | # find out how many edges in each sampling point with apply 81 | sapply(get.networks(test,start=0,end=5),network.edgecount) 82 | 83 | # generate a list of matrices 84 | lapply(get.networks(test,start=0,end=5),as.matrix) 85 | 86 | 87 | } -------------------------------------------------------------------------------- /man/get.timing.info.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/delete.activity.matrices.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{get.timing.info} 11 | \alias{get.change.times} 12 | \alias{get.edge.activity} 13 | \alias{get.vertex.activity} 14 | \title{ Retrieve the timing information present in a networkDynamic. } 15 | \description{ 16 | These methods return either the activity spells of each vertex or edge 17 | or the unique time points at which edges and vertices become active or 18 | inactive. 19 | 20 | Finds all of the unique time points at which the edges and/or vertices 21 | become active or inactive. 22 | } 23 | \usage{ 24 | get.change.times(x, vertex.activity=TRUE, edge.activity=TRUE, ignore.inf=TRUE, 25 | vertex.attribute.activity = TRUE, edge.attribute.activity = TRUE, 26 | network.attribute.activity = TRUE) 27 | get.vertex.activity(x, v=seq_len(network.size(x)), 28 | as.spellList=FALSE, active.default=TRUE) 29 | get.edge.activity(x, e=seq_along(x$mel), as.spellList=FALSE, active.default=TRUE) 30 | } 31 | \arguments{ 32 | \item{x}{ an object, of class \code{network} or \code{networkDynamic}. } 33 | \item{vertex.activity}{ logical, whether the times at which vertices become 34 | active or inactive is to be returned. } 35 | \item{edge.activity}{ logical, whether the times at which edges become 36 | active or inactive is to be returned. } 37 | \item{vertex.attribute.activity}{logical, whether the times attached to any dynamic vertex attributes should be returned} 38 | \item{edge.attribute.activity}{logical, whether the times attached to any dynamic edge attributes should be returned} 39 | \item{network.attribute.activity}{logical, whether the times attached to any dynamic network attributes should be returned} 40 | \item{ignore.inf}{logical, whether Inf value will be ignored or not. } 41 | \item{e}{ IDs for the edges whose activity spells are wanted. } 42 | \item{v}{ IDs for the vertices whose activity spells are wanted. } 43 | \item{as.spellList}{should data be returned in spell matrix form? TODO: should this be callsed as.spellmatrix instead?} 44 | \item{active.default}{logical, should edges / vertices with no spell activity defined be treated as always active (\code{TRUE}) and included in output, or never active (\code{FALSE}) and skipped.} 45 | } 46 | \value{ 47 | For the \code{get.change.times} function, the default settings return a 48 | vector of all of the finite time points at which any edge or any 49 | vertex becomes active or inactive, or any of their dynamic attributes change. If only one of the logical 50 | arguments, say \code{vertex.activity}, is set to \code{FALSE}, then 51 | the time points for the corresponding parts of the data structure will not be returned. If both are 52 | \code{FALSE}, numeric(0) is returned. 53 | 54 | 55 | For the \code{get.vertex.activity} and \code{get.edge.activity} functions, a list 56 | of activity spells is returned with each list element corresponding to the id of the vertex or edge. Deleted edges will appear as NULL entries, as will any spell marked as inactive with the 'null' (Inf,Inf) spell. If the argument \code{as.spellList=TRUE} the activity spells are instead formatted as a \code{data.frame} and include additional columns to indicate possible onset- and terminus-censoring. Any 'null' spells and deleted edges will be omited. 57 | 58 | For \code{get.vertex.activity} the columns are \code{[onset,terminus,vertex.id,onset.censored,terminus.censored,duration]}. 59 | 60 | For \code{get.edge.activity} the columns are \code{[onset, terminus, tail, head, onset.censored, terminus.censored, duration, edge.id] }. 61 | 62 | The data.frames will be sorted by id, onset, terminus. 63 | 64 | If a \code{net.obs.period} network attribute is set, the range of its \code{$observations} element is substituted in for the -Inf and Inf values that otherwise indicate the onset- and terminus-censored observations. 65 | } 66 | 67 | %\references{ ~put references to the literature/web site here ~ } 68 | \author{ Ayn Leslie-Cook \email{aynlc3@uw.edu}, Carter T. Butts \email{buttsc@uci.edu},skyebend } 69 | %\note{ ~~further notes~~ 70 | % 71 | % ~Make other sections like Warning with \section{Warning }{....} ~ 72 | %} 73 | \seealso{ See also \code{\link{activity.attribute}},\code{\link{net.obs.period}},\code{\link{as.data.frame.networkDynamic}} } 74 | \examples{ 75 | library(networkDynamic) 76 | data(flo) 77 | net1 <- network(flo) 78 | activate.edges(net1, onset=1:20, terminus=101:120) 79 | activate.vertices(net1, at=seq(2,32,2)) 80 | get.change.times(net1) 81 | get.edge.activity(net1) 82 | get.edge.activity(net1,as.spellList=TRUE) 83 | get.vertex.activity(net1) 84 | 85 | a <-network.initialize(5) 86 | activate.vertices(a,onset=0,terminus=Inf) 87 | get.change.times(a,ignore.inf=FALSE) 88 | 89 | 90 | } 91 | 92 | -------------------------------------------------------------------------------- /man/is.active.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynic/man/is.active.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{is.active} 11 | \alias{is.active} 12 | %- Also NEED an '\alias' for EACH other topic documented here. 13 | \title{ Determine Activation State of Edges and Vertices } 14 | \description{ 15 | Query the activity state of one or more network elements (edges or vertices) for either a single time point or an extended interval. 16 | } 17 | \usage{ 18 | is.active(x, onset = NULL, terminus = NULL, length = NULL, at = NULL, e = NULL, v = NULL, 19 | rule = c("any", "all","earliest","latest"), active.default = TRUE) 20 | } 21 | %- maybe also 'usage' for other objects documented here. 22 | \arguments{ 23 | \item{x}{ an object of class \code{\link[network]{network}}. } 24 | \item{onset}{ an optional vector of timepoints that specifies the start of the queried interval(s). This must be accompanied by one of \code{terminus} or \code{length}. } 25 | \item{terminus}{ an optional vector of timepoints that specifies the end of the queried interval(s). This must be accompanied by one of \code{onset} or \code{length}. } 26 | \item{length}{ an optional vector of interval lengths for the queried interval(s). This must be 27 | accompanied by one of \code{onset} or \code{terminus}. } 28 | \item{at}{ an optional vector of single time point(s) to query. } 29 | \item{e}{ a vector of edge IDs to evaluate. } 30 | \item{v}{ a vector of vertex IDs to evaluate. } 31 | \item{rule}{ a character string indicating the definition of "active" for this query: \code{any} (default) to define active as any active spell during the interval, or \code{all} to define active as being active over the entire interval. Because we are only testing for activity, the values of \code{earliest} and \code{latest} are equivilent to \code{any} and are only included for compatibility with calling functions. } 32 | \item{active.default}{logical; should elements without an activity attribute be regarded as active by default? } 33 | } 34 | \details{ 35 | This function can be used to query the activity status of an element at single time point, or over an interval. 36 | The specification of timepoints and intervals is the same as for the \code{\link{activate}} function. 37 | The general rules are discussed in \code{\link{activity.attribute}}. 38 | 39 | To query status at a single time point, use one of the following: 40 | \itemize{ 41 | \item the \code{at} argument, or 42 | \item set \code{onset=terminus}. 43 | } 44 | 45 | To query status over a particular interval, one of the following valid combinations of \code{onset}, \code{terminus} and \code{length} is required: 46 | \itemize{ 47 | \item \code{onset} and \code{terminus}. 48 | \item \code{onset} and \code{length}. 49 | \item \code{terminus} and \code{length}. 50 | \item or, you can specify no information. 51 | } 52 | 53 | If the query is specified with no timing information the spell is defined as \code{(-Inf,Inf)}. 54 | The query interval spans the period from the onset (inclusive) to the terminus (exclusive), so [onset,terminus). 55 | 56 | There are some special behaviors associated with the arguments \code{Inf} and \code{-Inf}. 57 | \itemize{ 58 | \item The open-ended interval \code{c(-Inf,x)} includes \code{-Inf}. For consistency, we also allow the open-ended interval \code{c(x, Inf)} to include \code{Inf}. 59 | Thus [onset, terminus) will be interpreted as [onset, terminus] when terminus = \code{Inf}. 60 | \item Queries for intervals specified by \code{c(Inf, Inf)} or \code{c(-Inf, -Inf)} are ignored. 61 | } 62 | 63 | If the \code{e} argument includes edge ids corresponding to deleted edges, a warning will be generated because the length of the output vector will not match the vector of edge ids. In this case it is a good idea to use \code{\link[network]{valid.eids}} to determine the edge ids. 64 | } 65 | \value{ 66 | A logical vector indicating the activity states of vertices or edges. In the case of vertices, the elements of the vector correspond to the vertex ids provided via the \code{v} paramter. In the edges case, if the network has deleted edges, they will be omited from the result so the elements of the vector may not correspond to the eids provided via the \code{e} parameter. 67 | } 68 | %\references{ ~put references to the literature/web site here ~ } 69 | \author{ Ayn Leslie-Cook \email{aynlc3@uw.edu}, Carter T. Butts \email{buttsc@uci.edu} } 70 | %\note{ ~~further notes~~ 71 | % 72 | % ~Make other sections like Warning with \section{Warning }{....} ~ 73 | %} 74 | \seealso{ \code{\link{activity.attribute}}, \code{\link{activate}}, \code{\link[network]{valid.eids}} } 75 | \examples{ 76 | triangle <- network.initialize(3) # create a toy network 77 | add.edge(triangle,1,2) # add an edge between vertices 1 and 2 78 | add.edge(triangle,2,3) # add more edges 79 | add.edge(triangle,3,1) 80 | 81 | # turn on all edges at time 1 only (0 length spell) 82 | activate.edges(triangle,at=1) 83 | # activate edge (1,2) from t=2 to t=3 84 | activate.edges(triangle,onset=2, terminus=3, 85 | e=get.edgeIDs(triangle,v=1,alter=2)) 86 | # activate edge (2,3) from t=4 for 2 time lengths 87 | activate.edges(triangle,onset=4, length=2, 88 | e=get.edgeIDs(triangle,v=2,alter=3)) 89 | 90 | # are the edges active at a particular time? 91 | is.active(triangle, at=1, e=1:3) 92 | is.active(triangle, at=4, e=seq_along(triangle$mel)) 93 | 94 | # delete an edge 95 | delete.edges(triangle,e=2) 96 | is.active(triangle, at=4, e=seq_along(triangle$mel)) 97 | # gives warning, and only two values returned, which edges are they? 98 | # much safer to use 99 | is.active(triangle, at=4, e=valid.eids(triangle)) 100 | 101 | 102 | 103 | } 104 | -------------------------------------------------------------------------------- /man/nd_test_nets.Rd: -------------------------------------------------------------------------------- 1 | \name{nd_test_nets} 2 | \alias{nd_test_nets} 3 | \docType{data} 4 | \title{ 5 | networkDynamic testing networks 6 | } 7 | \description{ 8 | A list of \code{\link{networkDynamic}} objects to be used for testing package functions. Each network exemplifies a possible extreme case for the data structure representation. 9 | } 10 | \usage{data(nd_test_nets)} 11 | \format{ 12 | A list of \code{\link{networkDynamic}} objects. Each element is named with a short description 13 | } 14 | \details{ 15 | This list of networks is intended for testing purposes. Each element is a network with a different unusual configuration of the \code{\link{networkDynamic}} data structure. The idea is that the items on the list can be used when testing functions that use \code{networkDynamic} objects to make sure that they can properly handle (or explicitly reject) a wide range of network configurations and parameter settings. A short description of each test case can be printed with \code{names(nd_test_nets)}. Note that these test cases are intended for checking that functions process the data structures without error, but in most cases the networks are too trivial to be useful in testing algorithm results. 16 | 17 | } 18 | 19 | \examples{ 20 | 21 | data(nd_test_nets) 22 | # print the list of test cases 23 | names(nd_test_nets) 24 | # check that network.size.active works 25 | # (or at least doesn't fail) 26 | # for many types of networks 27 | lapply(nd_test_nets,network.size.active,at=1) 28 | 29 | } 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /man/net.obs.period.Rd: -------------------------------------------------------------------------------- 1 | % Part of the statnet package, http://statnetproject.org 2 | % 3 | % This software is distributed under the GPL-3 license. It is free, 4 | % open source, and has the attribution requirements (GPL Section 7) in 5 | % http://statnetproject.org/attribution 6 | % 7 | % Copyright 2013 the statnet development team 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | \name{net.obs.period} 10 | \alias{net.obs.period} 11 | \docType{data} 12 | \title{ 13 | Network attribute describing the observation properties of a networkDynamic object 14 | } 15 | \description{ 16 | \code{net.obs.period} is an optional network-level attribute that gives meta-information about the characteristics of the observations, time range and temporal model of a \code{networkDynamic} object. 17 | } 18 | \format{ 19 | If the attribute is present, it is required to have a specific structure. It is a 4-element \code{list} with named values. 20 | \itemize{ 21 | \item the \code{observations} element is a list of two-elment spell vectors that give the onset and terminus of the time period(s) during which the network was observed or simulated 22 | \item \code{mode} A string indicating the temporal model of the network: either \code{discrete} or \code{continuous} 23 | \item \code{time.increment} is an indicator of the `natural' time unit for iterating over the network (primarily useful for discrete time models) 24 | \item \code{time.unit} is the name of the unit used by all of the spells in the object: often set to \code{step} for discrete simulations. 25 | 26 | } 27 | } 28 | \details{ 29 | Some functions that work with \code{networkDynamic} objects need to know information about the observation design of the network. Is it discrete or continuous time model? When did the observation (or simulation) of the network processes start and end? What are the time units? This information may be stored in the \emph{optional} \code{net.obs.period} network attribute. 30 | 31 | Some examples of possible \code{net.obs.period} values for various networks: 32 | \itemize{ 33 | \item for an stergm output it might be: 34 | \code{list(observations=list(c(0,100)),mode="discrete", time.increment=1,time.unit="step")} 35 | \item For Lin's windsurfers , which is missing all observations on day 25: 36 | \code{list(observations=list(c(0,25),c(26,31)),mode="discrete", time.increment=1,time.unit="day")} 37 | 38 | \item For McFarland's classroom data: 39 | \code{list(observations=list(c(0,55),),mode="continuous", time.increment=NA,time.unit="minute")} 40 | 41 | \item A fictitious instantaneous panel example : 42 | \code{list(observations=list(c(0,0),c(21,21),c(56.5,56.5),c(68,68)),mode="discrete", time.increment=0,time.unit="seconds")} 43 | 44 | The values of the \code{net.obs.period} object are not checked for consistency with activity spells of the network itself. 45 | 46 | } 47 | 48 | 49 | 50 | } 51 | \seealso{ 52 | Several of the \code{\link{networkDynamic}} converter functions set the \code{net.obs.period} attribute on their output object. See also \code{\link{activity.attribute}} 53 | } 54 | \references{ 55 | Link to page on statnet wiki? 56 | } 57 | 58 | \examples{ 59 | nd<-network.initialize(5) 60 | activate.vertices(nd,onset=0,terminus=100) 61 | set.network.attribute(nd,'net.obs.period',list(observations=list(c(0,100)), 62 | mode="discrete", time.increment=1,time.unit="step")) 63 | # find the overall `expected' time range for the object 64 | range(get.network.attribute(nd,'net.obs.period')$observations) 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /man/network.collapse.Rd: -------------------------------------------------------------------------------- 1 | % Part of the statnet package, http://statnetproject.org 2 | % 3 | % This software is distributed under the GPL-3 license. It is free, 4 | % open source, and has the attribution requirements (GPL Section 7) in 5 | % http://statnetproject.org/attribution 6 | % 7 | % Copyright 2013 the statnet development team 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | \name{network.collapse} 10 | \alias{network.collapse} 11 | \alias{\%k\%} 12 | \title{ 13 | Convert a time range of a networkDynamic object into a static network object. 14 | } 15 | \description{ 16 | This function provides an easy way to sensibly collapse the time-related information in a \code{networkDynamic} object and return a plain \code{network} object with a set of vertices, edges, and attributes that appropriately correspond to those appearing in the original \code{networkDynamic} object during the query interval. 17 | } 18 | \usage{ 19 | network.collapse(dnet, onset = NULL, terminus = NULL, at = NULL, length = NULL, 20 | rule = c("any", "all","earliest","latest"), active.default = TRUE, 21 | retain.all.vertices=FALSE, rm.time.info=TRUE, ...) 22 | dnet\%k\%at 23 | } 24 | %- maybe also 'usage' for other objects documented here. 25 | \arguments{ 26 | \item{dnet}{ 27 | A \code{networkDynamic} object with possible vertex, edge, network, and attribute spell information. 28 | } 29 | \item{onset}{ optionally, the start of the specified interval. This must be accompanied by one of \code{terminus} or \code{length}. 30 | } 31 | 32 | \item{terminus}{ optionally, the end of the specified interval. This must be accompanied by one of \code{onset} or \code{length}. 33 | } 34 | \item{length}{ optionally, the length of the specified interval. This must be accompanied by one of \code{onset} or \code{terminus}. 35 | } 36 | \item{at}{ optionally, a single time point.} 37 | \item{rule}{ a text string for defining \dQuote{active} for this call: \code{any} if elements active at any time during the interval are to be used, or \code{all} if elements must be active over the entire interval. The value \code{earliest} behaves like \code{any} but specifies that when multiple attribute values are encountered, only the earliest will be returned. The value \code{latest} behaves like \code{any} but specifies that when multiple attribute values are encountered, only the latest will be returned. } 38 | \item{active.default}{ logical; should elements without an activity attribute be regarded as active by default?} 39 | \item{retain.all.vertices}{ logical; should the extracted network retain all vertices, ignoring the vertex activity spells of x in order to ensure that the network returned has the same size as dnet?} 40 | \item{rm.time.info}{logical; if \code{TRUE}, the \code{\link{net.obs.period}} attribute will be removed (if it exists), and the activity summary attributes \code{activity.count} and \code{activity.duration} will not be attached to edges and vertices} 41 | \item{\dots}{ Possible additional arguments (not yet invented) to handle aggregation of attributes. } 42 | } 43 | 44 | \details{ 45 | First performs a \code{\link{network.extract}} on the passed networkDynamic object with the specified time range to get the appropriate set of active edges. Extracts appropriate values from any dynamic attributes and stores them as static attributes and optionally (if \code{rm.time.info=FALSE}) computes some crude summary attributes for edge and vertex spells (\code{activity.count}, \code{activity.duration}),. Then removes all \code{\link{activity.attribute}} and \code{\link{dynamic.attributes}} information and returns a plain network without the \code{networkDynamic} class. 46 | 47 | 48 | The \code{\%k\%} operator (`K' for kollapse) is a shortcut for the 'at' version of \code{network.collapse}. 49 | 50 | If no temporal arguments are specified, defaults to collapsing entire time range of the input network (\code{onset=-Inf,terminus=Inf}). Original network is not modified. 51 | 52 | Arbitrary attribute values may be returned when query spells with a duration are used for continuous time networks (i.e. anything other than 'at') or query spells that don't line up with the discrete units for discrete time networks are used. If a query spell intersects with multiple attribute values, a warning will be produced and only the earliest value will be used (see \code{\link{get.vertex.attribute.active}}). To avoid ambiguity (and the warning), appropriate handling can be specified by setting \code{rule='earliest'} or \code{rule='latest'} to indicate which of the multiple values should be returned. 53 | 54 | The duration values returned for edges do not account for any potential `censoring' of observations in the original network. 55 | 56 | } 57 | \value{ 58 | A new 'static' \code{network} object corresponding to the specified time range of the \code{networkDynamic} argument. If the original network contained dynamic TEA attributes (i.e. 'weight.active'), the appropriate (if possible) value is queried and stored as a non-TEA attribute ('weight'). 59 | } 60 | 61 | \author{ 62 | Skye Bender-deMoll 63 | } 64 | \note{ 65 | 66 | This function may be quite computationally expensive if the network contains lots of attributes. For many tasks it is possible to avoid collapsing the network by using \code{\link{is.active}}, the dynamic \code{\link{network.extensions}}, and the \code{\link{attribute.activity.functions}}. 67 | } 68 | 69 | 70 | \seealso{ 71 | See also \code{\link{network.extract}} for extracting sub-ranges of a networkDynamic, \code{\link{get.vertex.attribute.active}} for more on TEA attributes, and \code{\link{as.network.networkDynamic}} for stripping the the networkDynamic class from an object without the expense of modifying or removing the activity attributes. 72 | } 73 | \examples{ 74 | # create a network with some basic activity 75 | test<-network.initialize(5) 76 | add.edges.active(test, tail=c(1,2,3), head=c(2,3,4),onset=0,terminus=1) 77 | activate.edges(test,onset=3,terminus=5) 78 | activate.edges(test,onset=-2,terminus=-1) 79 | 80 | # collapse the whole thing 81 | net <-network.collapse(test) 82 | is.networkDynamic(net) 83 | get.vertex.attribute(net,'activity.duration') 84 | get.edge.value(net,'activity.count') 85 | get.edge.value(net,'activity.duration') 86 | 87 | # add a dynamic edge attribute 88 | activate.edge.attribute(test,'weight',5,onset=3,terminus=4) 89 | activate.edge.attribute(test,'weight',3,onset=4,terminus=5) 90 | 91 | # collapse with an interval query 92 | net3<-network.collapse(test,onset=3,terminus=4) 93 | get.edge.value(net3,'weight') 94 | 95 | # note that if we use a query that intersects mutiple 96 | # attribute values it will generate a warning. 97 | # try commented line below: 98 | 99 | # net3<-network.collapse(test,onset=3,terminus=5) 100 | 101 | # but should be safe from attribute issues when 102 | # collapsing with a point query 103 | net3<-network.collapse(test,at=3) 104 | get.edge.value(net3,'weight') 105 | 106 | # can use operator version for point query instead 107 | net3<-test\%k\%4.5 108 | get.edge.value(net3,'weight') 109 | 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /man/network.dynamic.check.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/network.dynamic.check.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{network.dynamic.check} 11 | \alias{network.dynamic.check} 12 | \alias{is.networkDynamic} 13 | %- Also NEED an '\alias' for EACH other topic documented here. 14 | \title{ Verify a Dynamically Extended Network Object } 15 | \description{ 16 | Checks a networkDynamic object for any activity information that is not correctly specified. 17 | } 18 | \usage{ 19 | network.dynamic.check(x, verbose = TRUE, complete = TRUE) 20 | is.networkDynamic(x) 21 | 22 | } 23 | %- maybe also 'usage' for other objects documented here. 24 | \arguments{ 25 | \item{x}{ an object, hopefully of class \code{networkDynamic}. } 26 | \item{verbose}{ logical; should output messages be printed to the 27 | user? } 28 | \item{complete}{ logical; should a complete test be ran, including 29 | checks of the activity matrices for edges and vertices, versus a 30 | check of only edge activity invovling non-active vertices} 31 | } 32 | \details{ 33 | Currently, \code{network.dynamic.check} runs three types of checks on an input object: 34 | \enumerate{ 35 | \item{If a complete test is run, vertex spell matrices and edge spell 36 | matrices (if any) are checked for legality, specifically these are 37 | checked for correct dimensionality and proper spell ordering.} 38 | \item{If vertex and edge spell matrices are correctly specified or 39 | assumed to be using \code{complete=FALSE}, incident vertices of 40 | active edges (if any) are checked to ensure that they are also 41 | active during the specified period(s).} 42 | \item{If a complete test is run, and any TEA attributes are attached to the network, vertices or edges, they will be checked for correct structure.} 43 | } 44 | If spell matrices are only acted upon by network or 45 | networkDynamic methods, there is no need to run a complete test - 46 | correct dimensionality and spell ordering are guaranteed. 47 | 48 | \code{is.networkDynamic} checks if its argument has the class 'networkDynamic'. 49 | } 50 | \value{ 51 | For \code{network.dynamic.check}: A list of logical vectors, one for 52 | each network component checked: 53 | \itemize{ 54 | \item{\code{$vertex.checks} : Whether the spell matrix of each vertex (if any) 55 | is correctly specified} 56 | \item{\code{$edge.checks} : Whether the spell matrix of each edge (if any) 57 | is correctly specified} 58 | \item{\code{$dyad.checks} : Corresponding to edges, whether the incident vertices 59 | of each edge are active when the edge is active} 60 | \item{\code{$vertex.tea.checks} : Corresponding to vertices, whether the vertex has 61 | correctly formed TEA attributes} 62 | \item{\code{$edge.tea.checks} : Corresponding to edges, whether the edge has 63 | correctly formed TEA attributes} 64 | \item{\code{$network.tea.checks} : Single boolean, whether the network TEA attributes are formed correctly} 65 | \item{\code{$net.obs.period.check} : NULL, if no \code{net.obs.period} network attribute is present, otherwise a single boolean, whether the attribute is formed correctly. } 66 | 67 | } 68 | For \code{is.networkDynamic}: a boolean which is true if the class matches 69 | } 70 | %\references{ ~put references to the literature/web site here ~ } 71 | \author{ Ayn Leslie-Cook \email{aynlc3@uw.edu}, Carter T. Butts \email{buttsc@uci.edu}, Skye Bender-deMoll } 72 | %\note{ ~~further notes~~ 73 | % 74 | % ~Make other sections like Warning with \section{Warning }{....} ~ 75 | %} 76 | \seealso{ \code{\link{activity.attribute}}, \code{\link{net.obs.period}} } 77 | \examples{ 78 | test <-network.initialize(2) # make a network 79 | # only activate one vertex 80 | activate.vertices(test,onset=2,length=5,v=1) 81 | test[1,2] <-1 # add an edge between the verticies 82 | # activate the edge for a spell not including vertex spell 83 | activate.edges(test,onset=0,terminus=7, e=1) 84 | network.dynamic.check(test) # find the bad edge 85 | 86 | # name a vertex attrible like a TEA but with the wrong structure 87 | set.vertex.attribute(test,'letters','a') 88 | network.dynamic.check(test) 89 | } 90 | % Add one or more standard keywords, see file 'KEYWORDS' in the 91 | % R documentation directory. 92 | \keyword{ manip } 93 | \keyword{ graphs }% __ONLY ONE__ keyword per line 94 | -------------------------------------------------------------------------------- /man/network.extract.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/network.extract.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{network.extract} 11 | \alias{network.extract} 12 | \alias{\%t\%} 13 | %- Also NEED an '\alias' for EACH other topic documented here. 14 | \title{ Temporal Extracts/Cross-sections of Dynamically Extended Network Objects } 15 | \description{ 16 | Given a networkDynamic and a specified time point (or interval), return a reduced networkDynamic that only contains the vertices and edges active at the given point or over the given interval. 17 | } 18 | \usage{ 19 | network.extract(x, onset = NULL, terminus = NULL, length = NULL, at = NULL, 20 | rule = c("any", "all"), active.default = TRUE, retain.all.vertices = FALSE, 21 | trim.spells=FALSE) 22 | 23 | x \%t\% at 24 | } 25 | %- maybe also 'usage' for other objects documented here. 26 | \arguments{ 27 | \item{x}{ an object of class \code{\link[network]{network}}. } 28 | \item{onset}{ optionally, the start of the specified interval. This must be accompanied by one of \code{terminus} or \code{length}.} 29 | \item{terminus}{ optionally, the end of the specified interval. This must be accompanied by one of \code{onset} or \code{length}.} 30 | \item{length}{ optionally, the length of the specified interval. This must be accompanied by one of \code{onset} or \code{terminus}.} 31 | \item{at}{ optionally, a single time point.} 32 | \item{rule}{ a text string for defining \dQuote{active} for this call: \code{any} if elements active at any time during the interval are to be used, or \code{all} if elements must be active over the entire interval. } 33 | \item{active.default}{ logical; should elements without an activity attribute be regarded as active by default? } 34 | \item{retain.all.vertices}{ logical; should the extracted network retain all vertices, ignoring the vertex activity spells of x in order to ensure that the network returned has the same size as x?} 35 | \item{trim.spells}{ logical; should the spells of vertices, edges and their attributes in the extracted network be trimmed to match the query range? (Sensible thing to do, but could be expensive)} 36 | } 37 | \details{ 38 | For the purposes of extraction, edges are only considered active over some interval if: the edge itself is active over this time period, and both of the incident vertices are also active over the given time period. 39 | 40 | When \code{retain.all.vertices=FALSE} (the default), the function has the following behavior: 41 | \itemize{ 42 | \item If \code{at} is used to specify the spell of interest, the returned network consists of all edges and vertices 43 | active at that time point. 44 | \item If an interval is supplied to specify the spell (via \code{onset} and one of \code{terminus} or \code{length}), edges and vertices active 45 | over the specified interval are used. If \code{rule="any"}, then edges and vertices active at any time during the interval are returned; otherwise, only those active during the entire period are returned. 46 | } 47 | Vertices in the extracted network will have the same order as the original network, with inactive vertices removed. 48 | 49 | When \code{retain.all.vertices=TRUE} 50 | \itemize{ 51 | \item{All vertices are preserved in the output net to preserved network size and ids.} 52 | \item{if \code{trim.spells=TRUE}, 'retained' vertices will be marked as inactive (they will have 'null' spell (Inf,Inf)) } 53 | \item{Edges that are active (by the specified \code{rule}) during the specified spell are included in the returned network (same as above.)} 54 | \item{Edges with one or more inactive vertices still will be removed (even if the vertex is being 'retained' to preserve network size)} 55 | 56 | } 57 | 58 | If a \code{\link{net.obs.period}} network attribute is present, its observation spells will be truncated by the onset and terminus of extraction. If the onset and terminus do not intersect with any observation spells, the `$observations` component will be set to the `null` spell \code{c(Inf,Inf)}. 59 | 60 | \code{\%t\%} (the temporal cross-section operator) is a 61 | simplified (and less flexible) wrapper for \code{network.extract} that 62 | returns the network of active vertices and edges at a given time point. 63 | 64 | } 65 | \value{ 66 | A \code{networkDynamic} object containing the active edges and vertices for the specified spell, when \code{retain.all.vertices=FALSE}, otherwise the network object containing all vertices, and only those edges active for the specified spell. 67 | } 68 | 69 | \note{ 70 | Note that only active vertices are included by default (\code{retain.all.vertices=FALSE}). As a result, the size of the extracted network may be smaller than the original. Vertex and edge ids will be translated, but may not correspond to their original values. If it is necessary to maintain the identities of vertices, see \code{\link{persistent.ids}}. 71 | } 72 | %\references{ ~put references to the literature/web site here ~ } 73 | \author{ Carter T. Butts \email{buttsc@uci.edu}, skyebend} 74 | %\note{ ~~further notes~~ 75 | % 76 | % ~Make other sections like Warning with \section{Warning }{....} ~ 77 | %} 78 | \seealso{ \code{\link{is.active}}, \code{\link{activity.attribute}}, \code{\link{network.extensions}}, and \code{\link[network:get.inducedSubgraph]{get.inducedSubgraph}} for a related non-temporal version, \code{\link{network.collapse}} to squish a \code{networkDynamic} object into a static \code{network}} 79 | \examples{ 80 | 81 | triangle <- network.initialize(3) # create a toy network 82 | 83 | # add edges with activity 84 | # first add an edge between vertices 1 and 2 85 | add.edges.active(triangle,onset=0,terminus=10,tail=1,head=2) 86 | # add a more edges 87 | add.edges.active(triangle,onset=0,length=4,tail=2,head=3) 88 | add.edges.active(triangle,at=4.5,tail=3,head=1) 89 | 90 | # specify some vertex activity 91 | activate.vertices(triangle,onset=0,terminus=10) 92 | deactivate.vertices(triangle,onset=1,terminus=2,v=3) 93 | 94 | degree<-function(x){as.vector(rowSums(as.matrix(x)) 95 | + colSums(as.matrix(x)))} # handmade degree function 96 | 97 | degree(triangle) # degree of each vertex, ignoring time 98 | 99 | degree(network.extract(triangle,at=0)) 100 | degree(network.extract(triangle,at=1)) # just look at t=1 101 | degree(network.extract(triangle,at=2)) 102 | degree(network.extract(triangle,at=5)) 103 | 104 | # watch out for empty networks! they are just an empty list 105 | t10 <- network.extract(triangle,at=10) 106 | t10 107 | 108 | # notice difference between 'at' syntax and 'onset,terminus' 109 | # when network is not in discrete time 110 | degree(network.extract(triangle,at=4)) 111 | degree(network.extract(triangle,onset=4,terminus=5)) 112 | 113 | # the \%t\% (time) operator is like an alias for the 'at' extraction syntax 114 | degree(triangle\%t\%4) 115 | 116 | par(mfrow=c(2,2)) 117 | #show multiple plots 118 | plot(triangle,main='ignoring dynamics',displaylabels=TRUE) 119 | plot(network.extract(triangle,onset=1,terminus=2),main='at time 1',displaylabels=TRUE) 120 | plot(network.extract(triangle,onset=2,terminus=3),main='at time 2',displaylabels=TRUE) 121 | plot(network.extract(triangle,onset=5,terminus=6),main='at time 5',displaylabels=TRUE) 122 | 123 | } 124 | 125 | -------------------------------------------------------------------------------- /man/networkDynamic-internal.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/networkDynamic-internal.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{networkDynamic-internal} 11 | \title{Internal networkDynamic objects} 12 | \alias{.First.lib} 13 | \alias{insert.spell} 14 | \alias{delete.spell} 15 | \description{Internal networkDynamic objects.} 16 | \details{These are not to be called by the user.} 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/networkDynamic-package.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/networkDynamic-package.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{networkDynamic-package} 11 | \alias{networkDynamic-package} 12 | \docType{package} 13 | \title{ 14 | Dynamic Extensions for Network Objects 15 | } 16 | \description{ 17 | Simple interface routines to facilitate the handling of dynamic network objects with different types of temporal data. This allows the user to create, store and query networks that change over time. Changes include edges that form and dissolve over time, and vertices that enter or leave the network. The package also includes support for defining and querying temporally changing attributes of vertices, edges, and network properties. 18 | } 19 | \details{ 20 | \tabular{ll}{ 21 | Package: \tab networkDynamic\cr 22 | Type: \tab Package\cr 23 | Version: \tab 0.7\cr 24 | Date: \tab 2014-09-25\cr 25 | Depends: \tab network\cr 26 | License: \tab GPL-3\cr 27 | LazyLoad: \tab yes\cr 28 | } 29 | 30 | The \code{networkDynamic} package provides support for a simple family of dynamic extensions to the \code{\link[network]{network}} class; these employ the standard \code{network} attribute functionality (and hence the resulting objects are still compatible with all conventional routines), but greatly facilitate the practical storage, manipulation and query of dynamic network data. 31 | 32 | The basis for the dynamic extensions is described in \link{activity.attribute}. Dynamic attributese are explained in \link{attribute.activity.functions}. Id systems which are persistent throughout manipulations and changes in network size are explained in \link{persistent.ids}. Other core routines can be found in the links below. 33 | 34 | Additional example data sets can be found in the \code{networkDynamicData} package. 35 | } 36 | \author{ 37 | Originally created by Carter T. Butts \email{buttsc@uci.edu}, 38 | 39 | Current Maintainer: Skye Bender-deMoll \email{skyebend@uw.edu} 40 | 41 | Contributions from: 42 | Pavel Krivitsky \email{pavel@uow.edu.au}, 43 | Ayn Leslie-Cook \email{aynlc3@uw.edu}, 44 | David Hunter \email{dhunter@stat.psu.edu}, 45 | Li Wang \email{lxwang@gmail.com}, 46 | Kirk Li \email{kirkli@uw.edu}, 47 | StevenGoodreau \email{goodreau@uw.edu}, 48 | Zack Almquist \email{almquist@uci.edu}, 49 | Jeffrey Horner \email{jeffrey.horner@gmail.com}, 50 | Martina Morris \email{morrism@u.washington.edu}, 51 | Michal Bojanowski \email{michal2992@gmail.com} 52 | 53 | With support from the statnet team \url{https://statnet.org} 54 | 55 | 56 | 57 | } 58 | %\references{ 59 | %~~ Literature or other references for background information ~~ 60 | %} 61 | %~~ Optionally other standard keywords, one per line, from file KEYWORDS in ~~ 62 | %~~ the R documentation directory ~~ 63 | \keyword{ package } 64 | \seealso{ 65 | \code{\link{activity.attribute}}, \code{\link{activate}}, \code{\link{is.active}}, \code{\link{network.extract}}, \code{\link{network.extensions}} \code{\link[network]{network}} 66 | } 67 | %\examples{ 68 | %~~ simple examples of the most important functions ~~ 69 | %} 70 | -------------------------------------------------------------------------------- /man/print.networkDynamic.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/print.networkDynamic.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{print.networkDynamic} 11 | \alias{print.networkDynamic} 12 | %- Also NEED an '\alias' for EACH other topic documented here. 13 | \title{ 14 | Provide a view of a networkDynamic object including timing information 15 | } 16 | \description{ 17 | Prints out some very basic descriptive stats about the network's dynamics, and the the normal information printed for network objects. 18 | } 19 | \usage{ 20 | 21 | \method{print}{networkDynamic}(x, ...) 22 | } 23 | %- maybe also 'usage' for other objects documented here. 24 | \arguments{ 25 | \item{x}{ an object of class networkDynamic including dynamic relational information 26 | } 27 | \item{\dots}{ 28 | additional items to be passed for consideration by other classes 29 | } 30 | } 31 | \details{ 32 | Prints some info about the number of time events in a networkDynamic object, then calls print.network 33 | } 34 | \value{ 35 | Returns the networkDynamic object passed to the function. 36 | } 37 | 38 | \author{ 39 | Pavel 40 | } 41 | \note{ 42 | Only prints out the network information without any dynamic data. 43 | } 44 | 45 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 46 | 47 | \seealso{ 48 | \code{\link[network]{print.network}} 49 | } 50 | \examples{ 51 | library(networkDynamic) 52 | data(flo) 53 | net1 <- network(flo) 54 | activate.edges(net1, onset=1:20, terminus=101:120) 55 | activate.vertices(net1, at=seq(2,32,2)) 56 | print(net1) 57 | } 58 | 59 | -------------------------------------------------------------------------------- /man/read.son.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/read.son.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{read.son} 11 | \alias{read.son} 12 | %- Also NEED an '\alias' for EACH other topic documented here. 13 | \title{ 14 | Read .son-formatted (SoNIA) input files containing longitudinal network data and create a corresponding networkDynamic object 15 | } 16 | \description{ 17 | A .son file is a tab-separated text file with two sections, the first describing node attribute events and the second arc attribute events. Each section has a set of defined column names as a header. See the SoNIA file specification for more information: \url{https://sourceforge.net/p/sonia/wiki/Son_format/}. 18 | } 19 | \usage{ 20 | read.son(file, guess.TEA=TRUE) 21 | } 22 | %- maybe also 'usage' for other objects documented here. 23 | \arguments{ 24 | \item{file}{path to the file to be read} 25 | \item{guess.TEA}{logical: should the parser guess that non-changing attribute values are intended to be static instead of TEAs?} 26 | } 27 | \details{ 28 | Uses \code{\link{networkDynamic}} internally to build a dynamic network out of an array of vertex spells and an array of edge spells. Vertex and edge attributes will be attached, usually as TEA. However, If the values of an attribute never change, they will be attached as a static attribute. This is convenient but will be incorrect if a value was intended to be defined for only a single spell matching with the vertex activation. Setting \code{guess.TEA=FALSE} will force all attributes to be loaded as TEAs (slower). 29 | } 30 | \value{ 31 | A network dynamic object with vertex and edge durations and attributes corresponding the the spells defined in the input file. 32 | } 33 | \references{ 34 | \url{https://sourceforge.net/p/sonia/wiki/Son_format/}. 35 | } 36 | \author{ 37 | Skye Bender-deMoll 38 | } 39 | \note{ 40 | The current version of this function does not support reading clusters. 41 | } 42 | 43 | 44 | \seealso{ 45 | See Also \code{\link{networkDynamic}} 46 | } 47 | \examples{ 48 | classroom<-read.son(system.file('extdata/cls33_10_16_96.son',package='networkDynamic')) 49 | } 50 | 51 | % Add one or more standard keywords, see file 'KEYWORDS' in the 52 | % R documentation directory. 53 | \keyword{ graphs } 54 | \keyword{ utilities } 55 | \keyword{ IO } 56 | \keyword{ files } 57 | -------------------------------------------------------------------------------- /man/reconcile.activity.Rd: -------------------------------------------------------------------------------- 1 | % Part of the statnet package, http://statnetproject.org 2 | % 3 | % This software is distributed under the GPL-3 license. It is free, 4 | % open source, and has the attribution requirements (GPL Section 7) in 5 | % http://statnetproject.org/attribution 6 | % 7 | % Copyright 2013 the statnet development team 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | \name{reconcile.activity} 10 | \alias{reconcile.vertex.activity} 11 | \alias{reconcile.edge.activity} 12 | \alias{reconcile.activity} 13 | %- Also NEED an '\alias' for EACH other topic documented here. 14 | \title{ 15 | Modify the activity spells of vertices to match incident edges or the other way around 16 | } 17 | \description{ 18 | When networkDynamic objects are created from real-world data it is often the case that activity information for vertices and edges may not come from the same source and may not match up exactly. Vertices may be inactive when incident edges are active, etc. The \code{reconcile.vertex.activity} function modifies the activity of a network's vertices acording to the \code{mode} specified, while \code{reconcile.edge.activity} performs similar operations for edges. 19 | } 20 | \usage{ 21 | reconcile.vertex.activity(net, 22 | mode = c ("expand.to.edges", "match.to.edges", "encompass.edges"), 23 | edge.active.default = TRUE) 24 | 25 | reconcile.edge.activity(net, 26 | mode = c("match.to.vertices", "reduce.to.vertices"), 27 | active.default = TRUE) 28 | } 29 | %- maybe also 'usage' for other objects documented here. 30 | \arguments{ 31 | \item{net}{a \code{\link{networkDynamic}} object 32 | } 33 | \item{mode}{ string indicating the method for reconciling 34 | } 35 | \item{edge.active.default}{ 36 | boolean, should edges with no definied activity be considered active?} 37 | \item{active.default}{ 38 | boolean, should vertices with no definied activity be considered active? 39 | 40 | } 41 | } 42 | \details{ 43 | 44 | \itemize{ 45 | The \code{mode} argument takes the following values: 46 | \item \code{match.to.edges} vertices will be modified so as to be only active when incident edges are active. Existing vertex spells are deleted. 47 | \item \code{expand.to.edges} vertices activity will be expanded to include the activity periods of any incident edges (still permits isolated vertices). Existing vertex spells are preserved. 48 | \item \code{encompass.edges} vertices activity will be modified so that it has a single spell beginning with the earliest incident edge activity, and encompasses the last edge activity. (Note that this implies that isolated vertices will become inactive). 49 | 50 | \item \code{match.to.vertices} edges will be modified so as to be active whenever all incident vertices are active. Existing inactive edges will be activated if necessary. 51 | \item \code{reduce.to.vertices} edges will be modified so as to have no active spells when incident vertices are inactive. Inactive edges will not be activated. 52 | } 53 | 54 | } 55 | \value{ 56 | The input \code{networkDynamic} object is modified in place and returned invisibly. 57 | } 58 | 59 | \author{ 60 | skyebend, lxwang 61 | } 62 | 63 | 64 | 65 | \examples{ 66 | nd<-network.initialize(6) 67 | add.edges.active(nd,tail=1:3,head=2:4,onset=1,terminus=3) 68 | add.edges.active(nd,tail=4,head=1,onset=5,terminus=7) 69 | add.edge(nd,tail=1,head=6) 70 | # before 71 | get.vertex.activity(nd,as.spellList=TRUE) 72 | reconcile.vertex.activity(nd) 73 | # after 74 | get.vertex.activity(nd,as.spellList=TRUE) 75 | 76 | # induce edge activity for known vertex timing 77 | nd<-network.initialize(4,directed=FALSE) 78 | activate.vertices(nd,onset=1:4,terminus=3:6) 79 | nd[,]<-1 80 | get.edge.activity(nd,as.spellList=TRUE) 81 | reconcile.edge.activity(nd, mode="reduce.to.vertices") 82 | get.edge.activity(nd,as.spellList=TRUE) 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /man/spell_comparisons.Rd: -------------------------------------------------------------------------------- 1 | % Part of the statnet package, http://statnetproject.org 2 | % 3 | % This software is distributed under the GPL-3 license. It is free, 4 | % open source, and has the attribution requirements (GPL Section 7) in 5 | % http://statnetproject.org/attribution 6 | % 7 | % Copyright 2013 the statnet development team 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | \name{spells.overlap} 10 | \alias{spells.overlap} 11 | \alias{spells.hit} 12 | \alias{search.spell} 13 | %- Also NEED an '\alias' for EACH other topic documented here. 14 | \title{ 15 | Functions to compare and search spell intervals 16 | } 17 | \description{ 18 | spells.overlap checks if two spells overlap at all, spells.hit searches a spell matrix for an overlapping spell 19 | } 20 | \usage{ 21 | spells.overlap(s1, s2) 22 | 23 | spells.hit(needle, haystack) 24 | 25 | search.spell(needle, haystack) 26 | } 27 | %- maybe also 'usage' for other objects documented here. 28 | \arguments{ 29 | \item{s1}{ 30 | First spell for in the comparison, must be a two-element numeric vector in the form [onset,terminus] 31 | } 32 | \item{s2}{ 33 | Second spell for in the comparison, must be a two-element numeric vector in the form [onset,terminus] 34 | } 35 | 36 | \item{needle}{ 37 | The query spell used in the search, must be a two-element numeric vector in the form [onset,terminus] 38 | } 39 | 40 | \item{haystack}{ 41 | The spell matrix to be searched by \code{needle}. Must be two column numeric matrix meeting the order specifications of a spell matrix. See \link{activity.attribute} 42 | } 43 | } 44 | \details{ 45 | Spell overlap is defined as true if one of the following conditions sets is met, otherwise false: 46 | 47 | onset1 >= onset2 AND onset1 < terminus2 48 | 49 | terminus1 > onset2 AND terminus1 <= terminus2 50 | 51 | onset1 <= onset2 AND terminus1 >= terminus2 52 | 53 | } 54 | \value{ 55 | \code{spells.overlap} returns a boolean indicating if the two spells overlap or not. 56 | 57 | \code{spells.hit} returns the integer row index of the first (earliest) spell in \code{haystack} that overlaps with \code{needle}, or -1 if no overlaps are found 58 | 59 | \code{search.spell} returns a vector containing the row indices of spells in haystack that overlap with needle, or numeric(0) if none found 60 | } 61 | 62 | \author{ 63 | skyebend@uw.edu 64 | } 65 | 66 | 67 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 68 | 69 | \seealso{ 70 | See Also \code{\link{activity.attribute}} 71 | } 72 | \examples{ 73 | a <- c(1,3) 74 | b <- c(2,5.5) 75 | c <- c(-1,10) 76 | d <- c(4,4) 77 | spells.overlap(a,b) 78 | spells.overlap(b,c) 79 | spells.overlap(a,d) 80 | 81 | spellmat <- rbind(c(0,1), c(1,2), c(2,3)) 82 | spells.hit(c(1,2),spellmat) 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /man/when.attrs.match.Rd: -------------------------------------------------------------------------------- 1 | \name{when.vertex.attrs.match} 2 | \alias{when.vertex.attrs.match} 3 | \alias{when.edge.attrs.match} 4 | %- Also NEED an '\alias' for EACH other topic documented here. 5 | \title{ 6 | return the times at which the TEA attributes of elements of a network match a value 7 | } 8 | \description{ 9 | The functions query the TEA attributes of network elements (vertices or edges) and return the time that each element matches the specified value. The match operator defaults to '==', but other binary comparison operators that return logical, such as '>' or even '\%in\%' can be used as well. 10 | } 11 | \usage{ 12 | when.vertex.attrs.match(nd, attrname, value, match.op = "==", rule = "earliest", 13 | no.match = Inf, v = seq_len(network.size(nd))) 14 | 15 | when.edge.attrs.match(nd, attrname, value, match.op = "==", rule = "earliest", 16 | no.match = Inf, e = seq_along(nd$mel)) 17 | } 18 | %- maybe also 'usage' for other objects documented here. 19 | \arguments{ 20 | \item{nd}{ 21 | a \code{networkDynamic} object 22 | } 23 | \item{attrname}{ 24 | character name of the TEA attribute to be queried 25 | } 26 | \item{value}{ 27 | the value to be passed to the comparison operator to be matched against the TEA values 28 | } 29 | \item{match.op}{ 30 | the binary operator to be used in determining a match (defaults to '==') 31 | } 32 | \item{rule}{ 33 | character giving the name of the rule to determine what value should be returned from the spell of matching attributes. Options are \code{'earliest'} (the default) and \code{'latest'} which will return the onset and terminus of the spell respectively. 34 | } 35 | \item{no.match}{ 36 | The value to be returned when the TEA attribute never matches \code{value}. Default is \code{Inf}, \code{NA} may be useful as well. 37 | } 38 | \item{v}{ 39 | possible numeric vector of vertex ids indicating a subset of vertices to be queried 40 | } 41 | \item{e}{ 42 | possible numeric vector of edge ids indicating a subset of edges to be queried 43 | } 44 | } 45 | \details{ 46 | The \code{no.match} argument is included to make it possible for user to distinguish cases where the attribute is missing from the network element (which will return \code{NA}) from cases where the value of the attribute never matches \code{value} according to the operation \code{match.op} 47 | } 48 | \value{ 49 | A numeric vector of attribute onset times (if \code{rule='earliest'}) or termination times (if \code{rule='latest'}) 50 | } 51 | 52 | \author{ 53 | skyebend 54 | } 55 | \note{ 56 | this is a draft implementation, suggestions on function and argument names welcome. 57 | } 58 | 59 | 60 | \seealso{ 61 | See also \link{attribute.activity.functions} 62 | } 63 | \examples{ 64 | 65 | # create a network with TEA attribute 66 | net<-network.initialize(5) 67 | net<-activate.vertex.attribute(net,'test','A',onset=0,terminus=2) 68 | net<-activate.vertex.attribute(net,'test','B',onset=2,terminus=3) 69 | net<-activate.vertex.attribute(net,'test','C',onset=4,terminus=5) 70 | 71 | net<-activate.vertex.attribute(net,'weight',0,onset=-Inf,terminus=Inf) 72 | net<-activate.vertex.attribute(net,'weight',-1,at=6,v=2) 73 | 74 | # when does 'test' take the value 'B' for each vertex? 75 | when.vertex.attrs.match(net,'test',value='B') 76 | 77 | # when is the terminus of when 'test' takes a value 'A' or 'C'? 78 | when.vertex.attrs.match(net,'test',value=c('A','C'),match.op='\%in\%',rule='latest') 79 | 80 | # when does 'weight' first take a value less than 0? 81 | when.vertex.attrs.match(net,'weight',value=0,match.op='<') 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /man/windsurfers.Rd: -------------------------------------------------------------------------------- 1 | % File networkDynamic/man/windsurfers.Rd 2 | % Part of the statnet package, http://statnetproject.org 3 | % 4 | % This software is distributed under the GPL-3 license. It is free, 5 | % open source, and has the attribution requirements (GPL Section 7) in 6 | % http://statnetproject.org/attribution 7 | % 8 | % Copyright 2012 the statnet development team 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | \name{windsurfers} 11 | \alias{windsurfers} 12 | \alias{beach} 13 | \docType{data} 14 | \title{ 15 | Lin Freeman's Dynamic Network of Windsurfer Social Interactions 16 | } 17 | \description{ 18 | A dynamic network object describing daily social interactions between windsurfers on California beaches over a months time. Collected by Lin Freeman in 1988. 19 | } 20 | \usage{data(windsurfers)} 21 | \format{ 22 | The format is is a \link{networkDynamic} object with node and edge \link{activity.attribute}s defined by spell matricies. 23 | } 24 | \details{ 25 | The data in this network was originally collected and 26 | analyzed in aggregate by Freeman et al. (1988) and has since been used in 27 | a number of influential articles (see Cornwell, 2009; Hummon and Doreian, 28 | 2003; Zeggelink et al., 1996, etc.). While this network is typically analyzed 29 | in aggregate, it was originally collected as a dynamically evolving network 30 | (where the vertex set is composed of windsurfers and the edge set is composed of interpersonal communication). 31 | 32 | The network was collected daily (sampled at two time points each day) for 31 days (August 28, 1986 to September 27,1986). From Almquist and Butts, 201: 33 | 34 | "Individuals were tracked with a unique ID, and were divided by Freeman 35 | et al. into those we will here call, 'regulars' (N = 54) -- frequent attendees 36 | who were well-integrated into the social life of the beach community -- and 'irregulars' (N = 41) on ethnographic grounds. The former category was further broken down by the researchers into two groups, Group 1 (N = 22) and Group 2 (N = 21), with 11 individuals not classified as belonging to 37 | either Group 1 or Group 2. Altogether, the union of vertex sets (Vmax ) 38 | consists of 95 individuals. On any given day during the observation period, 39 | the number of windsurfers appearing on the beach ranged from 3 to 37, with 40 | the number of communication ties per day ranging from 0 to 96." 41 | 42 | The dynamicNetwork object was created from a list of network objects 43 | (length 31, but there is one missing entry index 25 marked with an NA). Each list entry is labeled 828, 829 ... 927 -- this corresponds to the date the network was collected. Vertex 44 | attributes include: group1, group2, regular, vertex.names -- 45 | group1, group2, and regular are ethnographically defined (and are 46 | simply dummies in this case, i.e., 0/1), and vertex.names is the original code number used by Lin. This are static vertex attributes. 47 | 48 | The original set of static networks have been merged into a single dynamic network object with vertex activity coded in a spell matrix following the conventions of networkDynamic objects. There is very high daily turnover of who is present on the beach on each day. 49 | 50 | Several dynamic network level attributes (e.g., list.network.attributes) have been added by Zack Almquist. These include: 51 | 52 | \itemize{ 53 | \item \code{atmp} atmospheric temperature. 54 | \item \code{cord} Grid location on the beach. 55 | \item \code{day} simply the Monday/Tuesday/etc labeling. 56 | \item \code{gst} ground surface temperature (celsius). 57 | \item \code{week} week is the position within the month (e.g., first week in august) 58 | \item \code{wspd} Wind speed from noaa.gov. 59 | \item \code{wvht} Wave height noaa.gov. 60 | } 61 | 62 | atm, gst, wspd, wvht are from the national atmospheric data (noaa.gov) and come from the 63 | closest beach that had accurate weather data. Day of week is relevant because weekly periodicity of the nodeset is quite high. 64 | } 65 | 66 | \source{ 67 | Dr. Lin Freeman (Research Professor UCI) and Zack W Almquist (Graduate Student, UCI) 68 | } 69 | 70 | \references{ 71 | Almquist, Zack W. and Butts, Carter T. (2011). "Logistic Network Regression for Scalable Analysis of Networks with Joint Edge/Vertex Dynamics." IMBS Technical Report MBS 11-03, University of California, Irvine. \cr 72 | 73 | Freeman, L. C., Freeman, S. C., Michaelson, A. G., 1988. "On human social 74 | intelligence." Journal of Social Biological Structure 11, 415--425. 75 | 76 | } 77 | \examples{ 78 | data(windsurfers) 79 | 80 | data(windsurferPanels) 81 | } 82 | 83 | \keyword{datasets} 84 | -------------------------------------------------------------------------------- /nonsource/README: -------------------------------------------------------------------------------- 1 | IMPORTANT NOTES FOR networkDynamic DEVELOPERS--------------------------------- 2 | 3 | 4 | Where things go in the networkDynamic archive: 5 | 6 | - The package TODO file remains in the trunk root. 7 | 8 | - Specifications and other developer documentation resides in the 9 | docs.und.specifications directory. 10 | 11 | - The package itself sits in its usual spot. 12 | 13 | - If there are other important addons (e.g., testing code, data for 14 | tests, etc.), then these should be added in appropriate subdirectories from 15 | the trunk root. (If need be, these may get moved later.) 16 | 17 | Some additional reminders: 18 | 19 | - networkDynamic should be considered FOUNDATIONAL CODE. That means that 20 | changes may break existing data objects, programs, etc., making you the 21 | enemy of all who live. Resist the urge to go all cowboy and whatnot. 22 | 23 | - Please read the specifications and man pages before doing anything that 24 | might change behavior, including adding new functions or options. Always 25 | write to spec - if the spec needs to be changed, propose edits there 26 | first. If the spec is not currently documented, please document the 27 | missing portion. Etc. 28 | 29 | - Anything that can reasonably/easily be done at the user level, and/or that 30 | is not highly generic in functionality, should probably not be in this 31 | package. The goal is to provide a quorum of highly reliable, reasonably 32 | efficient low-level tools from which users and other developers can 33 | construct more elaborate applications. Adding lots of new features can 34 | seem like a good idea at first, but leads to maintenance and compatibility 35 | nightmares down the road. (You and others may have to live with this code 36 | for 10+ years, if you are lucky. Don't get fancy.) 37 | 38 | 39 | Thanks to all! 40 | 41 | -CTB 42 | 04/21/10 43 | 44 | -------------------------------------------------------------------------------- /nonsource/build_to_Rlib: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | pkg=${1:-.} 4 | pkg='networkDynamic' 5 | 6 | if [ -d "$pkg/.svn" ] 7 | then 8 | echo "Updating version information." 9 | ./update_DESCRIPTION "$pkg" 10 | else 11 | echo "Not a working copy: just building." 12 | fi 13 | env MAKE='make -j4' PKG_CFLAGS='-Wall -D_REENTRANT' R CMD INSTALL "$pkg" 14 | cp networkDynamic/vignettes/networkDynamic.pdf networkDynamic/inst/doc/ 15 | 16 | -------------------------------------------------------------------------------- /nonsource/networkDynamic.TODO.txt: -------------------------------------------------------------------------------- 1 | General networkDynamic TODO List 2 | 3 | 1. Introduce semantics for startswithin/endswithin interval queries. 4 | 5 | a. Spell (i,j) startswithin [g,h) iff (i>=g)&(i=g)&(j0){ #Find spells 24 | start<-evec[1] 25 | stop<-start 26 | pos<-1 27 | while((length(evec)>pos)&&(evec[pos+1]-evec[pos]==1)) #Find terminus 28 | pos<-pos+1 29 | stop<-evec[pos] 30 | evec<-evec[-(1:pos)] #Shorten string 31 | intlist<-list(i,j,start,stop,intlist) #Push interval to stack 32 | intcnt<-intcnt+1 33 | } 34 | } 35 | } 36 | #Convert from stack to matrix form 37 | if(verbose) 38 | cat("Converting",intcnt,"intervals from stack to matrix form.\n") 39 | intmat<-matrix(nr=intcnt,nc=4) 40 | for(i in 1:intcnt){ 41 | intmat[i,1]<-intlist[[1]] 42 | intmat[i,2]<-intlist[[2]] 43 | intmat[i,3]<-intlist[[3]] 44 | intmat[i,4]<-intlist[[4]] 45 | intlist<-intlist[[5]] #Pop! 46 | } 47 | #Now, build the network 48 | if(verbose) 49 | cat("Building dynamic network from interval information.\n") 50 | net<-network.initialize(n) #Create empty network 51 | em<-unique(intmat[,1:2]) #Add the edges 52 | net<-add.edges(net,tail=em[,1],head=em[,2]) 53 | for(i in 1:NROW(intmat)){ #Activate edges 54 | net<-activate.edges(net,onset=intmat[i,3],terminus=intmat[i,4], 55 | e=get.edgeIDs(net,intmat[i,1],alter=intmat[i,2])) 56 | } 57 | net 58 | } 59 | -------------------------------------------------------------------------------- /nonsource/relatedCode/mcfarlandDataFormat.R: -------------------------------------------------------------------------------- 1 | # R script to load and format the mcfarland clasroom networks 2 | library(networkDynamic) 3 | vertexData <-read.table(system.file('extdata/cls33_10_16_96_vertices.tsv', package='networkDynamic'),header=T) 4 | edgeData <-read.table(system.file('extdata/cls33_10_16_96_edges.tsv', package='networkDynamic'),header=T,stringsAsFactors = FALSE) 5 | clss33new<-networkDynamic(vertex.spells=vertexData[,c(3,4,1)],edge.spells = edgeData[,c(3,4,1,2,5,6)],create.TEAs = TRUE,edge.TEA.names = c('weight','interaction_type')) 6 | 7 | # set net obs period 8 | nobs <-clss33new%n%'net.obs.period' 9 | nobs$time.unit<-'minutes' 10 | clss33new%n%'net.obs.period'<-nobs 11 | 12 | 13 | # load up vertex data 14 | set.vertex.attribute(clss33new,"data_id",vertexData$data_id) 15 | set.vertex.attribute(clss33new,"gender",as.character(vertexData$sex)) 16 | set.vertex.attribute(clss33new,"type",as.character(vertexData$role)) 17 | 18 | # define persistant id 19 | clss33new%n%'vertex.pid'<-'data_id' 20 | 21 | 22 | # check that the spell matricies and attributes matches the old version 23 | data('McFarland_cls33_10_16_96') 24 | all.equal(as.data.frame(clss33new),as.data.frame(cls33_10_16_96)) 25 | 26 | cls33_10_16_96<-clss33new 27 | save(cls33_10_16_96,file='data/McFarland_cls33_10_16_96.rda') 28 | -------------------------------------------------------------------------------- /nonsource/relatedCode/networkTets.R: -------------------------------------------------------------------------------- 1 | # tests for networks 2 | 3 | mat <- as.data.frame(list(c(1,2,3), c(2,3,4),c(10,11,12))) 4 | net <- network(mat,matrix.type='edgelist',ignore.eval=FALSE,names.eval="myEdges") 5 | net%e%'myEdges' 6 | 7 | mat <- as.data.frame(list(c("z","y","x"), c("y","x","w"),c(10,11,12))) 8 | net <- network(mat,matrix.type='edgelist',ignore.eval=FALSE,names.eval="myEdges") 9 | net%e%'myEdges' 10 | as.matrix.network.edgelist(net) 11 | 12 | net2 <- network(mat,matrix.type='edgelist') 13 | net2%e%'myEdges'<-mat[,3] 14 | net2%e%'myEdges' 15 | as.matrix.network.edgelist(net2) 16 | 17 | 18 | mat2 <- as.data.frame(list(c("x","y","z"), c("w","x","y"),c(10,11,12))) 19 | net3 <- network(mat2,matrix.type='edgelist') 20 | net%e%'myEdges' 21 | as.matrix.network.edgelist(net3) 22 | 23 | # input order doesn't seem to matter for data.frames 24 | mat[1,1] 25 | as.numeric(mat[1,1]) 26 | 27 | mat2[3,1] 28 | as.numeric(mat2[3,1]) 29 | -------------------------------------------------------------------------------- /nonsource/relatedCode/speedTests.R: -------------------------------------------------------------------------------- 1 | # this script is to test the timings of the dynamic attribute (TEA) methods 2 | require(networkDynamic) 3 | 4 | # adding a vertex TEA vs network size 5 | tries = 50 6 | max =10000 7 | netSizes <- runif(tries,min=0,max=max) 8 | setTimes <- numeric(tries) 9 | setComplexTimes <- numeric(tries) 10 | firstInsertTimes <- numeric(tries) 11 | thirdInsertTimes<- numeric(tries) 12 | fourthInsertTimes<- numeric(tries) 13 | getTimes<- numeric(tries) 14 | setEdgeTimes <-numeric(tries) 15 | firstActivateEdgeTimes <-numeric(tries) 16 | secondActivateEdgeTimes <-numeric(tries) 17 | thirdActivateEdgeTimes <-numeric(tries) 18 | getEdgeTimes <-numeric(tries) 19 | 20 | Rprof(filename='~/SNA_health/statnet_research/networkDynamic/trunk/tea_rprof') 21 | Rprof(NULL) 22 | 23 | for (n in 1:tries){ 24 | net <- network.initialize(netSizes[n]) 25 | start <- as.numeric(Sys.time()) 26 | activate.vertex.attribute(net,"letters","a",onset=1,terminus=2) 27 | firstInsertTimes[n]<-as.numeric(Sys.time())-start 28 | 29 | activate.vertex.attribute(net,"letters","c",onset=3,terminus=4) 30 | start <- as.numeric(Sys.time()) 31 | activate.vertex.attribute(net,"letters","d",onset=4,terminus=5) 32 | thirdInsertTimes[n]<-as.numeric(Sys.time())-start 33 | start <- as.numeric(Sys.time()) 34 | activate.vertex.attribute(net,"letters","b",onset=2,terminus=3) 35 | fourthInsertTimes[n]<-as.numeric(Sys.time())-start 36 | 37 | Rprof(filename='~/SNA_health/statnet_research/networkDynamic/trunk/tea_rprof',append=TRUE) 38 | start <- as.numeric(Sys.time()) 39 | get.vertex.attribute.active(net,"letters",onset=2,terminus=3) 40 | getTimes[n]<-as.numeric(Sys.time())-start 41 | 42 | Rprof(NULL) 43 | 44 | start <- as.numeric(Sys.time()) 45 | set.vertex.attribute(net,"numbers","one") 46 | setTimes[n]<-as.numeric(Sys.time())-start 47 | 48 | start <- as.numeric(Sys.time()) 49 | set.vertex.attribute(net,"attribute",list(list("a","b"),c(1,2,3))) 50 | setComplexTimes[n]<-as.numeric(Sys.time())-start 51 | 52 | # now do stuff with edges 53 | add.edges(net,tail=as.list(1:(netSizes[n]-1)),head=as.list(2:netSizes[n])) 54 | 55 | start <- as.numeric(Sys.time()) 56 | activate.edge.attribute(net,"letters","a",onset=0,terminus=1) 57 | firstActivateEdgeTimes[n]<-as.numeric(Sys.time())-start 58 | 59 | start <- as.numeric(Sys.time()) 60 | activate.edge.attribute(net,"letters","b",onset=1,terminus=2) 61 | secondActivateEdgeTimes[n]<-as.numeric(Sys.time())-start 62 | 63 | start <- as.numeric(Sys.time()) 64 | activate.edge.attribute(net,"letters","d",onset=3,terminus=4) 65 | thirdActivateEdgeTimes[n]<-as.numeric(Sys.time())-start 66 | 67 | start <- as.numeric(Sys.time()) 68 | set.edge.attribute(net,"numbers","one") 69 | setEdgeTimes[n]<-as.numeric(Sys.time())-start 70 | 71 | start <- as.numeric(Sys.time()) 72 | get.edge.value.active(net,"letters",onset=3,terminus=4) 73 | getEdgeTimes[n]<-as.numeric(Sys.time())-start 74 | 75 | } 76 | 77 | 78 | 79 | 80 | vertexPlots <-function(){ 81 | plot(netSizes,firstInsertTimes,main="vertex TEA operations",xlab="network size", ylab="seconds",ylim=c(0,max(getTimes))) 82 | points(netSizes,thirdInsertTimes,col="blue") 83 | points(netSizes,fourthInsertTimes,col="purple") 84 | points(netSizes,getTimes,col="green") 85 | points(netSizes,setTimes,col="red") 86 | points(netSizes,setComplexTimes,col="pink") 87 | } 88 | 89 | edgePlots <-function(){ 90 | plot(netSizes,firstActivateEdgeTimes,main="Times for edge TEA operations",xlab="~num edges", ylab="seconds",ylim=c(0,max(getEdgeTimes))) 91 | points(netSizes,setEdgeTimes,col="red") 92 | points(netSizes,secondActivateEdgeTimes,col="blue") 93 | points(netSizes,thirdActivateEdgeTimes,col="purple") 94 | points(netSizes,getEdgeTimes,col="green") 95 | } 96 | 97 | par(mfrow=c(2,1)) 98 | vertexPlots() 99 | edgePlots() 100 | par(mfrow=c(1,1)) 101 | 102 | -------------------------------------------------------------------------------- /nonsource/relatedCode/tea_timings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/nonsource/relatedCode/tea_timings.pdf -------------------------------------------------------------------------------- /nonsource/relatedCode/test_network_generator.R: -------------------------------------------------------------------------------- 1 | # generate a series of networks that include lots of edge cases to be used for testing 2 | 3 | nd_test_nets<-list() 4 | 5 | # non-dynamic network 6 | net0<-network.initialize(5) 7 | add.edges(net0,tail=1:2,head=3:4) 8 | nd_test_nets[['non-dynamic network']]<-net0 9 | 10 | # network with 0 vertices 11 | net1<-as.networkDynamic(network.initialize(0)) 12 | nd_test_nets[['0 vertices']]<-net1 13 | 14 | 15 | # network with 0 edges 16 | net2<-as.networkDynamic(network.initialize(3)) 17 | nd_test_nets[['0 edges']]<-net2 18 | 19 | # network with 1 vertex 20 | net3<-as.networkDynamic(network.initialize(1)) 21 | nd_test_nets[['single vertex']]<-net3 22 | 23 | # network with 1 edge 24 | net3a<-as.networkDynamic(network.initialize(3)) 25 | add.edge(net3a,tail=3,head=2) 26 | nd_test_nets[['one edge']]<-net3a 27 | 28 | # network with 1 edge activated 29 | net3b<-as.networkDynamic(network.initialize(3)) 30 | add.edges.active(net3b,tail=3,head=2,onset=-Inf,terminus=Inf) 31 | nd_test_nets[['one edge explicitly activated']]<-net3b 32 | 33 | # network with vertices explicitly deactivated 34 | net4<-network.initialize(3) 35 | net4<-deactivate.vertices(net4) 36 | nd_test_nets[['vertices explicitly deactivated']]<-net4 37 | 38 | # network with edges that are explicitly deactivated 39 | net5<-network.initialize(3) 40 | add.edges(net5,tail=1:2,head=2:3) 41 | deactivate.edges(net5) 42 | nd_test_nets[['edges that are explicitly deactivated']]<-net5 43 | 44 | # network in which not all edges have activation spells 45 | net6<-network.initialize(5) 46 | add.edges(net6,tail=1:4,head=2:5) 47 | activate.edges(net6,onset=0,terminus=5,e=2:3) 48 | nd_test_nets[['not all edges have activation spells']]<-net6 49 | 50 | # network in which not all vertices have activation spells 51 | net7<-network.initialize(5) 52 | activate.vertices(net7,onset=0,terminus=5,v=2:4) 53 | nd_test_nets[['not all vertices have activation spells']]<-net7 54 | 55 | # network with some edges deleted (nulls in edgelist) 56 | net8<-network.initialize(7) 57 | add.edges.active(net8,tail=1:6,head=2:7,onset=0,terminus=5) 58 | delete.edges(net8,eid=3:5) 59 | nd_test_nets[['some edges deleted (nulls in edgelist)']]<-net8 60 | 61 | # network with some vertices deleted (vertex names will be out of line) 62 | net9<-as.networkDynamic(network.initialize(7)) 63 | delete.vertices(net9,vid=2:5) 64 | nd_test_nets[['some vertices deleted (vertex names will be out of line)']]<-net9 65 | 66 | 67 | # network with multiple edge activation spells 68 | net10<-network.initialize(5) 69 | add.edges(net10,tail=1:5,head=2:5) 70 | activate.edges(net10,onset=0,terminus=1) 71 | activate.edges(net10,onset=2,terminus=3) 72 | nd_test_nets[['multiple edge activation spells']]<-net10 73 | 74 | # network with multiple vertex activation spells 75 | net11<-network.initialize(5) 76 | activate.vertices(net11,onset=0,terminus=1) 77 | activate.vertices(net11,onset=2,terminus=3) 78 | nd_test_nets[['multiple vertex activation spells']]<-net11 79 | 80 | # network in which edge and vertex activations do not sync up 81 | net12<-network.initialize(5) 82 | activate.vertices(net12,onset=0,terminus=1) 83 | add.edges(net12,tail=1:5,head=2:5) 84 | activate.edges(net12,onset=5,terminus=6) 85 | nd_test_nets[['edge and vertex activations do not sync up']]<-net12 86 | 87 | 88 | # network in which edge and vertex activations have negative values 89 | net13<-network.initialize(5) 90 | activate.vertices(net13,onset=-10,terminus=11) 91 | add.edges(net13,tail=1:5,head=2:5) 92 | activate.edges(net13,onset=-10,terminus=-1) 93 | nd_test_nets[['edge and vertex activations have negative values']]<-net13 94 | 95 | # hyper network with flag set 96 | net14<-as.networkDynamic(network.initialize(5,hyper=TRUE)) 97 | add.edge(net14,tail=1:3,head=4:5) 98 | nd_test_nets[['hyper network with flag set']]<-net14 99 | 100 | # hyper network with flag not set 101 | net14<-as.networkDynamic(network.initialize(5)) 102 | add.edge(net14,tail=1:3,head=4:5) 103 | nd_test_nets[['hyper network with flag NOT set']]<-net14 104 | 105 | # multiplex network with flag set 106 | net15<-as.networkDynamic(network.initialize(5,multiple=TRUE)) 107 | add.edge(net15,tail=1:3,head=4:5) 108 | add.edge(net15,tail=1:3,head=4:5) 109 | nd_test_nets[['multiplex network']]<-net15 110 | 111 | # multiplex network with flag not set 112 | net16<-as.networkDynamic(network.initialize(5)) 113 | add.edge(net16,tail=1:3,head=4:5) 114 | add.edge(net16,tail=1:3,head=4:5) 115 | nd_test_nets[['multiplex network with flag NOT set']]<-net16 116 | 117 | # loops network with flag set 118 | net17<-as.networkDynamic(network.initialize(4,loops=TRUE)) 119 | add.edges(net17,tail=1:4,head=1:4) 120 | nd_test_nets[['has loops']]<-net17 121 | 122 | # loops network with flag not set 123 | net18<-as.networkDynamic(network.initialize(4)) 124 | add.edges(net18,tail=1:4,head=1:4) 125 | nd_test_nets[['has loops but flag NOT set']]<-net18 126 | 127 | # bipartite network 128 | net19<-as.networkDynamic(network.initialize(10,bipartite=5)) 129 | add.edges(net19,tail=1:5,head=6:10) 130 | nd_test_nets[['bipartite network']]<-net19 131 | 132 | 133 | # undirected network 134 | net20<-as.networkDynamic(network.initialize(10,directed=FALSE)) 135 | add.edges(net20,tail=6:10,head=1:5) 136 | nd_test_nets[['undirected tail > head']]<-net20 137 | 138 | # network with net.obs.period having narrower range than data 139 | net21<-network.initialize(10) 140 | add.edges.active(net21,tail=1:9,head=2:10,onset=1:9,terminus=2:10) 141 | net21%n%'net.obs.period'<-list(observations=list(c(3,7)),mode="discrete", time.increment=1,time.unit="step") 142 | nd_test_nets[['net.obs.period having narrower range than data']]<-net21 143 | 144 | # network with vertex pid set 145 | net22<-network.initialize(10) 146 | add.edges.active(net22,tail=1:9,head=2:10,onset=1:9,terminus=2:10) 147 | net22%n%'vertex.pid'<-'vertex.names' 148 | nd_test_nets[['vertex.pid set']]<-net22 149 | 150 | # network with edge pid set 151 | net23<-network.initialize(10) 152 | add.edges.active(net23,tail=1:9,head=2:10,onset=1:9,terminus=2:10) 153 | set.edge.attribute(net23,'pid',1:9) 154 | net23%n%'edge.pid'<-'pid' 155 | nd_test_nets[['edge.pid set']]<-net23 156 | 157 | # network with non-numeric vertex and edge pids 158 | net24<-network.initialize(10) 159 | add.edges.active(net24,tail=1:9,head=2:10,onset=1:9,terminus=2:10) 160 | initialize.pids(net24) 161 | nd_test_nets[['non-numeric vertex and edge pids']]<-net24 162 | 163 | 164 | # small tree network 165 | 166 | # small DAG network 167 | 168 | # network with directed cycle 169 | 170 | # network with two components 171 | 172 | # network with missing (na) edges 173 | 174 | # network with missing (na) vertices 175 | 176 | 177 | save(nd_test_nets,file='../networkDynamic/data/nd_test_nets.rda') 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /nonsource/relatedCode/transExample.R: -------------------------------------------------------------------------------- 1 | require(networkDynamic) 2 | data(newcomb) 3 | newcombDyn <- networkDynamic(network.list=newcomb) 4 | # create network, time units are in weeks 5 | # how often do people have a chance to pass ? 6 | # have a 1-in-10 chance of passing rumor each week 7 | # stay in descrete time, use week as unit 8 | timeStep <- 1 # since time units are in weeks 9 | transProb <- 0.1 # 10 | forgetProb <- 0.1 11 | # start the rumor out on vertex 1 12 | activate.vertex.attribute(newcombDyn,"heardRumor",TRUE,v=1,onset=0-timeStep,length=timeStep) 13 | 14 | # loop through time, updating states 15 | times<-seq(from=0,to=max(get.change.times(newcombDyn)),by=timeStep) 16 | for(t in times){ 17 | # find all the people who knew at last timestep 18 | knowers <- which(!is.na(get.vertex.attribute.active(newcombDyn,'heardRumor',at=t-timeStep))) 19 | # get the edge ids of active friendships of people who knew 20 | for (knower in knowers){ 21 | friendships<-get.edgeIDs.active(newcombDyn,v=knower,at=t) 22 | for (friendship in friendships){ 23 | # ignore friendships that already passed rumor MEANS NO RE-RUMOR FROM SAME SOURCE 24 | if (is.null(get.edge.attribute(newcombDyn$mel[friendship],'passedRumor'))){ 25 | # select friendship for transmission with appropriate probability 26 | if (runif(1)<=transProb){ 27 | # update state of vertices at other end of transmitting edges 28 | # but we don't know which way the edge points.. 29 | v<-c(newcombDyn$mel[[friendship]]$inl,newcombDyn$mel[[friendship]]$outl) 30 | # ignore the v we already know 31 | v<-v[v!=knower] 32 | activate.vertex.attribute(newcombDyn,"heardRumor",TRUE, 33 | v=v,onset=t,length=timeStep) 34 | # record which frienships the rumor spread across 35 | set.edge.attribute(newcombDyn,'passedRumor',value=TRUE,e=friendship) 36 | } 37 | } 38 | } 39 | } 40 | # decide who forgets rumor 41 | knowers <-knowers[runif(length(knowers))>forgetProb] 42 | # update state of people who didn't forget the rumor 43 | activate.vertex.attribute(newcombDyn,"heardRumor",TRUE, 44 | v=knowers,onset=t,length=timeStep) 45 | } 46 | 47 | # how many had heard rumor by week 7 48 | sum(get.vertex.attribute.active(newcombDyn,'heardRumor',at=7),na.rm=TRUE) 49 | # did anybody forget and get reminded? 50 | 51 | 52 | # problems: presumeably the underlying friendship network changes more rapidly than once per week, thats just how it was measured. because we are running the infection sim at faster rate than the edge dynamics. assumes people don't forget in the same timestep. Same vertex can be infected twice in one step (not a problem, just slwoer) 53 | 54 | # try a version on windsurfers 55 | data(windsurfers) 56 | # start the rumor out on vertex 1 57 | activate.vertex.attribute(windsurfers,"knowsRumor",TRUE,v=1,onset=0-timeStep,terminus=Inf) 58 | activate.vertex.attribute(windsurfers,"heardRumorFrom",1,v=1,onset=0-timeStep,length=timeStep) 59 | 60 | runSim<-function(net,timeStep,transProb){ 61 | # loop through time, updating states 62 | times<-seq(from=0,to=max(get.change.times(net)),by=timeStep) 63 | for(t in times){ 64 | # find all the people who know and are active 65 | knowers <- which(!is.na(get.vertex.attribute.active( 66 | net,'knowsRumor',at=t,require.active=TRUE))) 67 | # get the edge ids of active friendships of people who knew 68 | for (knower in knowers){ 69 | conversations<-get.edgeIDs.active(net,v=knower,at=t) 70 | for (conversation in conversations){ 71 | # select conversation for transmission with appropriate prob 72 | if (runif(1)<=transProb){ 73 | # update state of people at other end of conversations 74 | # but we don't know which way the edge points so.. 75 | v<-c(net$mel[[conversation]]$inl, 76 | net$mel[[conversation]]$outl) 77 | # ignore the v we already know 78 | v<-v[v!=knower] 79 | activate.vertex.attribute(net,"knowsRumor",TRUE, 80 | v=v,onset=t,terminus=Inf) 81 | # record who spread the rumor 82 | activate.vertex.attribute(net,"heardRumorFrom",knower, 83 | v=v,onset=t,length=timeStep) 84 | # record which friendships the rumor spread across 85 | activate.edge.attribute(net,'passedRumor', 86 | value=TRUE,e=conversation,onset=t,terminus=Inf) 87 | } 88 | } 89 | } 90 | } 91 | return(net) 92 | } 93 | 94 | windsurfers<-runSim(windsurfers,1,0.2) 95 | 96 | # to extract infection tree 97 | 98 | transTree<-function(net){ 99 | # for each vertex in net who knows 100 | knowers <- which(!is.na(get.vertex.attribute.active(net,'knowsRumor',at=Inf))) 101 | # find out who the first transmission was from 102 | transTimes<-get.vertex.attribute.active(net,"heardRumorFrom", 103 | onset=-Inf,terminus=Inf,return.tea=TRUE) 104 | # subset to only ones that know 105 | transTimes<-transTimes[knowers] 106 | # get the first value of the TEA for each knower 107 | tellers<-sapply(transTimes,function(tea){tea[[1]][[1]]}) 108 | # create a new net of appropriate size 109 | treeIds <-union(knowers,tellers) 110 | tree<-network.initialize(length(treeIds),loops=TRUE) 111 | # copy labels from original net 112 | set.vertex.attribute(tree,'vertex.names',treeIds) 113 | # translate the knower and teller ids to new network ids 114 | # and add edges for each transmission 115 | add.edges(tree,tail=match(tellers,treeIds), 116 | head=match(knowers,treeIds) ) 117 | return(tree) 118 | } 119 | -------------------------------------------------------------------------------- /nonsource/relatedCode/windsurfer.R: -------------------------------------------------------------------------------- 1 | #Lin Freeman's windsurfer data' 2 | 3 | #From Zack and Carter's paper: 4 | #The data analyzed in the following sections was originally collected and 5 | #analyzed in aggregate by Freeman et al. (1988) and has since been used in 6 | #a number of influential articles (see Cornwell, 2009; Hummon and Doreian, 7 | #2003; Zeggelink et al., 1996, etc.). While this network is typically analyzed 8 | #in aggregate, it was originally collected as a dynamically evolving network 9 | #(where the vertex set is composed of windsurfers and the edge set is composed 10 | #of interpersonal communication). The network was collected daily (sampled 11 | #at two time points each day) for 31 days (August 28, 1986 to September 27, 12 | #191986) 13 | 14 | #Individuals were tracked with a unique ID, and were divided by Freeman 15 | #et al. into those we will here call “regulars” (N = 54) – frequent attendees 16 | #who were well-integrated into the social life of the beach community – and 17 | #“irregulars” (N = 41) on ethnographic grounds. The former category was 18 | #further broken down by the researchers into two groups, Group 1 (N = 22) 19 | #and Group 2 (N = 21), with 11 individuals not classified as belonging to 20 | #either Group 1 or Group 2. Altogether, the union of vertex sets (Vmax ) 21 | #consists of 95 individuals. On any given day during the observation period, 22 | #the number of windsurfers appearing on the beach ranged from 3 to 37, with 23 | #the number of communication ties per day ranging from 0 to 96. 24 | #These basic characteristics will be used in the illustrative analysis that 25 | #follows, which centers on the question of what drives the evolution of inter- 26 | #personal communication in this open, uncontrolled setting. 27 | 28 | #from Zack's email: 29 | #Attached is the windsurfer networks (WindSurfers.rda); this is a list 30 | #of network objects (length 31, but there is one missing entry index 25 31 | #marked with an NA). Each list entry is labeled 828, 829 ... 927 -- 32 | #this corresponds to the date the network was collected. Vertex 33 | #attributes include: "group1", "group2", "regular", "vertex.names" -- 34 | #group1, group2, and regular are ethnographically defined (and are 35 | #simply dummies in this case, i.e., 0/1), and vertex.names is the 36 | #original code number used by Lin. I have also attached several network 37 | #level attributes (e.g., list.network.attributes). This includes 38 | #"atmp", "cord", "day", "gst", "week", "wspd", "wvht" -- atm, gst, 39 | #wspd, wvht are from the national atmospheric data and come from the 40 | #closest beach I could find that had accurate weather data. day is 41 | #simply the Monday/Tuesday/etc labeling and week is the position within 42 | #the month (e.g., first week in august). 43 | 44 | require(network) 45 | require(networkDynamic) 46 | require(sna) 47 | require(ndtv) 48 | require(MASS) 49 | 50 | 51 | #convert to a network dynamic object 52 | load("windsurferPanels.rda") 53 | 54 | days <- c(1:24,26:31) 55 | #find the vertex set with data ids 56 | vert_ids <- numeric() 57 | for (n in days){ 58 | vert_ids <-unique(c(vert_ids,beach[[n]]%v%'vertex.names')) 59 | } 60 | windsurfers <- network.initialize(length(vert_ids),directed=F) 61 | for (n in days){ 62 | #get the set of active node data ids 63 | active <- sapply(beach[[n]]%v%'vertex.names', function(x){which(vert_ids==x)}) 64 | windsurfers <- activate.vertices(windsurfers,onset=n-1,terminus=n,v=active) 65 | #copy attribute data. In this case, the attributes are not dynamic, but not fully specified by any subnetwork 66 | windsurfers <- set.vertex.attribute(windsurfers,"group1",beach[[n]]%v%"group1",v=active) 67 | windsurfers <- set.vertex.attribute(windsurfers,"group2",beach[[n]]%v%"group2",v=active) 68 | windsurfers <- set.vertex.attribute(windsurfers,"regular",beach[[n]]%v%"regular",v=active) 69 | #copy network vars, don't have a function for this, argg' 70 | windsurfers <- activate.network.attribute(windsurfers,"atmp",beach[[n]]%n%"atmp",onset=n-1,terminus=n) 71 | windsurfers <- activate.network.attribute(windsurfers,"day",beach[[n]]%n%"day",onset=n-1,terminus=n) 72 | windsurfers <- activate.network.attribute(windsurfers,"cord",list(beach[[n]]%n%"cord"),onset=n-1,terminus=n) 73 | windsurfers <- activate.network.attribute(windsurfers,"gst",beach[[n]]%n%"gst",onset=n-1,terminus=n) 74 | windsurfers <- activate.network.attribute(windsurfers,"week",beach[[n]]%n%"week",onset=n-1,terminus=n) 75 | windsurfers <- activate.network.attribute(windsurfers,"wspd",beach[[n]]%n%"wspd",onset=n-1,terminus=n) 76 | windsurfers <- activate.network.attribute(windsurfers,"wvht",beach[[n]]%n%"wvht",onset=n-1,terminus=n) 77 | #TODO: handle NAs for missing day 78 | #copy edges, have to do in loop so we can translate ids 79 | data_ids <-beach[[n]]%v%'vertex.names' 80 | for (edge in beach[[n]]$mel){ 81 | from <- which(vert_ids==data_ids[edge$outl]) 82 | to <- which(vert_ids==data_ids[edge$inl]) 83 | #create edge if doesn't exist 84 | if(windsurfers[from,to] < 1){ 85 | windsurfers[from,to] <- 1; 86 | #TODO copy edge attributes. what does weight mean? 87 | #windsurfers[from,to]<-get.edge.value(beach[[1]],"weight")[1] 88 | } 89 | newEid <- get.edgeIDs(windsurfers,v=from,alter=to) 90 | windsurfers <- activate.edges(windsurfers,onset=n-1,terminus=n,e=newEid) 91 | } 92 | 93 | 94 | } 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /nonsource/update_DESCRIPTION: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Get the package directory (defaulting to working directory). 4 | pkg=${1:-.} 5 | 6 | # Use svnversion to get the revision number, but ignore changes to 7 | # DESCRIPTION, since there is a good change that was done by the 8 | # previous run of the script. 9 | mv $pkg/DESCRIPTION $pkg/DESCRIPTION.tmp 10 | svn revert $pkg/DESCRIPTION 2>&1 > /dev/null 11 | rev=`svnversion -n $pkg | sed -e s/M/.1/g -e s/S/.2/g -e s/:/-/g -e s/exported/0/g` 12 | mv $pkg/DESCRIPTION.tmp $pkg/DESCRIPTION 13 | 14 | # Extract the user specified part of the package version (the part 15 | # before the dash). 16 | vnum=`grep -x '^Version:.*' $pkg/DESCRIPTION | sed -e s/Version:// -e s/-.*$// -e s/\ //g` 17 | 18 | # Put together the new version number. 19 | vrev=$vnum-$rev-`date +%Y.%m.%d-%H.%M.%S` 20 | 21 | # Back up DECRIPTION. 22 | cp $pkg/DESCRIPTION $pkg/DESCRIPTION.bak 23 | # Construct new DESCRIPTION. 24 | cat $pkg/DESCRIPTION.bak | \ 25 | sed -e s/'^Version:.*$'/"Version: $vrev"/ \ 26 | -e s/'^Date:.*$'/"Date: `date +%F`"/ > $pkg/DESCRIPTION 27 | 28 | # Update the timestamp on the DESCRIPTION file. Subversion seems to 29 | # get confused, otherwise. 30 | sleep 2 31 | touch $pkg/DESCRIPTION 32 | -------------------------------------------------------------------------------- /src/diagnostics.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/diagnostics.c 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | /* This is a collection of functions used to calculate diagnostic 12 | statistics for dynamic networks. */ 13 | 14 | #include "diagnostics.h" 15 | #include 16 | 17 | /* These #defines are not really necessary but may make the code a bit 18 | easier to read. They come at a price (the possibility of hard-to-track 19 | errors). */ 20 | #define DMATRIX(a,b) (dmatrix[(a)+(offset)*(b)]) 21 | #define EDGE(a,b) (edges[(a)+(*n_edges)*(b)]) 22 | #define CHANGE(a,b) (changes[(a)+(*n_changes)*(b)]) 23 | 24 | /* Helper functions defined inline. */ 25 | 26 | R_INLINE void AddNewDurationRow (int *dmatrix, int row, int t, int h, int time, int offset, int def_end, int left_censored) { 27 | DMATRIX(row, 0) = time; /* timestamp: edge begins */ 28 | DMATRIX(row, 1) = def_end; /* simulation end time */ 29 | DMATRIX(row, 2) = t; /* tail node number */ 30 | DMATRIX(row, 3) = h; /* head node number */ 31 | DMATRIX(row, 4) = left_censored; /* left-censoring */ 32 | DMATRIX(row, 5) = 1; /* right-censoring indicator: 1=censored, 0=not */ 33 | } 34 | 35 | /**********************************************************/ 36 | 37 | 38 | void DurationMatrix (int *n, int *n_edges, int *edges, int *start, int *end, 39 | int *n_changes, int *changes, 40 | int *dmatrix) { 41 | int row, j, k, t, h, time, offset = *n_edges + *n_changes; 42 | 43 | /* Note: This code assumes always that edges are listed in 44 | (tail, head) order, where, for bipartite and underected networks, tail < head. */ 45 | 46 | /* First, initialize dmatrix by putting in time-zero network */ 47 | for (row=0; row<*n_edges; row++) { 48 | AddNewDurationRow (dmatrix, row, EDGE(row,0), EDGE(row,1), *start, offset, *end, 1); 49 | } /* Note: Value of i upon leaving loop is important */ 50 | 51 | /* Next, step through time one click at a time */ 52 | for (time=*start,j=0; time<=*end; time++) { 53 | for(; CHANGE(j,0) == time && j<*n_changes; j++) { 54 | t = CHANGE(j,1); 55 | h = CHANGE(j,2); 56 | for(k=row; !(DMATRIX(k, 2)==t && DMATRIX(k, 3)==h) && k>=0; k--); 57 | if (k>=0 && DMATRIX(k,5) == 1) { 58 | /* We found a match for the (t, h) edge that must be ended */ 59 | DMATRIX(k, 1) = time; 60 | DMATRIX(k, 5) = 0; /* Censored indicator */ 61 | } else { 62 | AddNewDurationRow(dmatrix, row++, t, h, time, offset, *end, 0); 63 | } 64 | } 65 | } 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/diagnostics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/diagnostics.h 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | #ifndef DIAGNOSTICS_H 12 | #define DIAGNOSTICS_H 13 | 14 | #include 15 | #include "wtedgetree.h" 16 | 17 | /* Function prototypes */ 18 | void DurationMatrix (int *n, int *n_edges, int *edges, 19 | int *start, int *end, 20 | int *n_changes, int *changes, 21 | int *dmatrix); 22 | void AddNewDurationRow (int *dmatrix, int row, int t, int h, int time, int offset, int def_end, int left_censored); 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /src/edgetree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/edgetree.h 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | #ifndef EDGETREE_H 12 | #define EDGETREE_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) 20 | #define MAX(a,b) ((a)<(b) ? (b) : (a)) 21 | 22 | /*typedef unsigned int Vertex; 23 | typedef unsigned int Edge; */ 24 | typedef int Vertex; 25 | typedef int Edge; 26 | 27 | 28 | 29 | /* TreeNode is a binary tree structure, which is how the edgelists 30 | are stored. The root of the tree for vertex i will be inedges[i] 31 | or outedges[i]. inedges[0] and outedges[0] are unused, since the 32 | index 0 will indicate no link. Indices are long unsigned integers, 33 | which means networks can contain 2^32-1= 4294967295 edges (enough to 34 | hold all edges in a 92682-vertex undirected network or a 65536-vertex 35 | directed network, assuming no multiple edges or loops), though for this 36 | MAXEDGES must be adjusted accordingly. 37 | */ 38 | typedef struct TreeNodestruct { 39 | Vertex value; /* the vertex at the other end of this edge */ 40 | Edge parent; /* parent of this node in the tree (0 for root) */ 41 | Edge left; /* left child (0 if none) */ 42 | Edge right; /* right child (0 if none) */ 43 | } TreeNode; 44 | 45 | /* Dur_Inf is a structure containing information about durations of 46 | edges in a network structure. 47 | */ 48 | typedef struct Dur_Infstruct { 49 | int MCMCtimer; 50 | int *lasttoggle; 51 | } Dur_Inf; 52 | 53 | 54 | 55 | /* Network is a structure containing all essential elements 56 | of a given network; it is a slightly rewritten version of the old Gptr, 57 | with some changes of awkard things, deletion of unnecessary things, and 58 | a new name more reflective of what it does! 59 | 60 | Some of the fields in a Network structure are: 61 | inedges and outedges are arrays of TreeNode that are used to 62 | store all of the incoming and outgoing edges, respectively. 63 | directed_flag is 1 or 0, depending on whether or not the 64 | network is directed. 65 | next_inedge and next_outedge are continually updated to give 66 | the smallest index of an edge object not being used. 67 | outdegree[] and indegree[] are continually updated to give 68 | the appropriate degree values for each vertex. These should 69 | point to Vertex-vectors of length nnodes+1. 70 | value: optional value(s) associated with this network 71 | */ 72 | typedef struct Networkstruct { 73 | TreeNode *inedges; 74 | TreeNode *outedges; 75 | int directed_flag; 76 | Vertex bipartite; 77 | Vertex nnodes; 78 | Edge nedges; 79 | Edge next_inedge; 80 | Edge next_outedge; 81 | Vertex *indegree; 82 | Vertex *outdegree; 83 | double *value; 84 | Dur_Inf duration_info; 85 | Edge maxedges; 86 | } Network; 87 | 88 | 89 | /* *** don't forget, tails -> heads, so all the functions below using 90 | heads & tails, now list tails before heads */ 91 | 92 | /* Initialization and destruction. */ 93 | Network NetworkInitialize(Vertex *tails, Vertex *heads, Edge nedges, 94 | Vertex nnodes, int directed_flag, Vertex bipartite, 95 | int lasttoggle_flag, int time, int *lasttoggle); 96 | void NetworkDestroy(Network *nwp); 97 | Network NetworkInitializeD(double *tails, double *heads, Edge nedges, 98 | Vertex nnodes, int directed_flag, Vertex bipartite, 99 | int lasttoggle_flag, int time, int *lasttoggle); 100 | 101 | Network *NetworkCopy(Network *dest, Network *src); 102 | 103 | /* Accessors. */ 104 | Edge EdgetreeSearch (Vertex a, Vertex b, TreeNode *edges); 105 | Edge EdgetreeSuccessor (TreeNode *edges, Edge x); 106 | Edge EdgetreePredecessor (TreeNode *edges, Edge x); 107 | Edge EdgetreeMinimum (TreeNode *edges, Edge x); 108 | Edge EdgetreeMaximum (TreeNode *edges, Edge x); 109 | 110 | /* Modifiers. */ 111 | 112 | /* *** don't forget, tails -> heads, so all the functions below using 113 | heads & tails, now list tails before heads */ 114 | 115 | int ToggleEdge (Vertex tail, Vertex head, Network *nwp); 116 | int ToggleEdgeWithTimestamp (Vertex tail, Vertex head, Network *nwp); 117 | int AddEdgeToTrees(Vertex tail, Vertex head, Network *nwp); 118 | void AddHalfedgeToTree (Vertex a, Vertex b, TreeNode *edges, Edge next_edge); 119 | void UpdateNextedge (TreeNode *edges, Edge *nextedge, Network *nwp); 120 | int DeleteEdgeFromTrees(Vertex tail, Vertex head, Network *nwp); 121 | int DeleteHalfedgeFromTree(Vertex a, Vertex b, TreeNode *edges, 122 | Edge *next_edge); 123 | 124 | /* Duration functions. */ 125 | int ElapsedTime(Vertex tail, Vertex head, Network *nwp); 126 | void TouchEdge(Vertex tail, Vertex head, Network *nwp); 127 | 128 | /* Utility functions. */ 129 | int FindithEdge (Vertex *tail, Vertex *head, Edge i, Network *nwp); 130 | int GetRandEdge(Vertex *tail, Vertex *head, Network *nwp); 131 | void printedge(Edge e, TreeNode *edges); 132 | void InOrderTreeWalk(TreeNode *edges, Edge x); 133 | void NetworkEdgeList(Network *nwp); 134 | void ShuffleEdges(Vertex *tails, Vertex *heads, Edge nedges); 135 | 136 | /* Others... */ 137 | Edge DesignMissing (Vertex a, Vertex b, Network *mnwp); 138 | Edge EdgeTree2EdgeList(Vertex *tails, Vertex *heads, Network *nwp, Edge nmax); 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /src/infection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/infection.h 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | #ifndef INFECTION_H 12 | #define INFECTION_H 13 | 14 | #include 15 | #include "wtedgetree.h" 16 | 17 | /* Function prototypes */ 18 | void Prevalence (int *nnodes, 19 | int *nedge, int *edge, int *ntimestep, int *nfem, int *nseeds, 20 | int *ntotal, int *nchange, int *change, int *ndissolve, int *dissolve, 21 | int *randomseeds, double *betarate, int *infected, int *totinfected, 22 | int *nsim, int *prev); 23 | void PrevalenceWithBernoulliOption(int *nnodes, 24 | int *nedge, int *edge, int *ntimestep, int *nfem, 25 | int *ntotal, int *nchange, int *change, int *ndissolve, int *dissolve, 26 | int *bernoulli, double *betarate, int *infected, int *nsim, int *prev); 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /src/is.active.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/is.active.c 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2013 the statnet development team 10 | */ 11 | /* This is a C helper function used by is.active() (access.R). */ 12 | 13 | #include "is.active.h" 14 | 15 | /**********************************************************/ 16 | 17 | /* Consider registering as native routine */ 18 | /* Function to determine if a query spell matches with any of the elements in a spell matrix 19 | onset = onset of query spell 20 | terminus = terminus of query spell 21 | spell_list = spell matrix to be tested 22 | all = use all rule? (default to any) 23 | */ 24 | Rboolean IsSpellActive_int(double onset, double terminus, SEXP spell_list, Rboolean all, Rboolean debug_output) { 25 | SEXP spell_dim; 26 | PROTECT(spell_dim = getAttrib(spell_list, R_DimSymbol)); 27 | int *dimp = INTEGER(spell_dim); 28 | int n_spells = dimp[0]; 29 | UNPROTECT(1); /* spell_dim */ 30 | double *onsets = REAL(spell_list); 31 | double *termini = onsets + n_spells; 32 | 33 | if (onsets[0] == R_NegInf && termini[0] == R_PosInf) 34 | return TRUE; 35 | 36 | for (int s = n_spells-1; s >= 0; --s) { 37 | if ( debug_output ) 38 | Rprintf("Test [%g,%g) against [%g,%g) ", 39 | onset, terminus, onsets[s], termini[s]); 40 | if (onsets[s] == R_PosInf) 41 | continue; 42 | if (onset == terminus) { /* point query */ 43 | if (onsets[s] == termini[s]) { 44 | if (onset == onsets[s]) 45 | return TRUE; 46 | } else if (termini[s] == R_PosInf && onset == R_PosInf) 47 | return TRUE; 48 | else if (onsets[s] <= onset && onset < termini[s]) 49 | return TRUE; 50 | } else { /* non-point query */ 51 | if (all) { 52 | /* test whether query is completely within spell */ 53 | /* this can produce false negative if spell_list isn't collapsed into minimal form */ 54 | if (onsets[s] <= onset && terminus <= termini[s]) 55 | return TRUE; 56 | } else { 57 | if (onsets[s] == termini[s]) { 58 | if (onset <= onsets[s] && onsets[s] < terminus) 59 | return TRUE; 60 | } else if (onset < termini[s] && onsets[s] < terminus) 61 | return TRUE; 62 | } 63 | } 64 | } 65 | /* failed to find sufficient overlap */ 66 | return FALSE; 67 | } 68 | 69 | SEXP IsSpellActive_R (SEXP onset_s, SEXP terminus_s, SEXP spell_list, SEXP all_s, SEXP debug_output_s) { 70 | double onset = asReal(onset_s), terminus = asReal(terminus_s); 71 | Rboolean all = asLogical(all_s); 72 | Rboolean debug_output = asLogical(debug_output_s); 73 | if (onset == NA_REAL) error("Bad value for 'onset'"); 74 | if (terminus == NA_REAL) error("Bad value for 'terminus'"); 75 | if (all == NA_LOGICAL) error("Bad value for 'all'"); 76 | if (debug_output == NA_LOGICAL) error("Bad value for 'debug_output'"); 77 | return ScalarLogical(IsSpellActive_int(onset, terminus, spell_list, all, debug_output)); 78 | } 79 | 80 | /* Function to loop over a list of spell matrices (corresponding to vertices or edges) and determine 81 | for each element if it is active during the specified spell 82 | onset_s = onset of query spell 83 | terminus_s = terminus of query spell 84 | spell_lists = list of spellmatrices to evaluate 85 | all = logical, use "all" rule? (matched spell must be active for entire duratin of query spell) 86 | active_default_s = logical, should elements with no spell matrix be considered active by default 87 | debug_output_s = logical, print debugging messages. 88 | */ 89 | SEXP IsActiveInVector_R (SEXP onset_s, SEXP terminus_s, SEXP spell_lists, SEXP all_s, SEXP active_default_s, SEXP debug_output_s) { 90 | double onset = asReal(onset_s), terminus = asReal(terminus_s); 91 | Rboolean all = asLogical(all_s); 92 | Rboolean active_default = asLogical(active_default_s); 93 | Rboolean debug_output = asLogical(debug_output_s); 94 | if (onset == NA_REAL) error("Bad value for 'onset'"); 95 | if (terminus == NA_REAL) error("Bad value for 'terminus'"); 96 | if (all == NA_LOGICAL) error("Bad value for 'all'"); 97 | if (active_default == NA_LOGICAL) error("Bad value for 'active_default'"); 98 | if (debug_output == NA_LOGICAL) error("Bad value for 'debug_output'"); 99 | 100 | SEXP any_s; 101 | PROTECT(any_s = allocVector(LGLSXP, length(spell_lists))); 102 | int *any = INTEGER(any_s); 103 | /* does this need to compile in more fussy C compilers? */ 104 | for (int i = length(spell_lists) - 1; i >= 0; --i) { 105 | SEXP active_i; 106 | PROTECT(active_i = VECTOR_ELT(spell_lists, i)); 107 | if (isNull(active_i)) 108 | any[i] = active_default; 109 | else { 110 | SEXP active_i_real; 111 | PROTECT(active_i_real = coerceVector(active_i, REALSXP)); 112 | any[i] = IsSpellActive_int(onset, terminus, active_i_real, all, debug_output); 113 | if ( debug_output ) 114 | Rprintf(": %c\n", any[i]? 'T':'F'); 115 | UNPROTECT(1); /* active_i_real */ 116 | } 117 | UNPROTECT(1); /* active_i */ 118 | } 119 | UNPROTECT(1); /* any_s */ 120 | return any_s; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /src/is.active.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/diagnostics.h 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | #ifndef IS_ACTIVE_H 12 | #define IS_ACTIVE_H 13 | 14 | #include 15 | #include 16 | 17 | /* Function prototypes */ 18 | SEXP IsSpellActive_R (SEXP onset_s, SEXP terminus_s, SEXP spell_list, SEXP all_s, SEXP debug_output); 19 | 20 | SEXP IsActiveInVector_R (SEXP onset_s, SEXP terminus_s, SEXP spell_lists, SEXP all_s, SEXP active_default_s, SEXP debug_output); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/spellfunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/spellfunctions.h 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | #ifndef SPELLFUNCTIONS_H 12 | #define SPELLFUNCTIONS_H 13 | 14 | #include 15 | #include 16 | 17 | // replaces most of is.active() 18 | SEXP IsActiveInVector_R(SEXP onset_s, SEXP terminus_s, SEXP spell_lists, SEXP all_s, SEXP active_default_s, SEXP debug_output); 19 | 20 | // replaces most of insert.spell() 21 | SEXP InsertSpell_R(SEXP spell_list, SEXP onset_s, SEXP terminus_s, SEXP debug_output); 22 | 23 | // replaces most of activate.edges() 24 | SEXP ActivateEdges_R(SEXP network, SEXP onset, SEXP terminus, SEXP e, SEXP debug_output); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/wtedgetree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File networkDynamic/src/wtedgetree.h 3 | * Part of the statnet package, http://statnetproject.org 4 | * 5 | * This software is distributed under the GPL-3 license. It is free, 6 | * open source, and has the attribution requirements (GPL Section 7) in 7 | * http://statnetproject.org/attribution 8 | * 9 | * Copyright 2012 the statnet development team 10 | */ 11 | #ifndef WTEDGETREE_H 12 | #define WTEDGETREE_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "edgetree.h" 19 | 20 | /* WtTreeNode is just like TreeNode but with an extra field for a 21 | weight, or value, that might be associated with the node */ 22 | typedef struct WtTreeNodestruct { 23 | Vertex value; /* the vertex at the other end of the edge */ 24 | Edge parent; /* parent of this node in the tree (0 for root) */ 25 | Edge left; /* left child (0 if none) */ 26 | Edge right; /* right child (0 if none) */ 27 | double weight; 28 | } WtTreeNode; 29 | 30 | 31 | 32 | 33 | 34 | /* Network is a structure containing all essential elements 35 | of a given network; it is a slightly rewritten version of the old Gptr, 36 | with some changes of awkard things, deletion of unnecessary things, and 37 | a new name more reflective of what it does! 38 | 39 | Some of the fields in a Network structure are: 40 | inedges and outedges are arrays of TreeNode that are used to 41 | store all of the incoming and outgoing edges, respectively. 42 | directed_flag is 1 or 0, depending on whether or not the 43 | network is directed. 44 | next_inedge and next_outedge are continually updated to give 45 | the smallest index of an edge object not being used. 46 | outdegree[] and indegree[] are continually updated to give 47 | the appropriate degree values for each vertex. These should 48 | point to Vertex-vectors of length nnodes+1. 49 | value: optional value(s) associated with this network 50 | Dur_Inf: See typedef for Dur_Infstruct above 51 | */ 52 | /* WtNetwork is a structure just like Network except it is for a network with 53 | weighted (valued) edges. */ 54 | typedef struct WtNetworkstruct { 55 | WtTreeNode *inedges; 56 | WtTreeNode *outedges; 57 | int directed_flag; 58 | Vertex bipartite; 59 | Vertex nnodes; 60 | Edge nedges; 61 | Edge next_inedge; 62 | Edge next_outedge; 63 | Vertex *indegree; 64 | Vertex *outdegree; 65 | double *value; 66 | Dur_Inf duration_info; 67 | Edge maxedges; 68 | } WtNetwork; 69 | 70 | /* Initialization and destruction. */ 71 | WtNetwork WtNetworkInitialize(Vertex *tails, Vertex *heads, double *weights, Edge nedges, 72 | Vertex nnodes, int directed_flag, Vertex bipartite, 73 | int lasttoggle_flag, int time, int *lasttoggle); 74 | void WtNetworkDestroy(WtNetwork *nwp); 75 | WtNetwork WtNetworkInitializeD(double *tails, double *heads, double *weights, Edge nedges, 76 | Vertex nnodes, int directed_flag, Vertex bipartite, 77 | int lasttoggle_flag, int time, int *lasttoggle); 78 | 79 | WtNetwork *WtNetworkCopy(WtNetwork *dest, WtNetwork *src); 80 | 81 | /* Accessors. */ 82 | Edge WtEdgetreeSearch (Vertex a, Vertex b, WtTreeNode *edges); 83 | double WtGetEdge (Vertex tail, Vertex head, WtNetwork *nwp); 84 | Edge WtEdgetreeSuccessor (WtTreeNode *edges, Edge x); 85 | Edge WtEdgetreePredecessor (WtTreeNode *edges, Edge x); 86 | Edge WtEdgetreeMinimum (WtTreeNode *edges, Edge x); 87 | Edge WtEdgetreeMaximum (WtTreeNode *edges, Edge x); 88 | 89 | /* Modifiers. */ 90 | 91 | /* *** don't forget, tails -> heads, so all the functions below using 92 | heads & tails, now list tails before heads */ 93 | 94 | 95 | void WtSetEdge (Vertex tail, Vertex head, double weight, WtNetwork *nwp); 96 | void WtSetEdgeWithTimestamp (Vertex tail, Vertex head, double weight, WtNetwork *nwp); 97 | int WtToggleEdge (Vertex tail, Vertex head, double weight, WtNetwork *nwp); 98 | int WtToggleEdgeWithTimestamp (Vertex tail, Vertex head, double weight, WtNetwork *nwp); 99 | int WtAddEdgeToTrees(Vertex tail, Vertex head, double weight, WtNetwork *nwp); 100 | void WtAddHalfedgeToTree (Vertex a, Vertex b, double weight, WtTreeNode *edges, Edge next_edge); 101 | void WtUpdateNextedge (WtTreeNode *edges, Edge *nextedge, WtNetwork *nwp); 102 | int WtDeleteEdgeFromTrees(Vertex tail, Vertex head, WtNetwork *nwp); 103 | int WtDeleteHalfedgeFromTree(Vertex a, Vertex b, WtTreeNode *edges, 104 | Edge *next_edge); 105 | 106 | /* Duration functions. */ 107 | int WtElapsedTime (Vertex tail, Vertex head, WtNetwork *nwp); 108 | void WtTouchEdge(Vertex tail, Vertex head, WtNetwork *nwp); 109 | 110 | /* Utility functions. */ 111 | int WtFindithEdge (Vertex *tail, Vertex *head, double *weight, Edge i, WtNetwork *nwp); 112 | int WtGetRandEdge(Vertex *tail, Vertex *head, double *weight, WtNetwork *nwp); 113 | void Wtprintedge(Edge e, WtTreeNode *edges); 114 | void WtInOrderTreeWalk(WtTreeNode *edges, Edge x); 115 | void WtNetworkEdgeList(WtNetwork *nwp); 116 | void WtShuffleEdges(Vertex *tails, Vertex *heads, double *weights, Edge nedges); 117 | 118 | /* Others... */ 119 | Edge WtDesignMissing (Vertex a, Vertex b, WtNetwork *mnwp); 120 | Edge WtEdgeTree2EdgeList(Vertex *tails, Vertex *heads, double *weights, WtNetwork *nwp, Edge nmax); 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /tests/age.at_tests.R: -------------------------------------------------------------------------------- 1 | # tests for age.at functions 2 | library(networkDynamic) 3 | library(testthat) 4 | 5 | # ---------- edges.age.at tests ------ 6 | test<-network.initialize(5) 7 | add.edges(test,tail = 1:4,head=2:5 ) 8 | activate.edges(test,onset=0:2,terminus=1:3,e=1:3) 9 | 10 | 11 | expect_equal(edges.age.at(test,at=0),c(0,NA,NA,Inf)) 12 | expect_equal(edges.age.at(test,at=2.5),c(NA,NA,0.5,Inf)) 13 | 14 | # test active default 15 | expect_equal(edges.age.at(test,at=0,active.default=FALSE),c(0,NA,NA,NA)) 16 | 17 | # test deleted edge 18 | delete.edges(test,e=2) 19 | 20 | expect_equal(edges.age.at(test,at=1),c(NA,NA,NA,Inf)) 21 | 22 | # test restricted edge set 23 | expect_equal(edges.age.at(test,at=1,e=c(1,3,4)),c(NA,NA,Inf)) 24 | 25 | 26 | # network size 0 27 | expect_equal(edges.age.at(network.initialize(0),at=0),logical(0)) 28 | 29 | # no edges in network 30 | expect_equal(edges.age.at(network.initialize(3),at=0),logical(0)) 31 | 32 | 33 | # ------------------- test for dyads.age.at ------- 34 | test<-network.initialize(5) 35 | add.edges(test,tail = 1:4,head=2:5 ) 36 | activate.edges(test,onset=0:2,terminus=1:3,e=1:3) 37 | 38 | expect_equal(dyads.age.at(test,at=0,tail=1,head=2),0) 39 | expect_equal(dyads.age.at(test,at=0,tail=2,head=1),NA) # reverse order 40 | expect_equal(dyads.age.at(test,at=1,tail=1,head=2),NA) 41 | 42 | # check for out of sync tail and head 43 | expect_error(dyads.age.at(test,at=0,tail=1,head=2:3),regexp = 'must be the same length') 44 | 45 | # check for multiple edges 46 | expect_equal(dyads.age.at(test,at=1,tail=1:2,head=2:3),c(NA,0)) 47 | expect_equal(dyads.age.at(test,at=0,tail=1:2,head=2:3),c(0,NA)) 48 | 49 | # non existing edges 50 | expect_equal(dyads.age.at(test,at=1,tail=5,head=1),NA) 51 | 52 | # head or tail out of range 53 | expect_equal(dyads.age.at(test,at=1,tail=5,head=6),NA) # no error returned 54 | 55 | # deleted edges 56 | delete.edges(test,e=2) 57 | expect_equal(dyads.age.at(test,at=1,tail=1:2,head=2:3),c(NA,NA)) 58 | 59 | # active default test 60 | expect_equal(dyads.age.at(test,at=0,tail=4,head=5),Inf) 61 | expect_equal(dyads.age.at(test,at=0,tail=4,head=5,active.default=FALSE),NA) 62 | 63 | # test edge format arge 64 | expect_equal(dyads.age.at(test,at=0),c(0,NA,Inf)) 65 | out<-dyads.age.at(test,at=0,format.out='edgelist') 66 | expect_equal(out[,'tails'],c(1,3,4)) 67 | expect_equal(out[,'heads'],c(2,4,5)) 68 | expect_equal(out[,'ages'],c(0,NA,Inf)) 69 | 70 | out<-dyads.age.at(test,at=0,format.out='matrix') 71 | expect_equal(out,matrix(c(NA, NA, NA, NA, NA, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, Inf, NA),nrow=5,ncol=5)) 72 | 73 | # test symmetry for non directed case 74 | test%n%'directed'<-FALSE 75 | out<-dyads.age.at(test,at=0,format.out='matrix') 76 | expect_equal(out,matrix(c(NA, 0, NA, NA, NA, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, Inf, NA, NA, NA, Inf, NA),nrow=5,ncol=5)) 77 | 78 | 79 | # ----- test vertices.age.at ----- 80 | test<-network.initialize(5) 81 | activate.vertices(test,v = 1:4,onset=0:3,terminus=1:4) 82 | expect_equal(vertices.age.at(test,at=0),c(0,NA,NA,NA,Inf)) 83 | expect_equal(vertices.age.at(test,at=0,active.default=FALSE),c(0,NA,NA,NA,NA)) 84 | expect_equal(vertices.age.at(network.initialize(0),at=0),logical(0)) 85 | expect_equal(vertices.age.at(test,at=1,v=c(1,2,4,5)),c(NA,0,NA,Inf)) 86 | 87 | 88 | -------------------------------------------------------------------------------- /tests/classTests.R: -------------------------------------------------------------------------------- 1 | # Part of the statnet package, http://statnetproject.org 2 | # 3 | # This software is distributed under the GPL-3 license. It is free, 4 | # open source, and has the attribution requirements (GPL Section 7) in 5 | # http://statnetproject.org/attribution 6 | # 7 | # Copyright 2013 the statnet development team 8 | ###################################################################### 9 | 10 | # tests to determine if the networkDynamic class is being set appropriately tested for 11 | 12 | library(networkDynamic) 13 | require(testthat) 14 | #check if activate.edge sets class. 15 | net <- network.initialize(5) 16 | net[1,2] <-1 17 | nD <-activate.edges(net,onset=0,terminus=1) 18 | if (!is.networkDynamic(nD)){ 19 | stop("activate edges did not set networkDynamic class") 20 | } 21 | nd <- NULL 22 | 23 | net <- network.initialize(5) 24 | net[1,2] <-1 25 | nD <-activate.vertices(net,onset=0,terminus=1) 26 | if (!is.networkDynamic(nD)){ 27 | stop("activate vertices did not set networkDynamic class") 28 | } 29 | 30 | expect_true(is.networkDynamic(as.networkDynamic(network.initialize(0)))) 31 | 32 | # ----- as.network.networkDynamic ------ 33 | # test removing class 34 | net <- network.initialize(5) 35 | activate.vertices(net,onset=1,terminus=2) 36 | # is networkDynamic class removed 37 | expect_false(is.networkDynamic(as.network(net))) 38 | # is network class retained? 39 | expect_is(net,'network') 40 | 41 | # ----- as.networkDynamic.network ---- 42 | expect_is(as.networkDynamic(network.initialize(2)),'networkDynamic') -------------------------------------------------------------------------------- /tests/utils_tests.R: -------------------------------------------------------------------------------- 1 | # tests for utilities functions 2 | require(networkDynamic) 3 | require(testthat) 4 | # ------- test for adjust.activity ----- 5 | 6 | test<-network.initialize(3) 7 | activate.vertices(test,onset=0,terminus=3,v=1:2) 8 | add.edges.active(test,tail=1:2,head=2:3,onset=0,terminus=3) 9 | add.edge(test,tail=3,head=1) 10 | activate.vertex.attribute(test,'fruit','apple',v=1:2,onset=0,terminus=3) 11 | activate.edge.attribute(test,'veggie','carrot',e=1:2,onset=0,terminus=3) 12 | activate.network.attribute(test,'meat','pork',onset=0,terminus=3) 13 | test%n%'net.obs.period'<-list(observations=list(c(0,1),c(1,2),c(2,3)),mode="discrete", time.increment=1,time.unit="step") 14 | 15 | # test offset and return value 16 | test2<-adjust.activity(test,offset=5) 17 | 18 | expect_equal(test2$val[[1]]$active,matrix(c(5,8),ncol=2)) 19 | expect_equal(test2$val[[3]]$active,NULL) 20 | expect_equal(test2$mel[[1]]$atl$active,matrix(c(5,8),ncol=2)) 21 | expect_equal(test2$mel[[3]]$atl$active,NULL) 22 | expect_equal(test2$val[[1]]$'fruit.active'[[2]],matrix(c(5,8),ncol=2)) 23 | expect_equal(test2$val[[3]]$'fruit.active'[[2]],NULL) 24 | expect_equal(test2$mel[[1]]$atl$'veggie.active'[[2]],matrix(c(5,8),ncol=2)) 25 | expect_equal(test2$mel[[3]]$atl$'veggie.active'[[2]],NULL) 26 | expect_equal(test2$gal$'meat.active'[[2]],matrix(c(5,8),ncol=2)) 27 | expect_equal(unlist((test2%n%'net.obs.period')$observations),c(5,6,6,7,7,8)) 28 | expect_equal((test2%n%'net.obs.period')$time.increment,1) 29 | 30 | # test factor and modify-in-place 31 | adjust.activity(test,factor=.5) 32 | 33 | expect_equal(test$val[[1]]$active,matrix(c(2.5,4),ncol=2)) 34 | expect_equal(test$val[[3]]$active,NULL) 35 | expect_equal(test$mel[[1]]$atl$active,matrix(c(2.5,4),ncol=2)) 36 | expect_equal(test$mel[[3]]$atl$active,NULL) 37 | expect_equal(test$val[[1]]$'fruit.active'[[2]],matrix(c(2.5,4),ncol=2)) 38 | expect_equal(test$val[[3]]$'fruit.active'[[2]],NULL) 39 | expect_equal(test$mel[[1]]$atl$'veggie.active'[[2]],matrix(c(2.5,4),ncol=2)) 40 | expect_equal(test$mel[[3]]$atl$'veggie.active'[[2]],NULL) 41 | expect_equal(test$mel[[1]]$atl$'veggie.active'[[2]],matrix(c(2.5,4),ncol=2)) 42 | expect_equal(unlist((test%n%'net.obs.period')$observations),c(2.5,3,3,3.5,3.5,4)) 43 | expect_equal((test%n%'net.obs.period')$time.increment,0.5) 44 | 45 | # ---- test for add.vertices.active ----- 46 | net<-network.initialize(3) 47 | # test for adding zero vertices 48 | add.vertices.active(net,nv=0) 49 | expect_equal(network.size(net),3) 50 | expect_true(is.networkDynamic(net)) 51 | 52 | add.vertices.active(net,nv=2, onset=1,terminus=2) 53 | expect_equal(network.size(net),5) 54 | expect_true(is.networkDynamic(net)) 55 | expect_equal(unlist(get.vertex.activity(net,as.spellList=TRUE)[4:5,1:2]),c(1,1,2,2),check.names=FALSE) 56 | 57 | 58 | # ---- tests for get.dyads.active ---- 59 | test_that("get.dyads.active works",{ 60 | 61 | expect_error( get.dyads.active(network.initialize(3,hyper=TRUE),at=1),regexp="does not currently support hypergraphic",info="error on hyper") 62 | expect_equal( nrow(get.dyads.active(network.initialize(0),at=1)),0,info="network size zero case") 63 | expect_equal( nrow(get.dyads.active(network.initialize(3),at=1)),0,info="zero edges case") 64 | 65 | test<-network.initialize(5) 66 | add.edges.active(test,tail=1,head=2,onset=0,terminus=1) 67 | add.edges.active(test,tail=2,head=3,onset=1,terminus=2) 68 | add.edges.active(test,tail=3,head=4,onset=1,terminus=3) 69 | activate.edges(test,e=1,onset=2,terminus=3) 70 | as.data.frame(test) 71 | expect_equal(get.dyads.active(test,at=0),rbind(1:2)) 72 | expect_equal(get.dyads.active(test,at=1),cbind(2:3,3:4)) 73 | expect_equal(get.dyads.active(test,onset=0,terminus=4),rbind(1:2,2:3,3:4)) 74 | 75 | # test with no (default) dynamics 76 | test2<-network.initialize(3) 77 | test2[1,2]<-1 78 | expect_equal(get.dyads.active(test2,onset=0,terminus=4),rbind(1:2)) 79 | # test active default 80 | expect_equal(get.dyads.active(test2,onset=0,terminus=4,active.default=FALSE),cbind(list(),list()), info='test active default arg') 81 | 82 | # deleted edges 83 | test2<-network.initialize(3) 84 | test2[1,2]<-1 85 | test2[2,3]<-1 86 | test2[3,1]<-1 87 | delete.edges(test2,eid=2) 88 | expect_equal(get.dyads.active(test2,at=1),rbind(1:2,c(3,1)),info='deleted edge case') 89 | 90 | }) 91 | 92 | test_that("conversions between network, networkLite, and networkDynamic behave as expected", { 93 | library(networkLite) 94 | 95 | m <- matrix(rbinom(20*20, 1, 1/10), nrow = 20, ncol = 20) 96 | m[lower.tri(m, diag = TRUE)] <- FALSE 97 | el <- which(m > 0, arr.ind = TRUE) 98 | el <- el[order(el[,1], el[,2]),,drop=FALSE] 99 | attr(el, "n") <- 20 100 | 101 | nw <- network(el, directed = FALSE, bipartite = FALSE, matrix.type = "edgelist") 102 | nwL <- as.networkLite(nw) 103 | nwLD <- as.networkDynamic(nwL) 104 | nwD <- as.networkDynamic(nw) 105 | nwDL <- as.networkLite(nwD) 106 | expect_identical(nwD, nwLD) 107 | expect_identical(nwDL, nwL) 108 | 109 | nwL <- networkLite(el) 110 | nw <- to_network_networkLite(nwL) 111 | nwD <- as.networkDynamic(nw) 112 | nwLD <- as.networkDynamic(nwL) 113 | nwDL <- as.networkLite(nwD) 114 | expect_identical(nwD, nwLD) 115 | expect_identical(nwDL, nwL) 116 | }) 117 | -------------------------------------------------------------------------------- /tests/when_tests.R: -------------------------------------------------------------------------------- 1 | # tests for the when functions 2 | require(testthat) 3 | require(networkDynamic) 4 | 5 | #------ when.vertex.attrs.match tests ----- 6 | 7 | test1<-network.initialize(5) 8 | test1<-activate.vertex.attribute(test1,'myValue',1:5,onset=1,terminus=2) 9 | test1<-activate.vertex.attribute(test1,'myValue',10:15,onset=2,terminus=3) 10 | test1<-activate.vertex.attribute(test1,'myValue',-5:0,onset=5,terminus=12) 11 | 12 | # basic test 13 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=3),c(Inf,Inf,1,Inf,Inf)) 14 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=-5),c(5,Inf,Inf,Inf,Inf)) 15 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=200),c(Inf,Inf,Inf,Inf,Inf)) 16 | 17 | # changing no.match value 18 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=200,no.match=NA),c(NA,NA,NA,NA,NA)) 19 | 20 | # changing operation 21 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=3,match.op='>'),c(2,2,2,1,1)) 22 | 23 | # complex operation, complex value 24 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=c(1,2,3),match.op='%in%'),c(1,1,1,Inf,Inf)) 25 | 26 | 27 | # bad type of operation 28 | expect_error(when.vertex.attrs.match(test1,attrname='myValue',value=3,match.op='min'),regexp='provide Logical results for every attribute value') 29 | 30 | # not a networkDynamic 31 | expect_error(when.vertex.attrs.match(5,attrname='myValue',value=3),regexp='argument to be a networkDynamic object') 32 | 33 | # non-existing attrname 34 | expect_equal(when.vertex.attrs.match(test1,attrname='foo',value=3),c(NA,NA,NA,NA,NA)) 35 | 36 | # missing attrname 37 | expect_error(when.vertex.attrs.match(test1,value=3),regexp="providing an 'attrname' argument") 38 | 39 | # missing value 40 | expect_error(when.vertex.attrs.match(test1,attrname='myValue'),regexp="requires providing a 'value' argument") 41 | 42 | # use v argument to query specific vertices 43 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=3,match.op='>',v=3:4),c(2,1)) 44 | 45 | # bad rule 46 | expect_error(when.vertex.attrs.match(test1,attrname='myValue',value=3,rule='guess'), regexp="no matching methods implemented for rule 'guess'") 47 | 48 | # latest rule 49 | expect_equal(when.vertex.attrs.match(test1,attrname='myValue',value=3, match.op='>',rule='latest'),c(3,3,3,3,3)) 50 | 51 | 52 | # what if attributes are missing from some elements 53 | 54 | test2<-network.initialize(5) 55 | test2<-activate.vertex.attribute(test2,'myValue',c(1,2,5),onset=1,terminus=2,v=c(1,2,5)) 56 | test2<-activate.vertex.attribute(test2,'myValue',c(10,11,15),onset=2,terminus=3,v=c(1,2,5)) 57 | test2<-activate.vertex.attribute(test2,'myValue',c(-5,-4,-1),onset=5,terminus=12,v=c(1,2,5)) 58 | expect_equal(when.vertex.attrs.match(test2,attrname='myValue',value=3,match.op='<'),c(1,1,NA,NA,5)) 59 | 60 | 61 | #------ when.edge.attrs.match tests ----- 62 | 63 | test1<-network.initialize(5) 64 | add.edges(test1,tail=1:5,head=c(2,3,4,5,1)) 65 | test1<-activate.edge.attribute(test1,'myValue',1:5,onset=1,terminus=2) 66 | test1<-activate.edge.attribute(test1,'myValue',10:15,onset=2,terminus=3) 67 | test1<-activate.edge.attribute(test1,'myValue',-5:0,onset=5,terminus=12) 68 | 69 | # basic test 70 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=3),c(Inf,Inf,1,Inf,Inf)) 71 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=-5),c(5,Inf,Inf,Inf,Inf)) 72 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=200),c(Inf,Inf,Inf,Inf,Inf)) 73 | 74 | # changing no.match value 75 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=200,no.match=NA),c(NA,NA,NA,NA,NA)) 76 | 77 | # changing operation 78 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=3,match.op='>'),c(2,2,2,1,1)) 79 | 80 | # complex operation, complex value 81 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=c(1,2,3),match.op='%in%'),c(1,1,1,Inf,Inf)) 82 | 83 | 84 | # bad type of operation 85 | expect_error(when.edge.attrs.match(test1,attrname='myValue',value=3,match.op='min'),regexp='provide Logical results for every attribute value') 86 | 87 | # not a networkDynamic 88 | expect_error(when.edge.attrs.match(5,attrname='myValue',value=3),regexp='argument to be a networkDynamic object') 89 | 90 | # non-existing attrname 91 | expect_equal(when.edge.attrs.match(test1,attrname='foo',value=3),c(NA,NA,NA,NA,NA)) 92 | 93 | # missing attrname 94 | expect_error(when.edge.attrs.match(test1,value=3),regexp="providing an 'attrname' argument") 95 | 96 | # missing value 97 | expect_error(when.edge.attrs.match(test1,attrname='myValue'),regexp="requires providing a 'value' argument") 98 | 99 | # use e argument to query specific vertices 100 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=3,match.op='>',e=3:4),c(2,1)) 101 | 102 | # bad rule 103 | expect_error(when.edge.attrs.match(test1,attrname='myValue',value=3,rule='guess'), regexp="no matching methods implemented for rule 'guess'") 104 | 105 | # latest rule 106 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=3, match.op='>',rule='latest'),c(3,3,3,3,3)) 107 | 108 | # what if some edges are deleted 109 | test1<-delete.edges(test1,e=c(2,3)) 110 | expect_equal(when.edge.attrs.match(test1,attrname='myValue',value=3),c(Inf,NA,NA,Inf,Inf)) 111 | 112 | # what if attributes are missing from some elements 113 | test2<-network.initialize(5) 114 | add.edges(test2,tail=1:5,head=c(2,3,4,5,1)) 115 | test2<-activate.edge.attribute(test2,'myValue',c(1,2,5),onset=1,terminus=2,e=c(1,2,5)) 116 | test2<-activate.edge.attribute(test2,'myValue',c(10,11,15),onset=2,terminus=3,e=c(1,2,5)) 117 | test2<-activate.edge.attribute(test2,'myValue',c(-5,-4,-1),onset=5,terminus=12,e=c(1,2,5)) 118 | expect_equal(when.edge.attrs.match(test2,attrname='myValue',value=3,match.op='<'),c(1,1,NA,NA,5)) 119 | 120 | # ---- when.next.edge.change ---- 121 | # test<-network.initialize(5) 122 | # add.edges.active(test,tail=1:5,head=c(2,3,4,5,1),onset=1:5,terminus=2:6) 123 | # activate.edges(test,e=2,onset=6,terminus=100) 124 | # add.edge(test,tail=4,head=5) 125 | # expect_equal(when.next.edge.change(test,at=0),1) 126 | # expect_equal(when.next.edge.change(test,at=2),3) 127 | # expect_equal(when.next.edge.change(test,at=2,v=1),Inf) 128 | # # test a query in the gap 129 | # expect_equal(when.next.edge.change(test,at=3,v=2),6) 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /vignettes/networkDynamic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/networkDynamic/223552ab5ed500b7786f5f37e055b6fda84e379e/vignettes/networkDynamic.pdf --------------------------------------------------------------------------------