(updated from original post)
I am having a problem plotting marginal effects using sjPlot package, after estimating a choice model using the mlogit package.
Reprex below, including error regarding "subscript out of bounds" . Tips?
NOTE: sjPlot package is apparently compatible with mlogit according to update 2.6.3.
library(mlogit) #> Warning: package 'mlogit' was built under R version 3.6.2 #> Loading required package: dfidx #> Warning: package 'dfidx' was built under R version 3.6.2 #> #> Attaching package: 'dfidx' #> The following object is masked from 'package:stats': #> #> filter library(sjPlot) #> Warning: package 'sjPlot' was built under R version 3.6.2 library(prediction) library(effects) #> Warning: package 'effects' was built under R version 3.6.2 #> Loading required package: carData #> Warning: package 'carData' was built under R version 3.6.2 #> lattice theme set by effectsTheme() #> See ?effectsTheme for details. # create ex. data set. 1 row per respondent (i show 2 respondents). Each resp answers 3 choice sets, w/ 2 alternatives in each set. Unlabeled choice experiemnt cedata.1 <- data.frame( id = c(1,1,1,1,1,1,2,2,2,2,2,2), # respondent ID. QES = c(1,1,2,2,3,3,1,1,2,2,3,3), # Choice set (with 2 alternatives) Alt = c(1,2,1,2,1,2,1,2,1,2,1,2), # Alt 1 or Alt 2 in choice set LOC = c(0,0,1,1,0,1,0,1,1,0,0,1), # attribute describing alternative. binary categorical variable SIZE = c(1,1,1,0,0,1,0,0,1,1,0,1), # attribute describing alternative. binary categorical variable Choice = c(0,1,1,0,1,0,0,1,0,1,0,1), # if alternative is Chosen (1) or not (0) gender = c(1,1,1,1,1,1,0,0,0,0,0,0) # male or female (repeats for each indivdual) ) # create data format for mlogit (i.e., indexes for panel dataset) # NOTE: this generates a "logical" structure for the "choice" (dep variable) cedata.2 <- mlogit.data(cedata.1, shape="long", choice="Choice", alt.var="Alt", id.var="id") # convert dep var Choice to factor (from logical), as required by plot_model cedata.2$Choice <- as.factor(cedata.2$Choice) # estimate model. ce.model1 <- mlogit(Choice ~ -1 + LOC + SIZE | gender, data=cedata.2) # plot Marg effect, based on attribute "SIZE" plot_model(ce.model1, type = "pred", terms = "SIZE") #> Error in tmp[["fit"]]: subscript out of bounds # Need help with error above: "subscript out of bounds" ??