conroylau / lpinfer

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

Replace many_qpci with the ability to pass a vector to qpci #10

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago

Instead of having a separate function, just let qpci be a driver that does something different depending on whether alpha is a vector or a scalar.

conroylau commented 4 years ago

Done! Integrated the function of generating multiple CIs into the main function invertci.

Based on whether alpha is a scalar or vector, print and summary will print the correct information.

Some sample outputs for print and summary below (I have omitted some rows below for brevity):

Vector-valued alpha

print

< Significance level: 0.01 >
Total number of iterations: 20.
Confidence interval: [0.35977, 0.6582].
--------------------------------------
< Significance level: 0.05 >
Total number of iterations: 20.
Confidence interval: [0.36289, 0.65273].

summary

Call:
invertci(f = dkqs, farg = farg, alpha = c(0.01, 0.05), lb0 = 0, 
    lb1 = 0.4, ub0 = 1, ub1 = 0.6, tol = 0.001, max_iter = 50, 
    df_ci = NULL, progress = TRUE)

Significance levels considered: 0.01  0.05  

< Confidence interval for alpha = 0.01 >
=== Iterations in constructing upper bound:
Iteration    Test point      Lower bound     Upper bound     p-value     Decision
Left end-pt.     0.60000     0.60000     NA      0.77780     Do not reject  
Right end-pt.    1.00000     NA      1.00000     0.00000     Reject     
1        0.80000     0.60000     1.00000     0.00000     Reject     
2        0.70000     0.60000     0.80000     0.00000     Reject     
......
8        0.65781     0.65625     0.65938     0.00660     Do not reject  
9        0.65859     0.65781     0.65938     0.00380     Reject     
>>> Reached maximum number of iterations

=== Iterations in constructing lower bound:
Iteration    Test point      Lower bound     Upper bound     p-value     Decision
Left end-pt.     0.00000     0.00000     NA      0.00000     Reject     
Right end-pt.    0.40000     NA      0.40000     0.78790     Do not reject  
1        0.20000     0.00000     0.40000     0.00000     Reject     
2        0.30000     0.20000     0.40000     0.00000     Reject     
......
8        0.36094     0.35938     0.36250     0.00790     Do not reject  
9        0.36016     0.35938     0.36094     0.00610     Do not reject  
>>> Reached maximum number of iterations

< Confidence interval for alpha = 0.05 >
=== Iterations in constructing upper bound:
Iteration    Test point      Lower bound     Upper bound     p-value     Decision
Left end-pt.     0.60000     0.60000     NA      0.77780     Do not reject  
Right end-pt.    1.00000     NA      1.00000     0.00000     Reject     
1        0.80000     0.60000     1.00000     0.00000     Reject     
2        0.70000     0.60000     0.80000     0.00000     Reject     
......
8        0.65156     0.65000     0.65312     0.03000     Do not reject  
9        0.65234     0.65156     0.65312     0.02570     Do not reject  
>>> Reached maximum number of iterations

=== Iterations in constructing lower bound:
Iteration    Test point      Lower bound     Upper bound     p-value     Decision
Left end-pt.     0.00000     0.00000     NA      0.00000     Reject     
Right end-pt.    0.40000     NA      0.40000     0.78790     Do not reject  
1        0.20000     0.00000     0.40000     0.00000     Reject     
2        0.30000     0.20000     0.40000     0.00000     Reject     
......
8        0.36406     0.36250     0.36562     0.03300     Do not reject  
9        0.36328     0.36250     0.36406     0.02780     Do not reject  

Scalar-valued alpha

print

< Significance level: 0.01 >
Total number of iterations: 20.
Confidence interval: [0.35977, 0.6582].

summary

Call:
invertci(f = dkqs, farg = farg, alpha = c(0.01), lb0 = 0, 
    lb1 = 0.4, ub0 = 1, ub1 = 0.6, tol = 0.001, max_iter = 50, 
    df_ci = NULL, progress = TRUE)

Significance level: 0.01  

< Confidence interval for alpha = 0.01 >
=== Iterations in constructing upper bound:
Iteration    Test point      Lower bound     Upper bound     p-value     Decision
Left end-pt.     0.60000     0.60000     NA      0.77780     Do not reject  
Right end-pt.    1.00000     NA      1.00000     0.00000     Reject     
1        0.80000     0.60000     1.00000     0.00000     Reject     
2        0.70000     0.60000     0.80000     0.00000     Reject     
......
8        0.65781     0.65625     0.65938     0.00660     Do not reject  
9        0.65859     0.65781     0.65938     0.00380     Reject     
>>> Reached maximum number of iterations

=== Iterations in constructing lower bound:
Iteration    Test point      Lower bound     Upper bound     p-value     Decision
Left end-pt.     0.00000     0.00000     NA      0.00000     Reject     
Right end-pt.    0.40000     NA      0.40000     0.78790     Do not reject  
1        0.20000     0.00000     0.40000     0.00000     Reject     
2        0.30000     0.20000     0.40000     0.00000     Reject     
......
8        0.36094     0.35938     0.36250     0.00790     Do not reject  
9        0.36016     0.35938     0.36094     0.00610     Do not reject  
>>> Reached maximum number of iterations