rggplot2data-visualizationlinear-regressionstdev

Is there a way to visualize a mutliple regression (more than 3 independent variables) +- 1 SD in R?


I am trying to (i) visualise a multiple linear regression (>3 independent variables) and (ii) plot a standard deviation corridor for my linear regression line, but I am not sure how to do this. Specifically, I would like to plot the line +- SD. An example with iris:

lm1 <- lm(iris$Sepal.Length ~ iris$Sepal.Width + iris$Petal.Width + iris$Species+ iris$Petal.Width)
summary(lm1)
library(car)
avPlots(lm1, intercept = TRUE)
 
library(ggplot2)

ggplot(iris, aes(x = iris$Sepal.Width, y = Sepal.Length,
                   
                   col = factor(Species)))+ geom_point(size=1)+ theme_bw()+geom_smooth(method=lm,se=FALSE, fullrange=TRUE)

Which gives me the added variable plots and the regression line for Sepal.Length~Sepal.Width + Species. I was wondering if (i) there is a more effective way than the added variable plots to summarise the results (I have already seen threads like https://stats.stackexchange.com/questions/89747/how-to-describe-or-visualize-a-multiple-linear-regression-model and https://stats.stackexchange.com/questions/71413/best-way-to-visually-present-relationships-from-a-multiple-linear-model I was just wondering if there is a more recently developed function like ggPredict which is appropriate for up to 3 variables) and (ii) how I can add the standard deviation on these two plots.

enter image description here enter image description here

Example of intended output on the regression line Sepal.Length~Sepal.Width in red:

enter image description here


Solution

  • Maybe something like this? Here, the band represents the standard error, which is a measure of how wrong the regression line is likely to be based on sampling error alone.

    library(tidyverse); library(ggforce)
    ggplot(iris, aes(x = .panel_x, y = .panel_y)) +
      geom_point() +
      geom_smooth(method = "lm") +
      facet_matrix(vars(Sepal.Length:Petal.Width), layer.diag = 3)
    

    enter image description here