-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGenerateNull.R
More file actions
112 lines (91 loc) · 4.54 KB
/
Copy pathGenerateNull.R
File metadata and controls
112 lines (91 loc) · 4.54 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
###############################################################################
# #
# Generate null Studies #
# #
###############################################################################
# Required input: a set of studies used for an ALE meta-analysis
# (for which the Fail-Safe N needs to be determined) and a pre-specified number of
# null studies. The coordinate space is set to MNI.
# From this set we deduct the set size, individual study sample sizes and number
# of peaks.
#
# Output: text-file containing the pre-specified number of null studies that
# can be added into the meta-analyses (coordinate space is MNI).
#
# To compute the Fail-Safe N (i.e. the number of null studies that can be added
# to your meta-analysis before the results are no longer statistically
# significant) a minimum and maximum FSN need to be determined beforehand.
# An ALE meta-analysis is then performed with a combination of the original data
# and a selection of null studies. See the accompanying document for the full
# algorithm that needs to be followed illustrated by an example.
###############################################################################
# To be filled out by the researcher
###############################################################################
# Read in data file
# Provide path to folder with file in variable home or set folder with file
# to working directory
home<-paste(getwd(),"/",sep="")
setwd(home)
namefoci <- "EickhoffHBM09.txt" # Name of file
space <- "MNI" # Either MNI or MNI152
# Required number of null studies is standard set to to 5k + 10. If you require
# more null studies set auto to "FALSE" and fill out number of required
# null studies
auto <- TRUE
k.null1 <- 375
###############################################################################
# Not to be altered
###############################################################################
# Read in foci
foci.info <- array(NA,dim=c(1,5))
colnames(foci.info) <- c("X","Y","Z","N","S")
tempfoci <- array(NA,dim=c(1,3))
foci.raw<-read.table(namefoci,fill=TRUE,header=FALSE,stringsAsFactors = FALSE)
allfoci<-array(data=NA,dim=c(dim(foci.raw)[1],5))
nvect <- vector()
j<-0
foci.raw2<-foci.raw[,1:3]
for (i in 1:dim(foci.raw2)[1]) {
if(foci.raw2[i,1]=="//" & (is.na(as.numeric(gsub("\\Subjects=", "", x=foci.raw2[i,2])))==FALSE)) {
j<-j+1
N<-as.numeric(gsub("\\Subjects=", "", x=foci.raw2[i,2])) # Number of participants
}
if(is.na(as.numeric(foci.raw2[i,2]))) next
allfoci[i,5] <- j # Study number
allfoci[i,4] <- N
nvect<-c(nvect,N)
allfoci[i,1:3]<-as.numeric(foci.raw2[i,1:3]) # next study
}
allfoci<-na.omit(allfoci)
foci.info <- allfoci[1:dim(allfoci)[1],1:dim(allfoci)[2]]
# Parameters
n.r <- nvect # Sample sizes of individual studies
k.r <- max (foci.info[,5]) # Number of studies in the meta-analysis
p.r <- as.numeric(table(foci.info[,5])) # Number of peaks
coord <- "MNI" # coordinate space
k.null <- ifelse(auto==TRUE,10 + (k.r*10), k.null1)
# Generate new studies
if (space == "MNI") {
allvox <- read.table("within_MNI.txt")
} else if (space == "MNI152") {
allvox <- read.table("within_MNI152.txt")
} else {
stop("Please choose either 'MNI' or 'MNI152' as template space!")
}
# Set up variables
p.n <- sample(p.r,k.null,replace=TRUE)
seed <- sample(c(1:1000000),1)
file<-array(data=NA,dim=c(sum(p.n)+(k.null*3),1))
row<-1
for (i in 1:k.null) {
nfoci<-p.n[i]
file[(row),1]<-paste("// NullStudy_",i,sep="")
set.seed(seed+i)
file[(row+1),1]<-paste("// Subjects=",sample(n.r,1),sep="")
set.seed(seed+i)
tempvox<-allvox[sample(dim(allvox)[1],nfoci,replace=FALSE),1:3]
file[((row+2):(row+1+nfoci)),1]<-paste(tempvox[1:nfoci,1]," ",tempvox[1:nfoci,2]," ",tempvox[1:nfoci,3],sep="")
file[(row+2+nfoci),1]<-paste(" ",sep="")
row<-row+3+nfoci
}
write.table(file,"NullStudies.txt",quote=FALSE,row.names=FALSE,col.names=FALSE)