gfSsa: Time-series forecasting based on singular spectrum analysis...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/gfSsa.R

Description

This function applies singular spectrum analysis (SSA) in order to impute missing values in a data set based on time-series forecasting. Note that the SSA method requires sufficiently long series of continuous measurements, i.e. with no data gaps at all. Therefore, gfLinInt and gfJulendat should be used to fill smaller and medium-sized gaps before applying gfSsa.

Usage

1
gfSsa(data, prm = "TEMP", reversed_forecast = FALSE, ...)

Arguments

data

Object of class 'ki.data' or a filepath that can be coerced to ki.data. The data set under investigation.

prm

Character, default is "TEMP". Parameter(s) to fill.

reversed_forecast

Logical, default is FALSE. If TRUE, the supplied measurement series is reversed prior to forecasting, i.e. values are predicted into the past rather than into the future.

...

Additional arguments passed to round.

Value

An object of class ki.data.

Author(s)

Florian Detsch

See Also

gfLinInt, gfJulendat

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
library(dplyr)

data(gsodstations)
gar <- filter(gsodstations, STATION.NAME == "GARISSA")

gsod_gar <- dlGsodStations(usaf = gar$USAF,
                           start_year = 1990, end_year = 1995,
                           dsn = paste0(getwd(), "/data/gar/"),
                           unzip = TRUE)

# Conversion to KiLi SP1 `ki.data` object
ki_gar <- gsod2ki(data = gsod_gar,
                  prm_col = c("TEMP", "MIN", "MAX"),
                  df2ki = TRUE)

# Fill small gaps (n <= 5) with linear interpolation
ki_gar_linint <- gfLinInt(data = ki_gar,
                          prm = c("TEMP", "MIN", "MAX"))

# Fill remaining gaps based on SSA
ki_gar_ssa <- gfSsa(data = ki_gar_linint,
                    prm = c("TEMP", "MIN", "MAX"),
                    reversed_forecast = FALSE,
                    digits = 2)

plot(slot(ki_gar_ssa, "Parameter")[["TEMP"]], type = "l", col = "red")
lines(slot(ki_gar_linint, "Parameter")[["TEMP"]], col = "green")
lines(slot(ki_gar, "Parameter")[["TEMP"]])

environmentalinformatics-marburg/eimarGsodTools documentation built on May 13, 2017, 6:11 p.m.