Propensity Analysis

I'm learning how to do a propensity analysis, my reprex works but when I replicate the same exact code with the real data, I get the following error

rr1 <- Match(Y = Y, Tr = Tr, X = proptest001$fitted)
Error in Match(Y = Y, Tr = Tr, X = proptest001$fitted) :
length(Tr) != nrow(X)

Here is the reprex

library(Matching)
#> Warning: package 'Matching' was built under R version 3.6.3
#> Loading required package: MASS
#> ## 
#> ##  Matching (Version 4.9-7, Build Date: 2020-02-05)
#> ##  See http://sekhon.berkeley.edu/matching for additional documentation.
#> ##  Please cite software as:
#> ##   Jasjeet S. Sekhon. 2011. ``Multivariate and Propensity Score Matching
#> ##   Software with Automated Balance Optimization: The Matching package for R.''
#> ##   Journal of Statistical Software, 42(7): 1-52. 
#> ##
datapasta::df_paste(head(corc002, 5)[, c('positive', 'arb', 'aarace')])
#> Error in head(corc002, 5): object 'corc002' not found
#so you can see where the data for DF comes from
DF<-data.frame(
positive = c(1, 1, 1, 1, 1),
arb = c(0, 0, 1, 0, 0),
aarace = c(0, 0, 1, 0, 0)
)
DF
#>   positive arb aarace
#> 1        1   0      0
#> 2        1   0      0
#> 3        1   1      1
#> 4        1   0      0
#> 5        1   0      0
Tr<-cbind(DF$arb)
Y<-cbind(DF$positive)
X<-cbind(DF$aarace)
glm1 <- glm(Tr ~ X, family=binomial(link = "probit"), data=DF)
rr1 <- Match(Y = Y, Tr = Tr, X = glm1$fitted)
summary(rr1)
#> 
#> Estimate...  0 
#> AI SE......  0 
#> T-stat.....  NaN 
#> p.val......  NA 
#> 
#> Original number of observations..............  5 
#> Original number of treated obs...............  1 
#> Matched number of observations...............  1 
#> Matched number of observations  (unweighted).  4

Here is the code I used

Y<cbind(corc002$positive)
Y<-cbind(corc002$positive)
Tr<-cbind(corc002$arb)
X<-cbind(corc002$aarace)
proptest001 <- glm(Tr ~ X, family=binomial(link = "probit"), data=corc002)
summary(proptest001)
rr1 <- Match(Y = Y, Tr = Tr, X = proptest001$fitted)

What gives? I'm still a noob so I'm sure I'm making a dumb mistake but I've spent hours on this and can only scream four letter expletives at my computer for so long.

must be resolved before proceeding

I put that in there just to show that the reprex used the same data I used for the problematic code, I got the code below it from putting the same code in the console where "corc002". I ran the reprex from the source.

For reproducing the error, corc002 is required

I'm sorry, I'm a bit confused, isn't the point of a reprex so I can just show a sample of my data and not attach the data set?

Code in the reprex must conform to the objects that have been put into the environment. The argument to head is missing, with no default, making the problem insufficiently specified.

The purpose of a reprex is to provide data and code that we can run that reproduces the error you're getting. The data can be a small sample of your real data, or fake data. Either way, running your code with the data sample should reproduce the error or problem you're having with your real data.

The key is that we need to be able to run your code so that we can diagnose the problem and test potential solutions. This saves a lot of time and makes it much easier to help you.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.