-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnull_ECDF_Utillity_Functions.R
62 lines (47 loc) · 1.85 KB
/
null_ECDF_Utillity_Functions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# This function takes the path to the folder of any simulated dataset
# and calculates the results of detection for each method.
# The output is a numeric vector where ach element is the calculated pvalue
# based on the permutation of case/control status of individuals.
#
# The output vector reports the pvalues in the following order:
# "FET", "SKATO", "dCor", "Mantel"
#
get_detection_results = function(path){
# Create an empty numeric vector to record the pvalue obtained by permutation
pvalue = numeric( length = 4)
if( file.exists( paste0(path, "FET_perm.RData") ) ){
load( paste0(path, "FET_perm.RData") )
n_perm = nrow(FET_permutations) - 1
perms = apply(X = -log(FET_permutations,base=10), MARGIN = 1, FUN = max)
pvalue[1] = mean( perms >= perms[ n_perm + 1 ] )
}else{
pvalue[1] = NA
}
if( file.exists(paste0(path, "SKATO_perm.RData")) ){
load( paste0(path, "SKATO_perm.RData") )
n_perm = nrow(SKATO_permutations) - 1
perms = apply(X = -log(SKATO_permutations,base=10), MARGIN = 1, FUN = max)
pvalue[2] = mean( perms >= perms[ n_perm + 1 ] )
}else{
pvalue[2] = NA
}
if( file.exists(paste0(path, "dCorN_perm.RData")) ){
load( paste0(path, "dCorN_perm.RData") )
n_perm = nrow(dCorN_permutation) - 1
perms = apply(X = dCorN_permutation , MARGIN = 1, FUN = max)
pvalue[3] = mean( perms >= perms[ n_perm + 1 ] )
}else{
pvalue[3] = NA
}
if( file.exists(paste0(path, "Mantel_perm.RData")) ){
load( paste0(path, "Mantel_perm.RData") )
n_perm = nrow(Mantel_permutation) - 1
perms = apply(X = Mantel_permutation^2 , MARGIN = 1, FUN = max)
pvalue[4] = mean( perms >= perms[ n_perm + 1 ] )
}else{
pvalue[4] = NA
}
names(pvalue) = c("FET", "SKATO", "dCor", "Mantel")
return(pvalue)
}