@@ -65,7 +65,7 @@ conditional_density = function(noise_scale, lasso_soln){
65
65
}
66
66
67
67
68
- run_instance = function (X ,y ,sigma , lam , noise_scale , ridge_term ){
68
+ randomized_inference = function (X ,y ,sigma , lam , noise_scale , ridge_term ){
69
69
n = nrow(X )
70
70
p = ncol(X )
71
71
lasso_soln = selectiveInference ::: randomizedLASSO(X , y , lam , noise_scale , ridge_term )
@@ -74,7 +74,7 @@ run_instance = function(X,y,sigma, lam, noise_scale, ridge_term){
74
74
nactive = length(active_set )
75
75
print(paste(" nactive" , nactive ))
76
76
77
- lasso_soln = conditional_density(noise_scale , lasso_soln )
77
+ # lasso_soln = conditional_density(noise_scale, lasso_soln)
78
78
79
79
dim = length(lasso_soln $ observed_opt_state )
80
80
print(paste(" chain dim" , dim ))
@@ -93,6 +93,7 @@ run_instance = function(X,y,sigma, lam, noise_scale, ridge_term){
93
93
observed_raw = lasso_soln $ observed_raw
94
94
95
95
pivots = rep(0 , nactive )
96
+ ci = matrix (0 , nactive , 2 )
96
97
for (i in 1 : nactive ){
97
98
target_transform = selectiveInference ::: linear_decomposition(observed_target [i ],
98
99
observed_internal ,
@@ -110,11 +111,24 @@ run_instance = function(X,y,sigma, lam, noise_scale, ridge_term){
110
111
observed_raw )
111
112
return (mean((target_sample < observed_target [i ])* weights )/ mean(weights ))
112
113
}
113
-
114
+ level = 0.9
115
+ rootU = function (candidate ){
116
+ return (pivot(observed_target [i ]+ candidate )- (1 - level )/ 2 )
117
+ }
118
+ rootL = function (candidate ){
119
+ return (pivot(observed_target [i ]+ candidate )- (1 + level )/ 2 )
120
+ }
114
121
pivots [i ] = pivot(0 )
122
+ line_min = - 10 * sd(target_sample )
123
+ line_max = 10 * sd(target_sample )
124
+ ci [i ,1 ] = uniroot(rootU , c(line_min , line_max ))$ root + observed_target [i ]
125
+ ci [i ,2 ] = uniroot(rootL ,c(line_min , line_max ))$ root + observed_target [i ]
115
126
}
116
127
print(paste(" pivots" , toString(pivots )))
117
- return (pivots )
128
+ for (i in 1 : nactive ){
129
+ print(paste(" CIs" , toString(ci [i ,])))
130
+ }
131
+ return (list (pivots = pivots , ci = ci ))
118
132
}
119
133
120
134
collect_results = function (n ,p ,s , nsim = 1 ){
@@ -129,8 +143,13 @@ collect_results = function(n,p,s, nsim=1){
129
143
y = data $ y
130
144
ridge_term = sd(y )/ sqrt(n )
131
145
noise_scale = sd(y )/ 2
132
- result = run_instance(X ,y ,sigma , lam , noise_scale , ridge_term )
133
- sample_pivots = c(sample_pivots , result )
146
+ # X = matrix(rnorm(n * p), n, p)
147
+ # y = rnorm(n)
148
+ # lam = 20 / sqrt(n)
149
+ # noise_scale = 0.01 * sqrt(n)
150
+ # ridge_term = .1 / sqrt(n)
151
+ result = randomized_inference(X ,y ,sigma ,lam ,noise_scale ,ridge_term )
152
+ sample_pivots = c(sample_pivots , result $ pivots )
134
153
}
135
154
136
155
jpeg(' pivots.jpg' )
0 commit comments