【问题标题】:Treatment asa binary variable作为二元变量处理
【发布时间】:2021-03-21 19:15:56
【问题描述】:

谁能帮我解决这个错误?

Error: The treatment must be a binary variable.

尝试继续运行以下代码行,但无法弄清楚问题出在哪里以及为什么会发生这种情况,尽管在运行了 matchit 函数相互需要的 mutate 函数之后。

    library(Matching)
    library(MatchIt)
    library(cobalt)
    library(WeightIt)
    library(twang)
    library(tidyverse)
    library(Hmisc)
    library(emmeans)
    library(rms)
    library(rpart) 
    library(randomForest)
    library(survey)
    library(glue)
    library(nnet)    
    
    set.seed(1)
        matching_lg_1 <- map(
          .x = ratios, ~ matchit(
            procedure ~ age + sub_id + intermacs_iv + gender + bsa + redo +
              ef + days_cvvh_preop, data = cardio_db_matched %>% 
            mutate(procedure = if_else(procedure =='proc_1', 1, 0), .data = cardio_db_matched), 
            distance = "logit", method = "nearest", ratio = .x, caliper = 0.2,
            m.order = "random", replace = FALSE
          )
        ) %>%
          set_names(x = ., nm = c("ratio_1:1", "ratio_1:2"))

原始数据集中的变量可能采用以下值: proc_1 proc_2

感谢关注。

【问题讨论】:

  • 我指定程序是我的治疗变量!!
  • 请问您使用的是什么版本的MatchIt
  • 同样的问题

标签: r variables binary dplyr


【解决方案1】:

我遇到了同样的问题,这告诉您treatment (procedure) 不包含介于 0 和 1 之间的值。很可能您有缺失值,在这种情况下,请设置 na.omit() 或检查任何变量的可能转换导致它不仅具有 0 和 1 的值。

【讨论】:

    猜你喜欢
    • 2015-01-18
    • 2014-08-08
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    相关资源
    最近更新 更多