# Dynamic network of class -diffnet-
# Name : A diffusion network
# Behavior : Random contagion_1, Random contagion_2
# # of nodes : 54 (1, 2, 3, 4, 5, 6, 7, 8, ...)
# # of time periods : 11 (1 - 11)
# Type : directed
# Num of behaviors : 2
# Prevalence : 0.96, 0.69
# Static attributes : real_threshold.1, real_threshold.2 (2)
# Dynamic attributes : -
Multiadoption visualization
We can use the split_behaviors function to split a diffnet object into a list of diffnet objects.
Tip
Until now, the multi-adoption module simulates behaviors independently, so the code above is equivalent to simulating the same behavior twice. Models with interdependent behaviors are supported via the disadopt parameter.
Then, we can use the plot_adopters (or any single-adoption function) to visualize the diffusion process for each behavior:
diffnets_1 <-split_behaviors(diffnet_1)op <-par(mfrow=c(1,2), cex = .8)plot_adopters(diffnets_1[[1]], main ="Behavior 1")plot_adopters(diffnets_1[[2]], main ="Behavior 2")
par(op)
Disadoption
The rdiffnet function includes the disadopt parameter to add a disadoption function, that:
Receives three arguments: expo, cumadopt, and time.
expo is the exposure array with three dimensions: # of nodes # of time points # of behaviors.
cumadopt is the cumulative adoption array, with the same dimensions as expo. So, if cumadopt[i, t, q] = 1, then i is an adopter of behavior q at time t.
time is the current time point in the simulation.
Must return a list with one element per behavior: the -th element is a vector with the nodes that disadopt behavior .
If no node disadopts a given behavior, return an empty vector integer() for that element.
We can build a disadoption function that restricts nodes from adopting more than one behavior at a time:
The following code shows how to build such a function:
second_only <-function(expo, cumadopt, time) {# Identifying double adopters ids <-which(rowSums(cumadopt[, time, ]) ==2)# If there are no double adopters, return an empty listif (length(ids) ==0)return(list(integer(), integer()))# Otherwise, make them disadopt the first behaviorreturn(list(ids, integer()))}
Let’s simulate a diffusion process with the disadoption function second_only:
disadoption_function <-function(expo, cumadopt, time) {# 1) set number of behaviors# 2) iterate through the behaviors# 3) identify adopters at time t - 1# 4) select 10% of adopters to disadopt# 5) if there are no disadopters, return(list(integer(), integer())) }
create a disadoption function that randomly selects 10% of the adopters at time t - 1 for behaviors. (solution file)
Create a disadoption function that makes younger individuals disadopt sooner. You can use the kfamily dataset. (solution file)
Using the template for a disadoption function, create a disadoption function that simulates a fashion that dies incrementally over time. You can try this for one or more fads. (solution file)
Appendix
Other examples with multiadoption
To study a multi-adoption process, you can pass a list as the seed.p.adopt parameter.
Here is a simple example with two behaviors and synthetic data:
# Dynamic network of class -diffnet-
# Name : A diffusion network
# Behavior : Random contagion_1, Random contagion_2
# # of nodes : 200 (1, 2, 3, 4, 5, 6, 7, 8, ...)
# # of time periods : 10 (1 - 10)
# Type : directed
# Num of behaviors : 2
# Prevalence : 0.83, 0.92
# Static attributes : real_threshold.1, real_threshold.2 (2)
# Dynamic attributes : -
The “Num of behaviors” entry now shows 2, the “Behavior” entry also shows two behaviors, "Random contagion \_1, Random contagion\_2", and finally, the “Prevalence” entry also shows two numbers: 0.29, 0.97.
We can specify different parameters for each behavior: