Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
weGotThePower
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ben Anderson
weGotThePower
Commits
868dd35b
Commit
868dd35b
authored
6 years ago
by
Ben Anderson
Browse files
Options
Downloads
Patches
Plain Diff
added new proportions power analysis; re-ran docs
parent
ac04c11c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
NAMESPACE
+2
-1
2 additions, 1 deletion
NAMESPACE
R/power.R
+15
-15
15 additions, 15 deletions
R/power.R
man/estimateMeanEffectSizes.Rd
+30
-0
30 additions, 0 deletions
man/estimateMeanEffectSizes.Rd
man/estimateProportionEffectSizes.Rd
+30
-0
30 additions, 0 deletions
man/estimateProportionEffectSizes.Rd
with
77 additions
and
16 deletions
NAMESPACE
+
2
−
1
View file @
868dd35b
# Generated by roxygen2: do not edit by hand
# Generated by roxygen2: do not edit by hand
export(estimateEffectSizes)
export(estimateMeanEffectSizes)
export(estimateProportionEffectSizes)
import(data.table)
import(data.table)
import(pwr)
import(pwr)
import(reshape2)
import(reshape2)
This diff is collapsed.
Click to expand it.
R/power.R
+
15
−
15
View file @
868dd35b
#--- Sample power related functions ---#
#--- 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{estimate
Mean
EffectSizes} 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.
#' 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 @@
...
@@ -15,9 +15,10 @@
#' @export
#' @export
#' @import data.table
#' @import data.table
#' @import reshape2
#' @import reshape2
#' @import pwr
#' @family Power functions
#' @family Power functions
estimateEffectSizes
<-
function
(
mean
,
sd
,
samples
,
power
){
estimate
Mean
EffectSizes
<-
function
(
mean
,
sd
,
samples
,
power
){
# obtain effect sizes using supplied mean & sd
# obtain effect sizes using supplied mean & sd
sigs
<-
c
(
0.01
,
0.05
,
0.1
,
0.2
)
# force these, can always remove later
sigs
<-
c
(
0.01
,
0.05
,
0.1
,
0.2
)
# force these, can always remove later
nSigs
<-
length
(
sigs
)
nSigs
<-
length
(
sigs
)
...
@@ -29,12 +30,13 @@ estimateEffectSizes <- function(mean,sd,samples,power){
...
@@ -29,12 +30,13 @@ estimateEffectSizes <- function(mean,sd,samples,power){
# loop over significance values
# loop over significance values
for
(
p
in
1
:
nSigs
){
for
(
p
in
1
:
nSigs
){
for
(
s
in
1
:
nSamps
){
# loop over the sample sizes
for
(
s
in
1
:
nSamps
){
# loop over the sample sizes
result
<-
power.t.test
(
# pwr.t.test?
result
<-
power.t.test
(
n
=
samples
[
s
],
n
=
samples
[
s
],
delta
=
NULL
,
delta
=
NULL
,
# what we want to calculate
sd
=
sd
,
sd
=
sd
,
sig.level
=
sigs
[
p
],
sig.level
=
sigs
[
p
],
power
=
power
,
power
=
power
,
type
=
c
(
"two.sample"
),
alternative
=
c
(
"one.sided"
)
alternative
=
c
(
"one.sided"
)
)
)
resultsArray
[
s
,
p
]
<-
result
$
delta
/
mean
# report effect size against sample size
resultsArray
[
s
,
p
]
<-
result
$
delta
/
mean
# report effect size against sample size
...
@@ -57,11 +59,11 @@ estimateEffectSizes <- function(mean,sd,samples,power){
...
@@ -57,11 +59,11 @@ estimateEffectSizes <- function(mean,sd,samples,power){
return
(
longDT
)
# returned the tidied & long form dt
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{estimateProportion
EffectSize
s} 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 mean the estimated mean value to use
#' @param sd the estimated stadnard deviation to use
#' @param sd the estimated stadnard deviation to use
...
@@ -75,7 +77,7 @@ estimateEffectSizes <- function(mean,sd,samples,power){
...
@@ -75,7 +77,7 @@ estimateEffectSizes <- function(mean,sd,samples,power){
#' @import pwr
#' @import pwr
#' @family Power functions
#' @family Power functions
estimateEffectSizes
<-
function
(
mean
,
sd
,
samples
,
power
){
estimate
Proportion
EffectSizes
<-
function
(
samples
,
power
){
# obtain effect sizes using supplied mean & sd
# obtain effect sizes using supplied mean & sd
sigs
<-
c
(
0.01
,
0.05
,
0.1
,
0.2
)
# force these, can always remove later
sigs
<-
c
(
0.01
,
0.05
,
0.1
,
0.2
)
# force these, can always remove later
nSigs
<-
length
(
sigs
)
nSigs
<-
length
(
sigs
)
...
@@ -88,15 +90,13 @@ estimateEffectSizes <- function(mean,sd,samples,power){
...
@@ -88,15 +90,13 @@ estimateEffectSizes <- function(mean,sd,samples,power){
for
(
p
in
1
:
nSigs
){
for
(
p
in
1
:
nSigs
){
for
(
s
in
1
:
nSamps
){
# loop over the sample sizes
for
(
s
in
1
:
nSamps
){
# loop over the sample sizes
# pwr.t.test?
# pwr.t.test?
result
<-
p
ower.t
.test
(
result
<-
p
wr
::
pwr.2p
.test
(
n
=
samples
[
s
],
n
=
samples
[
s
],
delta
=
NULL
,
h
=
NULL
,
sd
=
sd
,
sig.level
=
sigs
[
p
],
sig.level
=
sigs
[
p
],
power
=
power
,
power
=
power
alternative
=
c
(
"one.sided"
)
)
)
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
dt
<-
data.table
::
as.data.table
(
resultsArray
)
# convert to dt for tidying
...
...
This diff is collapsed.
Click to expand it.
man/estimateEffectSizes.Rd
→
man/estimate
Mean
EffectSizes.Rd
+
30
−
0
View file @
868dd35b
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/power.R
% Please edit documentation in R/power.R
\name{estimateEffectSizes}
\name{estimate
Mean
EffectSizes}
\alias{estimateEffectSizes}
\alias{estimate
Mean
EffectSizes}
\title{Estimate detectable effect sizes using statistical power analysis}
\title{Estimate detectable
mean
effect sizes using statistical power analysis}
\usage{
\usage{
estimateEffectSizes(mean, sd, samples, power)
estimateMeanEffectSizes(mean, sd, samples, power)
estimateEffectSizes(mean, sd, samples, power)
}
}
\arguments{
\arguments{
\item{mean}{the estimated mean value to use}
\item{mean}{the estimated mean value to use}
...
@@ -15,29 +13,18 @@ estimateEffectSizes(mean, sd, samples, power)
...
@@ -15,29 +13,18 @@ estimateEffectSizes(mean, sd, samples, power)
\item{samples}{a list of sample sizes to iterate over}
\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}
\item{power}{power value to use}
}
}
\description{
\description{
\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.
\code{estimateProportions} calculates required sample sizes for a given set of p values and samples.
}
}
\details{
\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.
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{
\author{
Ben Anderson, \email{b.anderson@soton.ac.uk}
Ben Anderson, \email{b.anderson@soton.ac.uk}
Ben Anderson, \email{b.anderson@soton.ac.uk}
}
}
\concept{Power functions}
\concept{Power functions}
This diff is collapsed.
Click to expand it.
man/estimateProportionEffectSizes.Rd
0 → 100644
+
30
−
0
View file @
868dd35b
% 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}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment