Page 1 of 1

Coding Ngene

PostPosted: Tue Mar 16, 2010 12:24 pm
by dmarsh
I am just trying to get started using ngene
I want to generate an efficient design using priors generated from a web survey
Are there any worked examples for unlabelled experiments - with discrete attribute levels - common in environmental economics?
I find it hard to apply the typical transport examples to what I am trying to achieve

My data is from an unlabelled choice experiment where each attribute has pre defined levels
I offer three choices - one being the status quo
The first level in each case is the status quo

Chance of algal blooms 50, 20, 10, 2 per cent - swim20, swim10, swim2
Water clarity 1 (SQ), 1.5, 2, 4 metres - clar15, clar2, clar4
Ecological health 40, 50, 60, 80 per cent - eco50, eco60, eco80
Change in jobs 0, 5, 10, 20 - jobs5, jobs10, jobs20
Cost 0, 50, 150, 300

I have the following priors (MNL)

swim20 0.01 - NS but I have chosen a small positive value
swim10 0.6
swim2 0.95

clar15 0.01 - NS but I have chosen a small positive value
clar2 0.02 - NS see above
clar4 0.59

eco50 0.5
eco60 0.7
eco80 1.0

jobs5 -0.4
jobs10 -0.6
jobs20 -0.83

Cost -0.003
ASC 0.31

Is dummy coding the correct approach
Does this coding look correct?

?MNL model-assuming fixed prior parameters
design
;alts=alt1,alt2,alt3
;rows=24
;block=4
;alg=swap(stop=noimprov(10000 iterations))
;con
;eff=(mnl,d) ? a,s can be used for other eff measures instead
;model:


U(alt1)= b2.dummy[0.01|0.6|0.95]* swim[50,20,10,2]+ b3.dummy[0.01|0.02|0.591]* clar[1,1.5,2,4] +
b4.dummy[0.5|0.7|1.01] *eco[40,50,60,80]+ b5.dummy[-0.4|-0.6|-0.83] *jobs[0,-5,-10,-20] +
b6[-0.003] * cost[0,50,150,300]/
U(alt2)= b2.dummy[0.01|0.6|0.95]* swim[50,20,10,2]+ b3.dummy[0.01|0.02|0.591]* clar[1,1.5,2,4] +
b4.dummy[0.5|0.7|1.01] *eco[40,50,60,80]+ b5.dummy[-0.4|-0.6|-0.83] *jobs[0,-5,-10,-20] +
b6[-0.003] * cost[0,50,150,300]/
U(alt3)= b1[0.31]$

Best Wishes
Dan

Re: Coding Ngene

PostPosted: Tue Mar 16, 2010 12:42 pm
by Andrew Collins
Hi Dan,

Ngene can indeed handle dummy coding. Section 7.2.8 of the manual has an extensive explanation. I have changed your syntax to be dummy coded below:

Code: Select all
?MNL model-assuming fixed prior parameters
design
;alts=alt1,alt2,alt3
;rows=24
;block=4
;alg=swap(stop=noimprov(10000 iterations))
;con
;eff=(mnl,d)   ? a,s can be used for other eff measures instead
;model:
U(alt1)=
b2.dummy[0.01|0.6 |0.95]    * swim[20,10,2,50]
+ b3.dummy[0.01|0.02|0.59]  * clar[1.5,2,4,1]
+ b4.dummy[0.5|0.7|1.0]     * eco[50,60,80,40]
+ b5.dummy[-0.4|-0.6|-0.83] * jobs[5,10,20,0]
+ b6[-0.003]                * cost[0,50,150,300]  /
U(alt2)= b2*swim + b3*clar + b4*eco + b5*jobs + b6*cost  /
U(alt3)= b1[0.31]
$


Keep in mind that the final attribute level in the list is the base level, which is why I changed the order. Also given how fast the MNL designs are generated, you could remove the stopping criteria and just let it run for a few hours.

Andrew

Re: Coding Ngene

PostPosted: Wed Mar 17, 2010 7:45 am
by dmarsh
That is great
much appreciated!

Now I am trying to get ngene to specify my status quo correctly
e.g. in every choice card the status quo should be
swim50
clar1
eco40
jobs0
cost0

The relevant section of the manual seems to be page 146
but I must be missing something ...
I have modified the specification for alt3 (I moved it to alt1 so that it appears first)
But I get the Error msg
"Two identically named attributes do not have consistently specified levels:'swim',alt1.swim'

Also - I have put in a prior of 0.31 for alt 3 because this is the value of the ASC for my MNL model
Is this correct?

design
;alts=alt1,alt2,alt3
;rows=24
;block=4
;alg=swap(stop=noimprov(10000 iterations))
;con
;eff=(mnl,d) ? a,s can be used for other eff measures instead
;model:
U(alt1)= b1[0.31]+b2*swim[50] + b3*clar[1] + b4*eco[40] + b5*jobs[0] + b6*cost[0] /
U(alt2)=
b2.dummy[0.01|0.6 |0.95] * swim[20,10,2,50]
+ b3.dummy[0.01|0.02|0.59] * clar[1.5,2,4,1]
+ b4.dummy[0.5|0.7|1.0] * eco[50,60,80,40]
+ b5.dummy[-0.4|-0.6|-0.83] * jobs[5,10,20,0]
+ b6[-0.003] * cost[0,50,150,300] /
U(alt3)= b2*swim + b3*clar + b4*eco + b5*jobs + b6*cost /
$

Re: Coding Ngene

PostPosted: Wed Mar 17, 2010 8:35 am
by admin
Pivot designs (p.146) are not necessary in this case. The error message results because priors and attributes are configured at the first place they appear - later references to the same prior or attribute have to be specified in the same way (same prior values, same attributes, etc). So, I have moved the SQ alternative back to the third alternative - of course it can be rearranged when presenting the survey.

I don't think there is any value in actually adding in the SQ levels of the various attributes in the SQ alternative, as the cost is 0, and the the SQ levels are the base level of the dummy codes. Consequently, the only contribution to utility comes from the ASC. You could just omit these attributes from the SQ alternative and manually add them in to the final designs. If you want to leave them in, then the syntax specification is a little tricky. You will want to use the same priors, but constrain the frequency of each of the attribute levels, so that there are 24 instances of the desired SQ level, and 0 instances of all other levels. There is a restriction in Ngene that forces the frequency constraints to be the same across alternatives for any given attribute (probably this is too restrictive, and will be relaxed in future point releases). However, you can get around this by specifying a new attribute that has a different name, the same number of levels (so that it can be associated with the same prior), and different attribute level frequency constrains. All of this should become a bit clearer with the adjusted syntax below:

Code: Select all
design
;alts=alt1,alt2,alt3
;rows=24
;block=4
;alg=swap(stop=noimprov(10000 iterations))
;con
;eff=(mnl,d) ? a,s can be used for other eff measures instead
;model:
U(alt1)=
b2.dummy[0.01|0.6 |0.95] * swim[20,10,2,50]
+ b3.dummy[0.01|0.02|0.59] * clar[1.5,2,4,1]
+ b4.dummy[0.5|0.7|1.0] * eco[50,60,80,40]
+ b5.dummy[-0.4|-0.6|-0.83] * jobs[5,10,20,0]
+ b6[-0.003] * cost[0,50,150,300] /
U(alt2)= b2*swim + b3*clar + b4*eco + b5*jobs + b6*cost /
U(alt3)= b1[0.31]
+ b2*swimSQ[20,10,2,50](0,0,0,24)
+ b3*clarSQ[1.5,2,4,1](0,0,0,24)
+ b4*ecoSQ[50,60,80,40](0,0,0,24)
+ b5*jobsSQ[5,10,20,0](0,0,0,24)
+ b6*costSQ[0]
$


Regarding the ASC, so long as it is associated with the SQ alternative in your model (is this from a pilot?), then it would make sense to add it in, as all the other priors will be relative to this amount of utility, not zero utility.

Re: Coding Ngene

PostPosted: Wed Mar 17, 2010 9:28 am
by dmarsh
many thanks
much appreciated
I can see why it may be easier to put the SQ in manually

Re: Dummy Coding Ngene RPEC

PostPosted: Fri Mar 19, 2010 10:40 am
by dmarsh
Hi All

Now I am trying to estimate a design for RP Error Component
I have estimated the model
Some attributes are "a bit odd" so I have adjusted the priors
Also I have changed the output levels in the square brackets to meet the assumed input for my web survey design ..
(e.g. clarity levels 1.5,2,4,0 become 2.0, 2.3, 3.2 ...)

Here is my code
Which gives error msg saying I have not specified priors
I have tried to put in priors as in manual section 7.2.3 in the format (normal distribution, mean, sd)
Does this work with dummy coding?

design
;alts=alt1,alt2,alt3
;rows=36
;block=6
;con
?;alg=swap(stop=noimprov(10000 iterations))
;eff=(rpecpanel,d)
;rep=500
;rdraws=halton(350)
;model:

U(alt1)=
b2.dummy[n,0.2,0.4|n,0.9,0.7|n,1.42,0.74] * swim[0.6,2,2.4,0]
+ b3.dummy[0.01|0.02|n,0.95,1.07] * clar[2.0,2.3,3.2,0]
+ b4.dummy[n,1.1,1|n,0.9,0.9|n,1.58,0.1] * eco[2.6,3,3.7,0]
+ b5.dummy[n,-0.29,1.6|n,-0.4,0.8|n,-0.98,0.88] * jobs[0.7,1.6,2.5,0]
+ b6[-0.0066] * cost[0,50,100,200] /
U(alt2)= b2*swim + b3*clar + b4*eco + b5*jobs + b6*cost /
U(alt3)= b1[1.34]
$

Many Thanks

Dan

Re: Coding Ngene

PostPosted: Fri Mar 19, 2010 3:45 pm
by Michiel Bliemer
Dear Dan,

Next time, please use a different thread on the forum for a different question.

To answer your question, yes, it does work with dummies, but the problem is that you have only specified the RP parameters, but no EC parameter (there is no error component), so you can replace "rpecpanel" with "rppanel" and it will run. HOWEVER, I would not advice you to run this code. You have 10 random parameters and use a panel formulation. With 350 Halton draws and rep=500, you are doing 350x500 = 175,000 draws for the evaluation of EACH design. So it will take your MONTHS (years?) to find an efficient design. Lowering the Haltonf draws and rep is not adviced either, as for 10 parameters you need high values, probably even much larger than 350 and 500.

It is well-known that generating efficient designs for a panel model is very time consuming. We would recommend the following, which seems to work well and is what we typically do:
(1) Assume an MNL model and generate an efficient design
(2) Evaluate the efficient design for the MNL model as being a RP panel model, so you can see how the design would behave if a an RP panel model is assumed instead of an MNL model
As we found in several case studies, an efficient design for MNL is usually also efficient for panel mixed logit models.

In your code, you only have to change "rppanel" to "mnl", so you leave all the specifications of the normal distributions as they are, and leave rdraws and rep as well. Ngene will then assume the mean of the normal as the prior. Run the code, and find an efficient design. Doubleclick on the design, and in the list on the left you should be able to see different models, so you can select "rppanel" (and then wait a little bit) and inspect the properties of the design under the rppanel assumption.

Hope that helps,
Michiel