Error

This forum is for posts that specifically focus on Ngene.

Moderators: Andrew Collins, Michiel Bliemer, johnr

Error

Postby Nina » Wed Sep 22, 2021 1:03 am

Hello,

i need help building my syntax in ngene. I do a choice experiment with 3 alternatives (AltA, AltB, Status quo) and an effizient design. Each alternative (AltA and AltB) is described by the same attributes and levels. I've already done a pretest to get the priors and want to integrate them into my syntax. Unfortunately I get errors and I couldn't find a solution so far.

My syntax before the pretest:
design

;alts = altA, altB, status quo
;rows = 9
;eff = (mnl, d)
;cond:
if(altA.x1 = 0, altB.x1 = [1,2]),
if(altA.x1 = 1, altB.x1 = [0,2]),
if(altA.x1 = 2, altB.x1 = [0,1]),
if(altA.x2 = 0, altB.x2 = [1,2,3]),
if(altA.x2 = 1, altB.x2 = [0,2,3]),
if(altA.x2 = 2, altB.x2 = [0,1,3]),
if(altA.x2 = 3, altB.x2 = [0,1,2]),
if(altA.x3 = 0, altB.x3 = [1,2]),
if(altA.x3 = 1, altB.x3 = [0,2]),
if(altA.x3 = 2, altB.x3 = [0,1]),
if(altA.x4 = 0, altB.x4 = [1,2]),
if(altA.x4 = 1, altB.x4 = [0,2]),
if(altA.x4 = 2, altB.x4 = [0,1]),
if(altA.x5 = 0, altB.x5 = [1,2]),
if(altA.x5 = 1, altB.x5 = [0,2]),
if(altA.x5 = 2, altB.x5 = [0,1])

;model:
U(altA) = b1[0.01]*x1[0,1,2] + b2[0.01]*x2[0,1,2,3] + b3[-0.02]*x3[0,1,2] + b4[0.01]*x4[0,1,2] + b5[-0.03]*x5[0,1,2]+ b1.dummy[0.1|0.1]*x1[0,1,2] + b2.dummy[0.1|0.1|0.1]*x2[0,1,2,3] + b4[0.1|0.1]*x4[0,1,2] /
U(altB) = b6[0.01]*x1 + b7[0.01]*x2 + b8[-0.02]*x3 + b9[0.01]*x4 + b10[-0.03]*x5 + b6.dummy[0.1|0.1]*x1 + b7.dummy[0.1|0.1|0.1]*x2[0,1,2,3] + b9.dummy[0.1|0.1]*x4 /
U(status quo) = b11[0.01]

$


For the Syntax after the pretest I chose new names:
X1=pa_1,pa_2
x2=an_1,pa_2.....

design
;alts = altA, altB, status quo
;rows = 9
;eff = (mnl, d)
;cond:
if(altA.pa_1 = 0, altB.pa_2 = [1,2]),
if(altA.pa_1 = 1, altB.pa_2 = [0,2]),
if(altA.pa_1 = 2, altB.pa_2 = [0,1]),
if(altA.an_1 = 0, altB.an_2 = [1,2,3]),
if(altA.an_1 = 1, altB.an_2 = [0,2,3]),
if(altA.an_1 = 2, altB.an_2 = [0,1,3]),
if(altA.an_1 = 3, altB.an_2 = [0,1,2]),
if(altA.e_1 = 0, altB.e_2 = [1,2]),
if(altA.e_1 = 1, altB.e_2 = [0,2]),
if(altA.e_1 = 2, altB.e_2 = [0,1]),
if(altA.vb_1 = 0, altB.vb_2 = [1,2]),
if(altA.vb_1 = 1, altB.vb_2 = [0,2]),
if(altA.vb_1 = 2, altB.vb_2 = [0,1]),
if(altA.sr_1 = 0, altB.sr_2 = [1,2]),
if(altA.sr_1 = 1, altB.sr_2 = [0,2]),
if(altA.sr_1 = 2, altB.sr_2 = [0,1])


