Could anyone may help me to fix this error?
Error: The treatment must be a binary variable.
Trying keeping on running such following code lines and cannot figure out where the problem is and why this is occurring, although after running the mutate function, which is required mutually by the matchit function.
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(
A ~ B + C + D + E + F + G +
H + J, data = data %>%
mutate(A = if_else(A =='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"))
The variable in the original dataset may assume the following values:
1
2
Thanks for paying attention.
I had the same problem and this is telling you that the treatment
(procedure
) does not contain values between 0 and 1. Most likely you have missing values, in that case, set na.omit()
or check any possible transformation of the variable that leads to it not having just values of 0 and 1.