################################################################################ ### ### ---- RscriptSienaSymmetric.R: a script for analyzing symmetric networks ### ### version June 21, 2023 ### ### This script gives a bare-bones demonstration ### of using RSiena for nondirected networks. ### ### The model is presented in ### Snijders, T. A. B. and Pickup, M. (2017). ### Stochastic actor-oriented models for network dynamics. ### In Victor, J. N., Montgomery, A. H., and Lubell, M., editors, ### Oxford Handbook of Political Networks, pages 221-247. ### Oxford University Press, Oxford. ### http://www.stats.ox.ac.uk/~snijders/SnijdersPickup2016.pdf ### ################################################################################ library(RSiena) # input data; for a description see the data page of the Siena website and ?s50 # The data used here are internal to RSiena. friend.data.w1 <- s501 friend.data.w2 <- s502 friend.data.w3 <- s503 drink <- s50a smoke <- s50s # These networks are not symmetric; we shall symmetrize them # just for the purpose of illustration. # Make a function that symmetrizes the network # requiring ties to be mutual sym.min <- function(x) { # Symmetrizing a square matrix by the minimum tx <- t(x) return(pmin(x[],tx[])) } # check this function a <- matrix(c(1,2),4,4) a sym.min(a) friend.data.w1 <- sym.min(friend.data.w1) friend.data.w2 <- sym.min(friend.data.w2) friend.data.w3 <- sym.min(friend.data.w3) # Prepare data for RSiena. friendship <- sienaDependent( array( c( friend.data.w1, friend.data.w2, friend.data.w3 ), dim = c( 50, 50, 3 ) ) )# create dependent variable smoke1 <- coCovar( smoke[ , 1 ] )# create constant covariate alcohol <- varCovar( drink )# create time varying covariate mydata <- sienaDataCreate( friendship, smoke1, alcohol )# define data myeff <- getEffects( mydata )# create effects structure myeff <- includeEffects( myeff, transTriads) print01Report( mydata, modelname = 's50_sym' )# siena01 for reports # Which effects are available for the symmetric network? effectsDocumentation(myeff) # Run the model in the various different specifications, myalgo <- sienaAlgorithmCreate(projname = "s50_sym", seed=111) myalgo2 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=2), seed=112) myalgo3 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=3), seed=113) myalgo4 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=4), seed=114) myalgo5 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=5), seed=115) myalgo6 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=6), seed=116) (ans <- siena07( myalgo, data = mydata, effects = myeff)) (ans2 <- siena07( myalgo2, data = mydata, effects = myeff)) (ans3 <- siena07( myalgo3, data = mydata, effects = myeff)) (ans4 <- siena07( myalgo4, data = mydata, effects = myeff)) (ans5 <- siena07( myalgo5, data = mydata, effects = myeff)) # In some cases with modelType=5, the requirement of # agreement between both actors lead to a blockade and the # impossibility to achieve the observed number of transitive triads. # That is the case here. # Try another model specification: myeff2 <- includeEffects( myeff, transTriads, include=FALSE) myeff2 <- includeEffects( myeff2, gwesp) (ans5.2 <- siena07( myalgo5, data = mydata, effects = myeff2)) # This also does not converge. myeff3 <- includeEffects( myeff, transTriads, include=FALSE) myeff3 <- includeEffects( myeff3, balance) (ans5.3 <- siena07( myalgo5, data = mydata, effects = myeff3)) # This does converge. # There are some special effects for non-directed networks; see the manual. # For example, the analogue of inAct/inPop/outAct/outPop is degPlus: (myeff4 <- includeEffects(myeff, degPlus)) (ans.4 <- siena07( myalgo, data = mydata, effects = myeff4)) (ans2.4 <- siena07( myalgo2, data = mydata, effects = myeff4)) (ans3.4 <- siena07( myalgo3, data = mydata, effects = myeff4)) (ans4.4 <- siena07( myalgo4, data = mydata, effects = myeff4)) # For modeltype 3, initiative and reciprocal confirmation, # an offset can be added to the confirmation part: myalgo3.1 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=3), Offset = c(friendship=1)) (ans31.4 <- siena07( myalgo3.1, data = mydata, effects = myeff4)) # Very large offset values let confirmation have probability close to 1, # reducing this model to almost the forcing model: myalgo3.10 <- sienaAlgorithmCreate(projname = "s50_sym", modelType = c(friendship=3), Offset = c(friendship=10)) (ans310.4 <- siena07( myalgo3.10, data = mydata, effects = myeff4)) # You can inspect file s50_sym.out for the results.