Reputation: 129
I face the following barrier.
My csv data look like this:
I want to use propensity score matching and compare different methods to see which is the optimum one for my data. However, I seem to get an error in the data and I can not figure out why:
Error: Missing and non-finite values are not allowed in the covariates. Covariates with missingness or non-finite values: pat_gender, pat_race, pat_ethnicity
I checked and don't have missing values. I don't understand what it means with "non-finite". I tried to change characters with numbers in the pat_gender, e.g. Male to 1, Female to 0, but I still get the same error. I attach my file to hopefully help.
library(MatchIt)
library(dplyr)
library(optmatch)
mydata<- read.csv("C:/Users/Desktop/prp_for_psm_pq.csv")
set.seed(1234)
match.itzs <- matchit(cohort_flag ~ pat_age + pat_gender + pt_hist_in_months + pt_visit_count + pat_race + pat_ethnicity, data = mydata, ratio=1)
df.matchzs <- match.data(match.itzs)[1:ncol(cohort_initial)]
prp_cohort_psm_zs_test <- df.matchzs
Upvotes: 3
Views: 2115
Reputation: 11
I got the code to run by setting the variables to factors, so something like this:
mydata <- mydata %>% mutate(pat_gender = factor(pat_gender))
Upvotes: 1