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

Error with cbc_design when keep_db_error = TRUE #36

Open
keikeisusu opened this issue Sep 12, 2024 · 2 comments
Open

Error with cbc_design when keep_db_error = TRUE #36

keikeisusu opened this issue Sep 12, 2024 · 2 comments

Comments

@keikeisusu
Copy link

Hi!
I'm trying to make a series of designs with cbc_design to pick ones with small DB-error.
But when keep_db_error = TRUE, the function returns the error as below:

Error in `[.data.frame`(as.data.frame(design), , c(metaNames, varNames)) :
undefined columns selected

Does anyone know how to deal with this?

set.seed(123)

prof_3233 <- cbc_profiles(
  A = c("A1", "A2", "A3"),
  B = c("B1", "B2"),
  C = c("C1", "C2", "C3"),
  D = c(3000, 3500, 4000)
)

cea_des <- cbc_design(
  profiles = prof_3233,
  n_resp = 100,
  n_alts = 2,
  n_q = 10,
  method = "CEA",
  priors = list(A = c(0, 0), B = 0, C = c(0, 0), D = 0), 
  parallel = TRUE,
  keep_db_error = TRUE
)

Thanks in advance!

@mmardehali
Copy link

I think I know why this is happening, but the line that may raise that error seems to be left out of the script here. I think you may be trying to read/print the DB-error without identifying the proper location to look for the value. To access the DB-error value, try the following:
DBerr <- as.numeric(cea_des$db_err)

This will store the error value in DBerr which you can then print, round, etc. For simplicity, I would also recommend rounding the error:
RoundedDBerror <- round(Dberr, 2)

I'm using version 0.4.0 of cbcTools, which at the time I designed my DCE was the most recent version. If you are using a different version, your results may vary. That said, when I ran the script you provided here, no errors were raised and everything worked as expected.

@keikeisusu
Copy link
Author

keikeisusu commented Sep 13, 2024

Thanks, mmardehali!

I'm using ver. 0.5.2 . The returned object from cbc_design is a data.frame, not a list, regardless of the value for keep_db_error.
I tried running the same code as above with v 0.4.0, as you said, it worked.
In addition, the object is indeed a list.

Although I've not scrutinized the source code here,
it seems the lines 871-873 don't function.

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