nb_ets: appply ets

Usage Arguments Examples

View source: R/nb_ets.R

Usage

1
nb_ets(data, freq, predlenth, force_positive)

Arguments

data
freq
predlenth
force_positive

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, freq, predlenth, force_positive) 
{
    for (j in 1:length(data$results.series_values)) {
        series_tags <- as.data.frame(data$results.series_tags[j])
        series_names <- paste(data$results.series_names[j], "pred", 
            sep = "_")
        temp <- as.data.frame(data$results.series_values[j])
        temp <- temp[complete.cases(temp), ]
        y = ts(temp$y, frequency = freq)
        res_y = stlm(y, s.window = freq, robust = FALSE, method = "ets", 
            etsmodel = "ZZN")
        pred_y = forecast(res_y, method = "ets", etsmodel = "ZZN", 
            forecastfunction = NULL, h = predlenth, level = 80, 
            fan = FALSE, lambda = res_y$lambda, biasadj = NULL, 
            xreg = NULL, newxreg = NULL)
        history <- history(data = temp, pred_y = pred_y, freq = freq, 
            width = 2)
        future <- future(data = temp, pred_y = pred_y, freq = freq, 
            pred_length = predlenth)
        output = rbind(history, future)
        if (force_positive) {
            output[output < 0] <- 0
        }
        output <- cbind(output, series_tags)
        influx_write(con = con, db = db, x = output, time_col = "time", 
            tag_cols = colnames(output)[-c(1:4)], measurement = series_names)
    }
  }

crab1234/influxdbr- documentation built on Jan. 12, 2020, 6:28 p.m.