Page 1 of 1

Coding interaction effects in RPL model

Posted: 17 Oct 2020, 16:35
by MattTDL
I'm trying to specify an RPL model with interaction effects between variables. I'm having some issues understanding the syntax of how this is done in Apollo.

Suppose I have two attributes and two alternatives, and I want to estimate the mean and standard deviation of the two attributes and the interaction between them. I.e., I want to estimate mu of b1, mu of b2, and mu of b1*b2, along with the inter-subject SD of each. Would someone be willing to point out how to do this?

Here's a mock-up of the code I have:

apollo_beta=c(
mu_b1 = 0
mu_b2 = 0
mu_b1_b2 = 0 ## This is the key variable I want to estimate (b1*b2)
sigma_b1 = 0
sigma_b2 = 0
sigma_b1_b2 = 0
)

apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 100,
interUnifDraws = c(),
interNormDraws = c(
"inter_draws_b1",
"inter_draws_b2",
"inter_draws_b1_b2
)
)

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

randcoeff[["b_X1"]] = mu_b1 + sigma_b1 * inter_draws_b1
randcoeff[["b_X2"]] = mu_b2 + sigma_b2 * inter_draws_b2

randcoeff[["b_X1_X2"]] = mu_b1_b2 + sigma_b1_b2 * inter_draws_b1_b2 ## I'm unsure about how to specify the coefficient

return(randcoeff)
}

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
## skipping some code
P = list()
V = list()
V[['Alt1']] = b_X1 * Alt1_X1 +
b_X2 * Alt1_X2 +
b_X1_X2 ## I'm unsure about how to specify the utility function for alternative 1

V[['Alt2']] = b_X1 * Alt2_X1 +
b_X2 * Alt2_X2 +
b_X1_X2 ## I'm unsure about how to specify the utility function for alternative 1

## skipping some code
}

Thanks!

Re: Coding interaction effects in RPL model

Posted: 21 Oct 2020, 18:18
by stephanehess
Hi

I think part of the confusion arises here as black box software doesn't make clear what interactions actually are. What you're looking for here is to model the interaction between the attributes, not the parameters, so it should say that you're estimating a mu for X1*X2, not b1*b2

The only change in your specification that is actually needed is

Code: Select all

V[['Alt1']] = b_X1 * Alt1_X1 + 
b_X2 * Alt1_X2 +
b_X1_X2 * Alt1_X1 * Alt1_X2

V[['Alt2']] = b_X1 * Alt2_X1 + 
b_X2 * Alt2_X2 +
b_X1_X2 * Alt2_X1 * Alt2_X2

Re: Coding interaction effects in RPL model

Posted: 26 Oct 2020, 16:52
by MattTDL
Ok thank you for the reply. I implemented the change in the specification you suggested, and the code runs.

Earlier, I had tried a 'hack' solution of creating new interaction variables outside of Apollo by multiplying the variables in the database together using base R prior to specifying the attributes. The outputs are essentially the same when I follow what you recommend vs my 'hack'.

//

I have one final question - I centered the original variables prior to multiplying them together to create interactions, so as to reduce multicollinearity between the original variables and their interaction terms. I take this from standard practice in 'normal' logistic regression, but does this also apply to RPL models? I notice the outputs are quite different if I don't center the variables.

//
# Here's a mock-up of my code in case the above isn't clear.

# Center the variables
database$cAlt1_X1 <- database$Alt1_X1 - mean(database$Alt1_X1)
database$cAlt1_X2 <- database$Alt1_X2 - mean(database$Alt1_X2)

# Multiplying one alternative vs another
database$Alt1_X1_X2 <- database$cAlt1_X1 * database$cAlt1_X2
...
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
P = list()
V = list()

V[['Alt1']] = b_X1 * cAlt1_X1 +
b_X2 * cAlt1_X2 +
b_X1_X2 * cAlt1_X1 * cAlt1_X2

V[['Alt2']] = b_X1 * cAlt2_X1 +
b_X2 * cAlt2_X2 +
b_X1_X2 * cAlt2_X1 * cAlt2_X2
...

Re: Coding interaction effects in RPL model

Posted: 11 Nov 2020, 17:25
by stephanehess
Hi

sorry for the slow reply.

I would definitely not mean centre them. Interactions aside, think about the fact that the mean is possibly different for the same attribute for different alternatives. Then you could end up with a situation where in the actual data, x1_alt1>x1_alt2, but with the mean centred one, x1_alt1<x1_alt2

Stephane