Friedman test in R gives different SPSS results

I recently switched from SPSS to R for some data analysis. As part of this, I have already done some of the already done analyzes in R that were previously in SPSS, just to have a good script order, which makes sense.

My data in this case is self-esteem on the feelings of hostility of 9 participants in an isolated and closed environment. I checked them five times (Summer, Autumn, Winter, Spring, Summer again). Data is not disseminated.

I conducted the Friedman test at SPSS, which gave me p=.012, χ2(4df)=12.79many years ago. I reran the test in R today, and he gave it to me: p=.951 (χ2(4df)=.69). It really torments me, because it gives me reason to doubt all my analyzes.

Once I discovered this, I re-exported the SPSS file to .csv, opened it with an R script, and ran the Friedman test again. To verify that I did not accidentally use different data files. Definitely not so.

I used the Friedman test as described by Andy Field:

Summer1   <- c(2,0,0,0,0,0,0,0,0)  
Autumn    <- c(3,0,1,0,0,4,2,0,1)  
Winter    <- c(1,0,0,0,0,2,5,1,1) 
Spring    <- c(1,0,2,2,2,8,4,0,1)  
Summer2   <- c(3,0,2,1,0,4,7,1,1) 
Hostility <- matrix(c(Summer1, Autumn, Winter, Spring, Summer2), nrow=9, byrow=TRUE) 
friedman.test(Hostility)

Does anyone have an explanation for this, or an idea whose result is correct?

+4
source share
2 answers

It is always a good idea to check that your matrix really looks the way you think:

> Hostility
       [,1] [,2] [,3] [,4] [,5]
  [1,]    2    0    0    0    0
  [2,]    0    0    0    0    3
  [3,]    0    1    0    0    4
  [4,]    2    0    1    1    0
  [5,]    0    0    0    2    5
  [6,]    1    1    1    0    2
  [7,]    2    2    8    4    0
  [8,]    1    3    0    2    1
  [9,]    0    4    7    1    1

The problem is byrow=TRUE. With proper construction, the Friedman test is consistent with SPSS:

> Hostility <- matrix(c(Summer1, Autumn, Winter, Spring, Summer2), nrow=length(Summer1))
> friedman.test(Hostility)

    Friedman rank sum test

data:  Hostility
Friedman chi-squared = 12.794, df = 4, p-value = 0.01233
+4
source

R. , . matrix() byrow FALSE. :

...
Hostility <- matrix(c(Summer1, Autumn, Winter, Spring, Summer2), nrow=9, byrow=TRUE) 
Hostility
#       [,1] [,2] [,3] [,4] [,5]
#  [1,]    2    0    0    0    0
#  [2,]    0    0    0    0    3
#  [3,]    0    1    0    0    4
#  [4,]    2    0    1    1    0
#  [5,]    0    0    0    2    5
#  [6,]    1    1    1    0    2
#  [7,]    2    2    8    4    0
#  [8,]    1    3    0    2    1
#  [9,]    0    4    7    1    1

Hostility2 <- matrix(c(Summer1, Autumn, Winter, Spring, Summer2), nrow=9, byrow=FALSE) 
Hostility2
#       [,1] [,2] [,3] [,4] [,5]
#  [1,]    2    3    1    1    3
#  [2,]    0    0    0    0    0
#  [3,]    0    1    0    2    2
#  [4,]    0    0    0    2    1
#  [5,]    0    0    0    2    0
#  [6,]    0    4    2    8    4
#  [7,]    0    2    5    4    7
#  [8,]    0    0    1    0    1
#  [9,]    0    1    1    1    1
friedman.test(Hostility2)
#   Friedman rank sum test
# 
# data:  Hostility2
# Friedman chi-squared = 12.794, df = 4, p-value = 0.01233
+3

Source: https://habr.com/ru/post/1673018/


All Articles