rm(list=ls())
library(foreign)
library(rstanarm)
library(rstan)
library(Hmisc)
library(data.table)
library(parallel)

ncores = 4

setwd('~/research/gTiger/Article_citsci/open_code')
source('settings/parameters.r')
source('settings/paths.r')
source('settings/functions.r')

setwd(path_to_data)

rstan_options(auto_write = TRUE)
options(mc.cores = ncores)

D = readRDS('ovitrap_model_dataset.Rds')

D$trials = 1

M = stan_glmer(cbind(Egg_pres, trials-Egg_pres)~Expos_days_std2 + sea_days_std2 + sea_days_std2_sq + sea_days_std2_cu + (1 | TigacellID) + (1 | Trap_ID),data=D, family=binomial(link = "logit"), prior = student_t(df = 1, location=0, scale=2.5), prior_intercept = student_t(df = 1, location=0, scale=2.5), chains = ncores, cores = ncores)

summary(M)

saveRDS(M, 'untracked/ovitrap_model_M0e.Rds')
