0
我想要建立指数平滑方法是我选择的预测技术之一。但是,我有一些代表ggplot和计算结果/报告的问题。R中的指数平滑和Shiny
最初,我正在生成随机数据集以便用于此技术,其中要预测的alpha和期数由用户确定。例如;我有100天,并且接下来的4天愿意用他们的线 - 上限和下限估计。然后,我想以表格的形式了解这些数据的值。
当我试图想象的情节,错误的是:GGPLOT2不知道如何处理类mtstsmatrix的数据
require(shiny)
require(ggplot2)
require(forecast)
require(TTR)
shinyServer(function(input, output, session){
set.seed(123)
output$es1 <- renderPlot({
tmp <- data.frame(time = 1:100, sales = round(runif(100, 150, 879)))
tmp.mean <- HoltWinters(x=tmp$sales, alpha = input$alpha, beta = FALSE,gamma=FALSE)
tmp.pred <- predict(tmp.mean,n.ahead = input$h, prediction.interval = TRUE)
y <- ggplot(tmp, aes(time, sales)) +
geom_line() +
geom_line(data=tmp.pred, aes(y=tmp.pred[,1]),color="red") +
geom_line(data=tmp.pred, aes(y=tmp.pred[,2]),color="blue") +
xlab("Days") +
ylab("Sales Quantity")+
ggtitle(title)
y })
output$infoes <- renderDataTable({
tmp <- data.frame(time = 1:100, sales = round(runif(100, 150, 879)))
tmp.mean <- HoltWinters(x=tmp$sales, alpha = input$alpha, beta = FALSE,gamma=FALSE)
tmp.pred <- predict(tmp.mean,n.ahead = input$h, prediction.interval = TRUE)
tmp.pred
})
UI
require(shiny)
require(ggplot2)
require(forecast)
require(TTR)
shinyUI(pageWithSidebar(
headerPanel("Forecasting Methods"),
sidebarPanel(
h3(strong("Exponential Smoothing",style = "color:black")),
br(),
sliderInput("h","Number of periods for forecasting:",
min = 1, max = 20, step= 1, value = 4),
sliderInput("alpha","Alpha (Smoothing Parameter):",
min = 0.05, max = 1, step= 0.05, value = 0.01)
),
mainPanel(
tabsetPanel(id="tabs",
tabPanel("Exponential Smoothing",
value="panel",
plotOutput(outputId = "es1",
width = "900px",height = "400px"),
dataTableOutput(outputId="infoes"))
))))
您需要指定要解决的问题。如果可以,请发布屏幕截图。如果您正在生成随机数据,则应在测试过程中指定种子,以便始终获得相同的数据。 –
我将编辑我的帖子以便清楚。 –
tmp.pred可能不是一个数据框,所以这就是为什么你会得到“错误是:ggplot2不知道如何处理类mtstsmatrix的数据” – MLavoie