library(tidyr)
typical = c(5, 1, 58, 29, 43, 87, 3, 18, 62, 4, 24)
uniformMutation = c(28, 16, 92, 72, 82, 100, 13, 25, 79, 10, 28)
sizeNeutral = c(32, 19, 87, 62, 88, 100, 21, 57, 80, 13, 38)
addDelete = c(42, 20, 87, 56, 92, 100, 26, 59, 82, 20, 48)
Note that this code is in the same directory.
(defn convert-pasted-spreadsheet-code-to-r
[success-values]
(str "c("
(apply str (interpose ", " success-values))
")"))
(doseq [x (map convert-pasted-spreadsheet-code-to-r
(list typical uniform-mutation size-neutral add+delete))]
(println x))
Friedman’s test for multiple achievements of multiple subjects.
#results = matrix(c(typical, uniformMutation, sizeNeutral, addDelete), nrow=11, dimnames = list(1:11, c("typical", "uniformMutation", "sizeNeutral", "addDelete")))
results = matrix(c(uniformMutation, sizeNeutral, addDelete), nrow=11, dimnames = list(1:11, c("uniformMutation", "sizeNeutral", "addDelete")))
apply(results, 1, function(x) rank(-x))
## 1 2 3 4 5 6 7 8 9 10 11
## uniformMutation 3 3 1.0 1 3 2 3 3 3 3 3
## sizeNeutral 2 2 2.5 2 2 2 2 2 2 2 2
## addDelete 1 1 2.5 3 1 2 1 1 1 1 1
rowMeans(apply(results, 1, function(x) rank(-x)))
## uniformMutation sizeNeutral addDelete
## 2.545455 2.045455 1.409091
friedman.test(results)
##
## Friedman rank sum test
##
## data: results
## Friedman chi-squared = 8.0513, df = 2, p-value = 0.01785
Make data long:
dfresults = as.data.frame(results)
dfresults$problem <- 1:11
longResults <- gather(dfresults, geneticOperators, successes, uniformMutation, sizeNeutral, addDelete)
Originally published on: http://www.r-statistics.com/2010/02/post-hoc-analysis-for-friedmans-test-r-code/
source("http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt")
friedman.test.with.post.hoc(successes ~ geneticOperators | problem, longResults)
## Loading required package: coin
## Warning: package 'coin' was built under R version 3.4.3
## Loading required package: survival
## Loading required package: multcomp
## Loading required package: mvtnorm
## Warning: package 'mvtnorm' was built under R version 3.4.3
## Loading required package: TH.data
## Loading required package: MASS
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
## Loading required package: colorspace
## $Friedman.Test
##
## Asymptotic General Symmetry Test
##
## data: successes by
## geneticOperators (addDelete, sizeNeutral, uniformMutation)
## stratified by problem
## maxT = 2.8307, p-value = 0.0128
## alternative hypothesis: two.sided
##
##
## $PostHoc.Test
##
## sizeNeutral - addDelete 0.25203033
## uniformMutation - addDelete 0.01286363
## uniformMutation - sizeNeutral 0.42634045
## $Friedman.Test
##
## Asymptotic General Symmetry Test
##
## data: successes by
## geneticOperators (addDelete, sizeNeutral, uniformMutation)
## stratified by problem
## maxT = 2.8307, p-value = 0.01304
## alternative hypothesis: two.sided
##
##
## $PostHoc.Test
##
## sizeNeutral - addDelete 0.25203033
## uniformMutation - addDelete 0.01286363
## uniformMutation - sizeNeutral 0.42634045