;model:
U(altA) = b1[-0.07163|0.25366|0]*pa_1[0,1,2] + b2[-0.67552|1.47051|1.04867|0]*an_1[0,1,2,3] + b3[-0.07081]*e_1[0,1,2] + b4[1.49265|0.33746|0]*vb_1[0,1,2] + b5[-0.32552|-0.23736|0.63482]*sr_1[0,1,2]+ b1.dummy[-0.07163|0.25366]*pa_1[0,1,2] + b2.dummy[-0.67552|1.47051|1.04867]*an_1[0,1,2,3] + b4.dummy[1.49265|0.33746]*vb_1[0,1,2] /
U(altB) = b1[-0.07163|0.25366|0]*pa_1[0,1,2] + b2[-0.67552|1.47051|1.04867|0]*an_1[0,1,2,3] + b3[-0.07081]*e_1[0,1,2] + b4[1.49265|0.33746|0]*vb_1[0,1,2] + b5[-0.32552|-0.23736|0.63482]*sr_2[0,1,2]+ b1.dummy[-0.07163|0.25366]*pa_1[0,1,2] + b2.dummy[-0.67552|1.47051|1.04867]*an_1[0,1,2,3] + b4.dummy[1.49265|0.33746]*vb_1[0,1,2] /
U(status quo) = b6[-0.07195]

$

Error: The 'model' property contains a prior that has dummy or effects coding without an appropriate suffix. 'b1'

Can you please help me?
Nina
 
Posts: 5
Joined: Tue Sep 21, 2021 8:29 pm

Re: Error

Postby Michiel Bliemer » Thu Sep 23, 2021 9:47 pm

It looks like you are using dummy or effects coding since you use levels 0,1,2.
The correct specification for categorical/qualitative variables is:

b1.dummy[-0.07163|0.25366] * pa_1[0,1,2]

where the last level (in this case, 2) is assumed to the base level in Ngene. If level 0 was the base level, then you can use

b1.dummy[-0.07163|0.25366] * pa_1[1,2,0]

You seem to have used ".dummy" for some parameters but not for all.

Michiel
Michiel Bliemer
 
Posts: 1727
Joined: Tue Mar 31, 2009 4:13 pm

Re: Error

Postby Nina » Thu Sep 23, 2021 10:54 pm

Dear Mr. Bliemer,

my base level is 2. Thats because I used:

b1.dummy[-0.07163|0.25366] * pa_1[0,1,2]

I didn't use the dummy coding for all attributes because:

"In order to use categorical variables with more than two variables in the regression model, dummy variables must be formed. Each expression of the categorical variables was assigned a new variable for dummy coding, resulting in three variables with two expressions each (0=no, 1=yes). The last expression corresponds to the reference category and is not dummy coded. The attributes "distance from residence to parking space" and "reduction of parking spaces in public areas" are metric variables and can be interpreted by their logical order and their distances to each other. Dummy coding is therefore not necessary for the attributes (Ngene 2018: 110ff.). "
Is this correct?

In the pretest, the reference categories took the value 0. Is it correct that in the front of the Synatx I have specified the parameter 0?
U(altA) = b1[-0.07163|0.25366|0]*pa_1[0,1,2] --> b1.dummy[-0.07163|0.25366]*pa_1[0,1,2]

Nina
Nina
 
Posts: 5
Joined: Tue Sep 21, 2021 8:29 pm

Re: Error

Postby Michiel Bliemer » Fri Sep 24, 2021 7:46 am

You are mixing up two things here.

Qualitative/categorical variables will require a coding scheme (dummy or effects coding) and will look like:

b1.dummy[0.1|0.2] * x1[0,1,2]

Quantitative/numerical variables do not require a coding scheme and their attribute levels can be used directly in the utility function with a linear effect:

b1[-0.1] * x1[50,250,500]

You seem to want nonlinear effects in your numerical variable. You can achieve this by using a transformation of attribute levels, e.g. compute log(50) and log(250) and log(500) and use those levels in your utility function. Alternatively, you can use dummy coding as shown above. You seem to want to do the latter, so you need to use .dummy for ALL your parameters since you have used dummy coding in model estimation to obtain your parameter estimates (otherwise it is not possible to get 2 or more parameter values for a single attribute).

I suggest that you read more into the use of dummy coding, there is a lot of literature on this (not only in choice modelling but also in linear regression).

With dummy coding, the base level indeed has utility 0, you only estimate the parameters of the other attribute levels. So you need to omit 0 from the list of priors since you are not estimating this parameter.

