## The following example is taken from section 4.1 and 4.2 in package vignette
## C. Stadtfeld: "Netsim: A Social Networks Simulation tool in R" (2013)
## Examples of the other models can be taken from that source
# construct process state
nActors <- 21
mat <- matrix(0, nActors, nActors)
att <- c(rep(0, nActors/3),rep(1, nActors/3),rep(2, nActors/3))
network <- create_network(mat)
attributeContainer <- create_scale_attribute_container(att,
min=0, max=3, by = 1)
processState <- create_process_state()
processState <- add_network(processState, network, name = "network")
processState <- add_attribute_container(processState, attributeContainer,
name = "attribute")
networkIndex <- get_network_index(processState)
attributeIndex <- get_attribute_container_index(processState)
# construct effect container
# homophily model with basic network effects
effectContainerHomophily <- create_effect_container()
effectContainerHomophily <- add_to_effect_container(
effectContainerHomophily,
create_effect("density", networkIndex),
-2.5)
effectContainerHomophily <- add_to_effect_container(
effectContainerHomophily,
create_effect("recip", networkIndex),
2.5)
effectContainerHomophily <- add_to_effect_container(
effectContainerHomophily,
create_effect("transTrip", networkIndex),
0.5)
effectContainerHomophily <- add_to_effect_container(
effectContainerHomophily,
create_effect("cycle3", networkIndex),
-0.5)
effectContainerHomophily <- add_to_effect_container(
effectContainerHomophily,
create_effect("simX",
attributeIndex,
networkIndex,
0.5),
1.0)
# effect container of the behavior change model
effectContainerInfluence <- create_effect_container()
effectContainerInfluence <- add_to_effect_container(
effectContainerInfluence,
create_effect("linear",
attributeIndex),
0.0)
effectContainerInfluence <- add_to_effect_container(
effectContainerInfluence,
create_effect("quad",
attributeIndex),
0.0)
effectContainerInfluence <- add_to_effect_container(
effectContainerInfluence,
create_effect("totSim",
attributeIndex,
networkIndex, 10/18),
2.0)
# Definition of SAOM network model manager
modelManager <- create_model_manager()
# assign homophily model to all actors
for (i in c(0 : (nActors - 1) ) ){
# Poisson models
poissonParameterInfluence <- 5
poissonModelInfluence <- create_poisson_model(
poissonParameterInfluence)
poissonParameter <- 40
poissonModel <- create_poisson_model(poissonParameter)
# saom change models
saomHomophilyModel <- create_multinomial_choice_network_change_model(
i,
networkIndex,
effectContainerHomophily)
behaviorSaom <- create_multinomial_choice_behavior_change_model(
i,
attributeIndex,
effectContainerInfluence
)
# updaters
setAttributeUpdater <- create_actor_attribute_set_updater(
attributeIndex, i)
tieSwapUpdater <- create_tie_swap_updater(networkIndex)
# define model chains
modelManager <<- add_time_model(modelManager,
poissonModel)
modelManager <<- add_change_model(modelManager,
poissonModel,
saomHomophilyModel)
modelManager <<- add_updater(modelManager,
saomHomophilyModel,
tieSwapUpdater)
modelManager <<- add_time_model(modelManager,
poissonModelInfluence)
modelManager <<- add_change_model(modelManager,
poissonModelInfluence,
behaviorSaom)
modelManager <<- add_updater(modelManager,
behaviorSaom,
setAttributeUpdater)
} # for loop
simulator <- create_simulator(processState, modelManager, 10)
# commented out due to Windows compilation problems. Further tests needed!
## Not run: simulate(simulator)
Run the code above in your browser using DataLab