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

bal.tab & love.plot functions throws error about the argument to treat #74

Closed
sherwinkuah opened this issue Nov 20, 2023 · 2 comments
Closed

Comments

@sherwinkuah
Copy link

Hello Noah!
When I try to use the functions bal.tab or love.plot on an output from twang::mnps, it gives the following error. My treatment variable has 5 categories and is a factor. Could you advise on this?

Error in `bal.tab()`:
! The argument to `treat` must be a vector of treatment statuses or the (quoted) name of a variable in `data` that contains treatment statuses.
---
Backtrace:
     ▆
  1. ├─cobalt::bal.tab(mnps, un = TRUE, disp = c("m", "sd"))
  2. │ └─base::eval.parent(.call)
  3. │   └─base::eval(expr, p)
  4. │     └─base::eval(expr, p)
  5. ├─cobalt::bal.tab(x = `<mnps>`, un = TRUE, disp = c("m", "sd"))
  6. └─cobalt:::bal.tab.mnps(...)
  7.   ├─base::do.call("x2base.ps", c(list(x), args), quote = TRUE)
  8.   └─cobalt:::x2base.ps(...)
  9.     └─cobalt:::process_treat(ps[["treat"]], datalist = list(data, ps.data))
 10.       └─cobalt:::.process_vector(...)
 11.         └─cobalt:::.err(...)
 12.           └─chk::err(..., call = pkg_caller_call(start = 2))
Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.

Code that I ran:

> mnps <- mnps(treatment ~ sex + age + , 
             data = psdf,
             estimand = "ATT",
             treatATT = "treat1",
             verbose = "False",
             stop.method = c("es.mean"), 
             n.trees = 2000)

> bal.tab(mnps, un = TRUE, disp = c("m", "sd"))

Versions

  • R version 4.3.0 (2023-04-21)
  • x86_64-pc-linux-gnu
  • cobalt 4.5.1
  • twang 2.5

Thanks in advance, let me know what other info i can provide!

@ngreifer
Copy link
Owner

Hi, that looks like a bug, which I'll fix shortly. In the meantime, you can always use the formula interface to bal.tab(), which is only a tiny bit more cumbersome:

bal.tab(treatment ~ sex + age , 
        data = psdf,
        estimand = "ATT",
        focal = "treat1",
        weights = m)

ngreifer added a commit that referenced this issue Nov 20, 2023
@sherwinkuah
Copy link
Author

Appreciate so much for the prompt reply and fix! Super helpful :) It works for me now.

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