@@ -80,10 +80,17 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, verbo
8080 # # Train with only marginally significant SNPs
8181 M0 = nrow(R )
8282 ME_p <- 2 - 2 * pnorm(abs(hatB / hatS ), 0 , 1 )
83- significant_thres = ifelse(" significant_thres" %in% names(args ), args $ significant_thres , 1e-1 )
84- idx <- which(ME_p < = significant_thres , arr.ind = TRUE )[, 1 ] %> % unique
83+ significant_thres = ifelse(" significant_thres" %in% names(args ),
84+ args $ significant_thres ,
85+ ifelse(sqrt(6 ) / sqrt(diag(N )) > = 0.05 , sqrt(6 ) / sqrt(diag(N )), 0.05 ))
86+ if (C == 1 ){
87+ idx <- which(ME_p < = significant_thres )
88+ } else {
89+ idx <- which(t(apply(ME_p , 1 , function (x ) x < = significant_thres )), arr.ind = TRUE )[, 1 ] %> % unique
90+ }
91+
8592 if (length(idx ) == 1 ){
86- idx = c( idx - 1 , idx , idx + 1 )
93+ idx = idx + ( - 2 ) : 2
8794 idx = idx [idx > = 1 & idx < = nrow(hatB )]
8895 }
8996 hatB = hatB [idx , ]
@@ -96,7 +103,7 @@ CASE_train <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, V = NULL, verbo
96103 if (verbose ){
97104 cat(" No marginally significant variants in the inputs." , " \n " )
98105 }
99- return (list (pi = 1 , U = list ( matrix ( 0 , C , C )), V = V , n.iter = 0 ))
106+ return (list (pi = 1 , n.iter = 0 ))
100107 }
101108
102109 J <- 0
@@ -310,10 +317,6 @@ CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, v
310317 cat(" Start Posterior Analysis." , " \n " )
311318 }
312319
313- U = CASE_training $ U
314- V = CASE_training $ V
315- pi = CASE_training $ pi
316-
317320 if (is.null(Z )){
318321 Z = hatB / hatS
319322 }
@@ -322,15 +325,19 @@ CASE_test <- function(Z = NULL, R, hatB = NULL, hatS = NULL, N, CASE_training, v
322325 hatBS = transform_Z(Z , N )
323326 hatB = hatBS $ hatB
324327 hatS = hatBS $ hatS
325-
328+
326329 C <- ncol(hatB )
327330 M <- nrow(R )
328331
332+ pi = CASE_training $ pi
329333 if (length(pi ) < = 1 ){
330334 post_mean = pip = matrix (0 , M , C )
331- return (list (pi = pi , U = U , V = V , pip = pip , post_mean = post_mean ))
335+ return (list (pip = pip , post_mean = post_mean ))
332336 }
333337
338+ U = CASE_training $ U
339+ V = CASE_training $ V
340+
334341 L = length(U )
335342 # # MC step
336343 gBc = gB_coef(U , V )
0 commit comments