Fitting a multispecies model of binomially-distributed 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)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.