ChristopherLucas / MatchingFrontier

Optimal pruning for imbalance minimization in causal inference
18 stars 8 forks source link

`makeFrontier()` throws uninformative error if `dataset` is tibble #32

Open bfifield opened 5 years ago

bfifield commented 5 years ago

This package and method are great, thanks for implementing it to make it easy to use!

makeFrontier() will throw an error about the treatment not being 0/1 or TRUE/FALSE when dataset is a tibble, even if the treatment is in fact 0/1. If the dataset is converted to data.frame(), the error goes away, but it took a bit of experimenting to figure that out. Either automatic conversion of tbl to data.frame(), or a more informative warning message would be a big help.

library(tidyverse)
library(MatchingFrontier)

## Make data - t is 0/1
df_tst <- tibble(t = rbinom(100, c(0, 1), .5), 
                 X1 = rnorm(100), 
                 X2 = rnorm(100), 
                 y = rnorm(100))

## Should error with: 
## "Error: In makeFrontier(), the treatment must be either 0/1 (integers) or "TRUE"/"FALSE" (logical)."
makeFrontier(dataset = df_tst, treatment = "t", outcome = "y", match.on = c("X1", "X2"))

## Should run after converting to dataframe
makeFrontier(dataset = as.data.frame(df_tst), treatment = "t", outcome = "y", match.on = c("X1", "X2"))
nielsenrich commented 5 years ago

Thanks. Don't use tibbles much so didn't know this.