Search code examples
rpsych

R - How to correctly run the testRetest command in the psych package?


I have what should be a very simply issue, but I cannot figure what is goign on. I want to calculate the test retest reliabilty of a variable measured at time 1 time1 and time 2 time2 using the psych package. The command is telling me that object 'values' is not found. I have no idea what this means. Any help would be appreciated.

psych::testRetest(t1=df$time1, t2=df$time2)

df <- structure(list(time1 = c(2.11111111111111, 2.05555555555556, 
4.44444444444444, 5.88888888888889, 5.16666666666667, 1.94444444444444, 
4.11111111111111, 2.22222222222222, 1.61111111111111, 1.5, 3.33333333333333, 
2.33333333333333, 3.66666666666667, 1.72222222222222, 4, 1.88888888888889, 
1.66666666666667, 3.33333333333333, 2.38888888888889, 2.77777777777778, 
2.38888888888889, 4.83333333333333, 1.88888888888889, 4, 2.61111111111111, 
4.83333333333333, 1.27777777777778, 1.55555555555556, 1.72222222222222, 
2.33333333333333, 2.16666666666667, 2.94444444444444, 2.11111111111111, 
1.11111111111111, 3.05555555555556, 3.5, 2.05555555555556, 6.16666666666667, 
2.33333333333333, 2.33333333333333, 2.77777777777778, 1.61111111111111, 
4, 1.27777777777778, 1.27777777777778, 3.16666666666667, 5.77777777777778, 
1.88888888888889, 1.94444444444444, 4.66666666666667, 3.5, 4.5, 
4.16666666666667, 3.94444444444444, 3.16666666666667, 2.11111111111111, 
2.44444444444444, 3.55555555555556, 2.94444444444444, 1.33333333333333, 
3.22222222222222, 4.94444444444444, 2.44444444444444, 4.11111111111111, 
2.38888888888889, 2.44444444444444, 3.5, 2.77777777777778, 4.77777777777778, 
3.77777777777778, 2.22222222222222, 2.11111111111111, 3.16666666666667, 
2.61111111111111, 2.16666666666667, 4.61111111111111, 4.83333333333333, 
4.72222222222222, 2.5, 3.44444444444444, 3.77777777777778, 2.22222222222222, 
3.88888888888889, 2.88888888888889, 2.16666666666667, 4.27777777777778, 
2.77777777777778, 3.5, 2.72222222222222, 3.61111111111111, 4.83333333333333, 
2.44444444444444, 4.27777777777778, 3.5, 4.72222222222222, 3.66666666666667, 
3.33333333333333, 3.5, 2.11111111111111, 2.22222222222222, 3.44444444444444, 
1.83333333333333, 1.94444444444444, 3.88888888888889, 4.33333333333333, 
2.83333333333333, 1.05555555555556, 4.61111111111111, 4.16666666666667, 
2.88888888888889, 2.11111111111111, 1.55555555555556, 2.5, 3.16666666666667, 
2.5, 4.05555555555556, 3.55555555555556, 4.83333333333333, 5.05555555555556, 
3.61111111111111, 2.27777777777778, 2.38888888888889, 3.55555555555556, 
1.94444444444444, 2.66666666666667, 4.38888888888889), time2 = c(2.05555555555556, 
2, 4.33333333333333, 5.55555555555556, 4.83333333333333, 1.94444444444444, 
4.33333333333333, 2.16666666666667, 1.44444444444444, 1.61111111111111, 
3.94444444444444, 1.83333333333333, 4.44444444444444, 1.5, 3.61111111111111, 
2.22222222222222, 2.5, 3.38888888888889, 2.55555555555556, 2.77777777777778, 
2.72222222222222, 5.55555555555556, 1.77777777777778, 3.77777777777778, 
2.83333333333333, 5.33333333333333, 1.5, 1.44444444444444, 1.33333333333333, 
2.44444444444444, 1.88888888888889, 3, 2, 1.33333333333333, 3.05555555555556, 
3.33333333333333, 1.94444444444444, 5.72222222222222, 2.38888888888889, 
2.61111111111111, 3.55555555555556, 1.94444444444444, 3.72222222222222, 
1.38888888888889, 1.38888888888889, 2.83333333333333, 5.72222222222222, 
1.83333333333333, 2.05555555555556, 4.5, 3.38888888888889, 4.94444444444444, 
4.27777777777778, 4.38888888888889, 2.44444444444444, 2.16666666666667, 
2.83333333333333, 3.72222222222222, 2.66666666666667, 1.16666666666667, 
2.72222222222222, 5.22222222222222, 2.11111111111111, 4.38888888888889, 
2.38888888888889, 4, 3.83333333333333, 2.22222222222222, 5.16666666666667, 
4.11111111111111, 1.94444444444444, 2.22222222222222, 3.55555555555556, 
2.88888888888889, 2.11111111111111, 4.61111111111111, 4.72222222222222, 
4.61111111111111, 2.16666666666667, 3.61111111111111, 3.66666666666667, 
2.94444444444444, 4.05555555555556, 3.27777777777778, 2.11111111111111, 
4.38888888888889, 2.83333333333333, 2.55555555555556, 3.16666666666667, 
3.33333333333333, 4.77777777777778, 2.55555555555556, 4.38888888888889, 
2.94444444444444, 4.77777777777778, 3.77777777777778, 3.33333333333333, 
3.55555555555556, 1.88888888888889, 2, 3.83333333333333, 2.22222222222222, 
1.38888888888889, 3.33333333333333, 3.27777777777778, 2.83333333333333, 
1.05555555555556, 4.61111111111111, 4.38888888888889, 2.94444444444444, 
1.94444444444444, 1.88888888888889, 2.22222222222222, 3.16666666666667, 
2.11111111111111, 5.5, 4.11111111111111, 4.83333333333333, 4.44444444444444, 
3.88888888888889, 2.05555555555556, 2, 3.44444444444444, 2.16666666666667, 
2.77777777777778, 4.72222222222222)), row.names = c(1L, 2L, 3L, 
4L, 5L, 6L, 8L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 18L, 19L, 
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L, 46L, 47L, 
48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 59L, 60L, 61L, 
63L, 64L, 65L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 86L, 88L, 89L, 90L, 91L, 
93L, 94L, 95L, 96L, 98L, 99L, 100L, 104L, 105L, 106L, 107L, 108L, 
109L, 110L, 111L, 112L, 114L, 116L, 117L, 118L, 119L, 120L, 121L, 
122L, 123L, 125L, 127L, 128L, 130L, 132L, 133L, 134L, 139L, 141L, 
144L, 146L, 147L, 149L, 150L, 154L, 156L, 157L, 158L, 163L, 167L
), class = "data.frame")

