Hello, I thought I should ask the experts here for some tips after I have spent hours upon days at this point getting nowhere on this multiple regression visualization task. I must first preface this post by stating that I still struggle with R, but am starting to get a grasp on the fundamental concepts.

Here is the problem I am looking at:

I need to plot a multiple regression and layer it over a scatter plot of actual values.

So I will just make up an example to get the idea across.

I want to find the effect of different factors on annual salary over time.

So for actual values I would just have a scatter plot, with salary amount on the y-axis and each year on the x-axis. That part is straight forward.

But now I have a multiple regression model where I want to find the effect of multiple independent variables on the dependent variable of salary.

so in R, this would look like

lm(formula = salary ~ health + happiness + education, data = mydata)

I want to create a graph that shows the actual salary values for each year, with the multiple regression line of predicted salary values layed over, so the y-axis would be salary, and the x-axis would be each year. How can I do this? I have tried to look up steps, but they are often way too complex for me to understand.

I have been confused with how to visualize this multiple regression, and conceptually I am not sure how this would work. I have the actual values of salary, so salary as a function of year, with year as the x-axis and salary as the y-axis. The multiple regression plot would as well have salary as the y-axis, but would this require 3 different x-axes? Since this would be salary as a function of health, happiness, and education. If I were to make the multiple regression plot show salary as a function of time, it would no longer be the multiple regression, and would just be the actual values it seems. This is the issue I am having trouble visualizing. Or can a multiple regression not be truly displayed in 2 dimensions? So for the multiple regression line it would just be salary on the y-axis, and year on the x-axis, but in those y-axis values I would want health, happiness, and education to be factored in, to make it different than the actual values.

I can't figure this out :(

So far this webpage has come the closest to what I am going for, but I just cannot figure out where I can insert my own code to make the function still work:

https://cran.r-project.org/web/packages/ggiraphExtra/vignettes/ggPredict.html

Thank you!

More Lino Sanchez's questions See All
Similar questions and discussions