melff / mclogit

mclogit: Multinomial Logit Models, with or without Random Effects or Overdispersion
http://melff.github.io/mclogit/
22 stars 4 forks source link

Fixed dynamic formulas in mblogit with random effect #17

Closed yalchik closed 3 years ago

yalchik commented 3 years ago

Dear Prof. Dr. Martin Elff,

My name is Ilya Yalchyk, I'm a master student in the University of Bonn, and a research assistant in Fraunhofer SCAI. I'm using your library for our research for Alzheimer's disease.

I've noticed a problem that made it hard for me to use your library. Let's consider an example with a random effect:

library(MASS)
house.mblogit <- mblogit(Sat ~ Infl + Cont, weights = Freq, data = housing, random = ~1|Type)

It converges.

But if we change the way how we provide the formula:

house.mblogit <- mblogit(as.formula("Sat ~ Infl + Cont"), weights = Freq, data = housing, random = ~1|Type)

It produces the following error:

Error in terms.formula(tmp, simplify = TRUE): invalid model formula in ExtractVars

If we provide the formula as a variable:

f <- Sat ~ Infl + Cont
house.mblogit <- mblogit(f, weights = Freq, data = housing, random = ~1|Type)

It produces another error:

Error in attributes(.Data) <- c(attributes(.Data), attrib): cannot set attribute on a symbol

In this pull request, I suggest a simple fix for this problem. I hope it will be useful.

Yours sincerely, Ilya Yalchyk

melff commented 3 years ago

That is helpful. Many thanks!