-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_all_ICC_thresholds.R
93 lines (82 loc) · 3.29 KB
/
gen_all_ICC_thresholds.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
##-------------------------------------------------------------------------------
## gen_all_ICC_thresholds: generate lower-threshold for ICCs using a surrogate-data
## approach
##
## Syntax: drT <- gen_all_ICC_thresholds(cohort="twins")
##
## Inputs:
## cohort - either "twins", "mcda", "dcda", or "singletons"
##
##
## Example:
## > source('gen_all_ICC_thresholds.R')
## > gen_all_ICC_thresholds("twins")
## > gen_all_ICC_thresholds("mcda")
## > gen_all_ICC_thresholds("dcda")
## > gen_all_ICC_thresholds("singletons")
##
## or can run this in parallel by using:
##
## > require('parallel')
## > no_cores <- detectCores() - 1
## > cl <- makeCluster(no_cores)
## > data_types <- c("twins", "mcda", "dcda", "singletons")
## > parLapply(cl, data_types, gen_all_ICC_thresholds)
## > stopCluster(cl)
##
## REQUIRES:
## lme4 (version 1.1.15)
## plyr (version 1.8.4)
##
## and local functions:
## set_paths.R
## gen_ICCs/load_twin_features.R
## gen_ICCs/do_all_ICCs_surrogate.R
## gen_ICCs/cal_ICC_threshold.R
## gen_ICCs/estimate_ICC.R
##
## John M. O' Toole, University College Cork
## Started: 22-10-2018
##
## last update: Time-stamp: <2018-10-23 17:40:58 (otoolej)>
##-------------------------------------------------------------------------------
gen_all_ICC_thresholds <- function(cohort = "twins"){
##-------------------------------------------------------------------
## load libraries and local files:
##-------------------------------------------------------------------
require(lme4)
require(plyr)
source('set_paths.R')
source(paste(r_files_dir, 'load_twin_features.R', sep=""))
source(paste(r_files_dir, 'do_all_ICCs_surrogate.R', sep=""))
source(paste(r_files_dir, 'cal_ICC_threshold.R', sep=""))
source(paste(r_files_dir, 'estimate_ICC.R', sep=""))
N_iter <- 1000
## only do for 1 group at a time (as computational slow):
if((cohort %in% c("twins","mcda","dcda"))){
##-------------------------------------------------------------------
## load the twin data:
##-------------------------------------------------------------------
dfFeats <- load_twin_features(dfNames_fin$twin_feats)
##-------------------------------------------------------------------
## subsets for MCDA and DCDA infants
##-------------------------------------------------------------------
if(cohort == "mcda"){
dfFeats.MCDA <- droplevels( subset(dfFeats,(twinType %in% "MCDA")) )
fname <- dfNames_fout$mcda_icc_thres
} else if(cohort == "dcda") {
dfFeats <- droplevels( subset(dfFeats,(twinType %in% "DCDA")) )
fname <- dfNames_fout$dcda_icc_thres
} else {
fname <- dfNames_fout$twin_icc_thres
}
} else if(cohort=="singletons"){
##-------------------------------------------------------------------
## load the SINGLETONS data:
##-------------------------------------------------------------------
dfFeats <- load_twin_features(dfNames_fin$sing_feats)
fname <- dfNames_fout$sing_icc_thres
}
## generate the ICC thresholds:
do_all_ICCs_surrogate(dfFeats, N_iter, fname)
}