Data simulation for negative binomial Nmix model

226 views
Skip to first unread message

Kery Marc

unread,
Aug 4, 2014, 6:15:23 AM8/4/14
to unma...@googlegroups.com
Dear unmarkers,

I am trying to simulate data under an N-mixture model with a negative binomial mixture for latent abundance N using R function rnbinom(n, size, prob, mu). Part of what the R help file says is this:

"An alternative parametrization (often used in ecology) is by the mean mu, and size, the dispersion parameter, where prob = size/(size+mu)."

So, I simulate the latent N's as this, where beta0=1, beta1=-1 and dispersion = 10 in my first trial:

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)


(I also have a detection model with one observational covariate, but that's of no importance here.)

When I simulate 100 data sets and analyse them in unmarked using pcount with the data-generating model, I get what look like unbiased estimates for the regression parameters (red is the truth, blue the mean of 100 estimates), but the estimates of the "dispersion parameter" are way off; see attached figure.

Does anybody know how the dispersion parameter in unmarked is defined ?

Thanks and kind regards  --  Marc




NB.Nmix.fig.pdf

Jeffrey Royle

unread,
Aug 4, 2014, 6:32:53 AM8/4/14
to unma...@googlegroups.com
hi Marc,
 I think it is log(size) in unmarked.....


--
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.

Kery Marc

unread,
Aug 4, 2014, 7:03:33 AM8/4/14
to unma...@googlegroups.com
Hi Andy,

thanks, that looks much better. Should have known ....

Regards  --- Marc



From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Jeffrey Royle [jar...@gmail.com]
Sent: 04 August 2014 12:32
To: unma...@googlegroups.com
Subject: Re: [unmarked] Data simulation for negative binomial Nmix model

log(dispersion) estimates.pdf

Kery Marc

unread,
Aug 4, 2014, 7:43:03 AM8/4/14
to unma...@googlegroups.com
btw, if anybody's interested, here is the function, regards  ---  Marc

# 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)





From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Kery Marc [marc...@vogelwarte.ch]
Sent: 04 August 2014 13:03
To: unma...@googlegroups.com
Subject: RE: [unmarked] Data simulation for negative binomial Nmix model

Fernando Arce

unread,
Aug 4, 2014, 4:18:29 PM8/4/14
to unma...@googlegroups.com
Hei Marc and unmarkers:

from your pieze of code, in line with code "N <- rnbinom(n = length(x), mu = lambda, size = dispersion)" (the 4th line of code in the abundance model part) x must be changed by x1. Otherwhise it does not run, or at least not in my system.
cheers:
Fer
PS, thats for the code :P

Kery Marc

unread,
Aug 4, 2014, 4:37:07 PM8/4/14
to unma...@googlegroups.com
Hola Fernando,

you are right, thanks for pointing out the error.

Kind regards  --  Marc


From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Fernando Arce [far...@gmail.com]
Sent: 04 August 2014 22:12
Reply all
Reply to author
Forward
0 new messages