with a single parameter in the list .the result would be following...
library(shiny)
library(dygraphs)
library(forecast)
library(tseries)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(readr)
qry2<-read.csv("c:/users/nic user/desktop/ab.csv")
data1<-aggregate(qry2$AbortionCount,by=list(qry2$Month),FUN=sum)
interval_value_formatter <- "function(num, opts, seriesName, g, row, col) {
value = g.getValue(row, col);
if(value[0] != value[2]) {
lower = Dygraph.numberValueFormatter(value[0], opts);
upper = Dygraph.numberValueFormatter(value[2], opts);
return '[' + lower + ', ' + upper + ']';
} else {
return Dygraph.numberValueFormatter(num, opts);
}
}"
timetravel<-ts(data1$x,start = 2019,frequency = 12)
timetravel %>%
stlf(lambda = 0, h = 12) %>%
{cbind(actuals=.$x, forecast_mean=.$mean,
lower_95=.$lower[,"95%"], upper_95=.$upper[,"95%"],
lower_80=.$lower[,"80%"], upper_80=.$upper[,"80%"])} %>%
dygraph(main="Random Records", ylab = "DATA") %>%
dyAxis("y", valueFormatter = interval_value_formatter) %>%
dySeries("actuals", color = "black") %>%
dySeries("forecast_mean", color = "blue", label = "forecast") %>%
dySeries(c("lower_80", "forecast_mean", "upper_80"),
label = "80%", color = "blue") %>%
dySeries(c("lower_95", "forecast_mean", "upper_95"),
label = "95%", color = "blue") %>%
dyLegend(labelsSeparateLines=TRUE) %>%
dyRangeSelector() %>%
dyOptions(digitsAfterDecimal = 1) %>%
dyCSS(textConnection(".dygraph-legend {background-color: rgba(255, 255, 255, 0.5) !important; }"))
output:
Error in stl(ts(deseas, frequency = msts[i]), s.window = s.window[i], : series is not periodic or has less than two periods
Created on 2020-09-15 by the reprex package (v0.2.1)
with two-parameter in the list, the result would be
library(shiny)
library(dygraphs)
library(forecast)
library(tseries)
library(dplyr)
library(readr)
qry2<-read.csv("c:/users/nic user/desktop/ab.csv")
data1<-aggregate(qry2$AbortionCount,by=list(qry2$Month,qry2$Unitname),FUN=sum)
interval_value_formatter <- "function(num, opts, seriesName, g, row, col) {
value = g.getValue(row, col);
if(value[0] != value[2]) {
lower = Dygraph.numberValueFormatter(value[0], opts);
upper = Dygraph.numberValueFormatter(value[2], opts);
return '[' + lower + ', ' + upper + ']';
} else {
return Dygraph.numberValueFormatter(num, opts);
}
}"
timetravel<-ts(data1$x,start = 2019,frequency = 12)
timetravel %>%
stlf(lambda = 0, h = 12) %>%
{cbind(actuals=.$x, forecast_mean=.$mean,
lower_95=.$lower[,"95%"], upper_95=.$upper[,"95%"],
lower_80=.$lower[,"80%"], upper_80=.$upper[,"80%"])} %>%
dygraph(main="Random Records", ylab = "DATA") %>%
dyAxis("y", valueFormatter = interval_value_formatter) %>%
dySeries("actuals", color = "black") %>%
dySeries("forecast_mean", color = "blue", label = "forecast") %>%
dySeries(c("lower_80", "forecast_mean", "upper_80"),
label = "80%", color = "blue") %>%
dySeries(c("lower_95", "forecast_mean", "upper_95"),
label = "95%", color = "blue") %>%
dyLegend(labelsSeparateLines=TRUE) %>%
dyRangeSelector() %>%
dyOptions(digitsAfterDecimal = 1) %>%
dyCSS(textConnection(".dygraph-legend {background-color: rgba(255, 255, 255, 0.5) !important; }"))
output:----
Note:- If I try to add a single parameter then it throws the time period error and it displays the wrong chart when I add two-parameter , I can not add the dummy data in order to complete the forecasting as this is all the real-time data that I have to work on.
could you please suggest to me what I should do to get rid of this kinda stuck situation.