简体   繁体   English

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

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

I have a dataset similar to the following:我有一个类似于以下的数据集:
在此处输入图片说明

237 participants all completed 4 experimental conditions which are described by the two levels of the variables A, B (YesxLow, Yes x High, No x Low, No x High). 237 名参与者全部​​完成了 4 个实验条件,这些条件由变量 A、B 的两个水平(YesxLow、Yes x High、No x Low、No x High)描述。

I am trying to conduct a repeated measures ANOVA, to identify the differences in the score means in the 4 different groups, A x B in R using the following function:我正在尝试进行重复测量方差分析,以使用以下函数识别 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)

But I keep getting the following error:但我不断收到以下错误:

Error: Must subset columns with a valid subscript vector.错误:必须使用有效的下标向量对列进行子集化。 x Can't convert from to due to loss of precision. x 由于精度损失,无法从 to 转换。

Debug info:调试信息:

> 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(...)

I have tried to turn the factors into numeric variables but I still get the same error.我试图将这些因素转换为数字变量,但我仍然遇到相同的错误。 Any idea what might be wrong?知道可能有什么问题吗?

The following seems to resolve the issue:以下似乎解决了这个问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM