lotze / COMPoissonReg

COMPoissonReg R package
GNU General Public License v2.0
8 stars 4 forks source link

Issue with offsets in ZICMP predict #10

Closed andrewraim closed 3 years ago

andrewraim commented 3 years ago

The ZICMP predict function initially had a mistake when support for offsets was added. This mistake is included in version v0.7.0, but has subsequently been fixed in the master branch.

Here are steps to reproduce the issue.

data(couple)
zicmp.out = glm.cmp(UPB ~ EDUCATION + ANXIETY, formula.nu = ~ 1,
    formula.p = ~ EDUCATION + ANXIETY, data=couple)
print(zicmp.out)

new.data = data.frame(EDUCATION = round(1:20 / 20), ANXIETY = seq(-3,3,
    length.out = 20))
predict(zicmp.out, newdata=new.data)

This results in the output

Error in fitted.zicmp.internal(X, S, W, object$beta, object$gamma, object$zeta,  : 
  dims [product 20] do not match the length of object [387]
In addition: Warning message:
In X %*% beta + off.x :
  longer object length is not a multiple of shorter object length
Called from: fitted.zicmp.internal(X, S, W, object$beta, object$gamma, object$zeta, 
    object$off.x, object$off.s, object$off.w)

Until the corrected code gets released, here is a workaround for the typical case when the user has not opted to use offsets.

# Manually set the saved offsets in zicmp.out to be 0 to be compatible with the data in new.data
zicmp.out$off.x = 0
zicmp.out$off.s = 0
zicmp.out$off.w = 0
predict(zicmp.out, newdata = new.data)

If offsets are required, they cannot be specified to predict via newdata in v0.7.0. Code to work around this is more involved. If anyone urgently needs this, let me know.

andrewraim commented 3 years ago

Copied the corrected predict functions from master branch to v0.7.1.

TanasitThai commented 3 years ago

i try to use predict() by new data in ZICMP model but have a problem pls help me image

TanasitThai commented 3 years ago

My purpose need to make prediction model by train data (80%) and test performance of model predict by test data (20%). Now I'm doing same method ( predict() ) with another count model such as ZIP ZINB but they still work . only ZICMP it doesn't work I don't know why? Thank you so much. image train data n = 200 independent variable =7 image test data n = 50 independent variable =7 image

andrewraim commented 3 years ago

Dear TanasitThai,

Could you supply a minimal working example in plain text rather than screenshots? That will be very helpful to reproduce your issue.

Thanks, Andrew