# NOT RUN {
# Example 1: Compare all imputation methods
library("kssa")
library("imputeTS")
# Create 20% random missing data in tsAirgapComplete time series from imputeTS
airgap_na <- missMethods::delete_MCAR(as.data.frame(tsAirgapComplete), 0.2)
# Convert to time series object
airgap_na_ts <- ts(airgap_na, start = c(1959, 1), end = c(1997, 12), frequency = 12)
# Apply the kssa algorithm with 5 segments, 10 iterations, 20% of missing data,
# compare among all available methods in the package.
# Remember that percentmd must match with
# the real percentage of missing data in the input time series
results_kssa <- kssa(airgap_na_ts,
start_methods = "all",
actual_methods = "all",
segments = 5,
iterations = 10,
percentmd = 0.2
)
# Print and check results
results_kssa
# For an easy interpretation of kssa results
# please use function kssa_plot
# }
# NOT RUN {
# Example 2: Compare only locf and linear imputation
library("kssa")
library("imputeTS")
# Create 20% random missing data in tsAirgapComplete time series from imputeTS
airgap_na <- missMethods::delete_MCAR(as.data.frame(tsAirgapComplete), 0.2)
# Convert to time series object
airgap_na_ts <- ts(airgap_na, start = c(1959, 1), end = c(1997, 12), frequency = 12)
# Apply the kssa algorithm with 5 segments, 10 iterations, 20% of missing data,
# compare among all applied methods (locf and linear interpolation).
# Remember that percentmd must match with
# the real percentage of missing data in the input time series
results_kssa <- kssa(airgap_na_ts,
start_methods = c("locf", "linear_i"),
actual_methods = c("locf", "linear_i"),
segments = 5,
iterations = 10,
percentmd = 0.2
)
# Print and check results
results_kssa
# For an easy interpretation of kssa results
# please use function kssa_plot
# }
Run the code above in your browser using DataLab