## Code evaluation for implementing Bayesian Prior

This forum is for posts that specifically focus on Ngene.

Moderators: Andrew Collins, Michiel Bliemer, johnr

### Code evaluation for implementing Bayesian Prior

Dear all,

I want to conduct a labeled SCE and already performed a pilot study. Now I want to use the estimation results based on MNL to create my design for the final survey using bayesian priors. However, I am not very experienced with writing codes in Ngene. That is why I would really appreciate if someone with more experience can have look at the code.

Code: Select all
`design;alts = alt1, alt2, alt3, alt4;rows = 30;block = 5;eff = (mnl,d);alg = mfederov;model:U(alt1) = asc1        + b1[(n,  -.0870758 , .0303124)]   * A1[2,7,14]        + b2[(n, -.1342338, .1347078)]   * B1        + b3[(n, -.0155826, .0070892)]   * C1[10,20,60]        + b4[(n, -.0512281, .070547)]   * D1        + b5[(n, -.0222957,  .0063588)]   * E1        /U(alt2) = asc2        + b1      * A2        + b2      * B2[2,4]        + b3      * C2        + b4      * D2[2,3,5]        + b5      * E2[16,24,32]        /U(alt3) = asc3        + b1      * A3[0,1,2]        + b2      * B3        + b3      * C3        + b4      * D3[1,2,3]        + b5      * E3[50,75,100]        /U(alt4) = b1      * A4        + b2      * B4        + b3      * C4        + b4      * D4[1,2,3]        + b5      * E4[50,75,100,125,150]\$`

Another concers I have with the code is that I do not really know how to hadle the respective asc. My parameter estimates are base on including the alternative specific constants. So, should I include those estimates in the brackets of the respective asc or is it better to estimate another MNL with excluding the constants and use those estimated coefficients / stdd instead?
jonnyK123

Posts: 4
Joined: Sun Apr 10, 2022 11:53 pm

### Re: Code evaluation for implementing Bayesian Prior

This looks quite good.

A few suggestions:

1. You need to include priors for your ASCs. In the model that you estimated using pilot data, I assume that you also included and estimated ASCs. So you must not only use the parameter estimates for the priors of the attributes, but also use the parameter estimates for the priors of the ASCs, all from the same model that you estimated.

2. I would remove ;alg = mfederov, since the modified Federov algorithm would not be able to guarantee attribute level balance. Since you have no constraints, there is not really a reason for using the modified Federov algorithm. Further, for a Bayesian efficient design you need to select "mean" or "median" and specify the Bayesian draws. See script below.

Code: Select all
`design;alts = alt1, alt2, alt3, alt4;rows = 30;block = 5;eff = (mnl,d,mean);bdraws = sobol(500);model:U(alt1) = asc1        + b1[(n,  -.0870758 , .0303124)]   * A1[2,7,14]        + b2[(n, -.1342338, .1347078)]   * B1        + b3[(n, -.0155826, .0070892)]   * C1[10,20,60]        + b4[(n, -.0512281, .070547)]   * D1        + b5[(n, -.0222957,  .0063588)]   * E1        /U(alt2) = asc2        + b1      * A2        + b2      * B2[2,4]        + b3      * C2        + b4      * D2[2,3,5]        + b5      * E2[16,24,32]        /U(alt3) = asc3        + b1      * A3[0,1,2]        + b2      * B3        + b3      * C3        + b4      * D3[1,2,3]        + b5      * E3[50,75,100]        /U(alt4) = b1      * A4        + b2      * B4        + b3      * C4        + b4      * D4[1,2,3]        + b5      * E4[50,75,100,125,150]\$`

3. When you check the choice tasks and if you observe some dominance of certain attributes, then you can consider imposing dominance checks. In that case, you will need the modified Federov algorithm, see script below.

Code: Select all
`design;alts = alt1*, alt2*, alt3*, alt4*;rows = 30;block = 5;eff = (mnl,d,mean);bdraws = sobol(500);alg = mfederov(candidates = 2000);model:U(alt1) = asc1        + b1[(n,  -.0870758 , .0303124)]   * A1[2,7,14]        + b2[(n, -.1342338, .1347078)]   * B1        + b3[(n, -.0155826, .0070892)]   * C1[10,20,60]        + b4[(n, -.0512281, .070547)]   * D1        + b5[(n, -.0222957,  .0063588)]   * E1        /U(alt2) = asc2        + b1      * A2        + b2      * B2[2,4]        + b3      * C2        + b4      * D2[2,3,5]        + b5      * E2[16,24,32]        /U(alt3) = asc3        + b1      * A3[0,1,2]        + b2      * B3        + b3      * C3        + b4      * D3[1,2,3]        + b5      * E3[50,75,100]        /U(alt4) = b1      * A4        + b2      * B4        + b3      * C4        + b4      * D4[1,2,3]        + b5      * E4[50,75,100,125,150]\$`

Michiel
Michiel Bliemer

Posts: 1387
Joined: Tue Mar 31, 2009 4:13 pm

### Re: Code evaluation for implementing Bayesian Prior

Thank you for help, Michiel.

I have one follow up question:

If I include the paramter estimates for the ASCs in the code in 2., do I include them as follwed:

1. U(alt2) = asc2[-.5062053]

or

2. U(alt2) = asc2[(n, -.5062053, .5740263)]

kind regards,

Jonas
jonnyK123

Posts: 4
Joined: Sun Apr 10, 2022 11:53 pm

### Re: Code evaluation for implementing Bayesian Prior

Since you are using bayesian priors for the other parameters, I would also used bayesian priors for the constants, so I would do option 2.

Michiel
Michiel Bliemer

Posts: 1387
Joined: Tue Mar 31, 2009 4:13 pm