Closed jburos closed 7 years ago
Notes from debugging on example above, working back along stacktrace:
validate_newdatas
:Browse[2]> sorted_ids
$Long1
[1] 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30 31 32 33 34 35 36 37 38 39 4 40 5 6 7 8 9
Levels: 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30 31 32 33 34 35 36 37 38 39 4 40 5 6 7 8 9
$Event
[1] "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "3" "30" "31" "32" "33" "34" "35" "36"
[31] "37" "38" "39" "4" "40" "5" "6" "7" "8" "9"
Browse[2]> ids
$Long1
[1] 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30 31 32 33 34 35 36 37 38 39 4 40 5 6 7 8 9
Levels: 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 28 29 3 30 31 32 33 34 35 36 37 38 39 4 40 5 6 7 8 9
$Event
[1] "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "3" "30" "31" "32" "33" "34" "35" "36"
[31] "37" "38" "39" "4" "40" "5" "6" "7" "8" "9"
jm_data
:Browse[2]> str(newdataLong[[1]]$id)
Factor w/ 40 levels "1","10","11",..: 1 1 2 3 3 3 3 3 3 3 ...
Browse[2]> str(newdataEvent$id)
chr [1:40] "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" "22" "23" "24" "25" "26" "27" ...
posterior_survfit
:The above reflect the data as stored in the stanjm object.
Looking at lines 257-265 of posterior_survfit.R:
# Construct prediction data
# ndL: dataLong to be used in predictions
# ndE: dataEvent to be used in predictions
if (!identical(is.null(newdataLong), is.null(newdataEvent)))
stop("Both newdataLong and newdataEvent must be supplied together.")
if (is.null(newdataLong)) { # user did not specify newdata
ndL <- model.frame(object)[1:M] ## <- here
ndE <- model.frame(object)$Event ## <- and here
} else { # user specified newdata
These objects are returned with the following structure:
Browse[2]> str(ndL[[1]]$id)
Factor w/ 40 levels "1","10","11",..: 1 1 2 3 3 3 3 3 3 3 ...
Browse[2]> str(ndE$id)
chr [1:40] "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" "22" "23" "24" "25" "26" "27" ...
What is needed is either to store the object more consistently, or transform the factors correctly back to their chr
counterparts.
Yeah, it seems that in the lme4 model frame, character grouping variables are promoted to factors, but integer or numeric grouping variables are not promoted to factors. I'm not sure why that is.
Instead of changing things at the ps_check stage, I went back to stan_jm and changed the class of the id variable stored in the model frame for the event submodel (such that it is promoted from a character to a factor).
Hopefully this works.
Agreed, this makes sense going forward. Thanks Sam. FWIW, a lot of my mangling was to avoid having to re-execute my models in the interim.
Summary:
I see the following error when running ps_check on a stan_jm fit object:
This is strange because there are no newdata passed in, so presumably there should not be an issue with the subject ids.
Description:
The problem appears to be a result of this line:
Here is the full traceback of the above:
Reproducible Steps:
(similar to those in #43):
Install fork with minor bugfixes, which builds off
develop2
branch of sambrilleman/rstanarmFit model & run ps_check on example data (works fine)
Fit model & run ps_check on same data, where ids are character values
Yields:
RStanARM Version:
See above