Including data points in plot(marginal_effects())

Hi

I’m trying to plot the marginal effects (conditional effects) that includes the data points using the marginal_effects() function by setting the argument points = TRUE. However, the resulting plot only shows one (1) data point where in fact, the data contains 1,504 samples.

Did I misunderstand the example?

The model I am estimating is a simple linear regression with 1 intercept, 3 categorical predictor variables, and 1 continuous predictor variable with a continuous response variable as follows:

fit3 <- brm(formula = wei.log ~ 1 + pre.f + yr.f + gds.f + grp.std,
data = df,
family = gaussian(),
prior = c(set_prior(“normal(0,1)”, class = “b”)),
iter = 10000, chains = 4, control = list(adapt_delta = 0.99, max_treedepth = 12))

I want to plot the marginal effects of grp.std to wei.log along with the data points.

  • Operating System: Windows 10
  • brms Version: version 2.10.0
1 Like

Welcome to Stan discourse. The marginal effects documentation says in the details section:

This also has an implication for the points argument: In the created plots, only those points will be shown that correspond to the factor levels actually used in the conditioning, in order not to create the false impression of bad model fit, where it is just due to conditioning on certain factor levels.

Hope this helps!