dCJS_vv dimension error

27 views
Skip to first unread message

Christoffer Høyvik Hilde

unread,
Dec 1, 2025, 7:16:22 AM (13 days ago) Dec 1
to nimble-users
Hi,

I'm trying to run a CJS-model using the dCJS_vv function from nimbleEcology. I have some individuals that first were captured at the second-to-last occasion (Tmax - 1), and when these are included in the analysis I get this error: "Dimension of distribution argument(s) 'probSurvive' does not match required dimension(s) for the distribution 'dCJS_vv'. Necessary dimension(s) are 1. You may need to ensure that you have explicit vectors and not one-row or one-column matrices."

If I remove the individuals with first capture at the second-to-last occasion, the model runs fine. Anyone encountered this issue or see an obvious error in my code? 
Thanks!
Chris


nimbleCode({
  ##-----------------------------##
  ## Define survival & recapture ##
  ##-----------------------------##
 
  for (i in 1:n.CH) {
    for (t in first[i]:(Tmax-1)) {
      # Survival
      logit(phi[i, t]) <- beta[age.phi[i, t]] + eps.phi[age.phi[i, t], t]
    }
  }
 
  # Detection
  for (i in 1:n.CH) {
    # p at the first capture occasion is fixed to 1
    p[i, first[i]] <- 1
   
    for (t in (first[i]+1):Tmax) {
      logit(p[i, t]) <- alpha[age.p[i, t]] + eps.p[t]
    }
  }
 
  ##----------------##
  ## Likelihood     ##
  ##----------------##
 
  for (i in 1:n.CH) {
    y[i, first[i]:Tmax] ~
      dCJS_vv(
        probSurvive = phi[i, first[i]:(Tmax-1)],
        probCapture = p[i, first[i]:Tmax],
        len = Tmax - first[i] + 1
      )
  }
 
  ##----------------------------##
  ## Priors ##
  ##----------------------------##
 
  # Age-specific survival parameters
  for (a in 1:n.age) {
    # Intercept
    beta[a] ~ dnorm(0, 1.5)
   
    # Random temporal effect standard deviation
    sdeps.phi[a] ~ dunif(0, 5)
   
    # Temporal random effect
   
    for (t in 1:(Tmax-1)) {
      eps.phi[a, t] ~ dnorm(0, sd = sdeps.phi[a])
    }
  }
 
  # Derived mean survival (probability scale)
  mean.phi[1:n.age] <- ilogit(beta[1:n.age])
 
  ## Recapture
  for (t in 1:Tmax) {
    eps.p[t] ~ dnorm(0, sd = sdeps.p)
  }
  sdeps.p ~ dunif(0, 5)
 
  for (u in 1:n.p) {
    alpha[u] ~ dnorm(0, 1.5)
  }
  mean.p[1:n.p] <- ilogit(alpha[1:n.p])
})

Russ Perry

unread,
Dec 1, 2025, 12:44:58 PM (13 days ago) Dec 1
to nimble-users
In your model, when first captures occur at Tmax-1, phi is a scalar (dimension of 0) but dCJS_vv expects phi to be vector (dimension of 1).  For individuals with first captures at Tmax-1, try using dCJS_sv, which expects a scalar value for phi.

Hope that works for you.
Russ

Christoffer Høyvik Hilde

unread,
Dec 2, 2025, 5:19:31 AM (12 days ago) Dec 2
to nimble-users
Thanks a lot Russ, using dCJS_sv for the individuals first captured at Tmax-1 works :)

Chris

Reply all
Reply to author
Forward
0 new messages