In your pre-test you did not specify dummy coding so you actually optimised your design for a linear model with levels 0,1,2... (design coding). Not a problem but the design will have lost efficiency since you did not optimise on the model you were going to use in model estimation (which is using dummy coding and has many more parameters).

Michiel
Michiel Bliemer
 
Posts: 1727
Joined: Tue Mar 31, 2009 4:13 pm

Re: Error

Postby Michiel Bliemer » Fri Sep 24, 2021 8:03 am

There is a large number of issues in your syntax. You have added all attributes TWICE in your utility function, you are referring to attributes that do not exist (e.g., pa_2) in your constraints, you do not have a consistent number of levels and parameters for certain attributes, the number of rows is likely too low, you may want to let Ngene check for dominant alternatives, etc. Please make sure that you write your syntax carefully and that you select appropriate coding schemes. You may want to read books on discrete choice modelling written by Kenneth Train or by Hensher, Rose, and Greene.

Below some of my comments in your syntax:

Code: Select all
design
;alts = altA, altB, sq   ? You may want to check for dominant alternatives by adding an asterisk after altA and altB
;rows = 9   ? this is likely not enough to estimate so many parameters. You may want to increase the number of rows and block the design
;eff = (mnl, d)
;cond:
if(altA.pa_1 = 0, altB.pa_1 = [1,2]),  ? pa_2 did not exist, changed to pa_1
if(altA.pa_1 = 1, altB.pa_1 = [0,2]),
if(altA.pa_1 = 2, altB.pa_1 = [0,1]),
if(altA.an_1 = 0, altB.an_1 = [1,2,3]), ? an_2 did not exist
if(altA.an_1 = 1, altB.an_1 = [0,2,3]),
if(altA.an_1 = 2, altB.an_1 = [0,1,3]),
if(altA.an_1 = 3, altB.an_1 = [0,1,2]),
if(altA.e_1 = 0, altB.e_1 = [1,2]),  ? e_2 did not exist
if(altA.e_1 = 1, altB.e_1 = [0,2]),
if(altA.e_1 = 2, altB.e_1 = [0,1]),
if(altA.vb_1 = 0, altB.vb_1 = [1,2]), ? vb_2 did not exist
if(altA.vb_1 = 1, altB.vb_1 = [0,2]),
if(altA.vb_1 = 2, altB.vb_1 = [0,1]),
if(altA.sr_1 = 0, altB.sr_1 = [1,2]),
if(altA.sr_1 = 1, altB.sr_1 = [0,2]),
if(altA.sr_1 = 2, altB.sr_1 = [0,1])


;model:
U(altA) = b1.dummy[-0.07163|0.25366]          * pa_1[0,1,2]   ? 0 = ..., 1 = ..., 2 = ... (base)
        + b2.dummy[-0.67552|1.47051|1.04867]  * an_1[0,1,2,3] ? 0 = ..., 1 = ..., 2 = ..., 3 = ... (base)
        + b3[-0.07081]                        * e_1[0,1,2]    ? this attribute is not coded correctly, you it either requires actual levels or you need to dummy code it, you should never use design coding for numerical attributes
        + b4.dummy[1.49265|0.33746]           * vb_1[0,1,2]   ? 0 = ..., 1 = ..., 2 = ... (base)
        + b5.dummy[-0.32552|-0.23736|0.63482] * sr_1[0,1,2,3]   ? this attribute is not coded correctly, it had 3 levels and 3 parameters; perhaps you mean 4 levels? I increased the number of levels
        /     
U(altB) = b1.dummy * pa_1
        + b2.dummy * an_1
        + b3       * e_1
        + b4.dummy * vb_1
        + b5.dummy * sr_1
        /
U(sq)   = b6[-0.07195]
$


Michiel
Michiel Bliemer
 
Posts: 1727
Joined: Tue Mar 31, 2009 4:13 pm

Re: Error

Postby Nina » Fri Sep 24, 2021 4:51 pm

Thank you Michiel for the prompt response and explanation.
I have integrated your comments into the Synatx but unfortunately I still get the error:
Error: The 'model' property contains a prior that has dummy or effects coding without an appropriate suffix. 'b1'

The attributes and levels of my two alternatives are the same and should be combined so that both alternatives do not represent the same level (that's why I put the restrictions in).
How can I integrate the priors that received the value 0 in the pretest? (value = because they are the base)

my numeric variables are:
e : stands for distance (200m, 500m, 700m)
and sr : stands for a reduction of 20%, 50% and 70%

my categorical variables are:
pa : Parking spots (Garage,...)
an
vb

design
;alts = altA, altB, status quo
;rows = 9
;eff = (mnl, d)
;cond:
if(altA.pa = 0, altB.pa = [1,2]),
if(altA.pa = 1, altB.pa = [0,2]),
if(altA.pa = 2, altB.pa = [0,1]),
if(altA.an = 0, altB.an = [1,2,3]),
if(altA.an = 1, altB.an = [0,2,3]),
if(altA.an = 2, altB.an = [0,1,3]),
if(altA.an = 3, altB.an = [0,1,2]),
if(altA.e = 200, altB.e = [500,700]),
if(altA.e = 500, altB.e = [200,700]),
if(altA.e = 700, altB.e = [200,500]),
if(altA.vb = 0, altB.vb = [1,2]),
if(altA.vb = 1, altB.vb = [0,2]),
if(altA.vb = 2, altB.vb = [0,1]),
if(altA.sr = 20, altB.sr = [50,70]),
if(altA.sr = 50, altB.sr = [20,70]),
if(altA.sr = 70, altB.sr = [20,50])


;model:
U(altA) = b1[-0.07163|0.25366|n]*pa[0,1,2]
+ b2[-0.67552|1.47051|1.04867|n]*an[0,1,2,3]
+ b3[-0.07081]*e[200,500,700]
+ b4[1.49265|0.33746|n]*vb[0,1,2]
+ b5[-0.32552|-0.23736|0.63482]*sr[20,50,70]
+ b1.dummy[-0.07163|0.25366]*pa[0,1,2]
+ b2.dummy[-0.67552|1.47051|1.04867]*an[0,1,2,3]
+ b4.dummy[1.49265|0.33746]*vb[0,1,2]
/

U(altB) = b6[-0.07163|0.25366|n]*pa[0,1,2]
+ b7[-0.67552|1.47051|1.04867|n]*an[0,1,2,3]
+ b8[-0.07081]*e[200,500,700]
+ b9[1.49265|0.33746|n]*vb[0,1,2]
+ b10[-0.32552|-0.23736|.63482]*sr[20,50,70]
+ b6.dummy[-0.07163|0.25366]*pa[0,1,2]
+ b7.dummy[-0.67552|1.47051|1.04867]*an[0,1,2,3]
+ b9.dummy[1.49265|0.33746]*vb[0,1,2]
/

U(status quo) = b10[-0.07195]

$

Thank you very much for helping me!
Nina
 
Posts: 5
Joined: Tue Sep 21, 2021 8:29 pm

Re: Error

Postby Michiel Bliemer » Sun Sep 26, 2021 9:00 am

Did you look in the syntax I posted? I already fixed most of it for you, for example:

b1.dummy[-0.07163|0.25366] * pa_1[0,1,2]

You do not need to put in the zero for the last level, this is the base and is automatically done by Ngene. You need to use .dummy.

You seem to have dummy coded numerical attribute sr: b10[-0.32552|-0.23736|.63482]*sr[20,50,70]
With 3 levels, you can only have 2 dummy coefficients (the third defaults to zero).

Michiel
Michiel Bliemer
 
Posts: 1727
Joined: Tue Mar 31, 2009 4:13 pm

Re: Error

Postby Nina » Mon Sep 27, 2021 9:57 pm

Hi Michiel,

yes, I looked at the syntax and now I understand the problem with the dummy coding! Thank you!


design
;alts = altA, altB, status quo
;rows = 9
;eff = (mnl, d)
;cond:
if(altA.pa = 0, altB.pa = [1,2]),
if(altA.pa = 1, altB.pa = [0,2]),
if(altA.pa = 2, altB.pa = [0,1]),
if(altA.an = 0, altB.an = [1,2,3]),
if(altA.an = 1, altB.an = [0,2,3]),
if(altA.an = 2, altB.an = [0,1,3]),
if(altA.an = 3, altB.an = [0,1,2]),
if(altA.e = 200, altB.e = [500,700]),
if(altA.e = 500, altB.e = [200,700]),
if(altA.e = 700, altB.e = [200,500]),
if(altA.vb = 0, altB.vb = [1,2]),
if(altA.vb = 1, altB.vb = [0,2]),
if(altA.vb = 2, altB.vb = [0,1]),
if(altA.sr = 20, altB.sr = [50,70]),
if(altA.sr = 50, altB.sr = [20,70]),
if(altA.sr = 70, altB.sr = [20,50])


;model:
U(altA) = b1.dummy[-0.07163|0.25366]*pa[0,1,2] + b2.dummy[-0.67552|1.47051|1.04867]*an[0,1,2,3] + b3[-0.07081]*e[200,500,700] + b4.dummy[1.49265|0.33746]*vb[0,1,2] + b5[-0.32552|-0.23736|0.63482]*sr[20,50,70]/
U(altB) = b1.dummy*pa + b2.dummy*an + b3*e + b4.dummy*vb + b5*sr /
U(status quo) = b6[-0.07195]

$

--> sr is a numeric variable --> i didn't dummy code this variable
20% gets the prior -0.32552
50% -0.23736
70% 0.63482

My Error is now:
Error: The 'model' property contains a prior that has dummy or effects coding without an appropriate suffix. 'b5'
Nina
 
Posts: 5
Joined: Tue Sep 21, 2021 8:29 pm

Re: Error

Postby Nina » Mon Sep 27, 2021 9:57 pm

Hi Michiel,

yes, I looked at the syntax and now I understand the problem with the dummy coding! Thank you!


design
;alts = altA, altB, status quo
;rows = 9
;eff = (mnl, d)
;cond:
if(altA.pa = 0, altB.pa = [1,2]),
if(altA.pa = 1, altB.pa = [0,2]),
if(altA.pa = 2, altB.pa = [0,1]),
if(altA.an = 0, altB.an = [1,2,3]),
if(altA.an = 1, altB.an = [0,2,3]),
if(altA.an = 2, altB.an = [0,1,3]),
if(altA.an = 3, altB.an = [0,1,2]),
if(altA.e = 200, altB.e = [500,700]),
if(altA.e = 500, altB.e = [200,700]),
if(altA.e = 700, altB.e = [200,500]),
if(altA.vb = 0, altB.vb = [1,2]),
if(altA.vb = 1, altB.vb = [0,2]),
if(altA.vb = 2, altB.vb = [0,1]),
if(altA.sr = 20, altB.sr = [50,70]),
if(altA.sr = 50, altB.sr = [20,70]),
if(altA.sr = 70, altB.sr = [20,50])


;model:
U(altA) = b1.dummy[-0.07163|0.25366]*pa[0,1,2] + b2.dummy[-0.67552|1.47051|1.04867]*an[0,1,2,3] + b3[-0.07081]*e[200,500,700] + b4.dummy[1.49265|0.33746]*vb[0,1,2] + b5[-0.32552|-0.23736|0.63482]*sr[20,50,70]/
U(altB) = b1.dummy*pa + b2.dummy*an + b3*e + b4.dummy*vb + b5*sr /
U(status quo) = b6[-0.07195]

$

--> sr is a numeric variable --> i didn't dummy code this variable
20% gets the prior -0.32552
50% -0.23736
70% 0.63482

My Error is now:
Error: The 'model' property contains a prior that has dummy or effects coding without an appropriate suffix. 'b5'
Nina
 
Posts: 5
Joined: Tue Sep 21, 2021 8:29 pm

Re: Error

Postby Michiel Bliemer » Tue Sep 28, 2021 10:45 am

I am not sure what software you are using to estimate the model, but if you did not dummy code attribute sr then you can only have ONE parameter estimate, NOT THREE. So please check your estimation software to see how these parameters as estimated, as currently it looks like dummy coding.

It should be the same for attribute e:

b3[-0.07081]*e[200,500,700]

There you can see that there is only ONE prior for 3 attributes.

Michiel
Michiel Bliemer
 
Posts: 1727
Joined: Tue Mar 31, 2009 4:13 pm


Return to Choice experiments - Ngene

Who is online

Users browsing this forum: No registered users and 11 guests