Discrete Choice Experiment (mlogit)

Hi there!

I am currently working on a discrete choice experiment. I have collected all my data and formatted/organized it in excel (see screenshot of my dataset in Rstudio).

I am currently trying to carry out coefficient estimation via the mlogit package. However.. I am not really an R/Rstudio guru so I am having trouble using the right coding.

I have already loaded my excel file into the Rstudio Library, loaded the required packages and formed an mlogit.data set. However.. I am most likely not doing it right as I now keep getting errors. I have also attached a screenshot of the code I entered into Rstudio.

My question now is; looking at my data in excel, have I entered the right code into the mlogit.data function. And what do I enter into the mlogit function. Really hoping someone has experience with this mlogit package and could help me.

Thanks in advance!


I am not familiar with the mlogit package and a quick look at the documentation did not make it clear to me everything you need to do. However, one problem is likely that in your call to mlogit() you have elements of the formula in single quotes. You should use the bare column names instead. The formula definitions in R generally take the bare column names.

choice ~ Crowding + Congestion + Number_of_Stops + Distance | Gender + Age + Daily_distance

Notice that I have added underscores to the column names that include spaces. Though it is possible to have column names with spaces, it is a source of needless trouble and you should just avoid it.
I hope that helps some.

Thank you for your reply! I have tried doing it like this but it still gives me an error somehow. The error it gives is:

Error: unexpected symbol in:
"cyclemodel <- mlogit(choice ~ Crowding + Congestion + Number_of_Stops + Distance | 
                       Gender + Age + Daily_Distance"

The ultimate goal is to do coefficient estimation once the model is set with the summary function. I have inserted my Rcode below for some clarification

#load data via window to the right
cycleroute <- read_excel("Cycling Route Survey Data - R versie.xlsx")

#mlogit data
cyclemlogit <- mlogit.data(cycleroute, choice = "Choice", shape = "long", alt.var = "Alternative")

#model
cyclemodel <- mlogit(choice ~ Crowding + Congestion + Number_of_Stops + Distance | 
                       Gender + Age + Daily_Distance, data = cyclemlogit)

A non syntactic name should be quoted with backtick symbols, but it is probably better to rename it earlier in your workflow

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.