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:
<- logitr(
model data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('price', 'feat', 'brand')
)
To do so, I could add "price*feat"
to the parNames
vector:
<- logitr(
model_price_feat 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.1s
#> Weights Used?: 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 **
#> brand_hiland -3.726000 0.146553 -25.4243 0.0000 ***
#> brand_weight -0.640484 0.054546 -11.7420 0.0000 ***
#> brand_yoplait 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
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:
<- logitr(
model_price_brand 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.32s
#> Weights Used?: 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 ***
#> brand_hiland -1.692200 0.623159 -2.7155 0.0067 **
#> brand_weight -2.228626 0.561644 -3.9680 0.0001 ***
#> brand_yoplait 0.438687 0.450428 0.9739 0.3302
#> price*brand_hiland -0.434193 0.115532 -3.7582 0.0002 ***
#> price*brand_weight 0.199939 0.069830 2.8632 0.0042 **
#> price*brand_yoplait 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
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”)
<- logitr(
model_price_feat_mxl 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_brand)
#> =================================================
#> MODEL SUMMARY:
#>
#> Model Space: Preference
#> Model Run: 1 of 1
#> Iterations: 39
#> Elapsed Time: 0h:0m:0.32s
#> Weights Used?: 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 ***
#> brand_hiland -1.692200 0.623159 -2.7155 0.0067 **
#> brand_weight -2.228626 0.561644 -3.9680 0.0001 ***
#> brand_yoplait 0.438687 0.450428 0.9739 0.3302
#> price*brand_hiland -0.434193 0.115532 -3.7582 0.0002 ***
#> price*brand_weight 0.199939 0.069830 2.8632 0.0042 **
#> price*brand_yoplait 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