Page 1 of 1

Lagged latent variable

Posted: 14 Oct 2022, 14:58
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

Re: Lagged latent variable

Posted: 17 Oct 2022, 12:18
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