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

Time:09-23

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 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

CodePudding user response:

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

  • Related