conroylau / lpinfer

lpinfer: An R Package for Inference in Linear Programs
GNU General Public License v3.0
3 stars 5 forks source link

a potential bug in FSST (?) #109

Closed nadavkun closed 3 years ago

nadavkun commented 3 years ago

Hi, While running FSST in parallel on my Windows machine with R-Studio it seems that the function runs forever. On closer inspection it seems that this is due to two issues.

I run the following code, taken from the documentation:

lpm <- lpmodel(A.obs = mixedlogit_Aobs(dgp),
               beta.obs = function(d) mixedlogit_betaobs(d, dgp),
               A.shp = rep(1, nrow(dgp$vdist)),
               beta.shp = 1,
               A.tgt = mixedlogit_Atgt_dfelast(dgp, w2eval = 1, eeval = -1))
plan(multisession,workers=3)
fsst(data = df, lpmodel = lpm, beta.tgt = .25,R=500)
conroylau commented 3 years ago

Hi Nadav,

Thanks for your feedback!

I have changed the package for parallelization to furrr in the last git commit https://github.com/conroylau/lpinfer/commit/3c6a7771709ca0c95d842c9e99ec9224cca35c70. The furrr package solves the missing globals problem (I think you are referring to the functions defined in the lpmodel object).

It looks like that both issues that you mentioned do not appear now. Running the example from the vignette again, out$R.succ gives 500 and out$df.error gives NULL. This matches the number of bootstrap replications we need.

rm(list = ls())
library(lpinfer)
source("./inst/example/dgp_mixedlogit.R")

dgp <- mixedlogit_dgp(dimw = 4, dimv = 16)
df <- mixedlogit_draw(dgp, n = 4000)
lpm <- lpmodel(A.obs = mixedlogit_Aobs(dgp),
               beta.obs = function(d) mixedlogit_betaobs(d, dgp),
               A.shp = rep(1, nrow(dgp$vdist)),
               beta.shp = 1,
               A.tgt = mixedlogit_Atgt_dfelast(dgp, w2eval = 1, eeval = -1))

plan(multisession, workers = 3)
out <- fsst(data = df, lpmodel = lpm, beta.tgt = .25, R = 500)
print(out$R.succ)
print(out$df.error)

Please let me know if this works on your side too. Thanks!

nadavkun commented 3 years ago

Hi, Thanks! it works now on my side as well!

conroylau commented 3 years ago

Great! Thanks for checking.