Estimating Models with Interactions

Interactions with continuous variables

To add interactions between coefficients in your model, you can add additional arguments in the parNames vector in the logitr() function separated by the * symbol. For example, let’s say we want to interact price with feat in the following model:

model <- logitr(
  data       = yogurt,
  choiceName = 'choice',
  obsIDName  = 'obsID',
  parNames   = c('price', 'feat', 'brand')
)

To do so, I could add "price*feat" to the parNames vector:

model_price_feat <- logitr(
  data       = yogurt,
  choiceName = 'choice',
  obsIDName  = 'obsID',
  parNames   = c('price', 'feat', 'brand', 'price*feat')
)
#> Running Model...
#> Done!

The model now has an estimated coefficient for the price*feat effect:

summary(model_price_feat)
#> =================================================
#> MODEL SUMMARY: 
#>                           
#> Model Space:    Preference
#> Model Run:          1 of 1
#> Iterations:             19
#> Elapsed Time:  0h:0m:0.13s
#> Exit Status:             3
#> Weights Used?:       FALSE
#> robust?              FALSE
#> 
#> Model Coefficients: 
#>               Estimate StdError    tStat   pVal signif
#> price        -0.357210 0.024704 -14.4595 0.0000    ***
#> feat          1.155939 0.378222   3.0562 0.0023     **
#> brandhiland  -3.726000 0.146553 -25.4243 0.0000    ***
#> brandweight  -0.640484 0.054546 -11.7420 0.0000    ***
#> brandyoplait  0.725047 0.080338   9.0249 0.0000    ***
#> price:feat   -0.086365 0.047272  -1.8270 0.0678      .
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Model Fit Values: 
#>                                      
#> Log-Likelihood:         -2655.5402257
#> Null Log-Likelihood:    -3343.7419990
#> AIC:                     5323.0805000
#> BIC:                     5357.8097000
#> McFadden R2:                0.2058178
#> Adj McFadden R2:            0.2040234
#> Number of Observations:  2412.0000000

Interactions with discrete variables

In the above example, both price and feat were continuous variables, so only a single interaction coefficient was needed.

In the case of interacting discrete variables, multiple interactions coefficients will be estimated according to the number of levels in the discrete attribute. For example, the interaction of price with brand will require three new interactions - one for each level of the brand variable except the first “baseline” level:

model_price_brand <- logitr(
  data       = yogurt,
  choiceName = 'choice',
  obsIDName  = 'obsID',
  parNames   = c('price', 'feat', 'brand', 'price*brand')
)
#> Running Model...
#> Done!

The model now has three estimated coefficients for the price*brand effect:

summary(model_price_brand)
#> =================================================
#> MODEL SUMMARY: 
#>                           
#> Model Space:    Preference
#> Model Run:          1 of 1
#> Iterations:             39
#> Elapsed Time:  0h:0m:0.22s
#> Exit Status:             3
#> Weights Used?:       FALSE
#> robust?              FALSE
#> 
#> Model Coefficients: 
#>                     Estimate StdError   tStat   pVal signif
#> price              -0.389516 0.045247 -8.6087 0.0000    ***
#> feat                0.421915 0.122579  3.4420 0.0006    ***
#> brandhiland        -1.692200 0.623159 -2.7155 0.0067     **
#> brandweight        -2.228626 0.561644 -3.9680 0.0001    ***
#> brandyoplait        0.438687 0.450428  0.9739 0.3302       
#> price:brandhiland  -0.434193 0.115532 -3.7582 0.0002    ***
#> price:brandweight   0.199939 0.069830  2.8632 0.0042     **
#> price:brandyoplait  0.033239 0.050372  0.6599 0.5094       
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Model Fit Values: 
#>                                      
#> Log-Likelihood:         -2643.2046779
#> Null Log-Likelihood:    -3343.7419990
#> AIC:                     5302.4094000
#> BIC:                     5348.7150000
#> McFadden R2:                0.2095070
#> Adj McFadden R2:            0.2071145
#> Number of Observations:  2412.0000000

Interactions in mixed logit models

Suppose I want to include an interaction between two variables and I also want one of those variables to be modeled as normally distributed across the population. The example below illustrates this cases, where a price*feat interaction is specified and the feat parameter is modeled as normally distributed by setting randPars = c(feat = "n"):randPars = c(feat = “n”)

model_price_feat_mxl <- logitr(
  data       = yogurt,
  choiceName = 'choice',
  obsIDName  = 'obsID',
  parNames   = c('price', 'feat', 'brand', 'price*feat'),
  randPars   = c(feat = "n")
)
#> Running Model...
#> Done!

In this case, the price*feat interaction parameter is interpreted as a difference in the feat_mu parameter and price; that is, it an interaction in the mean feat parameter and price:

summary(model_price_feat_mxl)
#> =================================================
#> MODEL SUMMARY: 
#>                          
#> Model Space:   Preference
#> Model Run:         1 of 1
#> Iterations:            33
#> Elapsed Time:   0h:0m:19s
#> Exit Status:            3
#> Weights Used?:      FALSE
#> robust?             FALSE
#> 
#> Model Coefficients: 
#>               Estimate StdError    tStat   pVal signif
#> price        -0.388106 0.027025 -14.3609 0.0000    ***
#> feat_mu       0.829946 0.552190   1.5030 0.1330       
#> brandhiland  -3.991534 0.165896 -24.0605 0.0000    ***
#> brandweight  -0.662058 0.055779 -11.8693 0.0000    ***
#> brandyoplait  0.787710 0.086231   9.1349 0.0000    ***
#> price:feat   -0.076849 0.071061  -1.0815 0.2796       
#> feat_sigma    2.341117 0.493312   4.7457 0.0000    ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Model Fit Values: 
#>                                      
#> Log-Likelihood:         -2645.2196914
#> Null Log-Likelihood:    -3343.7419990
#> AIC:                     5304.4394000
#> BIC:                     5344.9569000
#> McFadden R2:                0.2089044
#> Adj McFadden R2:            0.2068109
#> Number of Observations:  2412.0000000
#> 
#> Summary of 10k Draws for Random Coefficients: 
#>        Min.    1st Qu.    Median      Mean 3rd Qu.     Max.
#> 1 -8.269304 -0.7507041 0.8281574 0.8266687 2.40648 9.284091