Last active
February 22, 2022 16:04
-
-
Save debruine/a7d8d4c4b73d33613ff54c66efc8b8ef to your computer and use it in GitHub Desktop.
Find r given inferential stat and descriptives for a within-subject design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(faux) | |
library(afex) | |
f <- function(r, reported) { | |
# simulate data for 3-level within design (change for your design) | |
dat <- faux::sim_design( | |
# you can add these parameters to f() arguments | |
# if you need to check varying analyses | |
n = 100, within = 3, | |
mu = c(100, 105, 110), | |
sd = c(10, 11, 12), | |
r = r, # assume all r are the same | |
empirical = TRUE, # paramaters describe sample, not population | |
long = TRUE, # table format for analysis | |
plot = FALSE | |
) | |
# analyse data (change for your design/analysis) | |
a <- afex::aov_ez( | |
# generic column names from faux; | |
# change if you customise the simulation code | |
id = "id", | |
dv = "y", | |
within = "W1", | |
data = dat) | |
# get the relevant statistic | |
stat <- a$anova_table$F | |
# compare it to the reported stat | |
abs(reported - stat) | |
} | |
# search over a plausible range for the reported stat | |
op <- optimise(f, | |
interval = c(-.99, .99), | |
reported = 30.6) | |
r <- op$minimum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment