Measurement-error model

46 views
Skip to first unread message

keric...@gmail.com

unread,
Dec 6, 2022, 1:35:47 PM12/6/22
to nimble-users

Hi Nimble Users,

I am trying to use a measurement error model (Velásquez-Tibatá et al. 2016 Ecography  

https://doi.org/10.1111/ecog.01205) with presence-only data in Nimble, and I am running into issues. 

In our dataset, there are 3 kinds of records:

  • Precise presences (no geographic uncertainty), each corresponding to one environmental covariate value
  • Vague presences (with varying radii of geographic uncertainty), each with corresponding vectors of possible covariate values. The length of the vector of possible covariate values associated with each vague presence ranges from 5-24.
  • Precise pseudoabsences (no geographic uncertainty), corresponding to one environmental covariate value
code <- nimbleCode({
  for (i in 1:N) {
    #Likelihood
    Y[i] ~ dbern(p[i])
    logit(p[i]) <- b0 + b1*env1[i]

    #Measurement model
    k[i]~dcat(prob=weights[pos_start[i]:pos_end[i]])
    env1[i] <- X[pos_start_full[i]+k[i]-1]
  }
 
  #Regression priors
  b0 ~ dnorm(0,sd=100) #
  b1 ~ dnorm(0,sd=100)
}
)

data <- list(Y=Y,  #vector of 1s and 0s of length 1016
             X = X) #vector of covariates; length is 1110 because the vague presences have more than one value each

constants <- list(
  N= N, #Number of sites: 1016
  weights = weights, #weight vector specifying probability of each covariate value. For the vague records, these are values within (0,1) and sum to one for each site. Each precise record has a single weight that is 1. 
  pos_start = pos_start, #indexing to associate sites with correct covariates
  pos_end = pos_end)
inits <- list(b0 = mean(Y),
              b1 =0)

model <- nimbleModel(code,
                     constants = constants,
                     data = data,
                     inits = inits,
                     debug=F)

Currently this results in the following error: 
Error in if (any(dimensionsList[[dimVarName]] < varInfo[[dimVarName]]$maxs)) stop(paste0("dimensions specified are smaller than model specification for variable '",  : 
  missing value where TRUE/FALSE needed

I suspect this might have something to do with how the X vector is longer than the number of sites, because some sites have multiple possible covariates. Earlier I tried separating the likelihood into two pieces: one for the precise records and one for the vague records, but I ran into a different indexing error. 

I appreciate any suggestions! Thanks, 

Kelley 

Chris Paciorek

unread,
Dec 7, 2022, 3:27:51 PM12/7/22
to keric...@gmail.com, nimble-users
Hi Kelley,

I haven't fully unravelled why we are not trapping the problem and giving a clear error message, but I see that `pos_start_full` is not set anywhere. 

In terms of me determining the cause of the bad error trapping, it would help if you could send me (perhaps off-list) the values for 'data' and 'constants'?

-chris

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/e3a92855-d74a-4905-8156-217be40dfd0an%40googlegroups.com.

Chris Paciorek

unread,
Dec 10, 2022, 12:06:45 PM12/10/22
to Kelley Erickson, nimble-users
Hi Kelley (following up on an off-list email containing user-specific data),

It looks like the issue is that you have at least some cases where the prob vector is of length 1 because pos_start_full and pos_end_full are the same.
I would have thought that we would handle this special case, but apparently we don't because of dimensionality issues with the prob vector probably being treated as a scalar but we're expecting it to be a vector. I'll make a note for us to look into this.

I think you'll need to rework things to work around that, by making sure that the prob vector is always at least of length 2. Hopefully you'll be able to do that without too much trouble.

-chris

On Fri, Dec 9, 2022 at 3:27 PM Kelley Erickson <keric...@gmail.com> wrote:
Hi Chris, 

It turns out the previous error message was a result of how I simulated the data, which I have now fixed. 

Now I'm back to one of the original error(s) I've been trying to find a workaround for: 

Error in model$checkBasics() : 
  Dimension of distribution argument(s) 'prob' does not match required dimension(s) for the distribution 'dcat'. Necessary dimension(s) are 1. You may need to ensure that you have explicit vectors and not one-row or one-column matrices.

I have attached the .Rmd I have been working on. 

Thanks again for your help, 

Kelley 



Reply all
Reply to author
Forward
0 new messages