I'm trying to use the mlogit package in R in order to make a choice model on a panel dataset. For this, I have successfully specified the data in mlogit.data form. The y variable consists of TRUE / FALSE indicating the choice, the service variable consists of all choice options, and the id variable consists of all individuals who make the choices.
data <- mlogit.data(df, choice = "y",
shape = "long",
alt.var = "service",
id.var = "id")
Considering that I get the following error:
Error in str2lang(x) : <text>:2:0: unexpected end of input
1: . ~ . |
^
I'm assuming that I'm misspecifying my formula. I've tried to specify it in the following two manners, yet both result in the same error.
f1 <- mFormula(y ~ x1 + x2) # does not throw error
head(model.matrix(f1, data), 2) # throws the error
model1 <- mlogit(f1, data = data,
rpar = c(x1 = "n",
x2 = "n"),
panel = TRUE) # throws the error
and
f2 <- y ~ x1 + x2 # does not throw the error
head(model.matrix(f2, data), 2) # does not throw error
model2 <- mlogit(f2, data = data,
rpar = c(x1 = "n",
x2 = "n"),
panel = TRUE) # throws the error
The variables that I'm using in my formula are alternative-specific, meaning that for service s at period t, the variables have the same values.
Does anyone know what is causing the error? Thanks in advance!