Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

Lagged latent variable

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
bastian.henriquez
Posts: 1
Joined: 14 Oct 2022, 14:23

Lagged latent variable

Post by bastian.henriquez »

Hi! I'm trying to use Apollo to run a Latent variable model that explains the latent emotion of public transport users based on environmental information and measured by biometric indicators (skin temperature, heart rate and electrodermal activity). I have two models: (1) without lagged latent emotion and (2) with lagged latent emotion (the latent emotion in time t explains the latent emotion in time t+1, which is reasonable). I was able to run both models with functions made by myself, but I just could run the first model with Apollo (and I get the same results I get with my script). When I try to run the second model, I get this error:

Error in value[[3L]](cond) : unused argument (cond)

This is how I've tried to make the lagged latent variable:

apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["LAT_PPSE"]] = a0+logsum_CO2*a11+logsum_brightness*a21 + logsum_ambientNoise*a31+
var_ambientNoise*a32+logsum_temperature*a41+logsum_humidity*a42+ logsum_temperature*logsum_humidity*a43+
(mode_bus_electric==1)*a44+(mode_bus_conventional==1)*a45+(mode_metro==1 | mode_metro_new==1)*a46+
(sit==1)*a49+th1*(sex_id)+(oc_1B==1)*a51+ (oc_2==1)*a52+(oc_3==1)*a53+(oc_4==1)*a54+wait*a57+(time)*a55+eta

for (i in 2:N){
if (database$id_participant==database$id_participant[i-1]){
randcoeff[["LAT_PPSE"]]<-randcoeff[["LAT_PPSE"]] +a56*randcoeff[["LAT_PPSE"]][i-1]
}
}

return(randcoeff)
}

Where N is the total of observations (1499) and id_participant is the ID of each subject.


Looking forward to your kindly reply.

Bastián Henríquez
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Lagged latent variable

Post by dpalma »

Hi Bastián,

Internally, the random coefficients are stored as matrices, so I would recommend making the following change in your code (note the comma inside the square brackets):

Code: Select all

randcoeff[["LAT_PPSE"]][i,] <- randcoeff[["LAT_PPSE"]][i,] + a56*randcoeff[["LAT_PPSE"]][i-1,]
Let me know if this works. Otherwise, please share your code and script with me to check it in more detail (you can email it to D.Palma [at] leeds.ac.uk)

Best wishes
David
Post Reply