Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Commit 868dd35b authored by Ben Anderson's avatar Ben Anderson
Browse files

added new proportions power analysis; re-ran docs

parent ac04c11c
# Generated by roxygen2: do not edit by hand
export(estimateEffectSizes)
export(estimateMeanEffectSizes)
export(estimateProportionEffectSizes)
import(data.table)
import(pwr)
import(reshape2)
#--- Sample power related functions ---#
#' Estimate detectable effect sizes using statistical power analysis
#' Estimate detectable mean effect sizes using statistical power analysis
#'
#' \code{estimateEffectSizes} calculates required sample sizes for a given set of p values and samples.
#' \code{estimateMeanEffectSizes} calculates required sample sizes for a given set of p values and samples. Assumes a 1-sided test.
#'
#' 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.
#'
......@@ -15,9 +15,10 @@
#' @export
#' @import data.table
#' @import reshape2
#' @import pwr
#' @family Power functions
estimateEffectSizes <- function(mean,sd,samples,power){
estimateMeanEffectSizes <- function(mean,sd,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)
......@@ -29,12 +30,13 @@ estimateEffectSizes <- function(mean,sd,samples,power){
# loop over significance values
for (p in 1:nSigs){
for (s in 1:nSamps){ # loop over the sample sizes
result <- power.t.test( # pwr.t.test?
result <- power.t.test(
n = samples[s],
delta = NULL,
delta = NULL, # what we want to calculate
sd = sd,
sig.level = sigs[p],
power = power,
type = c("two.sample"),
alternative = c("one.sided")
)
resultsArray[s,p] <- result$delta/mean # report effect size against sample size
......@@ -57,11 +59,11 @@ estimateEffectSizes <- function(mean,sd,samples,power){
return(longDT) # returned the tidied & long form dt
}
#' Estimate proportion margins of error using statistical power analysis
#' Estimate detectable proportion differences for given sample sizes using statistical power analysis
#'
#' \code{estimateProportions} calculates required sample sizes for a given set of p values and samples.
#' \code{estimateProportionEffectSizes} calculates required sample sizes for a given set of p values and samples.
#'
#' 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.
#' 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
......@@ -75,7 +77,7 @@ estimateEffectSizes <- function(mean,sd,samples,power){
#' @import pwr
#' @family Power functions
estimateEffectSizes <- function(mean,sd,samples,power){
estimateProportionEffectSizes <- function(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)
......@@ -88,15 +90,13 @@ estimateEffectSizes <- function(mean,sd,samples,power){
for (p in 1:nSigs){
for (s in 1:nSamps){ # loop over the sample sizes
# pwr.t.test?
result <- power.t.test(
result <- pwr::pwr.2p.test(
n = samples[s],
delta = NULL,
sd = sd,
h = NULL,
sig.level = sigs[p],
power = power,
alternative = c("one.sided")
power = power
)
resultsArray[s,p] <- result$delta/mean # report effect size against sample size
resultsArray[s,p] <- result$h # report effect size against sample size
}
}
dt <- data.table::as.data.table(resultsArray) # convert to dt for tidying
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/power.R
\name{estimateEffectSizes}
\alias{estimateEffectSizes}
\title{Estimate detectable effect sizes using statistical power analysis}
\name{estimateMeanEffectSizes}
\alias{estimateMeanEffectSizes}
\title{Estimate detectable mean effect sizes using statistical power analysis}
\usage{
estimateEffectSizes(mean, sd, samples, power)
estimateEffectSizes(mean, sd, samples, power)
estimateMeanEffectSizes(mean, sd, samples, power)
}
\arguments{
\item{mean}{the estimated mean value to use}
......@@ -15,29 +13,18 @@ estimateEffectSizes(mean, sd, samples, power)
\item{samples}{a list of sample sizes to iterate over}
\item{power}{power value to use}
\item{mean}{the estimated mean value to use}
\item{sd}{the estimated stadnard deviation to use}
\item{samples}{a list of sample sizes to iterate over}
\item{power}{power value to use}
}
\description{
\code{estimateEffectSizes} calculates required sample sizes for a given set of p values and samples.
\code{estimateProportions} calculates required sample sizes for a given set of p values and samples.
\code{estimateMeanEffectSizes} calculates required sample sizes for a given set of p values and samples. Assumes a 1-sided test.
}
\details{
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.
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.
}
\seealso{
Other Power functions: \code{\link{estimateProportionEffectSizes}}
}
\author{
Ben Anderson, \email{b.anderson@soton.ac.uk}
Ben Anderson, \email{b.anderson@soton.ac.uk}
}
\concept{Power functions}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/power.R
\name{estimateProportionEffectSizes}
\alias{estimateProportionEffectSizes}
\title{Estimate detectable proportion differences for given sample sizes using statistical power analysis}
\usage{
estimateProportionEffectSizes(samples, power)
}
\arguments{
\item{samples}{a list of sample sizes to iterate over}
\item{power}{power value to use}
\item{mean}{the estimated mean value to use}
\item{sd}{the estimated stadnard deviation to use}
}
\description{
\code{estimateProportionEffectSizes} calculates required sample sizes for a given set of p values and samples.
}
\details{
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.
}
\seealso{
Other Power functions: \code{\link{estimateMeanEffectSizes}}
}
\author{
Ben Anderson, \email{b.anderson@soton.ac.uk}
}
\concept{Power functions}
Markdown is supported
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