Commit 2dc49c54 authored by Aqeel Padaria's avatar Aqeel Padaria

add option to not require authentication, and tweak stationarity check text

parent 371960e4
......@@ -3,7 +3,7 @@ Title: Time Series Aggregator GUI
Version: 0.0.0.9000
Authors@R: person("Aqeel", "Padaria", email = "aqeel.padaria@gramener.com", role = c("aut", "cre"))
Description: GUI Frontend for the Time Series Aggregated Forecasting tool.
Depends: R (>= 3.3.2), openxlsx, shiny, DT, shinycssloaders, ggplot2, googleAuthR, shinyjs, ggseas, lubridate, tseries
Depends: R (>= 3.3.2), openxlsx, shiny, DT, shinycssloaders, ggplot2, googleAuthR, shinyjs, ggseas, lubridate, tseries, urca
License:
Encoding: UTF-8
LazyData: true
......
......@@ -6,7 +6,7 @@
#' @examples
#' forecastUI("./forecastFiles/")
forecastUI <- function(directory = ".", run = TRUE)
forecastUI <- function(directory = ".", run = TRUE, auth = TRUE)
{
library(openxlsx)
......@@ -87,7 +87,14 @@ server = shinyServer(
#source(paste0(directory,"/google_auth.R"),local = T)
observe({
user<<-user_details()
if(auth)
{
user<<-user_details()
}
if(!auth)
{
user <<- data.frame(auth = "good", displayName = "local", imageurl = "", fullname = "")
}
if(is.null(user)){
options(spinner.size=0)
output$logintext<- renderUI({
......@@ -381,7 +388,7 @@ server = shinyServer(
v <- qs[[1]]
paste0(v$method, ":\n", names(v$statistic), " = ", v$statistic, ", ", names(v$parameter), " = ", v$parameter, ", p value = ", v$p.value, "\n Alternative Hypothesis: ", v$alternative)
v
})
output$acf <- renderPlot({
......@@ -424,33 +431,139 @@ server = shinyServer(
originalts <- ts(original$value, start = c(year(original$valdate[1]), yday(original$valdate[1])), end = c(year(original$valdate[nrow(original)]), yday(original$valdate[nrow(original)])), frequency = freq)
stationary <- adf.test(originalts)
# v <- adf.test(originalts)
#
# adf <- paste0(v$method, ":\n", names(v$statistic), " = ", v$statistic, ", ", names(v$parameter), " = ", v$parameter, ", p value = ", v$p.value, "\n Alternative Hypothesis: ", v$alternative)
conf.level <- 0.95
ciline <- qnorm((1 - conf.level)/2)/sqrt(length(originalts))
for(i in 1:15)
{
if (i == 1) {
diffData <- originalts
}
else {
diffData <- diff(diffData)
}
stationarityTest <- ur.df(diffData)
if (stationarityTest@teststat > ciline) {
# print("Data is non-stationary")
next
}
else {
# print("Data is stationary")
d = i
# print(d)
break
}
}
if(d==1)
adf <- paste0(stationarityTest@test.name, ": Data is stationary")
if(d>1)
adf <- paste0(stationarityTest@test.name, ": Data is non-stationary; Stationarity achieved after differencing order ", d)
for(i in 1:15)
{
if (i == 1) {
diffData <- originalts
}
else {
diffData <- diff(diffData)
}
stationarityTest <- kpss.test(diffData)
if (stationarityTest$p.value < 0.05) {
# print("Data is non-stationary")
next
}
else {
# print("Data is stationary")
d = i
# print(d)
break
}
}
if(d==1)
kpss <- paste0(stationarityTest$method, ": Data is stationary")
if(d>1)
kpss <- paste0(stationarityTest$method, ": Data is non-stationary; Stationarity achieved after differencing order ", d)
stationarity <- paste(adf, kpss, sep = "\n")
bacf <- acf(originalts, plot = FALSE)
bacfdf <- with(bacf, data.frame(lag, acf))
acfmax <- min(setdiff((which(bacfdf$acf[bacfdf$lag!=0]>(-ciline))), 1))
acfmin <- min(setdiff((which(bacfdf$acf<(ciline))), 1))
if(is.infinite(acfmax))
{
acfmaxflag <- "No significant positive autocorrelations"
} else
{
acfmaxflag <- paste0("Significant positive autocorrelations at lag ", acfmax)
}
if(is.infinite(acfmin))
{
acfminflag <- "No significant negative autocorrelations"
} else
{
acfminflag <- paste0("Significant negative autocorrelations at lag ", acfmin)
}
acfflag <- paste(acfmaxflag, acfminflag, sep = "\n")
q1 <- ggplot(data = bacfdf, mapping = aes(x = lag, y = acf)) +
geom_hline(aes(yintercept = 0)) +
geom_hline(aes(yintercept = ciline), col = "blue", linetype="dotted") +
geom_hline(aes(yintercept = -ciline), col = "blue", linetype="dotted") +
geom_segment(mapping = aes(xend = lag, yend = 0)) +
ggtitle("ACF") + ylab("ACF") + xlab("Lag")
ggtitle(paste0("ACF\n", acfflag)) + ylab("ACF") + xlab("Lag")
bpacf <- pacf(originalts, plot = FALSE)
bpacfdf <- with(bpacf, data.frame(lag, acf))
# pacfdf does not have the correlation with lag 0
pacfmax <- min(setdiff((which(bpacfdf$acf>(-ciline))), 0))
pacfmin <- min(setdiff((which(bpacfdf$acf<(ciline))), 0))
if(is.infinite(pacfmax))
{
pacfmaxflag <- "No significant positive autocorrelations"
} else
{
pacfmaxflag <- paste0("Significant positive autocorrelations at lag ", pacfmax)
}
if(is.infinite(pacfmin))
{
pacfminflag <- "No significant negative autocorrelations"
} else
{
pacfminflag <- paste0("Significant negative autocorrelations at lag ", pacfmin)
}
pacfflag <- paste(pacfmaxflag, pacfminflag, sep = "\n")
q2 <- ggplot(data = bpacfdf, mapping = aes(x = lag, y = acf)) +
geom_hline(aes(yintercept = 0)) +
geom_hline(aes(yintercept = ciline), col = "blue", linetype="dotted") +
geom_hline(aes(yintercept = -ciline), col = "blue", linetype="dotted") +
geom_segment(mapping = aes(xend = lag, yend = 0)) +
ggtitle("PACF") + ylab("PACF") + xlab("Lag")
ggtitle(paste0("PACF\n", pacfflag)) + ylab("PACF") + xlab("Lag")
list(stationary, q1, q2)
list(stationarity, q1, q2)
})
......@@ -970,7 +1083,7 @@ ui = #ui.R
condition = "input.var=='All'",
tabsetPanel(
tabPanel("Decomposition", withSpinner(plotOutput("decomp"))),
tabPanel("ACF/PACF", withSpinner(verbatimTextOutput("station")), withSpinner(plotOutput("acf")), withSpinner(plotOutput("pacf"))),
tabPanel("Stationarity Tests", withSpinner(verbatimTextOutput("station")), withSpinner(plotOutput("acf")), withSpinner(plotOutput("pacf"))),
tabPanel("Models", column(12,withSpinner(DT::dataTableOutput("table")),align="center"))
)
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment