ryantibs / quantgen

Tools for generalized quantile modeling
https://ryantibs.github.io/quantgen
14 stars 9 forks source link

Make intercept=TRUE and noncross=TRUE compatible for multiple tau groups, or note incompatibility #7

Open brookslogan opened 3 years ago

brookslogan commented 3 years ago

It appears that intercept=TRUE is incompatible with noncross=TRUE (at least with multiple tau groups):

qarr = array(42, c(6,3,5)) # or try aperm(apply(array(rexp(6*3*5), c(6,3,5)), 1:2, sort), c(2:3, 1L))
y = 1:6 # or try qarr[,1,1] + rnorm(6)
tau = c(0.1, 0.3, 0.5, 0.7, 0.9)
tau_groups = c(1,2,2,2,3)
quantile_ensemble(qarr, y, tau, tau_groups=tau_groups, intercept = TRUE, nonneg = FALSE, unit_sum = FALSE, noncross = TRUE)

produces

Error in a0[, , k] <- cbind(rep(1, n0), q0[, , k]) : 
  number of items to replace is not a multiple of replacement length

Replacing

n0 = dim(q0)[1]; a0 = array(NA, dim=c(n0,p,r))

with

n0 = dim(q0)[1]; a0 = array(NA, dim=c(n0,1+p,r))

generates a different error:

Error in replCmat4(x, i1 = if (iMi) 0:(di[1] - 1L) else .ind.prep2(i,  : 
  number of items to replace is not a multiple of replacement length

from from line 351 in quantile_ensemble.R:

      B[(k-1)*n0 + 1:n0, (k-1)*p + 1:p] = -q0[,,k]

which looks like it will require a bit more thought to debug.