-2

I am a freshman in doing regerssion and also in using python / r I am now studying the non-linear relationship between ESG performance and Financial Performance of companies, with a set of panel data and the following equation:

ROA = C(1) + C(2)*ENV + C(3)*ENV2 + C(4)*SOC + C(5)*SOC2 + C(6)*GOV + 
             C(7)*GOV2 + C(8)*LNA + C(9)*LEV + C(10)*PB + C(11)*LNOE

ENV2, SOC2 & GOV2 are the quadratic terms for ENV, SOC & GOV respectively, and C(8)-C(11) are control variables.

I would like to plot a graph to show the marginal effect of ENV/SOC/GOV on ROA, so my question is how can I do that the plot the u-shaped or inverse u-shaped fitting curve via python or r?

Many thanks!

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 2
    Welcome to SO! You maximise your chance of getting a useful answer if you provide a minimal reproducible example. [This post](https://stackoverflow.com/help/minimal-reproducible-example) may help. – Limey Apr 15 '22 at 06:22
  • 3
    I suspect the downvote is from someone who doubts that you have actually done any of the work needed to set this problem up, much less having done the regression. You need tor read [ask] and [MCVE] – IRTFM Apr 15 '22 at 06:23
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 15 '22 at 08:58

1 Answers1

1

You can use the plot_cap() function from the marginaleffects package for R (disclaimer: I am the author). For example, here is a model with a quadratic term:

library(marginaleffects)

# simulate
x <- rnorm(100)
y <- x + x^2 + rnorm(100)

# fit
mod <- lm(y ~ x + I(x^2), data = mtcars)

# plot
plot_cap(mod, condition = "x")

Vincent
  • 15,809
  • 7
  • 37
  • 39