-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpower80table.R
More file actions
38 lines (33 loc) · 1.46 KB
/
power80table.R
File metadata and controls
38 lines (33 loc) · 1.46 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
### a script to calculate the number of individuals for a power of .8 in all conditions.
vec_p <- paste("p", 1:11, sep = "")
vec_c <- paste("c", 1:12, sep = "")
df_results <- matrix(nrow = 12, ncol = 11)
colnames(df_results) <- vec_p
rownames(df_results) <- vec_c
lunit <- .00001
ssize <- 1:1000000
l_vec <- lunit*ssize
powerCal <- function(lamda,df){
1- pchisq(qchisq(1-.05, df), df, lamda)
}
powVec <- as.numeric(lapply(l_vec,powerCal, df = 2))
tgt_lunit <- which.min(abs(powVec-.80))*lunit
for (p in 1: 11){
for (c in 1: 12){
dir <- paste0("~/R-Project/BalancedPed/Simulations/p",p,"/p",p, "c",c)
if (dir.exists(dir)){
#cat("starttime:", as.character(Sys.time()))
cat("\n","running", dir)
setwd(dir)
load("modelSmr.Rdata")
meanDiffLL_mtam <- smr2$Minus2LogLikelihood - smr1$Minus2LogLikelihood
PN <- ncol(smr1[["dataSummary"]][["fam1"]])*length(smr1[["dataSummary"]])
lamdaUnit <- meanDiffLL_mtam/PN
df_results[c,p] <- round(tgt_lunit/lamdaUnit)
#cat("finished at" , as.character(Sys.time()))
}else{
next
}
}
}
write.table(df_results, "~/R-Project/BalancedPed/Graphs/PowerTable.csv", quote = FALSE, sep = ",")