datchi <- read.delim("/Users/riku/Documents/zxy/all.txt", row.names = 1)

chi_t <- rbind(datchi['atama_ts',], datchi['heiban_ts',],datchi['naka_ts',], datchi['o_ts',])
chi_p <- rbind(datchi['atama_ps',], datchi['heiban_ps',],datchi['naka_ps',], datchi['o_ps',])

chi_atama <- rbind(datchi['atama_ts',], datchi['atama_ps',])
chi_heiban <- rbind(datchi['heiban_ts',], datchi['heiban_ps',])
chi_naka <- rbind(datchi['naka_ts',], datchi['naka_ps',])
chi_o <- rbind(datchi['o_ts',], datchi['o_ps',])



chisq_test(chi_t)
## # A tibble: 1 × 6
##       n statistic        p    df method          p.signif
## * <int>     <dbl>    <dbl> <int> <chr>           <chr>   
## 1   184      24.6 0.000412     6 Chi-square test ***
chisq_test(chi_p)
## # A tibble: 1 × 6
##       n statistic      p    df method          p.signif
## * <int>     <dbl>  <dbl> <int> <chr>           <chr>   
## 1   184      13.8 0.0316     6 Chi-square test *
chisq_test(chi_atama)
## # A tibble: 1 × 6
##       n statistic     p    df method          p.signif
## * <int>     <dbl> <dbl> <int> <chr>           <chr>   
## 1    92      1.18 0.554     2 Chi-square test ns
chisq_test(chi_heiban)
## # A tibble: 1 × 6
##       n statistic     p    df method          p.signif
## * <int>     <dbl> <dbl> <int> <chr>           <chr>   
## 1    92      1.59 0.452     2 Chi-square test ns
chisq_test(chi_naka)
## # A tibble: 1 × 6
##       n statistic     p    df method          p.signif
## * <int>     <dbl> <dbl> <int> <chr>           <chr>   
## 1    92      4.44 0.109     2 Chi-square test ns
chisq_test(chi_o)
## # A tibble: 1 × 6
##       n statistic     p    df method          p.signif
## * <int>     <dbl> <dbl> <int> <chr>           <chr>   
## 1    92      2.77 0.251     2 Chi-square test ns

TS内

chisq <- chisq.test(chi_t)
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  chi_t
## X-squared = 24.559, df = 6, p-value = 0.000412
chisq$observed # Observed counts
##           down nil up
## atama_ts     4  13 29
## heiban_ts    8  26 12
## naka_ts      9  19 18
## o_ts        12  26  8
round(chisq$expected,2) # Expected counts
##           down nil    up
## atama_ts  8.25  21 16.75
## heiban_ts 8.25  21 16.75
## naka_ts   8.25  21 16.75
## o_ts      8.25  21 16.75
chisq$p.value
## [1] 0.0004119929
corrplot(chisq$residuals, is.cor = FALSE, title = "TS")

contrib <- 100*chisq$residuals^2/chisq$statistic
round(contrib, 3)
##            down    nil     up
## atama_ts  8.915 12.409 36.479
## heiban_ts 0.031  4.847  5.485
## naka_ts   0.278  0.776  0.380
## o_ts      6.941  4.847 18.612
corrplot(contrib, is.cor = FALSE, title = "TS")

PS内

chisq <- chisq.test(chi_p)
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  chi_p
## X-squared = 13.83, df = 6, p-value = 0.0316
chisq$observed # Observed counts
##           down nil up
## atama_ps     6  16 24
## heiban_ps   11  20 15
## naka_ps      5  13 28
## o_ps        13  19 14
round(chisq$expected,2) # Expected counts
##           down nil    up
## atama_ps  8.75  17 20.25
## heiban_ps 8.75  17 20.25
## naka_ps   8.75  17 20.25
## o_ps      8.75  17 20.25
chisq$p.value
## [1] 0.03159853
corrplot(chisq$residuals, is.cor = FALSE, title = "PS")

contrib <- 100*chisq$residuals^2/chisq$statistic
round(contrib, 3)
##             down   nil     up
## atama_ps   6.250 0.425  5.021
## heiban_ps  4.184 3.828  9.842
## naka_ps   11.621 6.806 21.447
## o_ps      14.927 1.701 13.948
corrplot(contrib, is.cor = FALSE, title = "PS")

Atama pstsé–“

chisq <- chisq.test(chi_atama)
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  chi_atama
## X-squared = 1.182, df = 2, p-value = 0.5538
chisq$observed # Observed counts
##          down nil up
## atama_ts    4  13 29
## atama_ps    6  16 24
round(chisq$expected,2) # Expected counts
##          down  nil   up
## atama_ts    5 14.5 26.5
## atama_ps    5 14.5 26.5
chisq$p.value
## [1] 0.5537613
corrplot(chisq$residuals, is.cor = FALSE, title = "atama")

contrib <- 100*chisq$residuals^2/chisq$statistic
round(contrib, 3)
##           down    nil     up
## atama_ts 16.92 13.127 19.953
## atama_ps 16.92 13.127 19.953
corrplot(contrib, is.cor = FALSE, title = "atama")

Heiban pstsé–“

chisq <- chisq.test(chi_heiban)
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  chi_heiban
## X-squared = 1.5896, df = 2, p-value = 0.4517
chisq$observed # Observed counts
##           down nil up
## heiban_ts    8  26 12
## heiban_ps   11  20 15
round(chisq$expected,2) # Expected counts
##           down nil   up
## heiban_ts  9.5  23 13.5
## heiban_ps  9.5  23 13.5
chisq$p.value
## [1] 0.4516656
corrplot(chisq$residuals, is.cor = FALSE, title = "heiban")

contrib <- 100*chisq$residuals^2/chisq$statistic
round(contrib, 3)
##             down    nil     up
## heiban_ts 14.899 24.616 10.485
## heiban_ps 14.899 24.616 10.485
corrplot(contrib, is.cor = FALSE, title = "heiban")

Naka pstsé–“

chisq <- chisq.test(chi_naka)
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  chi_naka
## X-squared = 4.4418, df = 2, p-value = 0.1085
chisq$observed # Observed counts
##         down nil up
## naka_ts    9  19 18
## naka_ps    5  13 28
round(chisq$expected,2) # Expected counts
##         down nil up
## naka_ts    7  16 23
## naka_ps    7  16 23
chisq$p.value
## [1] 0.108513
corrplot(chisq$residuals, is.cor = FALSE, title = "naka")

contrib <- 100*chisq$residuals^2/chisq$statistic
round(contrib, 3)
##           down    nil     up
## naka_ts 12.865 12.664 24.471
## naka_ps 12.865 12.664 24.471
corrplot(contrib, is.cor = FALSE, title = "naka")

O pstsé–“

chisq <- chisq.test(chi_o)
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  chi_o
## X-squared = 2.7653, df = 2, p-value = 0.2509
chisq$observed # Observed counts
##      down nil up
## o_ts   12  26  8
## o_ps   13  19 14
round(chisq$expected,2) # Expected counts
##      down  nil up
## o_ts 12.5 22.5 11
## o_ps 12.5 22.5 11
chisq$p.value
## [1] 0.2509187
corrplot(chisq$residuals, is.cor = FALSE, title = "o")

contrib <- 100*chisq$residuals^2/chisq$statistic
round(contrib, 3)
##       down    nil     up
## o_ts 0.723 19.689 29.588
## o_ps 0.723 19.689 29.588
corrplot(contrib, is.cor = FALSE, title = "o")