# including only those who lived to reproductive age
library(dplyr); library(brms)
setwd("/usr/users/rarslan/updated_data/")
args = commandArgs()
dataset = args[6]
uptobyear = args[7]
if (dataset == "swed") {
load("swed1.rdata")
} else {
load(paste0(dataset, ".rdata"))
}
model_data = get(paste0(dataset, ".1")) %>% tbl_df() %>%
filter(surviveR == T | is.na(surviveR)) %>%
filter(byear < uptobyear) %>%
select(ever_married, birth_cohort, male, maternalage.factor, paternalage.mean, paternalage, paternal_loss, maternal_loss, older_siblings, nr.siblings, last_born, idParents) %>%
na.omit()
model = brm( ever_married ~ paternalage + birth_cohort + male + maternalage.factor + paternalage.mean + paternal_loss + maternal_loss + older_siblings + nr.siblings + last_born + (1 | idParents),
prior = c(set_prior("normal(0,5)", class = "b"),
set_prior("student_t(3, 0, 5)", class = "sd")),
family = bernoulli(link = "cauchit"), data = model_data,
chains = 6, iter = 1500, warmup = 1000, cores = 6, ranef = FALSE)
summary(model)
saveRDS(model, file = paste0("coefs/", dataset, "/e3_ever_married.rds"))