Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lack of rownames in dataframe crashes caliper matching #21

Closed
lmiratrix opened this issue Dec 21, 2017 · 1 comment
Closed

lack of rownames in dataframe crashes caliper matching #21

lmiratrix opened this issue Dec 21, 2017 · 1 comment

Comments

@lmiratrix
Copy link

See demo script, below. matchit() fails in first call. Adding rownames fixes it in second call. This is due to some extraction breaking deep in the guts of matchit()

Small test case of possible bug?

library( MatchIt )

make.dat = function( p, N, beta0 = -1, beta1=1 ) {
X = matrix( rnorm( p * N ), ncol = p )
pi = arm::invlogit( beta0 + beta1 * X[,1] )
Z = 0 +( runif( N ) <= pi )

colnames(X) = paste( "X", 1:p, sep="" )
df = as.data.frame( X )
df$Z = Z
df

}

mydat = make.dat( 3, 100 )
head( mydat )
str( mydat )

m.out <- matchit(Z ~ X1 + X2 + X3, data = mydat, method = "nearest",
caliper = 0.2, mahvars = c("X1","X2") )

rownames( mydat ) = paste( "R", rownames(mydat), sep="" )
m.out <- matchit(Z ~ X1 + X2 + X3, data = mydat, method = "nearest",
caliper = 0.2, mahvars = c("X1","X2") )

@ngreifer
Copy link
Collaborator

ngreifer commented Nov 4, 2020

This has been fixed, thank you!

@ngreifer ngreifer closed this as completed Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants