comparing output from "marginal_effects" and "fitted"

118 views
Skip to first unread message

James

unread,
Mar 26, 2018, 4:25:33 AM3/26/18
to brms-users
I have a question about marginal_effects: I thought that the marginal effects plot would give me the same probabilities (from a logistic regression model) as "fitted". However, it doesn't seem to be the case and I'm wondering why. Here's a marginal effect plot:

m2 <- brm_multiple(transition ~ GenderCognition.z,family=binomial(link="logit"),data=data1.short,prior=m2priors)
marginal_effects(m2)
























From this plot you'd think that the predicted score for a person with a score of .5 on the x-variable is between .2 and .3. Now for the fitted values:

> fitted(object = m2,newdata =data.frame(GenderCognition.z = seq(-1.5,.5, 0.1)),allow_new_levels = TRUE)
Using the maximum response value as the number of trials.
Only 2 levels detected so that family 'bernoulli' might be a more efficient choice.
        Estimate  Est.Error    2.5%ile  97.5%ile
 [1,] 0.09496612  0.07085960 0.01286031 0.2798268
 [2,] 0.10469542  0.07242305 0.01647652 0.2896980
 [3,] 0.11554677  0.07382603 0.02101507 0.3004928
 [4,] 0.12764293  0.07500860 0.02678388 0.3117016
 [5,] 0.14111401   0.07590138 0.03407742 0.3233585
 [6,] 0.15609520  0.07642652 0.04311651 0.3353746
 [7,] 0.17272316  0.07650019 0.05444389 0.3479582
 [8,] 0.19113072   0.07603789 0.06850000 0.3614977
 [9,] 0.21143963   0.07496368 0.08562145 0.3756603
[10,] 0.23375088  0.07322548 0.10618030 0.3901145
[11,] 0.25813268  0.07081863 0.13055160 0.4059183
[12,] 0.28460638  0.06782001 0.15924051 0.4232239
[13,] 0.31313126  0.06443301 0.19177586 0.4433088
[14,] 0.34359007  0.06103594 0.22691224 0.4655358
[15,] 0.37577821  0.05820666 0.26375395 0.4919214
[16,] 0.40939983  0.05666195 0.29952325 0.5214995
[17,] 0.44407411  0.05704601 0.33324913 0.5567750
[18,] 0.47935342  0.05962631 0.36312906 0.5963512
[19,] 0.51475211  0.06414149 0.38948707 0.6397166
[20,] 0.54978165  0.06995015 0.41200293 0.6839591
[21,] 0.58398559  0.07631368 0.43157967 0.7283315
Warning message:
In max(out$Y, na.rm = TRUE) :
  no non-missing arguments to max; returning -Inf

Here it looks like the expected probability for a person with a score of .5 on the x-variable is .58. Should this be expected? What am I missing here?

Paul Buerkner

unread,
Mar 26, 2018, 4:27:22 AM3/26/18
to James, brms-users
This could be the result of you not specifiyng the number of trials. marginal_effects uses the median by default and apparently, fitted has problems finding anything as indicated by the warning. I suggest you refit the model, in which you explictely specify the number of trials via

transition | trials(<your trials variable>) ~ GenderCognition.z

--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/b722f9eb-a733-4747-b091-1693638e276d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted

Paul Buerkner

unread,
Mar 26, 2018, 7:01:41 PM3/26/18
to brms-users
Google spam filter deleted the following message:

Ok, but there is only 1 "trial" so to speak such that transition is just a binary outcome variable that was measured in the dataset. Thus I'd just do:

transition | trials(transition) ~ GenderCognition.z?

Paul Buerkner

unread,
Mar 26, 2018, 7:02:31 PM3/26/18
to brms-users
No, you should write

transition | trials(1) ~ GenderCognition.z

or alternatively set your family to bernoulli() instead of binomial()
Reply all
Reply to author
Forward
0 new messages