forked from hcp4715/R4Psy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter_5_task.Rmd
42 lines (41 loc) · 1.27 KB
/
chapter_5_task.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
---
title: "chapter_5_homework"
author: "yuki"
date: "2023-03-20"
output: html_document
---
```{r Read Match Task RawData}
# 读取原始数据
df.mt.raw <- read.csv('./data/match/match_raw.csv',
header = T, sep=",", stringsAsFactors = FALSE)
```
```{r}
df.mt.clean <- df.mt.raw %>%
dplyr::select(Sub, Block, Bin, # block and bin
Shape, Match, # 自变量
ACC, RT, # 反应结果
) %>%
tidyr::drop_na() %>% #删除缺失值
dplyr::group_by(Sub, Block, Bin, Shape) %>%
dplyr::summarise(
hit = length(ACC[Match == "match" & ACC == 1]),
fa = length(ACC[Match == "mismatch" & ACC == 0]),
miss = length(ACC[Match == "match" & ACC == 0]),
cr = length(ACC[Match == "mismatch" & ACC == 1]),
Dprime = qnorm(
ifelse(hit / (hit + miss) < 1,
hit / (hit + miss),
1 - 1 / (2 * (hit + miss))
)
) - qnorm(
ifelse(fa / (fa + cr) > 0,
fa / (fa + cr),
1 / (2 * (fa + cr))
)
)) %>%
dplyr::ungroup() %>%
select(-"hit",-"fa",-"miss",-"cr") %>%
dplyr::group_by(Sub, Shape) %>%
tidyr::pivot_wider(names_from = Shape,
values_from = Dprime)
```