Multinomial model with random effects to study social interactions

Hello,

I would be very much interested to use a multinomial model with random effects (for a mixed multinomial logistic regression using R).

For the present study, I already analysed independent variables with 2 categories using models of this type:

modele<-glmer(A~ B + C
+(1|Ra)+(1|Rb),family=“binomial”,data=table1)

My independent variable was “A” (with 2 nominal categories).
My two fixed variables were “B” (with 2 nominal categories) and “C” (with 3 nominal categories).
My two random variables were “Ra” and “Rb”.

However, I also have to analyse independent variables with 3 or more nominal categories.
Could you please tell me how I can use “bmrs” for mixed multinomial models? For instance by giving me an example to analyse the independent variable “X” (3 nominal categories) with the same fixed and random variables that I mentioned above.

I thank you very much in advance for your response and your help.
Best regards,

code_to_run_my_model(brms?)
  • Operating System: Windows 7 Professional
  • brms Version: 2.14.4

Hi, sorry it took so long to reply!

If you have an outcome that is categorical (not ordered categorical) then you can use the categorical() or multinomial() families in brms, e.g., if y consists of >2 categories, and you have two population-level predictors and two group-level predictors one way to model it in brms could be,

brm(y ~ B + C + (1 | Ra) + (1 | Rb), family = cumulative, data = d)

If you want to set a prior on a two-level predictor then it might be sane to code it as 1/2 and not 0/1 in order to set priors in a more straightforward way.

2 Likes

Hi Torkar,
Thanks a lot for your message and your help.

Following your advice, I ran this model:
brm(y ~ B + C + (1 | Ra) + (1 | Rb), family = categorical, data = d)

However, I got these error and warning messages:
Compiling Stan program…
trying URL ‘https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe
Content type ‘application/x-msdownload’ length 108622512 bytes (103.6 MB)
downloaded 103.6 MB

trying URL ‘https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe
Content type ‘application/x-msdownload’ length 108622512 bytes (103.6 MB)
downloaded 103.6 MB

make cmd is
make -f “C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-36~1.3/share/make/winshlib.mk” CXX=’(CXX11) (CXX11STD)’ CXXFLAGS=’(CXX11FLAGS)' CXXPICFLAGS='(CXX11PICFLAGS)’ SHLIB_LDFLAGS=’(SHLIB_CXX11LDFLAGS)' SHLIB_LD='(SHLIB_CXX11LD)’ SHLIB=“file782420b470fc.dll” WIN=64 TCLBIN=64 OBJECTS=“file782420b470fc.o”

make would use
if test “zfile782420b470fc.o” != “z”; then
if test -e “file782420b470fc-win.def”; then
echo C:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o file782420b470fc.dll file782420b470fc-win.def file782420b470fc.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
C:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o file782420b470fc.dll file782420b470fc-win.def file782420b470fc.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
C:/Rtools/mingw_64/bin/nm file782420b470fc.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^ ][^ ]*/"&"/g’ >> tmp.def;
echo C:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o file782420b470fc.dll tmp.def file782420b470fc.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
C:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o file782420b470fc.dll tmp.def file782420b470fc.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
rm -f tmp.def;
fi
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
file782420b470fc.o:file782420b470fc.cpp:(.data$_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2P1[_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2P1]+0x0): first defined hereC:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2Q2[_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2Q2]+0x0): multiple definition of `long double boost::math::detail::bessel_y0<long double, boost::ma
In addition: Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
display list redraw incomplete
2: In doTryCatch(return(expr), name, parentenv, handler) :
invalid graphics state
3: In doTryCatch(return(expr), name, parentenv, handler) :
invalid graphics state
4: Rows containing NAs were excluded from the model.
5: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘-E’ not found
Error in sink(type = “output”) : invalid connection

Could you please help me to solve these issues?
Many thanks in advance for your response.
Best regards,

Hi, that looks like a windows specific problem you have with your installation. Please start a new thread.

Thanks for your quick reply.
I closed my session and reopened Rstudio to run the above-mentioned model again. However, I got these error and warning messages:

Compiling Stan program…
make cmd is
make -f “C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-36~1.3/share/make/winshlib.mk” CXX=’(CXX11) (CXX11STD)’ CXXFLAGS=’(CXX11FLAGS)' CXXPICFLAGS='(CXX11PICFLAGS)’ SHLIB_LDFLAGS=’(SHLIB_CXX11LDFLAGS)' SHLIB_LD='(SHLIB_CXX11LD)’ SHLIB=“file106047a54bf1.dll” WIN=64 TCLBIN=64 OBJECTS=“file106047a54bf1.o”

make would use
if test “zfile106047a54bf1.o” != “z”; then
if test -e “file106047a54bf1-win.def”; then
echo C:/RBuildTools/3.5/mingw_64/bin/g++ -shared -s -static-libgcc -o file106047a54bf1.dll file106047a54bf1-win.def file106047a54bf1.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
C:/RBuildTools/3.5/mingw_64/bin/g++ -shared -s -static-libgcc -o file106047a54bf1.dll file106047a54bf1-win.def file106047a54bf1.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
C:/RBuildTools/3.5/mingw_64/bin/nm file106047a54bf1.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^ ][^ ]*/"&"/g’ >> tmp.def;
echo C:/RBuildTools/3.5/mingw_64/bin/g++ -shared -s -static-libgcc -o file106047a54bf1.dll tmp.def file106047a54bf1.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
C:/RBuildTools/3.5/mingw_64/bin/g++ -shared -s -static-libgcc -o file106047a54bf1.dll tmp.def file106047a54bf1.o “C:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/Pianobot/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Pianobot/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-36~1.3/bin/x64" -lR ;
rm -f tmp.def;
fi
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
file106047a54bf1.o:file106047a54bf1.cpp:(.data$_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2P1[_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2P1]+0x0): first defined hereC:/Users/Pianobot/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2Q2[_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2Q2]+0x0): multiple definition of `long double boost::math::detail::bessel_y0<long double, boost::ma
In addition: Warning messages:
1: Rows containing NAs were excluded from the model.
2: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘-E’ not found
Error in sink(type = “output”) : invalid connection

Could you please help me?

Hi, perhaps I was unclear. Make a new post with a new subject line. That way you are likely to get help quickly :)

Thanks Torkar for your clarification. I have just made a new post accordingly.
Best regards,