# パッケージ読み込み
library(plyr)
library(ggplot2)
library(reshape2)
library(knitr)

概要

実験概要

  • 縦縞と横縞を左右に提示
  • 課題は2種類(ブロックデザイン)
    • 「重さ」判断 vs. 「横幅」判断
  • 恒常法
    • 縦縞は正方形で固定。
    • 横縞は幅92%から108%まで7段階
  • 反応は、左右どちらが「重く見えたか」「幅が広く見えたか」

データの読み込みと確認

## データ読み込み
d = ldply(dir("data", "csv$", full.names = TRUE), read.csv)

## データの要約など確認
names(d) # 列名
##  [1] "Task"                 "Run"                  "Standard"             "Border"               "WH"                   "blocks.thisRepN"      "blocks.thisTrialN"    "blocks.thisN"         "blocks.thisIndex"     "trials.thisRepN"      "trials.thisTrialN"    "trials.thisN"         "trials.thisIndex"     "rTask"                "divx1"                "divx2"                "key_resp_answer.keys" "key_resp_answer.rt"   "date"                 "frameRate"            "expName"              "participant"          "X"
# kable(head(d)) # 先頭数行
dim(d) # サイズ
## [1] 6144   23
table(d$participant) # 被験者ごとの行数
## 
##   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24 
## 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256
unique(table(d$participant)) # 全部同じであることを確認
## [1] 256
np = length(table(d$participant)) # 被験者数

被験者数: 24

データについてのメモ書き

  • rTask: 1=大きさ 2=重さ
  • Run: 0なら練習
  • Standard: 縦縞刺激の位置(-1: 左, +1: 右)
  • WH: 横縞の縦横比(マイナスなら縦長、プラスなら横長)
  • key_resp_answer.keys: 反応キー(’f’なら左、’j’なら右)
  • key_resp_answer.rt: 反応時間
  • participant: 被験者ID

下処理

# 必要な行だけ抽出
dat = d
dat = subset(dat, Run == 1 & !is.na(key_resp_answer.rt))
dat = subset(dat, select = c(rTask, Standard, WH, key_resp_answer.keys, key_resp_answer.rt, participant))
# 確認
kable(head(dat))
rTask Standard WH key_resp_answer.keys key_resp_answer.rt participant
16 2 1 0.050 f 1.4382010 1
17 2 -1 0.050 j 1.2867029 1
18 2 1 0.075 f 1.1051371 1
19 2 -1 0.025 j 0.7384689 1
20 2 -1 0.000 f 1.2549250 1
21 2 -1 -0.075 f 1.1885650 1
table(dat$rTask, dat$participant) # 条件ごとの試行数、人数
##    
##       1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24
##   1 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112
##   2 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112 112
unique(table(dat$rTask, dat$participant)) # 全員一緒か?
## [1] 112
dat$resp = ifelse(dat$key_resp_answer.keys=='f', -1, 1) # 反応を数値に
dat$ans = ifelse(dat$Standard == -dat$resp, 1, 0) #反応と横縞刺激の位置が一致してたら1、そうでなければ0
dat$rTask = factor(dat$rTask, labels = c("大きさ", "重さ")) # 課題のラベルづけ

# 確認
kable(head(dat))
rTask Standard WH key_resp_answer.keys key_resp_answer.rt participant resp ans
16 重さ 1 0.050 f 1.4382010 1 -1 1
17 重さ -1 0.050 j 1.2867029 1 1 1
18 重さ 1 0.075 f 1.1051371 1 -1 1
19 重さ -1 0.025 j 0.7384689 1 1 1
20 重さ -1 0.000 f 1.2549250 1 -1 0
21 重さ -1 -0.075 f 1.1885650 1 -1 0

可視化

hist(dat$key_resp_answer.rt, breaks = 100)

dat2 = subset(dat, key_resp_answer.rt < 10)
# 長過ぎる試行の数、割合
c(nrow(dat)-nrow(dat2), (nrow(dat2)-nrow(dat))/nrow(dat))
## [1]  2.0000000000 -0.0003720238

