Advertisement
Guest User

HTML Java script MYSQL programmers dev.....(elmo)

a guest
Feb 17th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. I'm working on building a Shiny App for forecasting time series. One component of this is using ARIMA models to forecast. The user specifies the start and end of the historical data, what p, d, and q they would like to use in the ARIMA model (if they don't want to use auto.arima), and how many periods to forecast for.
  2.  
  3. Everything works fine for auto.arima, as well as other forecasting methods I'm using such as Holt and Holt-Winters. However, when using arima() to create a model with custom p, d, and q, I get the following error from forecast():
  4.  
  5.        Warning in .cbind.ts(list(e1, e2), c(deparse(substitute(e1))[1L],
  6.    deparse(substitute(e2))[1L]),  : non-intersecting series
  7.  
  8.  
  9. What's strange to me is that when I comment out the start and end arguments in the function that creates the time series, everything runs fine....
  10.  
  11. Here's the relevant bits of my code:
  12.  
  13. First, read in the specified csv file containing the values to be forecasted in the second column, and prepare that column to be forecasted:
  14.  
  15.    ## Reads in the historical data from the uploaded file
  16.    readData <- reactive({
  17.        inFile <- input$inputFile
  18.        if (is.null(inFile))
  19.          return(NULL)
  20.        data <- read.csv(inFile$datapath)
  21.        data
  22.      })
  23.      
  24.      ## Returns the historical values to be used in forecasting
  25.      historical <- reactive({
  26.        data <- readData()
  27.        ## Remove any commas and dollar signs, and convert to a number
  28.        data[,2] <- as.numeric(sub("\\,","",
  29.                                   sub("\\$","",data[,2])
  30.                                   )
  31.                               )
  32.        data
  33.      })
  34.  
  35. Create a time series:
  36.  
  37.          ## Converts the historical data to a time series
  38.          tsData <- reactive({
  39.            data <- historical()
  40.            data <- data[,2]
  41.            ts <- ts(data,
  42.                     start=c(input$startYear, input$startTime),
  43.                     end=c(input$endYear, input$endTime),
  44.                     frequency = strtoi(input$frequency)
  45.            )
  46.            ts
  47.          })
  48.    
  49.    Create the ARIMA model:
  50.      ## Create an ARIMA model for forecasting
  51.      arimaModel <- reactive({
  52.        ts <- tsData()
  53.        if(input$arimaAuto){
  54.          fit <- auto.arima(ts)
  55.        }
  56.        else{
  57.           fit <- arima(ts,order=c(strtoi(input$arimaP),
  58.                                  strtoi(input$arimaD),
  59.                                  strtoi(input$arimaQ)))
  60.        }
  61.        fit
  62.      })
  63.  
  64. And last but not least, forecasting - the part that throws the strange warning message:
  65.  
  66.      ## Creates an ARIMA model and returns a forecast based on that model.
  67.      arimaData <- reactive({
  68.        fit <- arimaModel()
  69.        print("Fit: ")
  70.        print(fit)
  71.        f <- forecast(fit#,
  72.                      #h = input$forecast_periods,
  73.                      #level=c(strtoi(input$confidence1), strtoi(input$confidence2))
  74.        )
  75.        print("Forecast:")
  76.        print(f)
  77.        f
  78.      })
  79.  
  80. Thanks in advance for any help! :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement