我正在尝试在R Shiny中建立Logistic回归,但是时间却非常困难。感谢Bruno在这里回答另一个问题,我能够提出一些想法,但是我的代码仍然无法正常工作。
但是,我现在完全迷失了方向,不知道如何继续。我真的很感谢任何人的任何帮助,指导或建议!
library(shinythemes)
library(shinyWidgets)
library(shiny)
library(shinydashboard)
library(recipes)
#data(mtcars)
AttributeChoices=c("Borough_X", "Avg..Income.H.hold", "Month", "Season", "PartOfDay")
# Define UI for application
ui = fluidPage(
navbarPage("R Shiny Dashboard",
tabPanel("Welcome",
tabName = "welcome",
icon=icon("door-open"),
fluidPage(theme=shinytheme("cerulean"),
h1("Welcome to my Shiny Dashboard!"),
br(),
p(strong(tags$u("What is this dashboard all about?"))),
p("I'm going to do stuff."),
br(),
p(strong(tags$u("Here's another question."))),
p("Here's my answer."),
br(),
p(strong(tags$u("How can I use this dashboard?"))),
p("You can click on any of the tabs above to see a different analysis of the data.")
)),
tabPanel("Regression",
tabname="regression",
icon=icon("calculator"),
selectInput(inputId = "indep", label = "Independent Variables",
multiple = TRUE, choices = as.list(AttributeChoices), selected = AttributeChoices[1]),
verbatimTextOutput(outputId = "RegOut")
)
))
# Define server logic
df <- read.csv('data/sidedf.csv')
server <- function(input, output) {
recipe_formula <- reactive(df %>%
recipe() %>%
update_role(df = "outcome") %>%
update_role(!!!input$indep,new_role = "predictor") %>%
formula())
glm_reg <- reactive(
glm(recipe_formula(),data = df)
)
output$RegOut = renderPrint({summary(glm_reg())})
}
我的数据:Y = Sidewalk_Condition,X =其余列
Sidewalk_Condition | Borough_X | Avg..Income.H.hold | Month | Season | PartOfDay
-------------------------------------------------------------------------------------
1 | Staten Island | 21109 | 6 | winter | evening
0 | Bronx | 32034 | 12 | fall | afternoon
1 | Queens | 52304 | 7 | summer | midday
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句