ICLV panel data:NameError: name 'condlike' is not defined

79 views
Skip to first unread message

Eva Lin

unread,
Mar 8, 2023, 10:01:07 AM3/8/23
to Biogeme
Dear professor  Bierlaire and everyone,

I have SP data set with 168 individuals and each individual choose one of three alternatives. The same individual repeated the choice 16 times (i.e., nbrQuestions = 16).

I am trying to build ICLV panel with one latent. I ran an ICLV model without considering panel effect and it worked successfully. I have four questions on my script. Please provide some solutions:

(1) Does the database.panel("ID") and nbrQuestions = 16 appear together?

(2) The fist error:
    <ipython-input-8-fba877a3a6d3> in <listcomp>(.0)
1 CAR_AV_SP = [ ----> 2 database.DefineVariable( 3 f'CAR_AV_SP_{q}', Variable(f'CAR_AV_{q}') * (SP != 0) 4 ) 5 for q in range(nbrQuestions) AttributeError: 'Database' object has no attribute 'DefineVariable'

 I changed the above code into this. Is this correct?
  CAR_AV_SP = Variable(f'CAR_AV_SP_{q}')
  CAR_AV_SP = [Variable(f'CAR_AV_SP_{q}') * (SP  != 0  ) for q in range(nbrQuestions)]

(3) The other error is following. I don't know how to deal with this problem.
    biogemeError Traceback (most recent call last)
<ipython-input-85-df35f7379bd7> in <module> ----> 1 condlike = P_CF1 * \ 2 P_CF2 * \ 3 P_CF3 * \ 4 obslogprob D:\ANACONDA\lib\site-packages\biogeme\expressions.py in __mul__(self, other) 204 f'to {self}: [{other}]' 205 ) --> 206 raise excep.biogemeError(error_msg) 207 return Times(self, other) 208 biogemeError: Invalid expression during multiplication

(4) Which is more appropriate in the script, a or b?
      a) condprobIndiv = PanelLikelihoodTrajectory(condlike)
      b) condprobIndiv = exp(bioMultSum(condlike))

Regards,
Eva

panel1.ipynb

jing ma

unread,
Apr 23, 2023, 2:04:55 PM4/23/23
to Biogeme

Hello Eva,

 

Have you solved this problem? I have encountered a similar problem and I hope I can ask you for advice.

 

Best regards,

Jing

Bierlaire Michel

unread,
Apr 23, 2023, 2:20:54 PM4/23/23
to w1918...@gmail.com, Bierlaire Michel, Biogeme
Sorry. It seems that I have missed this message.
My responses below.

> On 8 Mar 2023, at 17:44, Eva Lin <w1918...@gmail.com> wrote:
>
> Dear professor Bierlaire and everyone,
>
> I have SP data set with 168 individuals and each individual choose one of three alternatives. The same individual repeated the choice 16 times (i.e., nbrQuestions = 16).
>
> I am trying to build ICLV panel with one latent. I ran an ICLV model without considering panel effect and it worked successfully. I have four questions on my script. Please provide some solutions:
>
> (1) Does the database.panel("ID") and nbrQuestions = 16 appear together?

What do you mean? When you declare the data “panel” using the ID column, it means that this column identifies the individuals. All the observations corresponding to the same individual are grouped together. It does not have to be a fixed number. If it happens to be 16, fine, but you do not need to mention it.

>
> (2) The fist error:
> <ipython-input-8-fba877a3a6d3> in <listcomp>(.0)
> 1 CAR_AV_SP = [ ----> 2 database.DefineVariable( 3 f'CAR_AV_SP_{q}', Variable(f'CAR_AV_{q}') * (SP != 0) 4 ) 5 for q in range(nbrQuestions) AttributeError: 'Database' object has no attribute 'DefineVariable'


The “DefineVariable” function has been included in the database object starting from version 3.2.10. How is “database” defined? If it is like in the examples, the error message seems to mention that you are using an older version of the package.
By the way, 3.2.11 just went out.

>
> I changed the above code into this. Is this correct?
> CAR_AV_SP = Variable(f'CAR_AV_SP_{q}')
> CAR_AV_SP = [Variable(f'CAR_AV_SP_{q}') * (SP != 0 ) for q in range(nbrQuestions)]

It is better to use DefineVariable, as it defines a new column in the database, so that the calculations are done once for all. With the above syntax, the same calculations will be done again and again.

>
> (3) The other error is following. I don't know how to deal with this problem.
> biogemeError Traceback (most recent call last)
> <ipython-input-85-df35f7379bd7> in <module> ----> 1 condlike = P_CF1 * \ 2 P_CF2 * \ 3 P_CF3 * \ 4 obslogprob D:\ANACONDA\lib\site-packages\biogeme\expressions.py in __mul__(self, other) 204 f'to {self}: [{other}]' 205 ) --> 206 raise excep.biogemeError(error_msg) 207 return Times(self, other) 208 biogemeError: Invalid expression during multiplication

This exception is raised when one of the two factors of the multiplication is not of type biogeme.expressions.Expression, or a number. You need to display the type of the objects involved to track the cause of the problem.

>
> (4) Which is more appropriate in the script, a or b?
> a) condprobIndiv = PanelLikelihoodTrajectory(condlike)
> b) condprobIndiv = exp(bioMultSum(condlike))

There are two completely different things. The PanelLikelihoodTrajectory calculates the likelihood of a sequence of observations for the same individual. The bioMultSum is the sum of various expressions applied on the same observation.


>
> Regards,
> Eva
>
>
> --
> You received this message because you are subscribed to the Google Groups "Biogeme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/5575a0e5-b2a3-40c4-a8d0-cfb85e111725n%40googlegroups.com.
> <panel1.ipynb>

Michel Bierlaire
Transport and Mobility Laboratory
School of Architecture, Civil and Environmental Engineering
EPFL - Ecole Polytechnique Fédérale de Lausanne
http://transp-or.epfl.ch
http://people.epfl.ch/michel.bierlaire

Reply all
Reply to author
Forward
0 new messages