【发布时间】:2016-05-24 23:36:41
【问题描述】:
这个玩具示例允许我从 mtcars 数据集中响应性地更新我感兴趣的两个向量的 R 平方值,以进行线性回归。
library(shiny)
ui <- fluidPage(
selectInput("xcol","Select X Variable",""),
selectInput("ycol","Select Y Variable",""),
mainPanel(
tableOutput("file"),
verbatimTextOutput("detco")
)
)
server <- function(input, output, session) {
mtcars
output$file <- renderTable({head(mtcars)})
observe({updateSelectInput(session,"xcol",choices=colnames(mtcars))})
observe({updateSelectInput(session,"ycol",choices=colnames(mtcars))})
output$detco <- renderText({
detco.lm <- lm(mtcars[,input$xcol] ~ mtcars[,input$ycol], data=mtcars)
summary(detco.lm)$r.squared
})
}
shinyApp(ui = ui, server = server)
但是,我需要能够计算数据中几个不同组的 R 平方值(例如,使用“cyl”的级别)。添加
selectInput("group","Group","")、observe({updateSelectInput(session,"group",choices=colnames(mtcars))}) 和
detco.lm <- lm(mtcars[,input$xcol] ~ mtcars[,input$ycol], data=mtcars[,input$group])
没有产生预期的结果——我一直只得到一个 R 平方值。我正在寻找与输入组对应的 R 平方值的表或列表,例如
#Having selected "mpg" and "drat" as my x/y variables
cyl(4.00)=.4591
cyl(6.00)=.6679
cyl(8.00)=.1422
【问题讨论】:
标签: r shiny linear-regression lm