openanalytics / BIGL

GNU General Public License v3.0
7 stars 8 forks source link

Diverging marginal curves #4

Open vvarik opened 4 years ago

vvarik commented 4 years ago

Trying to fitSurface with alternative Loewe null model, I get diverging marginal curves error. Staring at the curves they do not seem to diverge. In one of my attempts to debug, it appeared as if the harbronLoewe somehow receives different coefficients than those present in MarginalFit object. Could be some issue with 4PL asymptotes (see two alternative ways to make the issue go away in reprex below), if that makes any sense.

foo = structure(list(effect = c(3.1, 2.3, 1.1, -0.2, -0.7, -1.9, 3.3, 
3.2, 1.9, -0.4, -1.6, -2, -3, -3.8, 0.1, 0, -1.4, -2, -3.2, 3, 
2.4, 1.2, -0.2, -0.6, -1.7, 3.2, 3.2, 2, -0.3, -1.5, -1.8, -3.1, 
-3.9, 0.1, 0.1, -1.2, -2, -3, 3.2, 2.6, 1.2, 0.1, -0.4, -1.7, 
3.3, 3.2, 2.1, -0.2, -1.2, -1.5, -2.7, -3.7, 0.2, 0.1, -1.1, 
-1.9, -3), d1 = c(0.01, 0.1, 0.3, 1, 10, 20, 0, 0, 0, 0, 0, 0, 
0, 0, 1, 1, 1, 1, 1, 0.01, 0.1, 0.3, 1, 10, 20, 0, 0, 0, 0, 0, 
0, 0, 0, 1, 1, 1, 1, 1, 0.01, 0.1, 0.3, 1, 10, 20, 0, 0, 0, 0, 
0, 0, 0, 0, 1, 1, 1, 1, 1), d2 = c(0, 0, 0, 0, 0, 0, 0.01, 0.1, 
0.3, 1, 3, 10, 30, 100, 0.01, 0.1, 1, 10, 30, 0, 0, 0, 0, 0, 
0, 0.01, 0.1, 0.3, 1, 3, 10, 30, 100, 0.01, 0.1, 1, 10, 30, 0, 
0, 0, 0, 0, 0, 0.01, 0.1, 0.3, 1, 3, 10, 30, 100, 0.01, 0.1, 
1, 10, 30)), row.names = c(NA, -57L), class = "data.frame")

## quick fix
#idx = with(foo, d2 == max(d2) & d1 == 0)
#foo[idx, ]$effect = foo[idx, ]$effect * c(0.8, 1, 1)

bar = fitMarginals(foo)

## alternative fix
#bar = fitMarginals(foo, fixed = c('h1' = 1, 'h2' = 1))

plot(bar)  # not diverging marginal curves
set.seed(1)
baz = fitSurface(foo, bar, null_model='loewe2', 
  statistic = "both", B.CP = 5, parallel = FALSE
)

Error in harbronLoewe(doseGrid, fitResult$coef) : 
  Alternative Loewe generalization does not work for diverging marginal curves.

Ubuntu 18.04.4, R 3.6.3, BIGL 1.4.3

mnazarov commented 4 years ago

I guess the error happens during one of the bootstrap iterations during CP matrix estimation, when the data is re-generated, so I don't think there is an issue with the code per se, even if we should foresee such possibility