Removed R content from simulation slides
This commit is contained in:
parent
2fba884cb7
commit
b1f14df62c
@ -2,6 +2,8 @@
|
||||
title: "Fake It Until You Make It"
|
||||
subtitle: "How and why to simulate research data"
|
||||
author: "Lisa DeBruine"
|
||||
execute:
|
||||
echo: true
|
||||
format:
|
||||
revealjs:
|
||||
logo: images/psyteachr_hex.png
|
||||
@ -12,22 +14,8 @@ format:
|
||||
|
||||
# Abstract
|
||||
|
||||
[debruine.github.io/talks/EMPSEB-fake-it-2023/](https://debruine.github.io/talks/EMPSEB-fake-it-2023/)
|
||||
|
||||
```{r, include = FALSE}
|
||||
library(tidyverse)
|
||||
library(ggdark)
|
||||
library(gt)
|
||||
library(faux)
|
||||
|
||||
knitr::opts_chunk$set(echo = FALSE)
|
||||
|
||||
theme_set(dark_theme_gray(base_size = 17))
|
||||
faux_options(plot = FALSE)
|
||||
```
|
||||
|
||||
::: {style="font-size: 18px;"}
|
||||
Being able to simulate data allows you to prep analysis scripts for pre-registration, calculate power and sensitivity for analyses that don’t have empirical methods, create reproducible examples when your data are too big or confidential to share, enhance your understanding of statistical concepts, and create demo data for teaching and tutorials. This workshop will cover the basics of simulation using the R package {faux}. We will simulate data with factorial designs by specifying the within and between-subjects factor structure, each cell mean and standard deviation, and correlations between cells where appropriate. This can be used to create simulated data sets to be used in preparing the analysis code for pre-registrations or registered reports. We will also create data sets for simulation-based power analyses.
|
||||
::: {style="font-size: 24px;"}
|
||||
Being able to simulate data allows you to prep analysis scripts for pre-registration, calculate power and sensitivity for analyses that don’t have empirical methods, create reproducible examples when your data are too big or confidential to share, enhance your understanding of statistical concepts, and create demo data for teaching and tutorials. This workshop will cover the basics of simulation. We will simulate data with factorial designs by specifying the within and between-subjects factor structure, each cell mean and standard deviation, and correlations between cells where appropriate. This can be used to create simulated data sets to be used in preparing the analysis code for pre-registrations or registered reports. We will also create data sets for simulation-based power analyses.
|
||||
:::
|
||||
|
||||
# Why Simulate Data?
|
||||
@ -58,149 +46,23 @@ Being able to simulate data allows you to prep analysis scripts for pre-registra
|
||||
|
||||
# Faux
|
||||
|
||||
::: {#fauxapp .panel-tabset}
|
||||
[](https://rstudio-connect.psy.gla.ac.uk/faux/)
|
||||
|
||||
### Plot
|
||||
Web App: [rstudio-connect.psy.gla.ac.uk/faux/](https://rstudio-connect.psy.gla.ac.uk/faux/)
|
||||
|
||||
[](https://shiny.psy.gla.ac.uk/debruine/fauxapp/)
|
||||
## Plot
|
||||
|
||||
### Data
|
||||

|
||||
|
||||
[](https://shiny.psy.gla.ac.uk/debruine/fauxapp/)
|
||||
## Data
|
||||
|
||||
### Code
|
||||

|
||||
|
||||
[](https://shiny.psy.gla.ac.uk/debruine/fauxapp/)
|
||||
## Code
|
||||
|
||||
:::
|
||||
|
||||
## Faux Code
|
||||
|
||||
```{r, echo = TRUE}
|
||||
sim_data <- faux::sim_design(
|
||||
within = list(version = c(V1 = "Version 1", V2 = "Version 2"),
|
||||
condition = c(ctl = "Control", exp = "Experimental")),
|
||||
between = list(age_group = c(young = "Age 20-29", old = "Age 70-79")),
|
||||
n = 30,
|
||||
mu = c(100, 100, 100, 100, 100, 90, 110, 110),
|
||||
sd = 20,
|
||||
r = 0.5,
|
||||
dv = c(score = "Score"),
|
||||
id = c(id = "Subject ID"),
|
||||
vardesc = list(version = "Task Version",
|
||||
condition = "Experiment Condition",
|
||||
age_group = "Age Group"),
|
||||
long = TRUE
|
||||
)
|
||||
```
|
||||
|
||||
## Faux Design Parameters
|
||||
|
||||
```{r}
|
||||
# sim_data[c(1, 31, 61, 91, 121, 151, 181, 211), ] |>
|
||||
get_design(sim_data)$params |>
|
||||
gt() |>
|
||||
gtExtras::gt_theme_dark(table.font.size = px(20)) |>
|
||||
tab_style(style = cell_text(size = px(25)),
|
||||
locations = cells_column_labels(everything()))
|
||||
```
|
||||

|
||||
|
||||
|
||||
## Faux Design Plot
|
||||
|
||||
```{r}
|
||||
sim_data |> get_design() |> plot() +
|
||||
dark_theme_gray(base_size = 17)
|
||||
```
|
||||
|
||||
## Faux Data Plot
|
||||
|
||||
```{r}
|
||||
sim_data |> plot(geoms = c("violin", "pointrangeSE")) +
|
||||
dark_theme_gray(base_size = 17)
|
||||
```
|
||||
|
||||
## Power Simulation: Replicate Data
|
||||
|
||||
```{r, echo = TRUE}
|
||||
sim_data <- faux::sim_design(
|
||||
within = list(version = c(V1 = "Version 1", V2 = "Version 2"),
|
||||
condition = c(ctl = "Control", exp = "Experimental")),
|
||||
between = list(age_group = c(young = "Age 20-29", old = "Age 70-79")),
|
||||
n = 30,
|
||||
mu = c(100, 100, 100, 100, 100, 90, 110, 110),
|
||||
sd = 20,
|
||||
r = 0.5,
|
||||
dv = c(score = "Score"),
|
||||
id = c(id = "Subject ID"),
|
||||
vardesc = list(version = "Task Version",
|
||||
condition = "Experiment Condition",
|
||||
age_group = "Age Group"),
|
||||
long = TRUE,
|
||||
rep = 100
|
||||
)
|
||||
```
|
||||
|
||||
## Power Simulation: Analysis Function
|
||||
|
||||
```{r, echo = TRUE}
|
||||
# setup options to avoid annoying afex message & run faster
|
||||
afex::set_sum_contrasts()
|
||||
afex::afex_options(include_aov = FALSE)
|
||||
|
||||
analysis <- function(data) {
|
||||
a <- afex::aov_ez(
|
||||
id = "id",
|
||||
dv = "score",
|
||||
between = "age_group",
|
||||
within = c("version", "condition"),
|
||||
data = data)
|
||||
|
||||
as_tibble(a$anova_table, rownames = "term") |>
|
||||
rename(p = `Pr(>F)`)
|
||||
}
|
||||
```
|
||||
|
||||
## Power Simulation: Analysis Result
|
||||
|
||||
```{r, echo = TRUE, eval = FALSE}
|
||||
# test on first data set
|
||||
analysis(sim_data$data[[1]])
|
||||
```
|
||||
|
||||
::: {style="font-size: 70%;"}
|
||||
```{r}
|
||||
analysis(sim_data$data[[1]]) |>
|
||||
gt() |>
|
||||
gt::fmt_number(MSE, decimals = 1) |>
|
||||
gt::fmt_number(F, decimals = 2) |>
|
||||
gt::fmt_number(ges:p, decimals = 3) |>
|
||||
gtExtras::gt_theme_dark(table.font.size = px(15)) |>
|
||||
tab_style(style = cell_text(size = px(15)),
|
||||
locations = cells_column_labels(everything()))
|
||||
```
|
||||
:::
|
||||
|
||||
## Power Simulation
|
||||
|
||||
```{r, echo = TRUE}
|
||||
power <- sim_data |>
|
||||
mutate(analysis = purrr::map(data, analysis)) |>
|
||||
select(-data) |>
|
||||
unnest(analysis) |>
|
||||
group_by(term) |>
|
||||
summarise(power = mean(p < .05))
|
||||
```
|
||||
|
||||
::: {style="font-size: 80%;"}
|
||||
```{r}
|
||||
power |>
|
||||
gt() |>
|
||||
gtExtras::gt_theme_dark(table.font.size = px(15)) |>
|
||||
tab_style(style = cell_text(size = px(20)),
|
||||
locations = cells_column_labels(everything()))
|
||||
```
|
||||
:::
|
||||
|
||||
# Further Resources
|
||||
|
||||
@ -213,11 +75,5 @@ power |>
|
||||
:::
|
||||
|
||||
|
||||
# Thank You!
|
||||
|
||||
[debruine.github.io/talks/EMPSEB-fake-it-2023/](https://debruine.github.io/talks/EMPSEB-fake-it-2023/)
|
||||
|
||||
Workshop Materials: [tinyurl.com/data-sim](https://debruine.github.io/data-sim-workshops/)
|
||||
|
||||
Prerequisites: Students will need to have very basic knowledge of R and familiarity with R Markdown, and have installed R and RStudio on their laptop and installed the packages {faux}, {afex}, {broom} and {tidyverse} from CRAN.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user