conroylau / lpinfer

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

Requirement of passing logical upper bound ub0 for invertci #83

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago

For FSST, we can automatically determine logical lower/upper bounds, same as in DKQS, so this shouldn't yield an error:

devtools::load_all()
source("../lpinfer/example/dgp_mixedlogit.R")

dgp <- mixedlogit_dgp()
set.seed(1)
data <- mixedlogit_draw(dgp, n = 2000)

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 <- invertci(f = fsst, farg = list())
 Error: Please provide the logical upper bound 'ub0'. 

However, there seems to be something additional wrong, as this also yields the same error:

r <- invertci(f = dkqs, farg = list())
conroylau commented 4 years ago

Done! The invertci will be taking the logical upper and lower bounds from the testing procedures if they are not passed. Do you think I should still keep the lb0 and ub0 arguments because they can be determined from the testing procedures anyway?

If I pass the data, lpmodel and set R = 500 in farg, the following output can be obtained:

 < Constructing confidence interval for alpha = 0.05 >                       

 === Computing upper bound of confidence interval ===
 Iteration   Lower bound     Upper bound     Test point      p-value     Reject?        
 Left end pt.    0.00000     NA      0.00000     0.00200     TRUE   
 Right end pt.   NA      1.00000     1.00000     0.00000     TRUE                     
 1       0.00000     1.00000     0.50000     0.93400     FALSE                          
 2       0.50000     1.00000     0.75000     0.55000     FALSE                          
 3       0.75000     1.00000     0.87500     0.00000     TRUE                            
 4       0.75000     0.87500     0.81250     0.11400     FALSE                          
 5       0.81250     0.87500     0.84375     0.01400     TRUE                            
 6       0.81250     0.84375     0.82812     0.06200     FALSE                          
 7       0.82812     0.84375     0.83594     0.05400     FALSE                          
 8       0.83594     0.84375     0.83984     0.00600     TRUE                            
 9       0.83594     0.83984     0.83789     0.00600     TRUE                            
 10          0.83594     0.83789     0.83691     0.00800     TRUE                           
 11          0.83594     0.83691     0.83643     0.04200     FALSE                         
 12          0.83643     0.83691     0.83667     0.03200     FALSE                         
 13          0.83667     0.83691     0.83679     0.02200     TRUE                           
 14          0.83667     0.83679     0.83673     0.04200     FALSE                         
 >>> Length of interval is below tolerance level. Bisection method is completed.

 === Computing lower bound of confidence interval ===
 Iteration   Lower bound     Upper bound     Test point      p-value     Reject?
 Left end pt.    0.00000     NA      0.00000     0.00200     TRUE   
 Right end pt.   NA      1.00000     1.00000     0.00000     TRUE   
 1       0.00000     1.00000     0.50000     0.93400     FALSE  
 2       0.00000     0.50000     0.25000     0.51800     FALSE                          
 3       0.00000     0.25000     0.12500     0.06400     FALSE                          
 4       0.00000     0.12500     0.06250     0.01200     TRUE                            
 5       0.06250     0.12500     0.09375     0.04400     FALSE                          
 6       0.06250     0.09375     0.07812     0.03400     FALSE                          
 7       0.06250     0.07812     0.07031     0.01800     TRUE                            
 8       0.07031     0.07812     0.07422     0.02800     FALSE                          
 9       0.07031     0.07422     0.07227     0.01800     TRUE                            
 10          0.07227     0.07422     0.07324     0.02000     TRUE                           
 11          0.07324     0.07422     0.07373     0.02000     TRUE                           
 12          0.07373     0.07422     0.07397     0.01400     TRUE                           
 13          0.07397     0.07422     0.07410     0.02600     FALSE                         
 14          0.07397     0.07410     0.07404     0.02200     TRUE                           
 >>> Length of interval is below tolerance level. Bisection method is completed.

Thanks!

a-torgovitsky commented 4 years ago

Do you think I should still keep the lb0 and ub0 arguments because they can be determined from the testing procedures anyway?

We still want to keep the option for the user to set the brackets, since this can be important for increasing speed of the bisection problem. However if a sensible default can be determined automatically, then we want to use that.

conroylau commented 4 years ago

I see, sure. Do you think I should still check if lb0 and ub0 are sensible? Or as long as lb0 or ub0 is provided, I do not need to compute the corresponding logical lower or upper bounds to determine the initial interval? Thanks!

a-torgovitsky commented 4 years ago

What do you mean? Maybe I have forgotten what the variables stand for.

Is this correct?

lb0 (ub0) are values that are logically smaller (larger) than the target parameter can take

conroylau commented 4 years ago

Yes you are right!

I also included two related variables in invertci that can be passed from the user:

So, what I meant earlier is that if ub0 and lb0 are provided by the user, do you think I still need to check the logical bounds before running the bisection method?

a-torgovitsky commented 4 years ago

So, what I meant earlier is that if ub0 and lb0 are provided by the user, do you think I still need to check the logical bounds before running the bisection method?

At least some of our testing procedures (like DKQS) reject immediately if testing a point outside of the logical bounds, right? So I don't think there's any problem if the user puts in stupid values of ub0 and lb0.

conroylau commented 4 years ago

Yes, that's right! The p-value is immediately set as 0 if a point is outside the logical bounds.

I will be closing this issue for now as I have added the part that takes the logical bounds from the testing procedures if ub0 and lb0 are not specified.