首页 > 解决方案 > svyglm 和交互包在 R4.0.2 而不是 R3.6.3 中显示错误

问题描述

我有一个 syvglm 代码,可以在 R3.6.3 中使用,但在 R4.0.2 中不能使用(它会给出以下错误消息:

对于 svylgm:

错误:必须使用有效的下标向量子集元素。x 下标类型错误omit。i 它必须是逻辑、数字或字符。回溯:

  1. 调查::svyglm(...)
  2. 调查:::svyglm.survey.design(...)
  3. 调查::: [.survey.design2(设计, -nas, )
  4. base:: [.data.frame(x$variables, i, ..1, drop = FALSE)
  5. vctrs::: [.vctrs_vctr(xj, i)
  6. vctrs:::vec_index(x, i, ...)
  7. vctrs::vec_slice(x, i)

对于交互包:

错误:<labelled> - 不允许回溯:

  1. 交互::probe_interaction(...)
  2. 交互作用::sim_slopes(...)
  3. 交互:::center_ss(...)
  4. 交互:::center_ss_survey(...)
  5. jtools::gscale(vars = ndfvars, data = design, center.only = TRUE) ...
  6. vctrs::: -.vctrs_vctr(左,右)
  7. 避风港:::vec_arith.haven_labelled.default("-", e1, e2)
  8. vctrs::stop_incompatible_op(op, x, y)
  9. vctrs:::stop_incompatible(...)
  10. vctrs:::stop_vctrs(...)

我的代码是:

 design <-
  svydesign(

    id = ~I_i ,
    data = sm ,
    weights = ~w ,
  )

fit <- svyglm(sc ~ sex + school +sex*school, design)

summary(fit)

probe_interaction(fit, pred = school, modx = sex)

我希望继续使用 R4.0.2,因为降级 R 会给其他 R 包带来很多问题。probe_Interaction 部分也不适用于旧版本的 R(PC 计算机)。任何线索出了什么问题?

数据:

structure(list(I_i = structure(c(-54, 1000987, 1000166), label = "ID institution", format.spss = "F39.0", display_width = 39L, labels = c(Filtered = -99, Don't know = -98, Refused = -97, Not in list = -96, Implausible value = -95, Not reached = -94, Does not apply = -93, Question erroneously not asked = -92, Survey aborted = -91, Unspecific missing = -90, Not participated = -56, Not determinable = -55, Missing by design = -54, Anonymized = -53, Implausible value removed = -52, No estimate in check module = -51 ), class = c("haven_labelled", "vctrs_vctr", "double")), w = c(0.197917401820921, 0.186422150045312, 0.275986837527898),sc = c(NA, 7.66666666666667, 8.66666666666667 ), sex = structure(c(1, 1, 0), label = "Gender", format.spss = "F3.0", display_width = 9L, labels = c(Implausible value = -95, Unspecific missing = -90, Missing by design = -54, <U+0085> male? = 1, <U+0085> female? = 2), class = c("haven_labelled", "vctrs_vctr", "double")), school = c(NA, 1L, 1L)), row.names = c(NA, 3L), class = "data.frame")

标签: r

解决方案


推荐阅读