skent259 / rsmatch

Matching Methods for Time-Varying Observational Studies, in R
https://skent259.github.io/rsmatch/
Other
2 stars 4 forks source link

brsmatch() fails when `id` refers to a character vector #2

Closed skent259 closed 3 years ago

skent259 commented 3 years ago

It seems reasonable that id should be able to be a character vector. This same error will occur when the 'trt_time' refers to a character vector, and I think that a warning should be thrown there.

library(rsmatch)
  df <- data.frame(
    hhidpn = rep(1:3, each = 3),
    wave = rep(1:3, 3),
    treatment_time = rep(c(2,3,NA), each = 3),
    X1 = c(2,2,2,3,3,3,9,9,9),
    X2 = rep(c("a","a","b"), each = 3),
    X3 = c(9,4,5,6,7,2,3,4,8),
    X4 = c(8,9,4,5,6,7,2,3,4)
  )

  df$hhidpn <- as.character(df$hhidpn)

  pairs <- brsmatch(n_pairs = 1, df = df, id = "hhidpn", time = "wave", trt_time = "treatment_time",
                    optimizer = "glpk", options = "between period treatment")
#> Error in t(B_p) - t(B_e): non-numeric argument to binary operator

Created on 2021-02-09 by the reprex package (v0.3.0)