Solution

  • It seems that testRetest() in psych isn't well-suited for looking at single items; it's geared towards multiple items which form a scale (if you look at the documentation, the return values - apart from r12 - don't work for a single item).

    If you're looking for a simple test-retest reliability, how about just using:

    cor(df$time1, df$time2)
    

    If you're looking at multiple items using testRetest(), you may also want to pivot_longer() your data (i.e. have a 'time' column which specifies the time point of the measurement):

    df2 <- df %>% 
      mutate(id = row_number()) %>% 
      pivot_longer(time1:time2, names_prefix = "time", names_to = "time", values_to = "item1")
    

    Your data will now look like this:

    # A tibble: 6 x 3
         id time  item1
      <int> <chr> <dbl>
    1     1 1      2.11
    2     1 2      2.06
    3     2 1      2.06
    4     2 2      2   
    5     3 1      4.44
    6     3 2      4.33
    

    If we run testRetest() on this, it won't work (noting that we need to coerce df2 back to a dataframe, as it doesn't like tibbles produced from dplyr):

    testRetest(as.data.frame(df2), select = "item1")
    
    # Error: grouping factors must have > 1 sampled level
    

    But if we add another item (with random data), testRetest() will work:

    df2 <- df2 %>% 
      mutate(item2 = sample(0:100, n(), replace = TRUE))
    
    testRetest(as.data.frame(df2), select = c("item1", "item2"))
    
    

    Results:

    Test Retest reliability 
    Call: testRetest(t1 = as.data.frame(df2), select = c("item1", 
    "item2"))
    
    Number of subjects =  126  Number of items =  2
     Correlation of scale scores over time -0.11
     Alpha reliability statistics for time 1 and time 2 
           raw G3 std G3   G6 av.r  S/N   se lower upper var.r
    Time 1   0.01   0.06 0.03 0.03 0.07 0.03  0.07     1     0
    Time 2   0.01   0.11 0.06 0.06 0.12 0.03  0.11     1     0