5

I've recently made the switch from SPSS to R for some of my data analysis. As part of this I was running some already-made analyses in R that were previously in SPSS, just to have a nice tidy script that makes sense.

My data in this case the self-ratings on feelings of Hostility of 9 participants in an isolated and confined setting. I tested them five times (Summer, Autumn, Winter, Spring, Summer again). The data is non-normally distributed.

I ran the Friedman test in SPSS which gave me p=.012, χ2(4df)=12.79 ages ago. I re-ran the test in R today and it gave me this: p=.951 (χ2(4df)=.69). This really freaks me out because it gives me reason to doubt all of my analyses so far.

Once I discovered this I re-exported the SPSS file into .csv, opened it with my R script and re-ran the Friedman test. To check that I wasn't accidentally using different data files. Definitely not the case.

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 which result is correct?

  • I'm voting to close this question as off-topic because it is about R results without a reproducible example. – gung - Reinstate Monica Mar 23 '17 at 15:12
  • I'll happily produce a reproducible example but how do I do that on here? –  Mar 23 '17 at 15:19
  • 1
    I apologise for my rookieness. Here is the reproducible example. It gives me the values as described above (p=.951 (χ2(4df)=.69)) in RStudio Version 1.0.136. `code` 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) I based this on Andy Field's description of how to run a Friedman test. –  Mar 23 '17 at 16:14
  • There's no need to apologize, you just need to provide that kind of information *in the body of your question*, so that people can figure out what happened. I added it to your question for you. Why not register your account (you can find information on how to do this in the **My Account** section of our [help]), & take our [tour], which has information for new users. – gung - Reinstate Monica Mar 23 '17 at 18:16

2 Answers2

4

Always a good idea to check that your matrix actually looks like what you think it should:

> 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 with byrow=TRUE. When constructed correctly, the Friedman test agrees 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
nth
  • 1,442
  • 15
  • 12
3

This is a mistake in your R code. You read the data into your matrix by rows, rather than by columns. In the matrix() function call, just change the byrow argument to FALSE. Consider:

...
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
gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79