簡體   English   中英

R - 如何正確運行 psych 包中的 testRetest 命令?

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

我有什么應該是一個非常簡單的問題,但我無法弄清楚發生了什么。 我想使用psych包計算在時間 1 time1time2測量的變量的測試重測可靠性。 該命令告訴我找不到對象“值”。 我不知道這是什么意思。 任何幫助,將不勝感激。

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")

似乎psych中的testRetest()不太適合查看單個項目; 它面向形成規模的多個項目(如果您查看文檔,返回值 - 除了 r12 - 不適用於單個項目)。

如果您正在尋找簡單的重測可靠性,那么使用:

cor(df$time1, df$time2)

如果您正在使用testRetest()查看多個項目,您可能還需要pivot_longer()您的數據(即有一個指定測量時間點的“時間”列):

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

您的數據現在將如下所示:

# 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

如果我們對此運行testRetest() ,它將不起作用(注意我們需要將df2強制轉換回數據幀,因為它不喜歡從dplyr生成的dplyr ):

testRetest(as.data.frame(df2), select = "item1")

# Error: grouping factors must have > 1 sampled level

但是如果我們添加另一個項目(帶有隨機數據), testRetest()將起作用:

df2 <- df2 %>% 
  mutate(item2 = sample(0:100, n(), replace = TRUE))

testRetest(as.data.frame(df2), select = c("item1", "item2"))

結果:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM