skent259 / rsmatch

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

NA row in brsmatch() result #4

Closed SusanJiao20 closed 3 years ago

SusanJiao20 commented 3 years ago

df1 and df2 both contain NA in treatment time, the results returned from brsmatch contain the matched pairs and a row of NA.

library(rsmatch)
library(reprex)
#> Warning: package 'reprex' was built under R version 4.0.3
df1 <- 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)
)
brsmatch(n_pairs = 1, df = df1, id = "hhidpn", time = "wave",
         trt_time = "treatment_time", optimizer = "glpk")
#>   hhidpn pair_id type
#> 1      1       1  trt
#> 2      2       1  all
#> 3      3      NA <NA>

df2 <- data.frame(
  hhidpn = rep(1:5, each = 3),
  wave = rep(1:3, 5),
  treatment_time = rep(c(2,3,2,3,NA), each = 3),
  X1 = c(2,2,2,3,3,3,9,9,9,10,10,10,7,7,7),
  X2 = rep(c("a","a","b"), each = 5),
  X3 = c(9,4,5,6,7,2,3,4,8,5,7,8,5,8,7),
  X4 = c(8,9,4,5,6,7,2,3,4,6,4,2,5,7,3)
)
brsmatch(n_pairs = 2, df = df2, id = "hhidpn", time = "wave",
         trt_time = "treatment_time", optimizer = "glpk")
#>   hhidpn pair_id type
#> 1      1       1  trt
#> 2      2       1  all
#> 3      3      NA <NA>
#> 4      4       2  trt
#> 5      5       2  all

Created on 2021-02-09 by the reprex package (v1.0.0)

skent259 commented 3 years ago

This output is to be expected. The NA values indicate that the individual was not paired. This can easily happen when there is an odd number of ids, or when n_pairs is small. To show only those that are matched, you can pass the output to na.omit().