0

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
set.seed(12345)
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)
print(Trt_Grp)
Race <-rbinom(100, 1, prob = 0.8)
print(Race)
Gender <-rbinom(100, 1, prob = 0.5)
print(Gender)
Patient_ID <-seq(1, 100, by=1)
print(Patient_ID)
Post_DBP <-rnorm(100, 80, 10)
print(Post_DBP)
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)
summary(y1) 
summary(y2)
summary(Post_DBP)
Trt_Grp <- ifelse(Post_DBP<=80, 1, Trt_Grp)
Trt_Grp <- ifelse(Post_DBP>80, 0, Trt_Grp)
print(Trt_Grp)
summary(Trt_Grp)
table(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
round(Trt_Difference)
Data <- cbind(Patient_ID, Age,  Race, Gender,Trt_Grp, Base_DBP, Post_DBP, Trt_Difference)
round(Data, digits = 0)
Peter Flom
  • 94,055
  • 35
  • 143
  • 276
Ese
  • 5
  • 2

1 Answers1

1

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().

Noah
  • 20,638
  • 2
  • 20
  • 58
  • 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? – Ese Mar 27 '19 at 22:11
  • 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. – Noah Mar 27 '19 at 22:23
  • Thank you so much. I am most grateful. – Ese Mar 27 '19 at 22:29
  • No problem. Please select my answer as correct if you feel your question was answered. – Noah Mar 28 '19 at 15:26
  • 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)? – Ese Mar 28 '19 at 16:48
  • The ideal way would be `Trt_Grp 0`, but you have to pick meaningful values for `b0`, `b1`, etc. This is a challenging thing to do and you might seek the help of a statistician. – Noah Mar 28 '19 at 18:45
  • I used the above code to simulate the treatment group and I got all "1". I tried using the following code but it did not work. Trt_Grp 0). Please help. – Ese Apr 01 '19 at 18:15
  • `=>` is not allowable in R. Did you pick values for `b0`, `b1`, etc., that make sense? (they should be between -1.5 and 1.5 typically for standardized predictors). – Noah Apr 01 '19 at 19:53