Hayes, Banner, Forrester & Navarro (2019).
Selective sampling and inductive inference: Drawing inferences based on observed and missing evidence
https://psyarxiv.com/2m83v/
Reading the data into R
library(tidyverse)frames <- read_csv(file = "data_reasoning.csv")
Reading the data into R
library(tidyverse)frames <- read_csv(file = "data_reasoning.csv")
## Parsed with column specification:## cols(## id = col_double(),## gender = col_character(),## age = col_double(),## condition = col_character(),## sample_size = col_character(),## n_obs = col_double(),## test_item = col_double(),## response = col_double()## )
Inspecting the data
print(frames)
## # A tibble: 4,725 x 8## id gender age condition sample_size n_obs test_item## <dbl> <chr> <dbl> <chr> <chr> <dbl> <dbl>## 1 1 male 36 category small 2 1## 2 1 male 36 category small 2 2## 3 1 male 36 category small 2 3## 4 1 male 36 category small 2 4## 5 1 male 36 category small 2 5## 6 1 male 36 category small 2 6## # β¦ with 4,719 more rows, and 1 more variable:## # response <dbl>
Inspecting the data
glimpse(frames)
## Rows: 4,725## Columns: 8## $ id <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, β¦## $ gender <chr> "male", "male", "male", "male", "malβ¦## $ age <dbl> 36, 36, 36, 36, 36, 36, 36, 36, 36, β¦## $ condition <chr> "category", "category", "category", β¦## $ sample_size <chr> "small", "small", "small", "small", β¦## $ n_obs <dbl> 2, 2, 2, 2, 2, 2, 2, 6, 6, 6, 6, 6, β¦## $ test_item <dbl> 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, β¦## $ response <dbl> 8, 7, 6, 6, 5, 6, 3, 9, 7, 5, 6, 4, β¦
The pipe, %>%
The pipe, %>%
frames %>% do_one_thing(.) %>% then_another(.) %>% and_then_one_more(.)
data %>% tidy() %>% describe() %>% visualise() %>% analyse()
The basic idea
frames %>% group_by( GROUP ) %>% summarise( EXPRESSION ) %>% ungroup()
group_by
to define groupssummarise
to... summariseungroup
to remove groupingGroup, summarise...
frames %>% group_by(test_item, sample_size, n_obs, condition) %>% summarise(response = mean(response))
Group, summarise...
frames %>% group_by(test_item, sample_size, n_obs, condition) %>% summarise(response = mean(response))
## # A tibble: 42 x 5## # Groups: test_item, sample_size, n_obs [21]## test_item sample_size n_obs condition response## <dbl> <chr> <dbl> <chr> <dbl>## 1 1 large 12 category 7.60## 2 1 large 12 property 7.16## 3 1 medium 6 category 7.32## 4 1 medium 6 property 6.66## # β¦ with 38 more rows
Group, summarise, and ungroup
frames %>% group_by(test_item, sample_size, n_obs, condition) %>% summarise(response = mean(response)) %>% ungroup()
## # A tibble: 42 x 5## test_item sample_size n_obs condition response## <dbl> <chr> <dbl> <chr> <dbl>## 1 1 large 12 category 7.60## 2 1 large 12 property 7.16## 3 1 medium 6 category 7.32## 4 1 medium 6 property 6.66## # β¦ with 38 more rows
A more realistic example
frames %>% group_by(test_item) %>% summarise( m = mean(response), s = sd(response), n = n() ) %>% ungroup()
A more realistic example
frames %>% group_by(test_item) %>% summarise( m = mean(response), s = sd(response), n = n() ) %>% ungroup()
## # A tibble: 7 x 4## test_item m s n## * <dbl> <dbl> <dbl> <int>## 1 1 6.77 2.56 675## 2 2 6.88 2.10 675## 3 3 5.71 2.41 675## 4 4 4.48 2.68 675## 5 5 3.76 2.81 675## 6 6 3.43 2.99 675## 7 7 3.26 3.11 675
A more realistic example
by_item <- frames %>% group_by(test_item) %>% summarise( m = mean(response), s = sd(response), n = n() ) %>% ungroup()
A more realistic example
ggplot( data = by_item, mapping = aes( x = test_item, y = m )) +geom_point()
A more realistic example
ggplot( data = by_item, mapping = aes( x = test_item, y = m )) +geom_point()
A more realistic example
ggplot( data = by_item, mapping = aes( x = test_item, y = m, ymin = m - s, ymax = m + s )) +geom_pointrange()
If we read with read_csv...
read_csv("data_reasoning.csv")
... then we write with write_csv!
write_csv(by_item, "summary_reasoning_by_item.csv")
Not in this class, but for future reference...
readxl
packagehaven
packagejsonlite
packagedbplyr
package
Want more information?
Data import chapter in R for Data Science
https://r4ds.had.co.nz/data-import.html
Keyboard shortcuts
β, β, Pg Up, k | Go to previous slide |
β, β, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |