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

View source: R/gfSsa.R

gfSsaR Documentation

Time-series forecasting based on singular spectrum analysis (SSA)

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

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

## Not run: 
gar <- subset(gsodstations, `STATION NAME` == "GARISSA")

gsod_gar <- dlGsodStations(usaf = gar$USAF,
                           start_year = 1990, end_year = 1995,
                           dsn = tempdir(),
                           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(methods::slot(ki_gar_ssa, "Parameter")[["TEMP"]], type = "l", col = "red")
lines(methods::slot(ki_gar_linint, "Parameter")[["TEMP"]], col = "green")
lines(methods::slot(ki_gar, "Parameter")[["TEMP"]])             

## End(Not run)


environmentalinformatics-marburg/GSODTools documentation built on Jan. 5, 2024, 12:19 a.m.