conroylau / lpinfer

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

Chorussell should not require beta.tgt when ci = TRUE #100

Closed a-torgovitsky closed 3 years ago

a-torgovitsky commented 4 years ago

beta.tgt plays no role in chorussell when ci = TRUE.

library("lpinfer")
source("~/R/x86_64-pc-linux-gnu-library/3.6/lpinfer/example/dgp_mixedlogit.R")

set.seed(5)
dgp <- mixedlogit_dgp()
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))

r <- chorussell(data = df, lpmodel = lpm, ci = TRUE)

leads to

Error in chorussell.check(data, lpmodel, beta.tgt, R, Rmulti, kappa, norm,  : 
  argument "beta.tgt" is missing, with no default
conroylau commented 4 years ago

Done! I have updated the code by setting the default of beta.tgt as NULL. The part of checking beta.tgt will be ignored if ci = TRUE as well.

Thanks!

a-torgovitsky commented 3 years ago

Sorry, I think this is not quite settled. I think the default should be this:

Currently, the second thing is not being done, which seems a bit weird.

library("lpinfer")
source("~/R/x86_64-pc-linux-gnu-library/3.6/lpinfer/example/dgp_mixedlogit.R")

set.seed(5)
dgp <- mixedlogit_dgp()
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))

r <- chorussell(data = df, lpmodel = lpm)
print(r) # good, confidence interval
r <- chorussell(data = df, lpmodel = lpm, beta.tgt = .2)
print(r) # bad, confidence interval
r <- chorussell(data = df, lpmodel = lpm, beta.tgt = .2, ci = FALSE)
print(r) # good, test
r <- chorussell(data = df, lpmodel = lpm, beta.tgt = .2, ci = TRUE)
print(r) # good, confidence interval

produces

95%-confidence interval: [0.62693, 0.84418]                                      
95%-confidence interval: [0.63283, 0.84376]                                      
p-value: 6e-05                                                                   
95%-confidence interval: [0.63751, 0.85403]
conroylau commented 3 years ago

Done! The above code now gives the followings:

95%-confidence interval: [0.62704, 0.85177]                                                             
p-value: 6e-05                                                                                         
p-value: 6e-05                                                                                         
95%-confidence interval: [0.63767, 0.85478]   

Thanks!