R 中的重复测量方差分析:必须使用有效的下标向量对列进行子集化

Repeated Measures ANOVA in R : Must subset columns with a valid subscript vector

我有一个类似于以下的数据集:

237 名参与者全部​​完成了 4 个实验条件,这些条件由变量 A、B 的两个水平(是 x 低、是 x 高、否 x 低、否 x 高)描述。

我正在尝试进行重复测量方差分析,以确定 4 个不同组中得分均值的差异,R 中的 A x B 使用以下函数:

res.aov <- anova_test(
  data = my.data, dv = my.data$Score, wid = my.data$id,
  within = c(my.data$A, my.data$B)
)
get_anova_table(res.aov)

但我不断收到以下错误:

Error: Must subset columns with a valid subscript vector. x Can't convert from to due to loss of precision.

调试信息:

> x
+-<error/vctrs_error_subscript_type>
| Must subset columns with a valid subscript vector.
| x Can't convert from <double> to <integer> due to loss of precision.
\-<error/vctrs_error_cast_lossy>
  Can't convert from <double> to <integer> due to loss of precision.
Backtrace:
     x
  1. +-rstatix::anova_test(...)
  2. | \-`%>%`(...)
  3. |   +-base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
  4. |   \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
  5. |     \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
  6. |       \-rstatix:::`_fseq`(`_lhs`)
  7. |         \-magrittr::freduce(value, `_function_list`)
  8. |           \-function_list[[i]](value)
  9. |             \-rstatix:::select_quo_variables(., data)
 10. |               \-rstatix:::get_quo_vars_list(data, .enquos)
 11. |                 \-.enquos %>% map(~get_quo_vars(data, .))
 12. |                   +-base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
 13. |                   \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
 14. |                     \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
 15. |                       \-rstatix:::`_fseq`(`_lhs`)
 16. |                         \-magrittr::freduce(value, `_function_list`)
 17. |                           +-base::withVisible(function_list[[k]](value))
 18. |                           \-function_list[[k]](value)
 19. |                             \-purrr::map(., ~get_quo_vars(data, .))
 20. |                               \-rstatix:::.f(.x[[i]], ...)
 21. |                                 \-rstatix:::get_quo_vars(data, .)
 22. |                                   \-names(data) %>% tidyselect::vars_select(!!vars) %>% magrittr::set_names(NULL)
 23. |                                     +-base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
 24. |                                     \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
 25. |                                       \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
 26. |                                         \-rstatix:::`_fseq`(`_lhs`)
 27. |                                           \-magrittr::freduce(value, `_function_list`)
 28. |                                             \-function_list[[i]](value)
 29. |                                               \-tidyselect::vars_select(., !!vars)
 30. |                                                 \-tidyselect:::eval_select_impl(...)
 31. |                                                   +-tidyselect:::with_subscript_errors(...)
 32. |                                                   | +-base::tryCatch(...)
 33. |                                                   | | \-base:::tryCatchList(expr, classes, parentenv, handlers)
 34. |                                                   | |   \-base:::tryCatchOne(expr, names, parentenv, handlers[[1L]])
 35. |                                                   | |     \-base:::doTryCatch(return(expr), name, parentenv, handler)
 36. |                                                   | \-tidyselect:::instrument_base_errors(expr)
 37. |                                                   |   \-base::withCallingHandlers(...)
 38. |                                                   \-tidyselect:::vars_select_eval(...)
 39. |                                                     \-tidyselect:::walk_data_tree(expr, data_mask, context_mask)
 40. |                                                       \-tidyselect:::eval_c(expr, data_mask, context_mask)
 41. |                                                         \-tidyselect:::reduce_sels(node, data_mask, context_mask, init = init)
 42. |                                                           \-tidyselect:::walk_data_tree(new, data_mask, context_mask)
 43. |                                                             \-tidyselect:::as_indices_sel_impl(...)
 44. |                                                               \-tidyselect:::as_indices_impl(x, vars, strict = strict)
 45. |                                                                 \-vctrs::vec_as_subscript(x, logical = "error")
 46. \-vctrs:::try_catch_impl(...)
 47.   +-base::tryCatch(try_catch_callback(data, NULL), ...)
 48.   | \-base:::tryCatchList(expr, classes, parentenv, handlers)
 49.   |   \-base:::tryCatchOne(expr, names, parentenv, handlers[[1L]])
 50.   |     \-base:::doTryCatch(return(expr), name, parentenv, handler)
 51.   \-vctrs:::try_catch_callback(data, NULL)
 52.     \-(function () ...
 53.       \-vctrs:::vec_cast.integer.double(...)
 54.         \-vctrs::maybe_lossy_cast(out, x, to, lossy, x_arg = x_arg, to_arg = to_arg)
 55.           +-base::withRestarts(...)
 56.           | \-base:::withOneRestart(expr, restarts[[1L]])
 57.           |   \-base:::doWithOneRestart(return(expr), restart)
 58.           \-vctrs:::stop_lossy_cast(...)
 59.             \-vctrs:::stop_vctrs(...)

我已经尝试将因子转换为数值变量,但我仍然遇到同样的错误。 知道哪里出了问题吗?

以下似乎可以解决问题:

    res.aov <- anova_test(
  data = my.data, dv = Score, wid = id,
  within = c(A,B)
   )
  get_anova_table(res.aov)