paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.28k stars 184 forks source link

post-hoc test for multinomial logistic regression brm model (categorical responce) #1669

Closed LeoJha closed 4 months ago

LeoJha commented 4 months ago

Hi brms community!

I apologise as I am very new to this package and I really appreciate any help I can get.

I have a brms model with a categorical response variable (Species) with the following formula, running a multinomial logistics regression (I believe). Species ~ Density_1 + Density_2 + Canopy_Height + Soil_texture + pH + (1 \| Fragment).

All the explanatory variables are continuous and represent different habitat characteristics for six different plant species. I want to see which variables are correlated with the presence of which species. I need now to conduct some post hoc analysis for this model since the first species was used as the intercept and I am unable to see the effect of the habitat variables on this first species. I have tried using emmeansand bayestestR but neither seem compatible with the categorical brmsfit object. Any suggestions for what I can do ?

Below is my model code:

model1_07<- brm(Species ~ 
                   Density_1 +
                   Density_2 +
                   Canopy_Height +
                   Soil_texture +
                   pH
                 + (1 | Fragment)
                 , data = df_scaled_use, 
                 family = categorical(), 
                 iter = 10000, #may need to have upwards of 10000
                 # burn =
                 thin=1,
                 save_pars = save_pars(all = TRUE))

Here is my model output if that is helpful:


 Family: categorical 
  Links: muCprestonianus = logit; muCpsammophilus = logit; muCsaintelucei = logit; muDbrevicaulis = logit; muDscottiana = logit 
Formula: Species ~ Density_1 + Density_2 + Canopy_Height + Soil_texture + pH + (1 | Fragment) 
   Data: df_scaled_use (Number of observations: 120) 
  Draws: 4 chains, each with iter = 10000; warmup = 5000; thin = 1;
         total post-warmup draws = 20000

Multilevel Hyperparameters:
~Fragment (Number of levels: 5) 
                              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(muCprestonianus_Intercept)     4.83      2.50     1.70    11.16 1.00    10823    11896
sd(muCpsammophilus_Intercept)     1.17      1.05     0.04     3.88 1.00     7864     9312
sd(muCsaintelucei_Intercept)      1.01      0.88     0.04     3.30 1.00     6633     5801
sd(muDbrevicaulis_Intercept)      4.80      2.91     1.61    12.87 1.00     2317      864
sd(muDscottiana_Intercept)        1.46      0.95     0.13     3.78 1.00     6741     6506

Regression Coefficients:
                              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
muCprestonianus_Intercept        -1.24      1.91    -5.34     2.26 1.00    12108    11102
muCpsammophilus_Intercept        -0.25      0.93    -2.22     1.44 1.00     8064     8688
muCsaintelucei_Intercept         -0.17      0.85    -1.99     1.45 1.00     8935     5006
muDbrevicaulis_Intercept         -2.78      2.36    -8.33     1.06 1.00    10170     8498
muDscottiana_Intercept            0.16      0.94    -1.70     2.05 1.00    11847    12408
muCprestonianus_Density_1        -1.75      1.10    -4.12     0.22 1.00     4875     1057
muCprestonianus_Density_2         0.72      0.85    -0.76     2.58 1.00    11069    12796
muCprestonianus_Canopy_Height    -0.45      0.57    -1.55     0.71 1.00    15702    12974
muCprestonianus_Soil_texture     -0.64      0.75    -2.16     0.78 1.00     6655     4310
muCprestonianus_pH                1.95      0.76     0.55     3.57 1.00    12281    11766
muCpsammophilus_Density_1        -1.91      0.77    -3.50    -0.46 1.00    10998    12544
muCpsammophilus_Density_2        -2.69      0.81    -4.33    -1.21 1.00    12036    14095
muCpsammophilus_Canopy_Height    -1.29      0.58    -2.47    -0.22 1.00    12979    14650
muCpsammophilus_Soil_texture      0.24      0.57    -0.88     1.38 1.00     9225    11769
muCpsammophilus_pH                0.28      0.66    -1.01     1.61 1.00    11301    11847
muCsaintelucei_Density_1          0.92      0.60    -0.22     2.13 1.00    11401    12351
muCsaintelucei_Density_2         -1.93      0.64    -3.27    -0.76 1.00    10004    11519
muCsaintelucei_Canopy_Height     -1.03      0.55    -2.14     0.03 1.00    12773    14404
muCsaintelucei_Soil_texture      -1.77      0.61    -3.06    -0.65 1.00    11457    12137
muCsaintelucei_pH                 0.37      0.59    -0.78     1.54 1.00    13250    13415
muDbrevicaulis_Density_1         -1.60      0.74    -3.14    -0.22 1.00    10458    11812
muDbrevicaulis_Density_2         -1.89      0.74    -3.42    -0.54 1.00    11121    11950
muDbrevicaulis_Canopy_Height     -0.86      0.57    -1.97     0.26 1.00    13287    14843
muDbrevicaulis_Soil_texture       1.30      0.64     0.09     2.61 1.00    10737    12441
muDbrevicaulis_pH                 1.68      0.71     0.35     3.16 1.00    11590    10872
muDscottiana_Density_1           -0.85      0.70    -2.28     0.48 1.00     8326    12671
muDscottiana_Density_2           -3.00      0.79    -4.67    -1.58 1.00    10508     8612
muDscottiana_Canopy_Height       -2.72      0.70    -4.16    -1.41 1.00    12085    13191
muDscottiana_Soil_texture         0.57      0.60    -0.58     1.76 1.00     9218    11485
muDscottiana_pH                   1.31      0.64     0.07     2.59 1.00     9169     5931

On a side note, I have been using conditional_effects() too. Many many thanks!

paul-buerkner commented 4 months ago

Hi, please ask brms related questions on Stan discourse.