jhelvy / cbcTools

An R package with tools for designing choice based conjoint (cbc) survey experiments and conducting power analyses
https://jhelvy.github.io/cbcTools/
Other
5 stars 5 forks source link

cbc_design includes profiles that have been previously restricted (either manually or through cbc_restrict) #16

Closed mmardehali closed 1 year ago

mmardehali commented 1 year ago

It seems like, for some reason, cbc_design still includes the profiles that have been previously restricted. The only difference is when printed, the profileID of restricted profiles appears as "NA" instead of a number that corresponds with the list of all available profiles. This seems to happen regardless of whether cbc_restrict is used or the profiles are manually excluded. Version used: v0.3.3. Same issue appeared with v0.3.2.

`library("cbcTools") library("logitr")

global variables

Nresp = 150 #global variable to identify number of respondents Nchoice = 12 #global variable for the number of choice sets Nalt = 4 #global variable for the number of alternatives per choice set HeadN <- Nalt*Nchoice #secondary gobal variable to only print out the first respID set in the DB-Efficient design, other respIDs are just repetition of the same design.

create full-factorial design based on attributes and levels

profiles <- cbc_profiles( cost = seq(20, 30, 5), #generates sequence of numbers between 20 and 30 inclusive, 5 by 5. --Ratio Data brand = c("known", "unknown"), #--Nominal Data usrrt = seq(4.8, 3.2, -0.8), #generates sequence of numbers between 4.8 and 3.2 inclusive, -0.8 by -0.8. accinf = c("high", "low", "unavailable") #--Nominal Data ) profiles

restrict undesired profiles

rstrct_profiles <- cbc_restrict( profiles, cost == 20 & brand == "known" & usrrt == 4.8 & accinf == "high", #exclude dominant alternative cost == 30 & brand == "unknown" & usrrt == 3.2 & accinf == "unavailable" #exclude the worst alternative ) rstrct_profiles

create DB-efficient design from restricted full-factorial design

design_dbeff <- cbc_design( profiles = rstrct_profiles, n_resp = Nresp, n_alts = Nalt, #number of alternatives in each choice set n_q = Nchoice, #number of "questions" or choice sets n_start = 50, #numeric value indicating the number of random start designs to use. priors = list( cost = 0, brand = 0, usrrt = 0, accinf = c(0, 0) ), #using priors in designing DB-efficient fractional-factorial design max_iter = 10000 ) head(design_dbeff, HeadN)`

jhelvy commented 1 year ago

Okay I can reproduce this issue. I was hoping the changes made in v0.3.3 would have addressed it, but I must be missing something else. The reason the NA is showing up is because of a joining process done when re-coding the design after it's been solved. So there is probably still a small issue there. I'll dig into it.

jhelvy commented 1 year ago

I believe the patch I just pushed should fix this. Can you test it?

remotes::install_github("jhelvy/cbcTools")
mmardehali commented 1 year ago

Yes I can confirm that after generating the DB-Efficient design 3 times, I haven't seen any restricted profiles appearing as "NA" in the optimal design. Thank you!

jhelvy commented 1 year ago

Just letting you know that v0.3.4 is now on CRAN and has all the fixes addressing this issue as well as an additional argument called keep_db_error that I added to cbc_design(). If you set keep_db_error = TRUE, you'll get a list back containing the design as well as the DB error score. I'm going to close out this issue now.