Created
October 7, 2019 18:05
-
-
Save monogenea/bf3981ec96085368e29af80dba1b8a6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define model effects | |
sigmaML <- cauchy(0, 1, truncation = c(0, Inf), dim = 3) | |
a_fem <- normal(0, sigmaML[1], dim = max(female_id)) | |
a_year <- normal(0, sigmaML[2], dim = max(year)) | |
a_group <- normal(0, sigmaML[3], dim = max(group_id)) | |
a <- normal(0, 5) | |
bA <- normal(0, 3) | |
bEL <- normal(0, 3) | |
bES <- normal(0, 3) | |
bGS <- normal(0, 3) | |
bP <- normal(0, 3) | |
bPA <- normal(0, 3) | |
# Model setup | |
mu <- a + a_fem[female_id] + a_year[year] + a_group[group_id] + | |
Age*bA + Eggs_laid*bEL + Mean_eggsize*bES + Parasite*bP + | |
Group_size*bGS + Parasite*Age*bPA | |
p <- ilogit(mu) | |
distribution(fro$Successful) <- bernoulli(p) | |
cuckooModel <- model(a, bA, bEL, bES, bP, bGS, bPA) | |
# Plot | |
plot(cuckooModel) | |
# HMC sampling | |
draws <- mcmc(cuckooModel, n_samples = 4000, | |
warmup = 1000, chains = 4, n_cores = 10) | |
# Trace plots | |
mcmc_trace(draws) | |
# Parameter posterior | |
mcmc_intervals(draws, prob = .95) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment