Error in parse(text = x) : negative length vectors are not allowed

269 views
Skip to first unread message

Magali Frauendorf

unread,
Apr 8, 2021, 4:51:25 AM4/8/21
to nimble-users

Hi all,

I have a multi-state capture recapture model incorporating a structural equation model (code attached). The model builds fine when I use calculate=F, however, when I use RModel$calculate() to check the initialization, I get the following error: Error in parse(text = x) : negative length vectors are not allowed. 

I found a post about a similar error here in the google group which seemed to be related to the initial values, but I cannot find my mistake in the initial values. If I run RModel$initializeInfo() I got the following message:

# Missing values (NAs) or non-finite values were found in model variables: alive.

# This is not an error, but some or all variables may need to be initialized for

# certain algorithms to operate properly. For more information on model initialization,

# see help(modelInitialization).

Alive is the initial state matrix that indeed has NAs for the occasions before the first capture. As far as I found in other multi-state examples, that should not cause the error about the negative length vectors?!

Next, when I compile the RModel I get the following warnings:

#compiling... this may take a minute. Use 'showCompilerOutput = TRUE' to see C++ compilation details.

#Warning: R object of different size than NimArrDouble. R obj has size 1 but NimArrDbl has size 1574.

#Warning: R object of different size than NimArrDouble. R obj has size 1 but NimArrDbl has size 1574.

#Warning: R object of different size than NimArrDouble. R obj has size 1 but NimArrDbl has size 1574.

#Warning: R object of different size than NimArrDouble. R obj has size 1 but NimArrDbl has size 1574.

#Warning: R object of different size than NimArrDouble. R obj has size 1 but NimArrDbl has size 1574.

#compilation finished.

 

May this be related to the above mentioned error?

 

Thank you very much!

Magali

 

NimbleModel.txt

Perry de Valpine

unread,
Apr 8, 2021, 11:38:49 AM4/8/21
to Magali Frauendorf, nimble-users
Hi Magali,

It's hard for us to diagnose what's happening without having your data file.  Here are the steps I suggest.

Check that all entries in the data, constants, and/or inits lists are the size and shape they should be.  A good guess is that something is not the right size or shape.

Check that first[i] < T for all i, because you have loops over (first[i] + 1):T and decreasing loops are not supported.

For the alive NAs, values before first[i] should not matter because they are not declared as nodes in the model as far as I see.  Values after first capture are best initialized, if that is not already the case.

You can narrow down where there is a problem by building the model with calculate = FALSE and then calculating pieces of it to determine which causes an error, like

model$calculate("PSI")
model$calculate("alive")
model$calculate("alive[1, ]")
model$calculate("alive[1, 3]")

You'll want to go in order.  You might get a nonsense value from one calculation if the previous calculations aren't done.

Actually since alive is sequentially dependent, you can be safe by doing:
model$calculate( model$topologicallySortNodes("alive") )
That will ensure nodes are in order.

You can also study the values of those variables.
model$PSI
model$alive

And the log probabilities of stochastic nodes after calculation:
model$getLogProb("alive")
model$getLogProb("alive[1, ]") # etc
Or more directly
model$logProb_alive

I hope that helps you debug the model.  If you're still stuck, you could share the data off-list if (understandably) you don't want to share it on-list.

-Perry


--
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/04f829b7-01e6-409e-980c-be7050236728n%40googlegroups.com.

Magali Frauendorf

unread,
May 9, 2021, 6:40:31 AM5/9/21
to nimble-users
Hi all,

Just to let you all know, it turned out that this error message was a sign that the model was too big. Using options(error = recover) helped in finding where the error came from. Using the model$calculate() function, Perry suggested, helped me in figuring out which variable was too large (in my case the PSI matrix) and I solved it in splitting up the model in two models with lower number of years, which now runs fine!

Best,
Magali

Reply all
Reply to author
Forward
0 new messages