-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectResults.R
76 lines (68 loc) · 3.12 KB
/
collectResults.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
<<<<<<< HEAD
# Collect all results and put it in a matrix
# original design is in the matrix Design
# Total number of rows of Design = TotalCells
#first load one workspace, for example, cell 1 of the Design matrix
#save the number of replications within that cell
Row <- 1
load(file.path("results",paste("MyResult", "Row", Row,".Rdata" , sep ="")))
K <- nrow(MyResult)
#Initialize a very large matrix with number of rows = K * TotalCells
Results_sim <- matrix(NA, ncol = ncol(MyResult), nrow = K*TotalCells)
#Fill in this matrix with the results that you obtained for each cell of the design (= each of the workspaces).
#Thus loop over the rows of Design
for (i in 1:TotalCells){
Row <- i
load(paste("MyResult", "Row", Row,".Rdata" , sep =""))
Results_sim[(K*(i-1)+1):(i*K), ] <- MyResult
}
#repeate the Design matrix K times
Results_des <- Design[rep(1:nrow(Design),each=K),]
rownames(Results_des) <- 1:nrow(Results_des)
#rbind the vector 1:K TotalCelss times
Results_K <- do.call(what = rbind, args = replicate(TotalCells, matrix(c(1:K), ncol = 1), simplify = F))
#Create the final results matrix
ResultsSimAll <-as.data.frame(cbind(Results_des, K = Results_K, Results_sim))
#Give the columns the right name:
names(ResultsSimAll) <- c(names(Design), "K", "Method1", "Method2")
head(ResultsSimAll)
save(ResultsSimAll, file = "AllResultsSim.Rdata")
#Optionally save it as a .sav file
library(haven)
workingDirectory <- paste(getwd(), "/", sep = "")
filenameToSave <- paste(workingDirectory, "AllResultsSim", ".sav", sep = "")
=======
# Collect all results and put it in a matrix
# original design is in the matrix Design
# Total number of rows of Design = TotalCells
#first load one workspace, for example, cell 1 of the Design matrix
#save the number of replications within that cell
Row <- 1
load(file.path("results",paste("MyResult", "Row", Row,".Rdata" , sep ="")))
K <- nrow(MyResult)
#Initialize a very large matrix with number of rows = K * TotalCells
Results_sim <- matrix(NA, ncol = ncol(MyResult), nrow = K*TotalCells)
#Fill in this matrix with the results that you obtained for each cell of the design (= each of the workspaces).
#Thus loop over the rows of Design
for (i in 1:TotalCells){
Row <- i
load(paste("MyResult", "Row", Row,".Rdata" , sep =""))
Results_sim[(K*(i-1)+1):(i*K), ] <- MyResult
}
#repeate the Design matrix K times
Results_des <- Design[rep(1:nrow(Design),each=K),]
rownames(Results_des) <- 1:nrow(Results_des)
#rbind the vector 1:K TotalCelss times
Results_K <- do.call(what = rbind, args = replicate(TotalCells, matrix(c(1:K), ncol = 1), simplify = F))
#Create the final results matrix
ResultsSimAll <-as.data.frame(cbind(Results_des, K = Results_K, Results_sim))
#Give the columns the right name:
names(ResultsSimAll) <- c(names(Design), "K", "Method1", "Method2")
head(ResultsSimAll)
save(ResultsSimAll, file = "AllResultsSim.Rdata")
#Optionally save it as a .sav file
library(haven)
workingDirectory <- paste(getwd(), "/", sep = "")
filenameToSave <- paste(workingDirectory, "AllResultsSim", ".sav", sep = "")
>>>>>>> bf47da6a1fdb87610a2366c79e6f55cd26b6b46f
write_sav(ResultsSimAll, filenameToSave)