Closed mmardehali closed 1 year ago
Current fix: I use the following code to circumvent the complexity of converting list to data frame (shown above):
DBerr <- design_dbeff$db_err
DF_design_dbeff <- as.data.frame(design_dbeff$design)
FirstDesign <- DF_design_dbeff[1:HeadN,]
This allows for assigning db_err value to DBerr, reading the actual design as a data frame and assigning it to DF_design_dbeff, and saving only the first design. The first design (or DF_design_dbeff) can now be used seamlessly with the rest of the cbc functions.
I added the keep_db_error
argument so that you can get both the design and DB error back. If you set this to TRUE
, it returns a list with the two objects db_err
and design
. So like you just did in your example, you can extract these using the $
symbol. This is all documented if you check the help for this function: ?cbc_design
This was implemented in v0.3.4 as noted in this issue.
After updating the R packages (which updated cbcTools from v0.3.4 to v0.4.0 for me), I noticed that my code wasn't functioning properly anymore. After checking the updates to the package, and my code, I noticed that the output of cbc_design function has changed from Data Frame to List. I suspect this has to do with the addition of reporting db_err. In my old code, I used to isolate only the design for the first respondent (respID = 1) to inspect the design for balance and overlap, I call it the first design. I did this because in my case (1 block, unlabeled experiment) cbc_design repeats the first design for all respondents (as determined by n_resp). This was causing the problem in my old code, as I was extracting the first design using the head function. By manipulating the object type (using as.data.frame), I am now getting the first design correctly, however, db_err is now added as a column and repeats the same value for all rows. I was wondering if it's possible that:
While obviously the output list from cbc_design can be manipulated to present a separate data frame for the design, and a value for db_err that can then be assigned to a variable, I think presenting the output as described above creates less complexity for using other functions in this package (e.g. inspecting the design using cbc_balance and cbc_overlap, or choice and power analysis simulation). Currently, the raw output of cbc_design, at least in my case, is incompatible with other functions in the package.
Here's my code, and the output will be pasted below the code:
Output: