I want to plot the marginal effects of an independent variable 'Shannon' estimated with a linear (lm) model. The variable appears both linearly and quadratically in the model, so the marginal effect changes along the range of 'Shannon' values.
To do this I use marginaleffects::plot_slopes(model = MODEL, variables = "Shannon", condition = 'Shannon', conf_level = 0.95)
I am very confused as to why my confidence interval is wiggly? I was expecting a smooth band around my estimated marginal effects line.
This appears to be an artefact of numerical instability when computing derivatives. One solution is to select a different step size manually using the
eps
argument:FYI, I am the author of the package and exchanged emails with the original poster. This solved their problem.