Back to the main Siena page

RSiena scripts



This page presents a number of RSiena scripts. They use data sets that can be downloaded from the Data sets page.

Firefox or Chrome will be better than Internet Explorer for showing the scripts presented here.

Remarks about errors or improvements may be sent to the RSiena Users' group at groups.io.

In case of an error, please do check that you are using the latest version of RSiena (check at RSiena at GitHub) - the error may have been corrected already. Error reports should be accompanied by complete data and scripts which reproduce the error! However, it should be noted that the functions in these scripts do not necessarily work for all (perhaps complicated) model specifications.



Scripts

    The five introductory scripts mentioned in Section 2.4 of the RSiena users' manual are contained with a sixth piece.

  1. basicRSiena.r
    An example of a basic sequence of commands for estimating a model by function siena07() of RSiena.

    See the associated MarkDown files:

  2. Rscript01DataFormat.R with some basic information about R, networks, data formats etc;
    with an example data file arclistdata.dat.
  3. RSienaSNADescriptives.R with some descriptives, using package sna.
  4. Rscript02SienaVariableFormat.R for how to specify data as variables in RSiena, and specify the model; using the s50 data set.
  5. Rscript03SienaRunModel.R for how to carry out the estimation and look at the results;
  6. Rscript04SienaBehaviour.R for how to specify models for dynamics of networks and behaviour;
  7. In addition there are some other scripts.

  8. RscriptSienaMultiple.R for how to specify models for dynamics of multiple (i.e., multivariate) networks;
    this uses a manufactured data set (longitudinal, 2 waves, 2 networks);
  9. RscriptSienaTimeTest.R an example of testing time heterogeneity, using the van de Bunt students data set.
  10. RscriptMultipleGroups_meta.R an example of meta-analysis with the metafor package and siena08, and of the multiple group option, using Chris Baerveldt's Dutch Social Behavior data set.
    This script uses friendship and delinquent behavior as dependent variables.
  11. RscriptMultipleGroups_meta2.R an example of meta-analysis with the metafor package and siena08, and of the multiple group option, using Chris Baerveldt's Dutch Social Behavior data set.
    This script uses only friendship as the dependent variable.
  12. RscriptMultipleGroups.R a more limited example (fewer groups) of the multiple group option and of meta-analysis using function siena08, using Chris Baerveldt's Dutch Social Behavior data set.
  13. RscriptSienaOrdered.R an example of modeling a network with ordered ties (i.e., valued ties with a small set of ordered categories), by representing them as multiple, ordered networks, using the van de Bunt students data set.
  14. RscriptSienaBipartite.R an example of co-evolution of a one-mode and several two-mode networks, using a set with substance use variables of the Glasgow Teenage Friends and Lifestyle Study data.
    This is an old script, written before the current high standards of convergence were followed.
  15. Two scripts showing how to analyze a two-mode network as a one-mode network, using structural zeros.
    This sometimes is useful because it opens up some further possibilities to use RSiena options. The scripts use the data set of the Glasgow Teenage Friends and Lifestyle Study.

  16. RscriptSienaSymmetric.R a brief example of modeling a non-directed network, using the s50 data set.
  17. Composition change in a network: R script and data for illustration, also see the slides.
  18. Simulation of networks with a given model specification: NetworkSimulation.R.
  19. Goodness of fit:
    An example script for how to use sienaGOF() is in sienaGOF_vdB.R.
  20. Scripts to help making selection tables (see the corresponding section in the manual):
    SelectionTables.r.
  21. Scripts to help making influence tables (see the corresponding section in the manual):
    InfluenceTables.r.
  22. A script illustrating the numerical description of the distinction between selection and influence by a decomposition of the Moran statistic according to Steglich, Snijders & Pearson (2010, Sociological Methodology):
    MoranDecompositionExample.R.
  23. Random coefficient multilevel estimation of the Stochastic Actor-Oriented Model:

  24. A script by Robert Krause, detailing how to implement multiple imputation of missing data as proposed in the paper
    Robert W. Krause, Mark Huisman, and Tom A.B. Snijders (2018), Multiple imputation for longitudinal network data. Italian Journal of Applied Statistics, 30, 33-57.
    http://sa-ijas.stat.unipd.it/sites/sa-ijas.stat.unipd.it/files/10.26398-IJAS.0030-002.pdf

  25. A script by Robert Krause and Anna Iashina, detailing how to implement multiple imputation of missing data for network and behavior studies.
  26. Script how to interpret the chains that are returned by siena07 when returnChains=TRUE:
  27. The scripts for executing the visualizations in the paper

    jimi Adams and David Schaefer (2018). Visualizing Stochastic Actor-based Model Microsteps. Socius, "Sociological Research for a Dynamic World", Sage Publications.
    DOI: https://doi.org/10.1177/2378023118816545

    Supplementary materials of the paper:

    1. 01_Model_and_Sim.R
      This file is code for running the Stochastic actor-oriented model, and outputting a single chain from the results in dataframe format, using the returnChains parameter. See also the file WorkOnChains.r mentioned above.
      In the example included in the paper, the 50th chain from the estimation between Waves I and II is used, with the s50 data set internal in RSiena. You can change these settings in the code.
    2. 02_Visualization.R
      This file takes the dataframe output from the script above, combines it with the initial network data from the s501 datafile, and converts those into a networkDynamic object that is visualized with the ndtv package. The connection between the previous script and this is the dataframe called df. Execution of this script requires that you have the networkDynamic and ndtv packages (with dependencies) installed.
    3. 03_Viz_Only.html (5MB)
      This file is only the dynamic visualization (Figure 1 in the paper) as an embeddable html file.
  28. A script for checking whether the number of runs in Phase 3 is large enough for reliable estimation of standard errors:
    SE_checks.R

    and a script illustrating its use:
    RscriptStandardErrors.R.

  29. script_traceRM.R, demonstrating the use of the option returnThetas=TRUE available in siena07 since version 1.3.3 of RSiena. This returns the values of parameters theta generated during Phase 2 of the algorithm in the Robbins-Monro steps.
  30. GMoMscript.R, demonstrating how to use the Generalized Method of Moments (GMoM), since version 1.2.32. Also see the manual, Sections 6.9 and 6.10.
  31. vdB_effsize.R, containing examples of effect size measures using options available since version 1.3.12. Also see the manual, Sections 13.5.2 and 13.5.3.
  32. At the code website of Nynke Niezink, there is an R Markdown tutorial on how to use in RSiena the model for the co-evolution of networks and continuous individual attributes. This tutorial uses a data set obtainable from the same website.


Practicals

  1. Lab exercise: sex segregation of friendship networks
  2. Some scripts on data conversion: zip archive with examples
  3. Modelling the co-evolution of networks and behaviour: slides and script.
  4. Co-evolution of friendship, alcohol consumption, and musical taste; re-analysis of Steglich, Snijders, and West (2006).
  5. Lab: multiple group analyses
  6. Lab: analysis of multiplex networks
  7. Lab: two-mode network analysis

Here are r scripts for some of the practicals.



Back to the main Siena page