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
2d9a2b05
Commit
2d9a2b05
authored
6 years ago
by
Ben Anderson
Browse files
Options
Downloads
Patches
Plain Diff
updated proportions code
parent
84f5582f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/power.R
+6
-10
6 additions, 10 deletions
R/power.R
with
6 additions
and
10 deletions
R/power.R
+
6
−
10
View file @
2d9a2b05
...
@@ -65,8 +65,8 @@ estimateMeanEffectSizes <- function(mean,sd,samples,power){
...
@@ -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.
#' 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
p1
the estimated
proportion in sample 1
#' @param sd the estimated
stadnard deviation to use
#' @param sd the estimated
proportion in sample 2
#' @param samples a list of sample sizes to iterate over
#' @param samples a list of sample sizes to iterate over
#' @param power power value to use
#' @param power power value to use
#'
#'
...
@@ -77,27 +77,23 @@ estimateMeanEffectSizes <- function(mean,sd,samples,power){
...
@@ -77,27 +77,23 @@ estimateMeanEffectSizes <- function(mean,sd,samples,power){
#' @import pwr
#' @import pwr
#' @family Power functions
#' @family Power functions
estimateProportion
Effect
Sizes
<-
function
(
samples
,
power
){
estimateProportion
Sample
Sizes
<-
function
(
p1
,
p2
,
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
)
nSamps
<-
length
(
samples
)
# initialise power results array
# initialise power results array
resultsArray
<-
array
(
numeric
(
nSamps
*
nSigs
),
resultsArray
<-
array
(
numeric
(
nSamps
*
nSigs
),
dim
=
c
(
nSamps
,
nSigs
)
dim
=
c
(
nSamps
,
nSigs
)
)
)
# 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
# pwr.t.test?
result
<-
pwr
::
pwr.2p.test
(
result
<-
pwr
::
pwr.2p.test
(
n
=
samples
[
s
]
,
h
=
ES.h
(
p1
=
p1
,
p2
=
p2
)
,
h
=
NULL
,
n
=
NULL
,
sig.level
=
sigs
[
p
],
sig.level
=
sigs
[
p
],
power
=
power
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
<-
data.table
::
as.data.table
(
resultsArray
)
# convert to dt for tidying
dt
<-
dt
[,
dt
<-
dt
[,
...
...
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