r shiny 中的 fitdist,错误需要有限的 'xlim' 值
fitdist in r shiny, error need finite 'xlim' values
我正在创建我的第一个闪亮应用程序,我正在努力绘制 fitdistrplus
包中的四个拟合优度测试。 (作为参考,我正在尝试从此处的参考资料中重现第 7 页的情节:
简而言之,我希望用户 select 基于变量 M 的数据子集,然后评估变量 Q 的不同概率分布密度。我使用代码创建了拟合优度图在 Shiny 之外,它工作得很好。在 R Shiny 中,我能够单独绘制拟合 (fw、fg、fl),但是当涉及到使用 denscomp
、qqcomp
、cdfcomp
和 ppcomp
时,我收到此错误消息:
Error: need finite 'xlim' values
我尝试在代码中添加 xlim
和 ylim
(例如:xlim =c(0,300), ylim=c(0.008)
),但我仍然收到错误消息。
有人知道如何解决这个问题吗?
我的代码如下:
library(fitdistrplus)
library(shiny)
library(dplyr)
ui<- shinyUI(pageWithSidebar(
headerPanel("Distribution analysis"),
sidebarPanel(
selectInput("input1",
label = "M",
choices = data$m,
selected = "M1"),
mainPanel(
tabsetPanel(
tabPanel("Fit", plotOutput("fit1")),
tabPanel("Distribution", plotOutput("hist1")),
tabPanel("Table", tableOutput("table"))
))
))
server<- shinyServer(function(input, output) {
dataInput <- reactive({
data %>%
filter(m==input$input1)
})
fw<- eventReactive(input$input1 {
fitdist(dataInput()$Q, "weibull")
})
fg<- eventReactive(input$input1 {
fitdist(dataInput()$Q, "gamma")
})
fln<- eventReactive(input$input1 {
fitdist(dataInput()$Q, "lnorm")
})
output$fit1 <- renderPlot({
if (!is.null(dataInput())) {
par(mfrow = c(2, 2))
plot.legend <- c("Weibull", "lognormal", "gamma")
denscomp(list(fw, fln, fg), legendtext = plot.legend)
qqcomp(list(fw, fln, fg), legendtext = plot.legend)
cdfcomp(list(fw, fln, fg), legendtext = plot.legend)
ppcomp(list(fw, fln, fg), legendtext = plot.legend)
}
})
})
shinyApp(ui=ui, server=server)
以及重新创建示例的数据:
m<- c("M1","M3","M3", "M2", "M3","M2","M2","M1","M1","M1","M1","M3","M3","M2","M2","M1","M3","M3", "M3","M2","M2","M2","M1","M1","M1","M1","M1","M3","M3","M3" )
Q<- c(265, 65, 40, 245,230,175, 185, 190, 290, 85, 75, 155, 110, 60, 35, 245, 300,175, 180, 265, 55, 200, 95, 185, 165, 55, 90, 190, 235, 200)
data<- data.frame(m,Q)
我修复了你的一些问题,但由于我不熟悉包 fitdistrplus
我无法完全调试其他警告。请注意,所有反应都是函数,因此应该这样使用,例如:fln()
而不是 fln
#rm(list = ls())
library(fitdistrplus)
library(shiny)
library(dplyr)
m<- c("M1","M3","M3", "M2", "M3","M2","M2","M1","M1","M1","M1","M3","M3","M2","M2","M1","M3","M3", "M3","M2","M2","M2","M1","M1","M1","M1","M1","M3","M3","M3" )
Q<- c(265, 65, 40, 245,230,175, 185, 190, 290, 85, 75, 155, 110, 60, 35, 245, 300,175, 180, 265, 55, 200, 95, 185, 165, 55, 90, 190, 235, 200)
data<- data.frame(m,Q)
ui<- shinyUI(pageWithSidebar(
headerPanel("Distribution analysis"),
sidebarPanel( selectInput("input1", label = "M",choices = data$m,selected = "M1")),
mainPanel(
tabsetPanel(
tabPanel("Fit", plotOutput("fit1")),
tabPanel("Distribution", plotOutput("hist1")),
tabPanel("Table", tableOutput("table"))
))
))
server<- shinyServer(function(input, output) {
dataInput <- reactive({
if(is.null(input$input1)){
return()
}
data %>% filter(m==input$input1)
})
fw <- eventReactive(input$input1, {
fitdist(dataInput()$Q, "weibull")
})
fg <- eventReactive(input$input1, {
fitdist(dataInput()$Q, "gamma")
})
fln <- eventReactive(input$input1, {
fitdist(dataInput()$Q, "lnorm")
})
output$fit1 <- renderPlot({
if(is.null(dataInput()) | nrow(dataInput()) ==0){
return()
}
par(mfrow = c(2, 2))
plot.legend <- c("Weibull", "lognormal", "gamma")
denscomp(list(fw(), fln(), fg()), legendtext = plot.legend)
qqcomp(list(fw(), fln(), fg()), legendtext = plot.legend)
cdfcomp(list(fw(), fln(), fg()), legendtext = plot.legend)
ppcomp(list(fw(), fln(), fg()), legendtext = plot.legend)
})
})
shinyApp(ui=ui, server=server)
注意这些您应该注意的消息错误,可能从这里开始 https://stats.stackexchange.com/questions/158163/why-does-this-data-throw-an-error-in-r-fitdistr
我正在创建我的第一个闪亮应用程序,我正在努力绘制 fitdistrplus
包中的四个拟合优度测试。 (作为参考,我正在尝试从此处的参考资料中重现第 7 页的情节:
简而言之,我希望用户 select 基于变量 M 的数据子集,然后评估变量 Q 的不同概率分布密度。我使用代码创建了拟合优度图在 Shiny 之外,它工作得很好。在 R Shiny 中,我能够单独绘制拟合 (fw、fg、fl),但是当涉及到使用 denscomp
、qqcomp
、cdfcomp
和 ppcomp
时,我收到此错误消息:
Error: need finite 'xlim' values
我尝试在代码中添加 xlim
和 ylim
(例如:xlim =c(0,300), ylim=c(0.008)
),但我仍然收到错误消息。
有人知道如何解决这个问题吗?
我的代码如下:
library(fitdistrplus)
library(shiny)
library(dplyr)
ui<- shinyUI(pageWithSidebar(
headerPanel("Distribution analysis"),
sidebarPanel(
selectInput("input1",
label = "M",
choices = data$m,
selected = "M1"),
mainPanel(
tabsetPanel(
tabPanel("Fit", plotOutput("fit1")),
tabPanel("Distribution", plotOutput("hist1")),
tabPanel("Table", tableOutput("table"))
))
))
server<- shinyServer(function(input, output) {
dataInput <- reactive({
data %>%
filter(m==input$input1)
})
fw<- eventReactive(input$input1 {
fitdist(dataInput()$Q, "weibull")
})
fg<- eventReactive(input$input1 {
fitdist(dataInput()$Q, "gamma")
})
fln<- eventReactive(input$input1 {
fitdist(dataInput()$Q, "lnorm")
})
output$fit1 <- renderPlot({
if (!is.null(dataInput())) {
par(mfrow = c(2, 2))
plot.legend <- c("Weibull", "lognormal", "gamma")
denscomp(list(fw, fln, fg), legendtext = plot.legend)
qqcomp(list(fw, fln, fg), legendtext = plot.legend)
cdfcomp(list(fw, fln, fg), legendtext = plot.legend)
ppcomp(list(fw, fln, fg), legendtext = plot.legend)
}
})
})
shinyApp(ui=ui, server=server)
以及重新创建示例的数据:
m<- c("M1","M3","M3", "M2", "M3","M2","M2","M1","M1","M1","M1","M3","M3","M2","M2","M1","M3","M3", "M3","M2","M2","M2","M1","M1","M1","M1","M1","M3","M3","M3" )
Q<- c(265, 65, 40, 245,230,175, 185, 190, 290, 85, 75, 155, 110, 60, 35, 245, 300,175, 180, 265, 55, 200, 95, 185, 165, 55, 90, 190, 235, 200)
data<- data.frame(m,Q)
我修复了你的一些问题,但由于我不熟悉包 fitdistrplus
我无法完全调试其他警告。请注意,所有反应都是函数,因此应该这样使用,例如:fln()
而不是 fln
#rm(list = ls())
library(fitdistrplus)
library(shiny)
library(dplyr)
m<- c("M1","M3","M3", "M2", "M3","M2","M2","M1","M1","M1","M1","M3","M3","M2","M2","M1","M3","M3", "M3","M2","M2","M2","M1","M1","M1","M1","M1","M3","M3","M3" )
Q<- c(265, 65, 40, 245,230,175, 185, 190, 290, 85, 75, 155, 110, 60, 35, 245, 300,175, 180, 265, 55, 200, 95, 185, 165, 55, 90, 190, 235, 200)
data<- data.frame(m,Q)
ui<- shinyUI(pageWithSidebar(
headerPanel("Distribution analysis"),
sidebarPanel( selectInput("input1", label = "M",choices = data$m,selected = "M1")),
mainPanel(
tabsetPanel(
tabPanel("Fit", plotOutput("fit1")),
tabPanel("Distribution", plotOutput("hist1")),
tabPanel("Table", tableOutput("table"))
))
))
server<- shinyServer(function(input, output) {
dataInput <- reactive({
if(is.null(input$input1)){
return()
}
data %>% filter(m==input$input1)
})
fw <- eventReactive(input$input1, {
fitdist(dataInput()$Q, "weibull")
})
fg <- eventReactive(input$input1, {
fitdist(dataInput()$Q, "gamma")
})
fln <- eventReactive(input$input1, {
fitdist(dataInput()$Q, "lnorm")
})
output$fit1 <- renderPlot({
if(is.null(dataInput()) | nrow(dataInput()) ==0){
return()
}
par(mfrow = c(2, 2))
plot.legend <- c("Weibull", "lognormal", "gamma")
denscomp(list(fw(), fln(), fg()), legendtext = plot.legend)
qqcomp(list(fw(), fln(), fg()), legendtext = plot.legend)
cdfcomp(list(fw(), fln(), fg()), legendtext = plot.legend)
ppcomp(list(fw(), fln(), fg()), legendtext = plot.legend)
})
})
shinyApp(ui=ui, server=server)
注意这些您应该注意的消息错误,可能从这里开始 https://stats.stackexchange.com/questions/158163/why-does-this-data-throw-an-error-in-r-fitdistr