R Under development (unstable) (2024-12-07 r87428 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > require("network") Loading required package: network 'network' 1.19.0 (2024-12-08), part of the Statnet Project * 'news(package="network")' for changes since last version * 'citation("network")' for citation information * 'https://statnet.org' for help, support, and other information > set.seed(1702) > > results = NULL > > data("flo") > data("emon") > > net <- network.initialize(5) > net Network attributes: vertices = 5 directed = TRUE hyper = FALSE loops = FALSE multiple = FALSE bipartite = FALSE total edges= 0 missing edges= 0 non-missing edges= 0 Vertex attribute names: vertex.names No edge attributes > > nmat <- matrix(rbinom(25, 1, 0.5), nr = 5, nc = 5) > net <- network(nmat, loops = TRUE) > net Network attributes: vertices = 5 directed = TRUE hyper = FALSE loops = TRUE multiple = FALSE bipartite = FALSE total edges= 9 missing edges= 0 non-missing edges= 9 Vertex attribute names: vertex.names No edge attributes > > summary(net) Network attributes: vertices = 5 directed = TRUE hyper = FALSE loops = TRUE multiple = FALSE bipartite = FALSE total edges = 9 missing edges = 0 non-missing edges = 9 density = 0.36 Vertex attributes: vertex.names: character valued attribute 5 valid vertex names No edge attributes Network adjacency matrix: 1 2 3 4 5 1 1 0 1 0 1 2 1 0 0 1 0 3 1 0 1 1 0 4 0 0 1 0 0 5 0 0 0 0 0 > results[1] = all(nmat == net[,]) > > net <- as.network(nmat, loops = TRUE) > results[2] = all(nmat == net[,]) > > nflo <- network(flo, directed = FALSE) > nflo Network attributes: vertices = 16 directed = FALSE hyper = FALSE loops = FALSE multiple = FALSE bipartite = FALSE total edges= 20 missing edges= 0 non-missing edges= 20 Vertex attribute names: vertex.names No edge attributes > > results[3] = all(nflo[9,] == c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1)) > results[4] = nflo[9,1] == 1 > results[5] = nflo[9,4] == 0 > results[6] = is.adjacent(nflo, 9, 1) == TRUE > results[7] = is.adjacent(nflo, 9, 4) == FALSE > > results[8] = network.size(nflo) == 16 > results[9] = network.edgecount(nflo) == 20 > results[10] = network.density(nflo) == 1/6 > results[11] = has.loops(nflo) == FALSE > results[12] = is.bipartite(nflo) == FALSE > results[13] = is.directed(nflo) == FALSE > results[14] = is.hyper(nflo) == FALSE > results[15] = is.multiplex(nflo) == FALSE > > as.sociomatrix(nflo) Acciaiuoli Albizzi Barbadori Bischeri Castellani Ginori Guadagni Acciaiuoli 0 0 0 0 0 0 0 Albizzi 0 0 0 0 0 1 1 Barbadori 0 0 0 0 1 0 0 Bischeri 0 0 0 0 0 0 1 Castellani 0 0 1 0 0 0 0 Ginori 0 1 0 0 0 0 0 Guadagni 0 1 0 1 0 0 0 Lamberteschi 0 0 0 0 0 0 1 Medici 1 1 1 0 0 0 0 Pazzi 0 0 0 0 0 0 0 Peruzzi 0 0 0 1 1 0 0 Pucci 0 0 0 0 0 0 0 Ridolfi 0 0 0 0 0 0 0 Salviati 0 0 0 0 0 0 0 Strozzi 0 0 0 1 1 0 0 Tornabuoni 0 0 0 0 0 0 1 Lamberteschi Medici Pazzi Peruzzi Pucci Ridolfi Salviati Strozzi Acciaiuoli 0 1 0 0 0 0 0 0 Albizzi 0 1 0 0 0 0 0 0 Barbadori 0 1 0 0 0 0 0 0 Bischeri 0 0 0 1 0 0 0 1 Castellani 0 0 0 1 0 0 0 1 Ginori 0 0 0 0 0 0 0 0 Guadagni 1 0 0 0 0 0 0 0 Lamberteschi 0 0 0 0 0 0 0 0 Medici 0 0 0 0 0 1 1 0 Pazzi 0 0 0 0 0 0 1 0 Peruzzi 0 0 0 0 0 0 0 1 Pucci 0 0 0 0 0 0 0 0 Ridolfi 0 1 0 0 0 0 0 1 Salviati 0 1 1 0 0 0 0 0 Strozzi 0 0 0 1 0 1 0 0 Tornabuoni 0 1 0 0 0 1 0 0 Tornabuoni Acciaiuoli 0 Albizzi 0 Barbadori 0 Bischeri 0 Castellani 0 Ginori 0 Guadagni 1 Lamberteschi 0 Medici 1 Pazzi 0 Peruzzi 0 Pucci 0 Ridolfi 1 Salviati 0 Strozzi 0 Tornabuoni 0 > > results[16] = all(nflo[,] == as.sociomatrix(nflo)) > results[17] = all(as.matrix(nflo) == as.sociomatrix(nflo)) > as.matrix(nflo,matrix.type = "edgelist") [,1] [,2] [1,] 9 1 [2,] 6 2 [3,] 7 2 [4,] 9 2 [5,] 5 3 [6,] 9 3 [7,] 7 4 [8,] 11 4 [9,] 15 4 [10,] 11 5 [11,] 15 5 [12,] 8 7 [13,] 16 7 [14,] 13 9 [15,] 14 9 [16,] 16 9 [17,] 14 10 [18,] 15 11 [19,] 15 13 [20,] 16 13 attr(,"n") [1] 16 attr(,"vnames") [1] "Acciaiuoli" "Albizzi" "Barbadori" "Bischeri" "Castellani" [6] "Ginori" "Guadagni" "Lamberteschi" "Medici" "Pazzi" [11] "Peruzzi" "Pucci" "Ridolfi" "Salviati" "Strozzi" [16] "Tornabuoni" > > net <- network.initialize(5, loops = TRUE) > net[nmat>0] <- 1 > results[18] = all(nmat == net[,]) > > net[,] <- 0 > net[,] <- nmat > results[19] = all(nmat == net[,]) > > net[,] <- 0 > for(i in 1:5) + for(j in 1:5) + if(nmat[i,j]) + net[i,j] <- 1 > results[20] = all(nmat == net[,]) > > net[,] <- 0 > add.edges(net, row(nmat)[nmat>0], col(nmat)[nmat>0]) > results[21] = all(nmat == net[,]) > > net[,] <- as.numeric(nmat[,]) > results[22] = all(nmat == net[,]) > > net <- network.initialize(5) > add.edge(net, 2, 3) > net[,] 1 2 3 4 5 1 0 0 0 0 0 2 0 0 1 0 0 3 0 0 0 0 0 4 0 0 0 0 0 5 0 0 0 0 0 > results[23] = net[2,3] == 1 > > add.edges(net, c(3, 5), c(4, 4)) > net[,] 1 2 3 4 5 1 0 0 0 0 0 2 0 0 1 0 0 3 0 0 0 1 0 4 0 0 0 0 0 5 0 0 0 1 0 > results[24] = (net[3,4] == 1 && net[5,4] == 1) > > net[,2] <- 1 > net[,] 1 2 3 4 5 1 0 1 0 0 0 2 0 0 1 0 0 3 0 1 0 1 0 4 0 1 0 0 0 5 0 1 0 1 0 > results[25] = net[2,2] == 0 > > delete.vertices(net, 4) > results[26] = all(net[,] == matrix(c(0,1,0,0,0,0,1,0,0,1,0,0,0,1,0,0), byrow=T, nrow=4)) > > add.vertices(net, 2) > net[,] 1 2 3 5 1 0 1 0 0 0 0 2 0 0 1 0 0 0 3 0 1 0 0 0 0 5 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > get.edges(net, 1) [[1]] [[1]]$inl [1] 2 [[1]]$outl [1] 1 [[1]]$atl [[1]]$atl$na [1] FALSE > get.edges(net, 2, neighborhood = "in") [[1]] [[1]]$inl [1] 2 [[1]]$outl [1] 4 [[1]]$atl [[1]]$atl$na [1] FALSE [[2]] [[2]]$inl [1] 2 [[2]]$outl [1] 3 [[2]]$atl [[2]]$atl$na [1] FALSE [[3]] [[3]]$inl [1] 2 [[3]]$outl [1] 1 [[3]]$atl [[3]]$atl$na [1] FALSE > get.edges(net, 1, alter = 2) [[1]] [[1]]$inl [1] 2 [[1]]$outl [1] 1 [[1]]$atl [[1]]$atl$na [1] FALSE > > results[27] = get.edgeIDs(net, 1) == 4 > results[28] = all(get.edgeIDs(net, 2, neighborhood = "in") == c(7, 5, 4)) > results[29] = get.edgeIDs(net, 1, alter = 2) == 4 > > results[30] = get.neighborhood(net, 1) == 2 > results[31] = all(get.neighborhood(net, 2, type = "in") == c(4, 3, 1)) > > net[2,3] <- 0 > results[32] = net[2,3] == 0 > > delete.edges(net, get.edgeIDs(net, 2, neighborhood = "in")) > results[33] = all(net[,] == matrix(0, 6,6)) > > net <- network.initialize(5) > set.network.attribute(net, "boo", 1:10) > net %n% "hoo" <- letters[1:7] > > results[34] = 'boo' %in% list.network.attributes(net) > results[35] = 'hoo' %in% list.network.attributes(net) > > results[36] = all(get.network.attribute(net, "boo") == c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) > results[37] = all(net %n% "hoo" == c("a", "b", "c", "d", "e", "f", "g")) > > delete.network.attribute(net, "boo") > results[38] = 'boo' %in% list.network.attributes(net) == FALSE > > set.vertex.attribute(net, "boo", 1:5) > net %v% "hoo" <- letters[1:5] > results[39] = 'boo' %in% list.vertex.attributes(net) > results[40] = 'hoo' %in% list.vertex.attributes(net) > > results[41] = all(get.vertex.attribute(net, "boo") == 1:5) > results[42] = all(net %v% "hoo" == letters[1:5]) > delete.vertex.attribute(net, "boo") > results[43] = 'boo' %in% list.vertex.attributes(net) == FALSE > > net <- network(nmat) > set.edge.attribute(net, "boo", sum(nmat):1) > set.edge.value(net, "hoo", matrix(1:25, 5, 5)) > net %e% "woo" <- matrix(rnorm(25), 5, 5) > net[,, names.eval = "zoo"] <- nmat * 6 > results[44] = 'boo' %in% list.edge.attributes(net) > results[45] = 'hoo' %in% list.edge.attributes(net) > > results[46] = all(get.edge.attribute(get.edges(net, 1), "boo") == c(3,7)) > results[47] = all(get.edge.value(net, "hoo") == c(2, 3, 11, 14, 17, 18, 21)) > net %e% "woo" [1] 0.8984226 0.4793125 3.7056453 0.7033602 -0.6100306 -0.4825138 -1.2331196 > as.sociomatrix(net, "zoo") 1 2 3 4 5 1 0 0 6 0 6 2 6 0 0 6 0 3 6 0 0 6 0 4 0 0 6 0 0 5 0 0 0 0 0 > delete.edge.attribute(net, "boo") > results[48] = 'boo' %in% list.edge.attributes(net) == FALSE > > MtSHloc <- emon$MtStHelens %v% "Location" > MtSHimat <- cbind(MtSHloc %in% c("L", "B"), MtSHloc %in% c("NL", "B")) > MtSHbyloc <- network(MtSHimat, matrix = "incidence", hyper = TRUE, + directed = FALSE, loops = TRUE) > MtSHbyloc %v% "vertex.names" <- emon$MtStHelens %v% "vertex.names" > MtSHbyloc Network attributes: vertices = 27 directed = FALSE hyper = TRUE loops = TRUE multiple = FALSE bipartite = FALSE total edges= 2 missing edges= 0 non-missing edges= 2 Vertex attribute names: vertex.names No edge attributes > > plot(nflo, displaylabels = TRUE, boxed.labels = FALSE) > plot(nflo, displaylabels = TRUE, mode = "circle") > plot(emon$MtSi) > > if (!all(results)) { + stop(paste('The following tests in vignette.R failed:', which(results==FALSE))) + } > > > proc.time() user system elapsed 0.54 0.26 0.79