Getting the following error when fitting a model with a single longitudinal biomarker (M = 1) and where the biomarker details (formulaLong, family, etc) are provided as a list.
Error in fm[[m + 1]] : subscript out of bounds
For context, I am creating the inputs to the Stan function programmatically (to support the simulation testing) and so it's easier to create all inputs as lists irrespective of the length. In that case, I encountered the error on this line of run_simtest():
within sim$func_inputs, formulaLong is provided as a list (here of length 1).
we are executing a modified version of stan_jm, which transforms the result of match.call().
I should also note that, in the course of creating a reproducible example, I found 3 different scenarios in which similar errors were produced. Figure it's worth documenting them here since all three are likely related to the same code-block.
there is no error, since formulaLong object is not a symbol.
The problem here appears to be a function of the calling env vs the env in which the functions are defined. Here we are getting close to the reproducible example, but not exactly there.
When debugging the subscript out of bounds error, the value of fm object is different than what is expected.
In the typical case (f1 in the examples above), the object fm looks like the following:
Browse[4]> str(fm)
language list(logBili ~ year + (1 | id))
Browse[4]> m
[1] 1
Browse[4]> fm[[m + 1]]
logBili ~ year + (1 | id)
Browse[4]> fm[[m]]
list
Browse[4]> is(fm, 'list')
[1] FALSE
Whereas in the bug-producing case (analogous to f6, above, however this was debugged using the simtest_jm code that originally produced the error) we have the following:
Browse[4]> str(fm)
List of 1
$ :Class 'formula' language Yij_1 ~ Z1 + Z2 + tij + (tij | id)
.. ..- attr(*, ".Environment")=<environment: 0x9a42eb0>
Browse[4]> m
[1] 1
Browse[4]> is(fm, 'list')
[1] TRUE
In this latter case, it's clear why the call to fm[[m+1]] yields an error.
RStanARM Version:
Most recent commit 8617674 of sambrilleman/rstanarm, master branch
Summary:
Getting the following error when fitting a model with a single longitudinal biomarker (M = 1) and where the biomarker details (
formulaLong
,family
, etc) are provided as a list.For context, I am creating the inputs to the Stan function programmatically (to support the simulation testing) and so it's easier to create all inputs as lists irrespective of the length. In that case, I encountered the error on this line of run_simtest():
Two details are relevant to the issue:
sim$func_inputs
, formulaLong is provided as a list (here of length 1).stan_jm
, which transforms the result ofmatch.call()
.I should also note that, in the course of creating a reproducible example, I found 3 different scenarios in which similar errors were produced. Figure it's worth documenting them here since all three are likely related to the same code-block.
Description:
The error occurs on this section of
stan_jm.R
:Although it's worth pointing out that the results of
validate_arg
(in whichbroadcast = TRUE
) are not used in this section. Perhaps they should be?Reproducible Steps:
Example of a standard model spec (works):
Now, fit a model where the formulaLong, dataLong, or family input is a list:
The above also works.
However, if you do something like the following:
You get:
This is not the same error as above, but it is related.
However, if you do the following:
there is no error, since
formulaLong
object is not a symbol.The problem here appears to be a function of the calling env vs the env in which the functions are defined. Here we are getting close to the reproducible example, but not exactly there.
This yields an error:
In order to reproduce the original error message, we have to modify the above slightly to use purrr::lift_dl.
Specifically:
This yields the above:
This leads to 3 specific & different bugs:
subscript out of bounds
Error: !checkLHS is not TRUE
object of type 'symbol' is not subsettable
Starting to debug
When debugging the
subscript out of bounds
error, the value offm
object is different than what is expected.In the typical case (
f1
in the examples above), the objectfm
looks like the following:Whereas in the bug-producing case (analogous to
f6
, above, however this was debugged using the simtest_jm code that originally produced the error) we have the following:In this latter case, it's clear why the call to
fm[[m+1]]
yields an error.RStanARM Version:
Most recent commit 8617674 of
sambrilleman/rstanarm
, master branchR Version:
Observed on both 3.3.3 & 3.4.0
Operating System:
Linux / ubuntu