Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

tomthe/rsoc

Repository files navigation

rsocsim - preliminary socsim R package

https://github.com/MPIDR/rsocsim is the new home of this package! Everything new will happen there!

Installation

From Source

To get the latest version, you need to have RTools and devtools installed and install from source directly from this repository

  • install devtools
install.packages("devtools")
  • install rsocsim from Github with devtools:
devtools::install_github("MPIDR/rsocsim")

Install precompiled package (Windows only)

If the compilation from suorce fails, you can also install a pre-compiled binary. This might be easier, but it might be not the most up-to-date version. You can find the most up-to-date binary release on https://github.com/tomthe/rsoc/releases

> url = "https://github.com/tomthe/rsoc/releases/download/1.3/rsoc_1.3.zip"
> install.packages(url, repos = NULL, type = "win.binary")

Use rsocsim

Getting started

library("rsocsim")

# create a new folder for all the files related to a simulation.
# this will be in your home- or user-directory:
folder = rsocsim::create_simulation_folder()
#folder = "C:/Users/tom/socsim/socsim_sim_3792/"

# create a new supplement-file. Supplement-files tell socsim what
# to simulate. create_sup_file will create a very basic supplement filee
# and it copies some rate-files that will also be needed into the 
# simulation folder:
supfile = rsocsim::create_sup_file(folder)

# Choose a random-number seed:
seed = 300

# Start the simulation:
rsocsim::run1simulationwithfile(folder,supfile,seed,process_method = "inprocess")

The results will be saved into a subfolder of the simulation-`folder´. For more sophisticated simulations you will need to edit the supplement file and provide rate files for fertility, mortality and marriage rates.

library("rsocsim")

# specify the working directory, where your supfile and ratefiles are:
folder = "D:\\dev\\r\\socsimprojects\\CousinDiversity" 

# name of the supplement-file, relative to the above folder:
supfile = "CousinDiversity.sup" 

# Random number generator seed:
seed="33" 

# run1simulationwithfile starts a simulation with the specified sup-file
rsocsim::run1simulationwithfile(folder,supfile,seed)

# if you run several simulations, previous simulations may influence/corrupt
# later simulations. Use one of the options "future" or "clustercall" for
# process_method to prevent this. "future" has problems on computers with more
# than 64 cores. Note that these options prevent SOCSIM from writing to the
# R-terminal.

rsocsim::run1simulationwithfile(folder,supfile,seed,process_method = "future")
rsocsim::run1simulationwithfile(folder,supfile,seed,process_method = "clustercall")

Develop the package

You will need RTools, devtools and rcpp. Clone this repository, change something, hit "Build-->clean and rebuild"

renew documentation and some stuff with: devtools.document()

Future plans

  • Testing and verification
  • including convenient R-functions for generating input and reading/processing output
    • possible options:
      • include those functions into this package
      • create another package that loads this package