Description Usage Arguments Details Value Examples
library(forecast) data <- read.csv("data/eneco.data") myts <- ts(data$gas, start=c(2007, 11), end=c(2019, 6), frequency=12) autoplot(myts, main='gas consumption', xlab="year", ylab="m3")
Calculates the percentage change between the current and a prior element.
1 2 3 |
x |
A vector or time series containing at least 2 elements |
fcf <- function(y, h) #' User defined forecast function #' #' @param y : time series #' @param h : prediction horizon fit <- nnetar(y, repeats=20, p=1, P=1, size=2, lambda=0) fc <- forecast(fit, h)
err <- tsCV(myts, fcf, h=1) fitted <- myts - lag(err, -1) y.fitted <- cbind(myts, fitted) par(mfcol=c(2,1))
plot1 <- (autoplot(y.fitted, xlab='year', ylab='y and predicted') + theme(legend.position = 'bottemright') + scale_x_continuous(breaks = seq(2008, 2020, 2)) + scale_color_manual(values=c('black', 'orange')) ) plot2 <- autoplot(lag(err, -1), xlab='year', ylab='y minus predicted', color='red') grid.arrange(plot1, plot2, nrow=2)
wf <- function(y) #' Generate 1 period ahead predictions #' #' @param y : time series err <- tsCV(myts, fcf, h=1) wf.predict <- myts - lag(err, -1)
vector or time series
1 2 3 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.