4
4
from ..lasso import lasso , selected_targets
5
5
from ..exact_reference import exact_grid_inference
6
6
7
- def test_approx_pivot (n = 500 ,
8
- p = 100 ,
9
- signal_fac = 1. ,
10
- s = 5 ,
11
- sigma = 2. ,
12
- rho = 0.4 ,
13
- randomizer_scale = 1. ,
14
- equicorrelated = False ,
15
- useIP = False ):
7
+ def test_inf (n = 500 ,
8
+ p = 100 ,
9
+ signal_fac = 1. ,
10
+ s = 5 ,
11
+ sigma = 2. ,
12
+ rho = 0.4 ,
13
+ randomizer_scale = 1. ,
14
+ equicorrelated = False ,
15
+ useIP = False ,
16
+ CI = True ):
16
17
17
18
while True :
18
19
@@ -66,37 +67,71 @@ def test_approx_pivot(n=500,
66
67
cov_target_score ,
67
68
useIP = useIP )
68
69
69
- pivot = exact_grid_inf ._pivots (beta_target )
70
+ if CI is False :
71
+ pivot = exact_grid_inf ._pivots (beta_target )
72
+ return pivot
73
+
74
+ else :
75
+ lci , uci = exact_grid_inf ._intervals (level = 0.90 )
76
+ coverage = (lci < beta_target ) * (uci > beta_target )
77
+ length = uci - lci
78
+ mle_length = 1.65 * 2 * np .sqrt (np .diag (exact_grid_inf .inverse_info ))
79
+ return np .mean (coverage ), np .mean (length ), np .mean (mle_length )
80
+
81
+ def main (nsim = 300 , CI = False ):
82
+
83
+ if CI is False :
84
+
85
+ import matplotlib as mpl
86
+ mpl .use ('tkagg' )
87
+ import matplotlib .pyplot as plt
88
+ from statsmodels .distributions .empirical_distribution import ECDF
89
+
90
+ _pivot = []
91
+ for i in range (nsim ):
92
+ _pivot .extend (test_inf (n = 100 ,
93
+ p = 400 ,
94
+ signal_fac = 1. ,
95
+ s = 0 ,
96
+ sigma = 2. ,
97
+ rho = 0.30 ,
98
+ randomizer_scale = 0.7 ,
99
+ equicorrelated = True ,
100
+ useIP = False ,
101
+ CI = False ))
102
+
103
+ print ("iteration completed " , i )
104
+
105
+ plt .clf ()
106
+ ecdf_pivot = ECDF (np .asarray (_pivot ))
107
+ grid = np .linspace (0 , 1 , 101 )
108
+ plt .plot (grid , ecdf_pivot (grid ), c = 'blue' )
109
+ plt .plot (grid , grid , 'k--' )
110
+ plt .show ()
111
+
112
+ else :
113
+ coverage_ = 0.
114
+ length_ = 0.
115
+ mle_length_ = 0.
116
+ for n in range (nsim ):
117
+ cov , len , mle_len = test_inf (n = 400 ,
118
+ p = 100 ,
119
+ signal_fac = 0.5 ,
120
+ s = 5 ,
121
+ sigma = 2. ,
122
+ rho = 0.30 ,
123
+ randomizer_scale = 0.7 ,
124
+ equicorrelated = True ,
125
+ useIP = False ,
126
+ CI = True )
127
+
128
+ coverage_ += cov
129
+ length_ += len
130
+ mle_length_ += mle_len
131
+ print ("coverage so far " , coverage_ / (n + 1. ))
132
+ print ("lengths so far " , length_ / (n + 1. ), mle_length_ / (n + 1. ))
133
+ print ("iteration completed " , n + 1 )
70
134
71
- return pivot
72
-
73
- def main (nsim = 300 ):
74
-
75
- import matplotlib as mpl
76
- mpl .use ('tkagg' )
77
- import matplotlib .pyplot as plt
78
- from statsmodels .distributions .empirical_distribution import ECDF
79
-
80
- _pivot = []
81
- for i in range (nsim ):
82
- _pivot .extend (test_approx_pivot (n = 100 ,
83
- p = 400 ,
84
- signal_fac = 1. ,
85
- s = 0 ,
86
- sigma = 2. ,
87
- rho = 0.30 ,
88
- randomizer_scale = 0.7 ,
89
- equicorrelated = True ,
90
- useIP = False ))
91
-
92
- print ("iteration completed " , i )
93
-
94
- plt .clf ()
95
- ecdf_pivot = ECDF (np .asarray (_pivot ))
96
- grid = np .linspace (0 , 1 , 101 )
97
- plt .plot (grid , ecdf_pivot (grid ), c = 'blue' )
98
- plt .plot (grid , grid , 'k--' )
99
- plt .show ()
100
135
101
136
if __name__ == "__main__" :
102
- main (nsim = 100 )
137
+ main (nsim = 100 , CI = True )
0 commit comments