-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_samples.R
executable file
·61 lines (46 loc) · 2 KB
/
generate_samples.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# This script is used to generate the samples required for results.R
# It is not recommended to run all samplers. Just choose the ones you need. The male fertility and co-resident samplers take a long time to run.
rm(list=ls())
library(tidyverse)
library(zoo)
library(viridis)
library(cowplot)
library(parallel)
library(doParallel)
source("R/supportFunctions.R")
cl <- makeCluster(5)
registerDoParallel(cl)
# Excess mortality (these functions save samples to the /samples/ folder)
source("R/sampleExcessMortality.R")
sampleExcessMortality()
loadAllCauseMortality()
loadMonthlyExcessMortality()
loadMonthlyAllCauseMortality()
# Female fertility
source("R/sampleFemaleFertility.R")
sampleFemaleFertility(by_child_age=FALSE)
sampleFemaleFertility(by_child_age=TRUE)
# Male fertility
source("R/sampleMaleFertility.R")
sampleMaleFertility(by_child_age=FALSE)
sampleMaleFertility(by_child_age=TRUE)
# Orphanhood
source("R/sampleOrphanhoodParental.R")
getPartnerAgeDist()
getPartnerAgeDist(regional=TRUE)
parentalOrphanhood = sampleParentalOrphanhood(mortality="allcause")
parentalOrphanhood = sampleParentalOrphanhood(mortality="excess")
# To estimate orphanhood by child-age, run the following command as an array job over CURRENT_AGE
# parentalOrphanhood = sampleParentalOrphanhood(mortality="excess", by_child_age=TRUE, current_child_age=CURRENT_AGE)
# and then call source("R/aggregateChildAgeSamples.R"), aggregateChildAgeSamples()
# Co-resident orphanhood. See R/sampleOrphanhoodCoresident.R for options. Run by_child_age as an array job as specified above.
source("R/sampleOrphanhoodCoresident.R")
coresidentOrphanhood = sampleCoresidentOrphanhood(N=5, mortality="allcause", output="any")
# Joint parental and co-res
source("R/sampleDoubleCoresAndParental.R")
sampleCoresAndParentalOrphanhood(mortality="allcause")
# Generate samples for supplementary material
source("R/estimateMaleFertilityAnnualRates.R")
estimateMaleAgeSpecificFertilityRates(regional=FALSE)
estimateMaleAgeSpecificFertilityRates(regional=TRUE)
stopCluster(cl)