I am doing a propensity score matching(nearest neighbor matching) in R with simulated data and I keep getting the above warning messages. please I need help.

The following is my code

m.out<- matchit(Trt_Grp~Age + Base_DBP + Gender + Race + Trt_Difference, data.frame(Data1), method = "nearest")

I generated my data using the following codes
Age <- rnorm(100, 50, 10)
round(Age, digits = 0)
Base_DBP <- rnorm(100,95 , 8)
round(Base_DBP, digits=0)
Trt_Grp <-rbinom(100, 1, prob =0.5)
Race <-rbinom(100, 1, prob = 0.8)
Gender <-rbinom(100, 1, prob = 0.5)
Patient_ID <-seq(1, 100, by=1)
Post_DBP <-rnorm(100, 80, 10)
round(Post_DBP, digits = 0)
n = 100; y1 = rnorm(n, 75, 5);  y2 = rnorm(n, 85, 5)  # same SD where y1 is post_DBP for drug and y2 for placebo
w = rbinom(n, 1, .20)     #where w is Trt_grp  
Post_DBP = w*y1 + (1-w)*y2  
round(Post_DBP, digits = 0)
round(y1, digits = 0)
round(y2, digits = 0)
Trt_Grp <- ifelse(Post_DBP<=80, 1, Trt_Grp)
Trt_Grp <- ifelse(Post_DBP>80, 0, Trt_Grp)
or <- cbind(Patient_ID, Age,  Race, Gender,Trt_Grp, Base_DBP, Post_DBP)
round(or, digits = 0)
Trt_Difference <- Base_DBP - Post_DBP
Data <- cbind(Patient_ID, Age,  Race, Gender,Trt_Grp, Base_DBP, Post_DBP, Trt_Difference)
round(Data, digits = 0)

This code is kind of a mess and not doing what you expect it to do. For example, the code Age <- rnorm(100, 50, 10); round(Age, digits = 0) doesn't round Age to whole numbers. You need Age <- round(Age, digits = 0) to do that.

That said, the reason you're getting this message is that the variable Post_DBP perfectly predicts Trt_Grp. This line of code

ifelse(Post_DBP<=80, 1, Trt_Grp); Trt_Grp <- ifelse(Post_DBP>80, 0, Trt_Grp)

which would be more clearly written as

Trt_Grp <- ifelse(Post_DBP>80, 0, 1)

means that Trt_grp is perfectly determined by Post_DBP. There is no overlap between your treated and control groups on this variable. There is a perfect discontinuity at Post_DBP==80. The warning message you get is from the logistic regression that matchit() runs using glm().

  • $\begingroup$ Thank you so much for this clarification. Please I would like to ask, is there a way to simulate the data for Trt_group and build in a treatment effect so that there can be an overlap between the treated and the control groups? $\endgroup$ – Ese Mar 27 '19 at 22:11
  • $\begingroup$ Yes. Generate your predictors, and then use a logistic regression model to generate probabilities for each individual. From the probabilities, generate treatment status using rbinom(). Then, generate an outcome variable using a regression on the treatment and predictors. $\endgroup$ – Noah Mar 27 '19 at 22:23
  • $\begingroup$ Thank you so much. I am most grateful. $\endgroup$ – Ese Mar 27 '19 at 22:29
  • $\begingroup$ No problem. Please select my answer as correct if you feel your question was answered. $\endgroup$ – Noah Mar 28 '19 at 15:26
  • $\begingroup$ Thank you again for your help. Please can you write out the code generating the Trt_group with built in treatment effect so that they overlap. For example let the distribution of the treated post_DBP be rnomal(100, 75, 5) and that of the control be rnormal(100, 85,5)? $\endgroup$ – Ese Mar 28 '19 at 16:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.