# (Single behavior): --------------------------------------------------------
# A simple example
set.seed(123)
diffnet_1 <- rdiffnet(100,10)
diffnet_1
summary(diffnet_1)
# Adopt if at least two neighbors have adopted ------
n <- 100; t <- 5;
graph <- rgraph_ws(n, t, p=.3)
diffnet_2 <- rdiffnet(seed.graph = graph, t = t, threshold.dist=function(x) 2,
exposure.args=list(valued=FALSE, normalized=FALSE))
# Re thinking the Adoption of Tetracycline ----------
newMI <- rdiffnet(seed.graph = medInnovationsDiffNet$graph,
threshold.dist = threshold(medInnovationsDiffNet), rewire=FALSE)
# (Multiple behavior): ------------------------------------------------------
# A simple example
set.seed(123)
diffnet_3 <- rdiffnet(100, 10, seed.p.adopt = list(0.1, 0.15))
diffnet_3
summary(diffnet_3)
# Fully specified multi-behavior example ------------
threshold_matrix <- matrix(runif(n * 2), nrow = n, ncol = 2)
seed_nodes <- sample(1:100, 10, replace = FALSE)
diffnet_4 <- rdiffnet(100, 10, seed.p.adopt = list(0, 0),
seed.nodes = list(seed_nodes, seed_nodes),
threshold.dist = threshold_matrix,
behavior = c("tobacco", "alcohol"))
diffnet_4
# Adopt if at least one neighbor has adopted the first behavior,
# and at least two neighbors have adopted the second behavior. ---
diffnet_5 <- rdiffnet(seed.graph = graph, t = t, seed.p.adopt = list(0.1, 0.1),
threshold.dist = list(function(x) 2, function(x) 2),
exposure.args=list(valued=FALSE, normalized=FALSE))
diffnet_5
# With a disadoption function -----------------------
set.seed(1231)
random_dis <- function(expo, cumadopt, time) {
num_of_behaviors <- dim(cumadopt)[3]
list_disadopt <- list()
for (q in 1:num_of_behaviors) {
adopters <- which(cumadopt[, time, q, drop=FALSE] == 1)
if (length(adopters) == 0) {
# only disadopt those behaviors with adopters
list_disadopt[[q]] <- integer()
} else {
# selecting 10% of adopters to disadopt
list_disadopt[[q]] <- sample(adopters, ceiling(0.10 * length(adopters)))
}
}
return(list_disadopt)
}
diffnet_6 <- rdiffnet(
seed.graph = graph, t = 10, disadopt = random_dis,
seed.p.adopt = list(0.1, 0.1)
)
# (Multiple simulations of single behavior): --------------------------------
# Simulation study comparing the diffusion with diff sets of seed nodes
# Random seed nodes
set.seed(1)
ans0 <- rdiffnet_multiple(R=50, statistic=function(x) sum(!is.na(x$toa)),
n = 100, t = 4, seed.nodes = "random", stop.no.diff=FALSE)
# Central seed nodes
set.seed(1)
ans1 <- rdiffnet_multiple(R=50, statistic=function(x) sum(!is.na(x$toa)),
n = 100, t = 4, seed.nodes = "central", stop.no.diff=FALSE)
boxplot(cbind(Random = ans0, Central = ans1), main="Number of adopters")
Run the code above in your browser using DataLab