R中的Spearman-Brown系数

ss2ws0br  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(147)

我很难找到一个创建斯皮尔曼-布朗系数的工作代码示例。我需要为一个有两项的和变量做这件事。
我试过这个和其他方法都没有成功。你会怎么做?

spearman_brown(df, var1, var2, SB_only = FALSE)

数据

structure(list(var1 = c(5, 2, NA, 2, 3, 1, 6, 1, 4, 5, 5, 2, 
2, 3, 1, 3, 2, NA, 5, 7, 5, 2, 2, 2, NA, 2, NA, 2, 2, 5, 2, 4, 
2, 3, 5, 5, 2, 5, 5, 2, 4, NA, 6, 7, 7, 3), var2 = c(2, 1, NA, 
2, 2, 1, 1, 1, 2, 2, 3, 1, 2, 2, 1, 2, 2, NA, 3, 2, 1, 2, 2, 
1, NA, 1, NA, 1, 1, 2, 1, 1, 2, 2, 2, 4, 2, 3, 2, 2, 1, NA, 2, 
2, 4, 1)), class = c("rowwise_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -46L), groups = structure(list(.rows = structure(list(
    1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
    27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 
    39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L), ptype = integer(0), class = c("vctrs_list_of", 
"vctrs_vctr", "list"))), row.names = c(NA, -46L), class = c("tbl_df", 
"tbl", "data.frame")))
vyswwuz2

vyswwuz21#

SB_only看起来像是https://github.com/LukasWallrich/rNuggets/blob/0a15ae9c9fc163687eb9f0ad25f899ee370eb4d6/R/make_scales.R上斯皮尔曼_brown的必需变量
所以,你可能指的是rNuggets包,而不是splithalfr包...下面的应该可以工作。

df<-structure(list(var1 = c(5, 2, NA, 2, 3, 1, 6, 1, 4, 5, 5, 2, 
    2, 3, 1, 3, 2, NA, 5, 7, 5, 2, 2, 2, NA, 2, NA, 2, 2, 5, 2, 4, 
    2, 3, 5, 5, 2, 5, 5, 2, 4, NA, 6, 7, 7, 3), var2 = c(2, 1, NA, 
    2, 2, 1, 1, 1, 2, 2, 3, 1, 2, 2, 1, 2, 2, NA, 3, 2, 1, 2, 2, 
    1, NA, 1, NA, 1, 1, 2, 1, 1, 2, 2, 2, 4, 2, 3, 2, 2, 1, NA, 2, 
    2, 4, 1)), class = c("rowwise_df", "tbl_df", "tbl", "data.frame"
    ), row.names = c(NA, -46L), groups = structure(list(.rows = structure(list(
    1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
    27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 
    39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = c(NA, -46L), class = c("tbl_df", 
    "tbl", "data.frame")))

spearman_brown(df, c("var1","var2"),name = "", SB_only=FALSE)

相关问题