0

I have a difficulty in finding a working code example for creating a Spearman-Brown coefficient. I need to do it for a sum variable with two items.

I have tried this and others without success. How would you do it?

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

Data

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")))
Gato
  • 389
  • 2
  • 12
  • 1
    It looks doable to write your own function that will do this based on the formula for it available online! Where's your current `spearman_brown` function coming from? – Dubukay Nov 16 '22 at 17:31
  • Yes, I just hoped there is an easier way. That ```spearman_brown``` comes from the package ```splithalfr``` – Gato Nov 16 '22 at 17:39
  • What does "without success" mean? Your data has missing values and the function you are using does not have an `SB_only=` argument. Try `df2 <- df[complete.cases(df),]` followed by `splithalfr::spearman_brown(df2$var1, df2$var2)`. – dcarlson Nov 16 '22 at 18:55
  • With this ```spearman_brown(df, var1, var2, SB_only = FALSE)``` R doesn't recognise the variables. With this ```spearman_brown(Data$cognitiveload1, Data$cognitiveload2, SB_only = FALSE)``` I get the error ```unused argument (SB_only = FALSE)```. I can't use ```complete.cases``` because it erases all the data I have, there is no complete cases apparently – Gato Nov 17 '22 at 11:28
  • What do you mean by "the function you are using does not have an ```SB_only=``` argument"? – Gato Nov 17 '22 at 11:30

1 Answers1

0

SB_only looks like an required variable from spearman_brown at https://github.com/LukasWallrich/rNuggets/blob/0a15ae9c9fc163687eb9f0ad25f899ee370eb4d6/R/make_scales.R

So, you're probably referring to the rNuggets package but not the splithalfr package...the below should work.

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)
TakTsun
  • 1
  • 1