集約

dat.m1 = ddply(dat, .(participant, rTask, WH), summarise, ans = mean(ans))
# 確認
kable(head(dat.m1))
participant rTask WH ans
1 大きさ -0.075 0.1250
1 大きさ -0.050 0.2500
1 大きさ -0.025 0.5625
1 大きさ 0.000 0.3125
1 大きさ 0.025 0.6875
1 大きさ 0.050 0.7500
dim(dat.m1) # 被験者数x2課題x7レベルのはず
## [1] 336   4
np*2*7
## [1] 336

可視化

library(ggplot2)
g  = ggplot(dat.m1, aes(WH, ans, colour = rTask, group = rTask)) +
  stat_summary(fun.data = mean_se) +
  stat_summary(fun.y = mean, geom = "line") +
  theme_bw(base_family = "Osaka") # Windowsの場合はフォントがないかも?
g

g + facet_wrap(~participant)
## Warning: Removed 336 rows containing missing values (geom_pointrange).

統計

source('anovakun_482.txt')
anovakun(dat.m1, "sAB", long = TRUE)
## 
## [ sAB-Type Design ]
## 
## This output was generated by anovakun 4.8.2 under R version 3.5.3.
## It was executed on Wed May 22 17:24:57 2019.
## 
##  
## << DESCRIPTIVE STATISTICS >>
## 
## --------------------------------------
##   rTask      WH   n    Mean    S.D. 
## --------------------------------------
## 大きさ  -0.075  24  0.2057  0.2687 
## 大きさ   -0.05  24  0.2995  0.2989 
## 大きさ  -0.025  24  0.4167  0.3137 
## 大きさ       0  24  0.5260  0.2788 
## 大きさ   0.025  24  0.6510  0.2242 
## 大きさ    0.05  24  0.7292  0.2372 
## 大きさ   0.075  24  0.8411  0.2117 
##  重さ  -0.075  24  0.4323  0.3358 
##  重さ   -0.05  24  0.4818  0.3109 
##  重さ  -0.025  24  0.5286  0.3144 
##  重さ       0  24  0.6276  0.2737 
##  重さ   0.025  24  0.6510  0.2837 
##  重さ    0.05  24  0.6797  0.3058 
##  重さ   0.075  24  0.7656  0.2555 
## --------------------------------------
## 
## 
## << SPHERICITY INDICES >>
## 
## == Mendoza's Multisample Sphericity Test and Epsilons ==
## 
## ----------------------------------------------------------------------------
##     Effect  Lambda  approx.Chi  df      p         LB     GG     HF     CM 
## ----------------------------------------------------------------------------
##     Global  0.0000    323.1748  90 0.0000 *** 0.0769 0.2530 0.3003 0.2938 
##      rTask  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##         WH  0.0000    127.1844  20 0.0000 *** 0.1667 0.2602 0.2758 0.2698 
## rTask x WH  0.0000     54.3881  20 0.0001 *** 0.1667 0.5009 0.5846 0.5719 
## ----------------------------------------------------------------------------
##                                  LB = lower.bound, GG = Greenhouse-Geisser
##                                 HF = Huynh-Feldt-Lecoutre, CM = Chi-Muller
## 
## 
## << ANOVA TABLE >>
## 
## --------------------------------------------------------------
##          Source       SS  df      MS  F-ratio  p-value      
## --------------------------------------------------------------
##               s  12.2186  23  0.5312                        
## --------------------------------------------------------------
##           rTask   0.4241   1  0.4241   1.7283   0.2016 ns   
##       s x rTask   5.6442  23  0.2454                        
## --------------------------------------------------------------
##              WH   8.7869   6  1.4645  38.1422   0.0000 ***  
##          s x WH   5.2985 138  0.0384                        
## --------------------------------------------------------------
##      rTask x WH   0.9627   6  0.1604   9.2234   0.0000 ***  
##  s x rTask x WH   2.4006 138  0.0174                        
## --------------------------------------------------------------
##           Total  35.7357 335  0.1067                        
##                   +p < .10, *p < .05, **p < .01, ***p < .001
## 
## 
## << POST ANALYSES >>
## 
## < MULTIPLE COMPARISON for "WH" >
## 
## == Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
## == The factor < WH > is analysed as dependent means. == 
## == Alpha level is 0.05. == 
##  
## ------------------------------
##      WH   n    Mean    S.D. 
## ------------------------------
##  -0.075  48  0.3190  0.3219 
##   -0.05  48  0.3906  0.3154 
##  -0.025  48  0.4727  0.3158 
##       0  48  0.5768  0.2781 
##   0.025  48  0.6510  0.2529 
##    0.05  48  0.7044  0.2719 
##   0.075  48  0.8034  0.2353 
## ------------------------------
## 
## --------------------------------------------------------------------------
##           Pair     Diff  t-value  df       p   adj.p                    
## --------------------------------------------------------------------------
##   -0.075-0.075  -0.4844   7.9018  23  0.0000  0.0000   -0.075 < 0.075 * 
##    -0.05-0.075  -0.4128   7.1840  23  0.0000  0.0000    -0.05 < 0.075 * 
##   -0.075-0.025  -0.3320   7.1131  23  0.0000  0.0000   -0.075 < 0.025 * 
##       -0.075-0  -0.2578   6.7504  23  0.0000  0.0000       -0.075 < 0 * 
##    -0.075-0.05  -0.3854   6.7345  23  0.0000  0.0000    -0.075 < 0.05 * 
##  -0.075--0.025  -0.1536   6.3994  23  0.0000  0.0000  -0.075 < -0.025 * 
##        0-0.075  -0.2266   6.2344  23  0.0000  0.0000        0 < 0.075 * 
##    -0.05-0.025  -0.2604   6.1144  23  0.0000  0.0000    -0.05 < 0.025 * 
##   -0.025-0.075  -0.3307   5.8873  23  0.0000  0.0001   -0.025 < 0.075 * 
##    0.025-0.075  -0.1523   5.8100  23  0.0000  0.0001    0.025 < 0.075 * 
##     -0.05-0.05  -0.3138   5.7924  23  0.0000  0.0001     -0.05 < 0.05 * 
##        -0.05-0  -0.1862   5.4206  23  0.0000  0.0002        -0.05 < 0 * 
##   -0.05--0.025  -0.0820   5.4169  23  0.0000  0.0002   -0.05 < -0.025 * 
##     0.05-0.075  -0.0990   5.1179  23  0.0000  0.0002     0.05 < 0.075 * 
##   -0.025-0.025  -0.1784   4.5549  23  0.0001  0.0010   -0.025 < 0.025 * 
##    -0.025-0.05  -0.2318   4.5451  23  0.0001  0.0010    -0.025 < 0.05 * 
##         0-0.05  -0.1276   4.1679  23  0.0004  0.0019         0 < 0.05 * 
##   -0.075--0.05  -0.0716   3.6221  23  0.0014  0.0057   -0.075 < -0.05 * 
##        0-0.025  -0.0742   3.5038  23  0.0019  0.0057        0 < 0.025 * 
##       -0.025-0  -0.1042   3.4300  23  0.0023  0.0057       -0.025 < 0 * 
##     0.025-0.05  -0.0534   2.3450  23  0.0280  0.0280     0.025 < 0.05 * 
## --------------------------------------------------------------------------
## 
## 
## < SIMPLE EFFECTS for "rTask x WH" INTERACTION >
## 
## ----------------------------------------------------------------------------------
##           Effect  Lambda  approx.Chi  df      p         LB     GG     HF     CM 
## ----------------------------------------------------------------------------------
##  rTask at -0.075  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##   rTask at -0.05  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##  rTask at -0.025  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##       rTask at 0  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##   rTask at 0.025  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##    rTask at 0.05  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##   rTask at 0.075  1.0000     -0.0000   0            1.0000 1.0000 1.0000 1.0000 
##  WH at 大きさ  0.0000     79.7927  20 0.0000 *** 0.1667 0.3709 0.4125 0.4035 
##     WH at 重さ  0.0000    123.8546  20 0.0000 *** 0.1667 0.2818 0.3018 0.2952 
## ----------------------------------------------------------------------------------
##                                        LB = lower.bound, GG = Greenhouse-Geisser
##                                       HF = Huynh-Feldt-Lecoutre, CM = Chi-Muller
## 
## ------------------------------------------------------------------
##               Source      SS  df      MS  F-ratio  p-value      
## ------------------------------------------------------------------
##      rTask at -0.075  0.6160   1  0.6160  17.1228   0.0004 ***  
##  s x rTask at -0.075  0.8274  23  0.0360                        
## ------------------------------------------------------------------
##       rTask at -0.05  0.3988   1  0.3988   9.3202   0.0056 **   
##   s x rTask at -0.05  0.9840  23  0.0428                        
## ------------------------------------------------------------------
##      rTask at -0.025  0.1505   1  0.1505   2.9733   0.0981 +    
##  s x rTask at -0.025  1.1640  23  0.0506                        
## ------------------------------------------------------------------
##           rTask at 0  0.1238   1  0.1238   2.2233   0.1495 ns   
##       s x rTask at 0  1.2805  23  0.0557                        
## ------------------------------------------------------------------
##       rTask at 0.025  0.0000   1  0.0000   0.0000   1.0000 ns   
##   s x rTask at 0.025  1.1445  23  0.0498                        
## ------------------------------------------------------------------
##        rTask at 0.05  0.0294   1  0.0294   0.4505   0.5088 ns   
##    s x rTask at 0.05  1.4999  23  0.0652                        
## ------------------------------------------------------------------
##       rTask at 0.075  0.0684   1  0.0684   1.3755   0.2529 ns   
##   s x rTask at 0.075  1.1444  23  0.0498                        
## ------------------------------------------------------------------
##      WH at 大きさ  7.7291   6  1.2882  51.0720   0.0000 ***  
##  s x WH at 大きさ  3.4807 138  0.0252                        
## ------------------------------------------------------------------
##         WH at 重さ  2.0205   6  0.3367  11.0162   0.0000 ***  
##     s x WH at 重さ  4.2184 138  0.0306                        
## ------------------------------------------------------------------
##                       +p < .10, *p < .05, **p < .01, ***p < .001
## 
## 
## < MULTIPLE COMPARISON for "WH at 大きさ" >
## 
## == Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
## == The factor < WH at 大きさ > is analysed as dependent means. == 
## == Alpha level is 0.05. == 
##  
## --------------------------------------------------------------------------
##           Pair     Diff  t-value  df       p   adj.p                    
## --------------------------------------------------------------------------
##   -0.075-0.075  -0.6354   9.8729  23  0.0000  0.0000   -0.075 < 0.075 * 
##   -0.075-0.025  -0.4453   9.2910  23  0.0000  0.0000   -0.075 < 0.025 * 
##    -0.075-0.05  -0.5234   8.6154  23  0.0000  0.0000    -0.075 < 0.05 * 
##    -0.05-0.075  -0.5417   8.5487  23  0.0000  0.0000    -0.05 < 0.075 * 
##    -0.05-0.025  -0.3516   7.4154  23  0.0000  0.0000    -0.05 < 0.025 * 
##     -0.05-0.05  -0.4297   7.1342  23  0.0000  0.0000     -0.05 < 0.05 * 
##       -0.075-0  -0.3203   7.0876  23  0.0000  0.0000       -0.075 < 0 * 
##   -0.025-0.075  -0.4245   6.9578  23  0.0000  0.0000   -0.025 < 0.075 * 
##        0-0.075  -0.3151   6.6118  23  0.0000  0.0000        0 < 0.075 * 
##        -0.05-0  -0.2266   5.8271  23  0.0000  0.0001        -0.05 < 0 * 
##    -0.025-0.05  -0.3125   5.7321  23  0.0000  0.0001    -0.025 < 0.05 * 
##   -0.025-0.025  -0.2344   5.5446  23  0.0000  0.0001   -0.025 < 0.025 * 
##  -0.075--0.025  -0.2109   5.5031  23  0.0000  0.0001  -0.075 < -0.025 * 
##     0.05-0.075  -0.1120   5.3478  23  0.0000  0.0001     0.05 < 0.075 * 
##    0.025-0.075  -0.1901   5.2547  23  0.0000  0.0002    0.025 < 0.075 * 
##         0-0.05  -0.2031   4.8245  23  0.0001  0.0004         0 < 0.05 * 
##   -0.05--0.025  -0.1172   4.4359  23  0.0002  0.0009   -0.05 < -0.025 * 
##        0-0.025  -0.1250   4.0899  23  0.0004  0.0018        0 < 0.025 * 
##   -0.075--0.05  -0.0938   3.0674  23  0.0055  0.0164   -0.075 < -0.05 * 
##       -0.025-0  -0.1094   2.9634  23  0.0070  0.0164       -0.025 < 0 * 
##     0.025-0.05  -0.0781   2.6112  23  0.0156  0.0164     0.025 < 0.05 * 
## --------------------------------------------------------------------------
## 
## 
## < MULTIPLE COMPARISON for "WH at 重さ" >
## 
## == Shaffer's Modified Sequentially Rejective Bonferroni Procedure ==
## == The factor < WH at 重さ > is analysed as dependent means. == 
## == Alpha level is 0.05. == 
##  
## --------------------------------------------------------------------------
##           Pair     Diff  t-value  df       p   adj.p                    
## --------------------------------------------------------------------------
##    0.025-0.075  -0.1146   4.7185  23  0.0001  0.0020    0.025 < 0.075 * 
##   -0.075-0.075  -0.3333   4.4828  23  0.0002  0.0025   -0.075 < 0.075 * 
##    -0.05-0.075  -0.2839   4.2180  23  0.0003  0.0049    -0.05 < 0.075 * 
##       -0.075-0  -0.1953   4.0257  23  0.0005  0.0079       -0.075 < 0 * 
##   -0.025-0.075  -0.2370   3.7120  23  0.0011  0.0172   -0.025 < 0.075 * 
##  -0.075--0.025  -0.0964   3.6229  23  0.0014  0.0214  -0.075 < -0.025 * 
##        -0.05-0  -0.1458   3.4308  23  0.0023  0.0342        -0.05 < 0 * 
##   -0.075-0.025  -0.2187   3.4263  23  0.0023  0.0342   -0.075 < 0.025 * 
##        0-0.075  -0.1380   3.4067  23  0.0024  0.0342        0 < 0.075 * 
##    -0.075-0.05  -0.2474   3.3847  23  0.0026  0.0342    -0.075 < 0.05 * 
##     0.05-0.075  -0.0859   3.0306  23  0.0059  0.0654     0.05 = 0.075   
##    -0.05-0.025  -0.1693   2.9832  23  0.0066  0.0665    -0.05 = 0.025   
##     -0.05-0.05  -0.1979   2.8801  23  0.0085  0.0761     -0.05 = 0.05   
##   -0.025-0.025  -0.1224   2.4560  23  0.0220  0.1542   -0.025 = 0.025   
##    -0.025-0.05  -0.1510   2.3661  23  0.0268  0.1874    -0.025 = 0.05   
##       -0.025-0  -0.0990   2.3258  23  0.0292  0.1874       -0.025 = 0   
##   -0.075--0.05  -0.0495   2.1628  23  0.0412  0.2060   -0.075 = -0.05   
##   -0.05--0.025  -0.0469   2.0695  23  0.0499  0.2060   -0.05 = -0.025   
##         0-0.05  -0.0521   1.2253  23  0.2329  0.6986         0 = 0.05   
##     0.025-0.05  -0.0286   0.7939  23  0.4353  0.8707     0.025 = 0.05   
##        0-0.025  -0.0234   0.5892  23  0.5615  0.8707        0 = 0.025   
## --------------------------------------------------------------------------
## 
## output is over --------------------///

結論