View source: R/dm.na.interpolation.R
| dm.na.interpolation | R Documentation |
Detects missing timestamps (based on provided resolution), inserts rows with NA,
and optionally interpolates missing values using either cubic spline interpolation
(na.spline) or seasonal decomposition interpolation
(na.interp).
Optionally, the function can test the reliability of interpolation for increasing gap lengths (e.g., 6 hours to 3 days) using real data. This allows the user to assess how well a given interpolation method recovers missing values over different durations.
dm.na.interpolation(
df,
resolution,
fill = FALSE,
method = "spline",
assess = FALSE,
assess_lengths_hours = seq(6, 72, by = 6),
assess_samples_per_length = 10,
assess_buffer_hours = 6,
assess_seed = NULL,
verbose = FALSE
)
df |
A data frame with the first column as datetime ( |
resolution |
Integer. Temporal resolution in minutes (e.g., 60 for hourly data). |
fill |
Logical. If |
method |
Character. Interpolation method (only used if
|
assess |
Logical. If |
assess_lengths_hours |
Integer vector. The gap durations (in hours) to test during
assessment. Default: |
assess_samples_per_length |
Integer. Number of artificial gaps per gap length
per series. Default: |
assess_buffer_hours |
Integer. Minimum number of hours of valid data required
before and after the artificial gap to allow valid assessment. Default: |
assess_seed |
Integer or |
verbose |
Logical. If |
The assessment simulates interpolation over artificial gaps of different durations. For each dendrometer series and each gap length:
Random windows (with clean data) are selected.
Data in the window is temporarily set to NA.
The gap is interpolated using the selected method.
The predicted values are compared to the original (true) values using:
MAPE — Mean Absolute Percentage Error.
MdAPE — Median Absolute Percentage Error.
RMSE_pct — Root Mean Square Error (%).
Bias_pct — Mean Percentage Error (%).
Max_diff_abs — Mean absolute difference in daily maximum.
Min_diff_abs — Mean absolute difference in daily minimum.
Time_max_diff_h — Mean absolute difference in time of daily maximum (hours).
Time_min_diff_h — Mean absolute difference in time of daily minimum (hours).
A list of class "dm_na_interpolation" with components:
$dataData frame containing the original or gap-filled series.
$gap_infoTable describing timestamp gaps and internal NA runs.
$assessmentA tibble summarizing interpolation accuracy for each
series and gap length, or NULL when assess = FALSE.
$filledLogical indicating whether interpolation was performed.
$assessedLogical indicating whether interpolation assessment was performed.
$methodInterpolation method used.
$resolutionTemporal resolution in minutes.
library(dendRoAnalyst)
data(nepa17)
#res0 <- dm.na.interpolation(nepa17[1:1000, ], resolution = 60)
#plot(res0)
#plot(res0, type = "gaps")
#res1 <- dm.na.interpolation(
# nepa17[1:1000, ],
# resolution = 60,
# fill = TRUE,
# method = "spline"
#)
#plot(res1)
#plot(res1, type = "gaps")
#plot(res1, type = "interpolation", original = nepa17[1:1000, ])
#res2 <- dm.na.interpolation(
# nepa17[1:1000, ],
# resolution = 60,
# fill = TRUE,
# method = "seasonal",
# assess = TRUE
# )
#plot(res2)
#plot(res2, type = "assessment", metric = "MdAPE")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.