Closed bchartoff closed 6 years ago
Confirmed that this error is within JS, this is NOT present in the R environment.
This is due to l_values[i]
approaching 0 and then 1 being divided by it in this line:
p_values.push(1-(1/l_values[i]));
Next step is search out this in the original and see how they handle this.
From the R script, some helpful notes:
# l = estimate for LOS based on proportion remaining in prison after one year
# p = proportion remaining in prison after one year
# L= 1/(1-p)
# p = 1-(1/l)
solved! The cursed FLOATING point issues strike again. I'm not exactly sure why, but in the R script, the calculation for the l_value[i]
for -100% Length of stay was calculating to 0, while in Js, error introduced somewhere would cause it to hover just under 0. The upshot of that is that 1/0 in js or R gives -Infinity. Still try to remember why this is the solution rather than something that breaks the program, but it is the solution. In the js, after calculating the l_value
, I included this conditional to reset the l_value
to 0 if it is very very close to 0, but not zero:
if (l_values[i] > -0.000000001 && l_values[i] < 0.000000001) {
l_values[i] = 0;
}
This worked, and the pop at year 25 is now the same in the R script and the JS for 100% reduction in length of stay.
To do:
Fixed in commit 0b8f92d
, good example to use for the blog post.
See comment commit b94958f6c2570eaf5aec9530726b4bb0b0fdd2e4 for partially isolated problem