fitdist在r中闪亮,误差需要有限';xlim&x27;价值观
我正在创建我的第一个闪亮的应用程序,我正在努力从fitdist在r中闪亮,误差需要有限';xlim&x27;价值观,r,shiny,fitdistrplus,R,Shiny,Fitdistrplus,我正在创建我的第一个闪亮的应用程序,我正在努力从fitdistrplus软件包中绘制四个拟合优度测试。(对于参考资料,我试图从这里的参考资料复制第7页的绘图: 简单地说,我希望用户根据变量M选择数据子集,然后评估变量Q的不同概率分布密度。我使用代码创建了Shiny之外的拟合优度图,效果非常好。在R Shining中,我能够单独绘制拟合(fw、fg、fl)但在使用denscomp、qqcomp、cdfcomp和ppcomp时,我会收到以下错误消息: 错误:需要有限的“xlim”值 我试图在代码中
fitdistrplus
软件包中绘制四个拟合优度测试。(对于参考资料,我试图从这里的参考资料复制第7页的绘图:
简单地说,我希望用户根据变量M选择数据子集,然后评估变量Q的不同概率分布密度。我使用代码创建了Shiny之外的拟合优度图,效果非常好。在R Shining中,我能够单独绘制拟合(fw、fg、fl)但在使用denscomp
、qqcomp
、cdfcomp
和ppcomp
时,我会收到以下错误消息:
错误:需要有限的“xlim”值
我试图在代码中添加xlim
和ylim
(例如:xlim=c(0300),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)
库(FitDistripPlus)
图书馆(闪亮)
图书馆(dplyr)
ui我修复了您的一些问题,但由于我不熟悉packageFitDistripPlus
我无法完全调试其他警告。请注意,所有的反应式都是函数,因此应该这样使用,例如: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)
#rm(list=ls())
图书馆(FitPlus)
图书馆(闪亮)
图书馆(dplyr)
谢谢你的回答。它确实解决了问题。也谢谢你的建议。非常感谢。
#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)