Multispecies

Fitting a multispecies model of binomially-distributed data

data

# make fake data
n_species <- 10
n_env <- 3
n_sites <- 20
n_obs <- 4

env <- matrix(rnorm(n_sites * n_env), nrow = n_sites)
occupancy <- matrix(rbinom(n_species * n_sites, n_obs, 0.5), nrow = n_sites)

greta code

alpha <- normal(0,10, dim = n_species)
beta <- normal(0, 10, dim = c(n_env, n_species))
env_effect <- env %*% beta

# matrix addition with `sweep()` create interim variable
eta <- sweep(env_effect, 2, alpha, FUN = '+')

# ilogit of linear predictor
p <- ilogit(eta)

distribution(occupancy) <- binomial(n_obs, p)


goldingn/greta documentation built on May 24, 2021, 11 a.m.