繁体   English   中英

plot 各种解释变量对响应变量的影响如何

[英]How to plot the effects of various explanatory variables on the response variable

我正在拟合多元回归 model,它旨在预测冰淇淋车每天销售的冰淇淋桶数量。 一些预测因素包括:当天可用的冰淇淋口味数量、日平均温度以及该地区的参赛者总数。 换句话说,我们有以下 model:

售出的桶数 = Beta_0 + Beta_1 * 冰淇淋口味数量 + Beta_2 * 平均每日温度 + Beta_3 * 竞争对手数量

假设我已经计算了每个预测变量的系数,我如何才能直观地显示每个系数对销售的冰淇淋桶总数的净影响?

可视化多个变量对响应的影响可能很困难,但是
您可以试验多面散点图

另一方面,一个简单的柱状图可以显示预测系数及其相对效应之间的量级差异。

例如:

library(ggplot2)

coefficients <- c(0.35,0.21,0.79)
predictors <- c('Flavors','Temp','Competitors')

data <- data.frame(coefficients, predictors)

ggplot(data, aes(x=predictors, y=coefficients)) + geom_col()

示例柱形图 output

此外,stats/stack_exchange.com 上的这篇帖子还有一些其他建议。


如果您熟悉 Shiny,创建一系列交互式视觉效果可能是最好的方法。 我创建了以下小应用程序,允许您调整可变系数和值,并查看对已售浴缸的影响。

library(ggplot2)
library(tidyverse)
library(shiny)

ui <- fluidPage(
  
  # App title ----
  titlePanel("Multiple Linear Regression App"),
  
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    
    # Sidebar panel for inputs ----
    sidebarPanel(
      
      sliderInput(inputId = "flavors",
                  label = "Number of Ice Cream Flavors",
                  min = 0,
                  max = 30,
                  value = 1),
      
      sliderInput(inputId = "temp",
                  label = "Average Daily Temperature (F)",
                  min = -10,
                  max = 110,
                  value = 63),
      
      sliderInput(inputId = "competitors",
                  label = "Number of Competitors",
                  min = 0,
                  max = 20,
                  value = 5),
      
      sliderInput(inputId = "flavors_coef",
                  label = "Flavor Coefficient",
                  min = -20,
                  max = 20,
                  value = 6),
      
      sliderInput(inputId = "competitors_coef",
                  label = "Competitors Coefficient",
                  min = -20,
                  max = 20,
                  value = -4),
      
      sliderInput(inputId = "temp_coef",
                  label = "Temperature Coefficient",
                  min = -20,
                  max = 20,
                  value = -2)
      
    ),

    mainPanel(
      
      textOutput("sold")
      
    )
  )
)


server <- function(input, output) {
  
  output$sold <- renderText({
    total_sold <- ((input$flavors_coef * input$flavors) + (input$temp_coef * input$temp) + (input$competitors_coef * input$competitors))
    paste("Total Sold Tubs", total_sold)
  }) 
}

shinyApp(ui, server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM