From 4b197a129f4ab3d83150899a17cd2d43d653ef2a Mon Sep 17 00:00:00 2001 From: Fiona Seaton Date: Tue, 19 Dec 2023 17:30:48 +0000 Subject: [PATCH] Add binomial distribution --- R/jsdm_stancode.R | 36 ++++++------ R/posterior_predict.R | 42 ++++++++++---- R/sim_data_funs.R | 86 ++++++++++++++++++---------- R/stan_jsdm.R | 43 ++++++++++++-- man/jsdm_sim_data.Rd | 59 ++++++++++--------- man/posterior_predict.jsdmStanFit.Rd | 5 ++ man/stan_gllvm.Rd | 3 +- man/stan_jsdm.Rd | 8 ++- man/stan_mglmm.Rd | 3 +- 9 files changed, 190 insertions(+), 95 deletions(-) diff --git a/R/jsdm_stancode.R b/R/jsdm_stancode.R index 85fe886..8ca61b0 100644 --- a/R/jsdm_stancode.R +++ b/R/jsdm_stancode.R @@ -36,7 +36,8 @@ jsdm_stancode <- function(method, family, prior = jsdm_prior(), log_lik = TRUE, site_intercept = "none", beta_param = "cor") { # checks - family <- match.arg(family, c("gaussian", "bernoulli", "poisson", "neg_binomial")) + family <- match.arg(family, c("gaussian", "bernoulli", "poisson", + "neg_binomial","binomial")) method <- match.arg(method, c("gllvm", "mglmm")) beta_param <- match.arg(beta_param, c("cor","unstruct")) site_intercept <- match.arg(site_intercept, c("none","grouped","ungrouped")) @@ -62,9 +63,11 @@ jsdm_stancode <- function(method, family, prior = jsdm_prior(), data <- paste( " int N; // Number of sites int S; // Number of species - ", ifelse(method == "gllvm", - "int D; // Number of latent dimensions", "" +", ifelse(method == "gllvm", + " int D; // Number of latent dimensions", "" ), + ifelse(family == "binomial", + " int Ntrials[N]; // Number of trials",""), " int K; // Number of predictor variables matrix[N, K] X; // Predictor matrix @@ -77,7 +80,8 @@ jsdm_stancode <- function(method, family, prior = jsdm_prior(), "gaussian" = "real", "bernoulli" = "int", "neg_binomial" = "int", - "poisson" = "int" + "poisson" = "int", + "binomial" = "int" ), "Y[N,S]; //Species matrix" ) transformed_data <- ifelse(method == "gllvm", " @@ -255,7 +259,8 @@ jsdm_stancode <- function(method, family, prior = jsdm_prior(), kappa ~ ", prior[["kappa"]], "; "), "bern" = "", - "poisson" = "" + "poisson" = "", + "binomial" = "" ) ) model_pt2 <- paste( @@ -265,7 +270,8 @@ jsdm_stancode <- function(method, family, prior = jsdm_prior(), "gaussian" = "normal(mu[i,], sigma);", "bernoulli" = "bernoulli_logit(mu[i,]);", "neg_binomial" = "neg_binomial_2_log(mu[i,], kappa);", - "poisson" = "poisson_log(mu[i,]);" + "poisson" = "poisson_log(mu[i,]);", + "binomial" = "binomial_logit(Ntrials[i], mu[i,]);" ) ) @@ -316,18 +322,12 @@ jsdm_stancode <- function(method, family, prior = jsdm_prior(), for(j in 1:S) { log_lik[i, j] = ", switch(family, - "gaussian" = "normal_lpdf", - "bernoulli" = "bernoulli_logit_lpmf", - "neg_binomial" = "neg_binomial_2_log_lpmf", - "poisson" = "poisson_log_lpmf" - ), - "(Y[i, j] | linpred[i, j]", - switch(family, - "gaussian" = ", sigma)", - "bernoulli" = ")", - "neg_binomial" = ", kappa)", - "poisson" = ")" - ), "; + "gaussian" = "normal_lpdf(Y[i, j] | linpred[i, j], sigma);", + "bernoulli" = "bernoulli_logit_lpmf(Y[i, j] | linpred[i, j]);", + "neg_binomial" = "neg_binomial_2_log_lpmf(Y[i, j] | linpred[i, j], kappa);", + "poisson" = "poisson_log_lpmf(Y[i, j] | linpred[i, j]);", + "binomial" = "binomial_logit_lpmf(Y[i, j] | Ntrials[i], linpred[i, j]);" + )," } } } diff --git a/R/posterior_predict.R b/R/posterior_predict.R index 9291c1f..768690d 100644 --- a/R/posterior_predict.R +++ b/R/posterior_predict.R @@ -161,7 +161,8 @@ posterior_linpred.jsdmStanFit <- function(object, transform = FALSE, "gaussian" = x, "bernoulli" = inv_logit(x), "poisson" = exp(x), - "neg_binomial" = exp(x) + "neg_binomial" = exp(x), + "binomial" = inv_logit(x) ) }) } @@ -184,6 +185,10 @@ posterior_linpred.jsdmStanFit <- function(object, transform = FALSE, #' #' @inheritParams posterior_linpred.jsdmStanFit #' +#' @param Ntrials For the binomial distribution the number of trials, given as +#' either a single integer which is assumed to be constant across sites or as +#' a site-length vector of integers. +#' #' @return A list of linear predictors. If list_index is \code{"draws"} (the default) #' the list will have length equal to the number of draws with each element of #' the list being a site x species matrix. If the list_index is \code{"species"} the @@ -200,7 +205,8 @@ posterior_linpred.jsdmStanFit <- function(object, transform = FALSE, posterior_predict.jsdmStanFit <- function(object, newdata = NULL, newdata_type = "X", ndraws = NULL, draw_ids = NULL, - list_index = "draws", ...) { + list_index = "draws", + Ntrials = NULL, ...) { transform <- ifelse(object$family == "gaussian", FALSE, TRUE) post_linpred <- posterior_linpred(object, newdata = newdata, ndraws = ndraws, @@ -214,20 +220,32 @@ posterior_predict.jsdmStanFit <- function(object, newdata = NULL, if (object$family == "neg_binomial") { mod_kappa <- rstan::extract(object$fit, pars = "kappa", permuted = FALSE) } + if(object$family == "binomial" & is.null(newdata)) { + Ntrials <- object$data_list$Ntrials + } n_sites <- length(object$sites) n_species <- length(object$species) - post_pred <- lapply(post_linpred, function(x, family = object$family) { - x2 <- x - x2 <- apply(x2, 1:2, function(x) { - switch(object$family, - "gaussian" = stats::rnorm(1, x, mod_sigma), - "bernoulli" = stats::rbinom(1, 1, x), - "poisson" = stats::rpois(1, x), - "neg_binomial" = rgampois(1, x, mod_kappa) - ) - }) + post_pred <- lapply(seq_along(post_linpred), + function(x, family = object$family) { + x2 <- post_linpred[[x]] + if(family == "binomial"){ + for(i in 1:nrow(x2)){ + for(j in 1:ncol(x2)){ + x2[i,j] <- stats::rbinom(1, Ntrials[i], x2[i,j]) + } + } + } else { + x2 <- apply(x2, 1:2, function(x) { + switch(object$family, + "gaussian" = stats::rnorm(1, x, mod_sigma), + "bernoulli" = stats::rbinom(1, 1, x), + "poisson" = stats::rpois(1, x), + "neg_binomial" = rgampois(1, x, mod_kappa) + ) + }) + } x2 }) diff --git a/R/sim_data_funs.R b/R/sim_data_funs.R index c18ecdf..8a26188 100644 --- a/R/sim_data_funs.R +++ b/R/sim_data_funs.R @@ -1,29 +1,29 @@ #' Generate simulated data within a variety of jSDM methodologies #' -#' The \code{jsdm_sim_data} function can simulate data with either a multivariate -#' generalised mixed model (MGLMM) or a generalised linear latent variable model -#' (GLLVM). The \code{gllvm_sim_data} and \code{mglmm_sim_data} are aliases for -#' \code{jsdm_sim_data} that set \code{method} to \code{"gllvm"} and \code{"mglmm"} -#' respectively. +#' The \code{jsdm_sim_data} function can simulate data with either a +#' multivariate generalised mixed model (MGLMM) or a generalised linear latent +#' variable model (GLLVM). The \code{gllvm_sim_data} and \code{mglmm_sim_data} +#' are aliases for \code{jsdm_sim_data} that set \code{method} to \code{"gllvm"} +#' and \code{"mglmm"} respectively. #' #' @details This simulates data based on a joint species distribution model with -#' either a generalised linear latent variable model approach or a multivariate -#' generalised linear mixed model approach. +#' either a generalised linear latent variable model approach or a +#' multivariate generalised linear mixed model approach. #' #' Models can be fit with or without "measured predictors", and if measured #' predictors are included then the species have species-specific parameter #' estimates. These can either be simulated completely independently, or have -#' information pooled across species. If information is pooled this can be modelled -#' as either a random draw from some mean and standard deviation or species -#' covariance can be modelled together (this will be the covariance used in the -#' overall model if the method used has covariance). +#' information pooled across species. If information is pooled this can be +#' modelled as either a random draw from some mean and standard deviation or +#' species covariance can be modelled together (this will be the covariance +#' used in the overall model if the method used has covariance). #' -#' Environmental covariate effects (\code{"betas"}) can be parameterised in two -#' ways. With the \code{"cor"} parameterisation all covariate effects are assumed -#' to be constrained by a correlation matrix between the covariates. With the -#' \code{"unstruct"} parameterisation all covariate effects are assumed to draw -#' from a simple distribution with no correlation structure. Both parameterisations -#' can be modified using the prior object. +#' Environmental covariate effects (\code{"betas"}) can be parameterised in +#' two ways. With the \code{"cor"} parameterisation all covariate effects are +#' assumed to be constrained by a correlation matrix between the covariates. +#' With the \code{"unstruct"} parameterisation all covariate effects are +#' assumed to draw from a simple distribution with no correlation structure. +#' Both parameterisations can be modified using the prior object. #' #' @export #' @@ -36,30 +36,36 @@ #' @param K is number of covariates, by default \code{0} #' #' @param family is the response family, must be one of \code{"gaussian"}, -#' \code{"neg_binomial"}, \code{"poisson"} or \code{"bernoulli"}. Regular -#' expression matching is supported. +#' \code{"neg_binomial"}, \code{"poisson"}, \code{"binomial"}, +#' or \code{"bernoulli"}. Regular expression matching is supported. #' #' @param method is the jSDM method to use, currently either \code{"gllvm"} or #' \code{"mglmm"} - see details for more information. #' -#' @param species_intercept Whether to include an intercept in the predictors, must -#' be \code{TRUE} if \code{K} is \code{0}. Defaults to \code{TRUE}. +#' @param species_intercept Whether to include an intercept in the predictors, +#' must be \code{TRUE} if \code{K} is \code{0}. Defaults to \code{TRUE}. +#' +#' @param Ntrials For the binomial distribution the number of trials, given as +#' either a single integer which is assumed to be constant across sites or as +#' a site-length vector of integers. #' #' @param site_intercept Whether a site intercept should be included, potential -#' values \code{"none"} (no site intercept) or \code{"ungrouped"} (site intercept -#' with no grouping). Defaults to no site intercept, grouped is not supported -#' currently. +#' values \code{"none"} (no site intercept) or \code{"ungrouped"} (site +#' intercept with no grouping). Defaults to no site intercept, grouped is not +#' supported currently. #' -#' @param beta_param The parameterisation of the environmental covariate effects, by -#' default \code{"unstruct"}. See details for further information. +#' @param beta_param The parameterisation of the environmental covariate +#' effects, by default \code{"unstruct"}. See details for further information. #' #' @param prior Set of prior specifications from call to [jsdm_prior()] jsdm_sim_data <- function(N, S, D = NULL, K = 0L, family, method = c("gllvm", "mglmm"), species_intercept = TRUE, + Ntrials = NULL, site_intercept = "none", beta_param = "unstruct", prior = jsdm_prior()) { - response <- match.arg(family, c("gaussian", "neg_binomial", "poisson", "bernoulli")) + response <- match.arg(family, c("gaussian", "neg_binomial", "poisson", + "bernoulli", "binomial")) site_intercept <- match.arg(site_intercept, c("none","ungrouped","grouped")) beta_param <- match.arg(beta_param, c("cor", "unstruct")) if(site_intercept == "grouped"){ @@ -89,6 +95,21 @@ jsdm_sim_data <- function(N, S, D = NULL, K = 0L, family, method = c("gllvm", "m stop("prior object must be of class jsdmprior, produced by jsdm_prior()") } + if(response == "binomial"){ + if(is.null(Ntrials)){ + stop("Number of trials must be specified for the binomial distribution") + } + if(!is.double(Ntrials) & !is.integer(Ntrials)){ + stop("Ntrials must be a positive integer") + } + if(!(length(Ntrials) %in% c(1, N))){ + stop("Ntrials must be of length 1 or N") + } + if(length(Ntrials) == 1L){ + Ntrials <- rep(Ntrials, N) + } + } + # prior object breakdown prior_split <- lapply(prior, strsplit, split = "\\(|\\)|,") if (!all(sapply(prior_split, function(x) { @@ -305,7 +326,8 @@ jsdm_sim_data <- function(N, S, D = NULL, K = 0L, family, method = c("gllvm", "m ), "gaussian" = stats::rnorm(1, mu_ij, sigma), "poisson" = stats::rpois(1, exp(mu_ij)), - "bernoulli" = stats::rbinom(1, 1, inv_logit(mu_ij)) + "bernoulli" = stats::rbinom(1, 1, inv_logit(mu_ij)), + "binomial" = stats::rbinom(1, Ntrials[i], inv_logit(mu_ij)) ) } } @@ -319,6 +341,9 @@ jsdm_sim_data <- function(N, S, D = NULL, K = 0L, family, method = c("gllvm", "m if(beta_param == "cor"){ pars$sigmas_preds <- sigmas_preds pars$z_preds <- z_preds + if(K != 0){ + pars$cor_preds <- cor_preds + } } if (site_intercept == "ungrouped") { @@ -352,6 +377,9 @@ jsdm_sim_data <- function(N, S, D = NULL, K = 0L, family, method = c("gllvm", "m output <- list( Y = Y, pars = pars, N = N, S = S, D = D, K = J, X = x ) + if(response == "binomial"){ + output$Ntrials <- Ntrials + } return(output) } @@ -431,7 +459,7 @@ rgampois <- function(n, mu, scale) { } inv_logit <- function(x) { - 1 / (1 + exp(x)) + 1 / (1 + exp(-x)) } diff --git a/R/stan_jsdm.R b/R/stan_jsdm.R index 26177f2..1dfd7de 100644 --- a/R/stan_jsdm.R +++ b/R/stan_jsdm.R @@ -27,7 +27,8 @@ #' @param D The number of latent variables within a GLLVM model #' #' @param family The response family for the model, required to be one of -#' \code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"} or \code{"neg_binomial"} +#' \code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"}, \code{"binomial"} +#' or \code{"neg_binomial"} #' #' @param species_intercept Whether the model should be fit with an intercept by #' species, by default \code{TRUE} @@ -44,6 +45,10 @@ #' @param site_groups If the site intercept is grouped, a vector of group identities #' per site #' +#' @param Ntrials For the binomial distribution the number of trials, given as +#' either a single integer which is assumed to be constant across sites or as +#' a site-length vector of integers. +#' #' @param prior Set of prior specifications from call to [jsdm_prior()] #' #' @param save_data If the data used to fit the model should be saved in the model @@ -97,9 +102,10 @@ stan_jsdm <- function(X, ...) UseMethod("stan_jsdm") stan_jsdm.default <- function(X = NULL, Y = NULL, species_intercept = TRUE, method, dat_list = NULL, family, site_intercept = "none", D = NULL, prior = jsdm_prior(), site_groups = NULL, - beta_param = "unstruct", + beta_param = "unstruct", Ntrials = NULL, save_data = TRUE, iter = 4000, log_lik = TRUE, ...) { - family <- match.arg(family, c("gaussian", "bernoulli", "poisson", "neg_binomial")) + family <- match.arg(family, c("gaussian", "bernoulli", "poisson", + "neg_binomial","binomial")) beta_param <- match.arg(beta_param, c("cor", "unstruct")) stopifnot( @@ -115,7 +121,7 @@ stan_jsdm.default <- function(X = NULL, Y = NULL, species_intercept = TRUE, meth D = D, site_intercept = site_intercept, site_groups = site_groups, dat_list = dat_list, phylo = FALSE, family = family, method = method, nu05 = "1", - delta = 1e-5 + delta = 1e-5, Ntrials = Ntrials ) # Create stancode @@ -221,7 +227,7 @@ stan_gllvm.formula <- function(formula, data = list(), ...) { validate_data <- function(Y, D, X, species_intercept, dat_list, family, site_intercept, phylo, - method, nu05, delta, site_groups) { + method, nu05, delta, site_groups, Ntrials) { method <- match.arg(method, c("gllvm", "mglmm")) # do things if data not given as list: @@ -283,6 +289,9 @@ validate_data <- function(Y, D, X, species_intercept, data_list$nu05 <- nu05 data_list$delta <- delta } + if(family == "binomial"){ + data_list$Ntrials <- Ntrials + } } else { if (!all(c("Y", "K", "S", "N", "X") %in% names(dat_list))) { stop("If supplying data as a list must have entries Y, K, S, N, X") @@ -298,6 +307,12 @@ validate_data <- function(Y, D, X, species_intercept, } } + if (identical(family, "binomial")) { + if (!all(c("Ntrials") %in% names(dat_list))) { + stop("Binomial models require Ntrials in dat_list") + } + } + if (site_intercept == "grouped") { if (!all(c("ngrp","grps") %in% names(dat_list))) { stop("Grouped site intercept models require ngrp and grps in dat_list") @@ -334,12 +349,28 @@ validate_data <- function(Y, D, X, species_intercept, ))) { stop("Y matrix is not binary") } - } else if (family %in% c("poisson", "neg_binomial")) { + } else if (family %in% c("poisson", "neg_binomial", "binomial")) { if (!any(apply(data_list$Y, 1:2, is.wholenumber))) { stop("Y matrix is not composed of integers") } } + # Check if Ntrials is appropriate given + if(identical(family, "binomial")) { + if(is.null(data_list$Ntrials)){ + stop("Number of trials must be specified for the binomial distribution") + } + if(!is.double(data_list$Ntrials) & !is.integer(data_list$Ntrials)){ + stop("Ntrials must be a positive integer") + } + if(!(length(data_list$Ntrials) %in% c(1, data_list$N))){ + stop("Ntrials must be of length 1 or N") + } + if(length(data_list$Ntrials) == 1L){ + data_list$Ntrials <- rep(data_list$Ntrials, data_list$N) + } + } + return(data_list) } diff --git a/man/jsdm_sim_data.Rd b/man/jsdm_sim_data.Rd index 20dc14f..30fa5df 100644 --- a/man/jsdm_sim_data.Rd +++ b/man/jsdm_sim_data.Rd @@ -14,6 +14,7 @@ jsdm_sim_data( family, method = c("gllvm", "mglmm"), species_intercept = TRUE, + Ntrials = NULL, site_intercept = "none", beta_param = "unstruct", prior = jsdm_prior() @@ -33,53 +34,57 @@ mglmm_sim_data(...) \item{K}{is number of covariates, by default \code{0}} \item{family}{is the response family, must be one of \code{"gaussian"}, -\code{"neg_binomial"}, \code{"poisson"} or \code{"bernoulli"}. Regular -expression matching is supported.} +\code{"neg_binomial"}, \code{"poisson"}, \code{"binomial"}, +or \code{"bernoulli"}. Regular expression matching is supported.} \item{method}{is the jSDM method to use, currently either \code{"gllvm"} or \code{"mglmm"} - see details for more information.} -\item{species_intercept}{Whether to include an intercept in the predictors, must -be \code{TRUE} if \code{K} is \code{0}. Defaults to \code{TRUE}.} +\item{species_intercept}{Whether to include an intercept in the predictors, +must be \code{TRUE} if \code{K} is \code{0}. Defaults to \code{TRUE}.} + +\item{Ntrials}{For the binomial distribution the number of trials, given as +either a single integer which is assumed to be constant across sites or as +a site-length vector of integers.} \item{site_intercept}{Whether a site intercept should be included, potential -values \code{"none"} (no site intercept) or \code{"ungrouped"} (site intercept -with no grouping). Defaults to no site intercept, grouped is not supported -currently.} +values \code{"none"} (no site intercept) or \code{"ungrouped"} (site +intercept with no grouping). Defaults to no site intercept, grouped is not +supported currently.} -\item{beta_param}{The parameterisation of the environmental covariate effects, by -default \code{"unstruct"}. See details for further information.} +\item{beta_param}{The parameterisation of the environmental covariate +effects, by default \code{"unstruct"}. See details for further information.} \item{prior}{Set of prior specifications from call to \code{\link[=jsdm_prior]{jsdm_prior()}}} \item{...}{Arguments passed to jsdm_sim_data} } \description{ -The \code{jsdm_sim_data} function can simulate data with either a multivariate -generalised mixed model (MGLMM) or a generalised linear latent variable model -(GLLVM). The \code{gllvm_sim_data} and \code{mglmm_sim_data} are aliases for -\code{jsdm_sim_data} that set \code{method} to \code{"gllvm"} and \code{"mglmm"} -respectively. +The \code{jsdm_sim_data} function can simulate data with either a +multivariate generalised mixed model (MGLMM) or a generalised linear latent +variable model (GLLVM). The \code{gllvm_sim_data} and \code{mglmm_sim_data} +are aliases for \code{jsdm_sim_data} that set \code{method} to \code{"gllvm"} +and \code{"mglmm"} respectively. } \details{ This simulates data based on a joint species distribution model with -either a generalised linear latent variable model approach or a multivariate -generalised linear mixed model approach. +either a generalised linear latent variable model approach or a +multivariate generalised linear mixed model approach. Models can be fit with or without "measured predictors", and if measured predictors are included then the species have species-specific parameter estimates. These can either be simulated completely independently, or have -information pooled across species. If information is pooled this can be modelled -as either a random draw from some mean and standard deviation or species -covariance can be modelled together (this will be the covariance used in the -overall model if the method used has covariance). - -Environmental covariate effects (\code{"betas"}) can be parameterised in two -ways. With the \code{"cor"} parameterisation all covariate effects are assumed -to be constrained by a correlation matrix between the covariates. With the -\code{"unstruct"} parameterisation all covariate effects are assumed to draw -from a simple distribution with no correlation structure. Both parameterisations -can be modified using the prior object. +information pooled across species. If information is pooled this can be +modelled as either a random draw from some mean and standard deviation or +species covariance can be modelled together (this will be the covariance +used in the overall model if the method used has covariance). + +Environmental covariate effects (\code{"betas"}) can be parameterised in +two ways. With the \code{"cor"} parameterisation all covariate effects are +assumed to be constrained by a correlation matrix between the covariates. +With the \code{"unstruct"} parameterisation all covariate effects are +assumed to draw from a simple distribution with no correlation structure. +Both parameterisations can be modified using the prior object. } \section{Functions}{ \itemize{ diff --git a/man/posterior_predict.jsdmStanFit.Rd b/man/posterior_predict.jsdmStanFit.Rd index fbc39e8..ca501f3 100644 --- a/man/posterior_predict.jsdmStanFit.Rd +++ b/man/posterior_predict.jsdmStanFit.Rd @@ -12,6 +12,7 @@ ndraws = NULL, draw_ids = NULL, list_index = "draws", + Ntrials = NULL, ... ) } @@ -32,6 +33,10 @@ number of samples.} \item{list_index}{Whether to return the output list indexed by the number of draws (default), species, or site.} +\item{Ntrials}{For the binomial distribution the number of trials, given as +either a single integer which is assumed to be constant across sites or as +a site-length vector of integers.} + \item{...}{Currently unused} } \value{ diff --git a/man/stan_gllvm.Rd b/man/stan_gllvm.Rd index 1adea80..37ede1f 100644 --- a/man/stan_gllvm.Rd +++ b/man/stan_gllvm.Rd @@ -43,7 +43,8 @@ Y, X, N, S, K, and site_intercept. See output of \code{\link[=jsdm_sim_data]{jsd example of how this can be formatted.} \item{family}{The response family for the model, required to be one of -\code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"} or \code{"neg_binomial"}} +\code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"}, \code{"binomial"} +or \code{"neg_binomial"}} \item{site_intercept}{Whether a site intercept should be included, potential values \code{"none"} (no site intercept), \code{"grouped"} (a site intercept diff --git a/man/stan_jsdm.Rd b/man/stan_jsdm.Rd index 10ee733..478f0f1 100644 --- a/man/stan_jsdm.Rd +++ b/man/stan_jsdm.Rd @@ -20,6 +20,7 @@ stan_jsdm(X, ...) prior = jsdm_prior(), site_groups = NULL, beta_param = "unstruct", + Ntrials = NULL, save_data = TRUE, iter = 4000, log_lik = TRUE, @@ -47,7 +48,8 @@ Y, X, N, S, K, and site_intercept. See output of \code{\link[=jsdm_sim_data]{jsd example of how this can be formatted.} \item{family}{The response family for the model, required to be one of -\code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"} or \code{"neg_binomial"}} +\code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"}, \code{"binomial"} +or \code{"neg_binomial"}} \item{site_intercept}{Whether a site intercept should be included, potential values \code{"none"} (no site intercept), \code{"grouped"} (a site intercept @@ -64,6 +66,10 @@ per site} \item{beta_param}{The parameterisation of the environmental covariate effects, by default \code{"unstruct"}. See details for further information.} +\item{Ntrials}{For the binomial distribution the number of trials, given as +either a single integer which is assumed to be constant across sites or as +a site-length vector of integers.} + \item{save_data}{If the data used to fit the model should be saved in the model object, by default TRUE.} diff --git a/man/stan_mglmm.Rd b/man/stan_mglmm.Rd index 42d4fc9..a25bb1a 100644 --- a/man/stan_mglmm.Rd +++ b/man/stan_mglmm.Rd @@ -40,7 +40,8 @@ Y, X, N, S, K, and site_intercept. See output of \code{\link[=jsdm_sim_data]{jsd example of how this can be formatted.} \item{family}{The response family for the model, required to be one of -\code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"} or \code{"neg_binomial"}} +\code{"gaussian"}, \code{"bernoulli"}, \code{"poisson"}, \code{"binomial"} +or \code{"neg_binomial"}} \item{site_intercept}{Whether a site intercept should be included, potential values \code{"none"} (no site intercept), \code{"grouped"} (a site intercept