Commit 2d9a2b05 authored by Ben Anderson's avatar Ben Anderson
Browse files

updated proportions code

parent 84f5582f
......@@ -65,8 +65,8 @@ estimateMeanEffectSizes <- function(mean,sd,samples,power){
#'
#' Returns a data.table of effect sizes (%) for a given sample size. Calculates these for p = 0.01, 0.05, 0.1 & 0.2. Pick out the ones you want.
#'
#' @param mean the estimated mean value to use
#' @param sd the estimated stadnard deviation to use
#' @param p1 the estimated proportion in sample 1
#' @param sd the estimated proportion in sample 2
#' @param samples a list of sample sizes to iterate over
#' @param power power value to use
#'
......@@ -77,27 +77,23 @@ estimateMeanEffectSizes <- function(mean,sd,samples,power){
#' @import pwr
#' @family Power functions
estimateProportionEffectSizes <- function(samples,power){
estimateProportionSampleSizes <- function(p1, p2, samples ,power){
# obtain effect sizes using supplied mean & sd
sigs <- c(0.01,0.05,0.1,0.2) # force these, can always remove later
nSigs <- length(sigs)
nSamps <- length(samples)
# initialise power results array
resultsArray <- array(numeric(nSamps*nSigs),
dim=c(nSamps,nSigs)
)
# loop over significance values
for (p in 1:nSigs){
for (s in 1:nSamps){ # loop over the sample sizes
# pwr.t.test?
result <- pwr::pwr.2p.test(
n = samples[s],
h = NULL,
h = ES.h(p1 = p1, p2 = p2),
n = NULL,
sig.level = sigs[p],
power = power
)
resultsArray[s,p] <- result$h # report effect size against sample size
}
resultsArray[s,p] <- result$n # report effect size against sample size
}
dt <- data.table::as.data.table(resultsArray) # convert to dt for tidying
dt <- dt[,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment