mu, and size, the dispersion parameter, where
prob = size/(size+mu)."x1 <- seq(-2, 2,, M) # Site covariate
lambda <- exp(beta0 + beta1 * x1)
size <- dispersion # Dispersion parameter
N <- rnbinom(n = length(x), mu = lambda, size = dispersion)
--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# Simulate Nmix data with NegBin abundance distribution
NB.data <- function(M = 267, T = 3, alpha0 = 1, alpha1 = -1, beta0 = -1, beta1 = 1, dispersion = 10){
# Function simulates data for the Nmix model with
# a negative binomial abundance distribution.
# alpha0 and alpha1 are the intercept and the slope of a logistic-linear
# regression of detection probability on an observation covariate x2.
# beta0 and beta1 are the intercept and the slope of a log-linear
# regression of expected abundance on a site covariate x1.
# M is the number of sites and T the number of temporal reps.
# dispersion is the negative binomial dispersion parameter, with
# lower values corresponding to increasing aggregation.
# Abundance model
x1 <- seq(-2, 2,, M) # Site covariate
lambda <- exp(beta0 + beta1 * x1)
size <- dispersion # Dispersion parameter
N <- rnbinom(n = length(x), mu = lambda, size = dispersion)
par(mfrow = c(2,2))
plot(x1, lambda, main = "Relationship x1-lambda")
hist(N, main = "Histogram of latent N", breaks = 50, col = "grey")
# Detection model
x2 <- matrix(rnorm(M*T), ncol = T) # Observational covariate
p <- plogis(alpha0 + alpha1 * x2)
plot(x2, p, main = "Relationship x2-p")
C <- array(dim = c(M,T))
for(j in 1:T){
C[,j] <- rbinom(M, N, p[,j])
}
hist(C, main = "Histogram of counts C", breaks = 50, col = "grey")
# Output
return(list(M=M, T=T, alpha0=alpha0, alpha1=alpha1, beta0=beta0, beta1=beta1, dispersion=dispersion, x1=x1, x2=x2, lambda=lambda, N=N, p=p, C=C))
}
# Check how it works
NB.data()
NB.data(alpha1=0, beta1=0)
NB.data(alpha1=-2, beta1=2)
NB.data(alpha1=-2, beta1=2, dispersion = 0.1)
NB.data(alpha0=0, alpha1=1, beta0 = 1, beta1=-1, dispersion = 10)