Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
power-calculation-r
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Boulakis Paradeisios Alexandros
power-calculation-r
Commits
dcfd5ca2
Commit
dcfd5ca2
authored
6 months ago
by
Boulakis Paradeisios Alexandros
Browse files
Options
Downloads
Patches
Plain Diff
eff plotter
parent
9f8b8727
No related branches found
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
plot_eff_against_power.R
+64
-0
64 additions, 0 deletions
plot_eff_against_power.R
with
64 additions
and
0 deletions
plot_eff_against_power.R
0 → 100644
+
64
−
0
View file @
dcfd5ca2
library
(
ggplot2
)
# specify how many simulations you want to run
nSimul
<-
10000
# specify how many effects size you want to test
effects
<-
seq
(
.1
,
.9
,
.2
)
# specify how many sample sizes you want to test
samples
<-
seq
(
10
,
150
,
10
)
# Storage for plotting
results
<-
list
()
# Simulation loop
for
(
effect
in
effects
)
{
sample.storage
<-
numeric
(
length
(
samples
))
for
(
ii
in
seq_along
(
samples
))
{
p.storage
<-
numeric
(
nSimul
)
for
(
simulation
in
seq
(
nSimul
))
{
# run statistical test
x
<-
rnorm
(
n
=
samples
[
ii
],
mean
=
0
,
sd
=
1
)
y
<-
rnorm
(
n
=
samples
[
ii
],
mean
=
effect
,
sd
=
1
)
#extract significance
z
<-
t.test
(
x
,
y
)
p.storage
[
simulation
]
<-
z
$
p.value
}
achieved.power
<-
mean
(
p.storage
<
0.05
)
sample.storage
[
ii
]
<-
achieved.power
}
# Store results for the current effect size
results
[[
paste0
(
"effect_"
,
effect
)]]
<-
data.frame
(
sample_size
=
samples
,
achieved_power
=
sample.storage
)
}
# Combine results into a single data frame for plotting
plot_data
<-
do.call
(
rbind
,
lapply
(
names
(
results
),
function
(
effect
)
{
data
<-
results
[[
effect
]]
data
$
effect
<-
effect
data
}))
# Convert effect to numeric for better plotting
plot_data
$
effect
<-
as.numeric
(
gsub
(
"effect_"
,
""
,
plot_data
$
effect
))
# Create the plot
ggplot
(
plot_data
,
aes
(
x
=
sample_size
,
y
=
achieved_power
,
color
=
factor
(
effect
)))
+
geom_line
(
linewidth
=
1
)
+
labs
(
title
=
"Achieved Power vs. Sample Size"
,
x
=
"Sample Size"
,
y
=
"Achieved Power"
,
color
=
"Effect Size"
)
+
theme_minimal
()
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