View source: R/network.interpolation.R
| network.interpolation | R Documentation |
Fills NA gaps in one or more focal dendrometer series by borrowing
information from a reference network recorded at the same site and on the
same time grid.
The focal dataset df is treated as the master time axis. The
reference network is aligned to that axis, so missing timestamps already
inserted into df are preserved during interpolation.
Two interpolation modes are available:
niMethod = "proportional" uses the average relative change in
the reference network between consecutive timestamps and propagates that
change to the focal series.
niMethod = "linear" fits a cross-sensor regression between
reference values at time t-1 and t, and predicts the focal
value at time t from the focal value at time t-1.
Optional bootstrap-based uncertainty limits can be attached, synthetic-gap validation can be used to assess recovery performance, and an optional post-processing step can detect and correct abrupt post-gap jumps in the interpolated series.
network.interpolation(
df,
referenceDF,
niMethod = c("proportional", "linear"),
n_boot = 1000,
return_flags = TRUE,
return_pi = TRUE,
pi_for_all = FALSE,
return_fit = FALSE,
assess = FALSE,
assess_lengths_steps = c(1, 2, 3, 6, 12, 24),
assess_samples_per_length = 20,
assess_buffer_steps = 1,
assess_seed = NULL,
assess_use_only_observed = TRUE,
progress = interactive(),
correct_gap_jumps = FALSE,
jump_threshold = NULL,
jump_adjustment_method = c("window_median", "point_diff"),
jump_adjust_window = 5,
jump_set_point_na = FALSE
)
df |
Data frame containing focal dendrometer data. The first column must
be datetime ( |
referenceDF |
Data frame containing reference dendrometer data. The first column must be datetime, and remaining columns are reference series. |
niMethod |
Character. Interpolation method. One of
|
n_boot |
Integer. Number of bootstrap resamples used in proportional mode. |
return_flags |
Logical. If |
return_pi |
Logical. If |
pi_for_all |
Logical. If |
return_fit |
Logical. If |
assess |
Logical. If |
assess_lengths_steps |
Integer vector. Artificial gap lengths, expressed in number of rows/time steps, to test during validation. |
assess_samples_per_length |
Integer. Number of sampled artificial gaps per gap length and per focal series. |
assess_buffer_steps |
Integer. Number of observed steps required before
and after each artificial gap when
|
assess_seed |
Integer or |
assess_use_only_observed |
Logical. If |
progress |
Logical. If |
correct_gap_jumps |
Logical. If |
jump_threshold |
Numeric. Minimum absolute jump size required before a
post-gap correction is applied. Required if
|
jump_adjustment_method |
Character. Method used to estimate the
post-gap offset. One of |
jump_adjust_window |
Integer. Window size used by
|
jump_set_point_na |
Logical. If |
The function assumes that missing timestamps have already been inserted into
df and corresponding measurements set to NA, for example with
dm.na.interpolation.
For a focal series a, let a_{t-1} be the last available focal
value before the current timestamp. Let b_{t-1} and b_t be the
vectors of reference values at the previous and current timestamps.
In proportional mode, the relative reference change is
\delta = \mathrm{mean}\left(\frac{b_t - b_{t-1}}{\max(b_{t-1}, \epsilon)}\right)
and the focal estimate is
\hat{a}_t = a_{t-1}(1 + \delta).
Bootstrap resampling of reference sensors is used to estimate a 95% interval.
In linear mode, a simple regression of b_t on b_{t-1} is fit
across reference sensors at each step, and the focal value is predicted from
a_{t-1} with a 95% prediction interval.
If fewer than two valid reference sensors are available at a timestamp pair, or if the focal previous value is missing, the focal value is left unchanged.
If correct_gap_jumps = TRUE, the function inspects the first observed
point immediately after each imputed run. If a jump larger than
jump_threshold is detected, the estimated offset is removed from that
point onward. This is useful when a dendrometer resumes from a shifted
baseline after a gap.
If assess = TRUE, the function inserts artificial gaps into observed
sections of each focal series, interpolates them with the chosen method, and
compares predictions with the true values. This produces both per-gap
summaries and seasonal diagnostics of interpolation error.
The returned object is a data frame with class
"network_interpolation".
A data frame with class "network_interpolation".
The data frame contains the original TIME column, focal series
columns, and optionally:
<series>_interpLogical flag for imputed rows.
<series>_pi_lo, <series>_pi_hi95% prediction limits.
<series>_fitModel-implied fitted values.
<series>_jump_correctionNumeric jump offset removed at the
first observed point after an imputed run. NA means no correction
was applied.
In addition, the following attributes are attached:
network_originalOriginal focal data on the aligned time grid.
network_referenceReference data aligned to the focal time grid.
network_diagnosticsLong-format diagnostics for plotting.
network_summaryPer-series interpolation summary table.
network_jump_correctionsTable of inspected and corrected post-gap jumps.
network_validation_rawPer-gap validation summary table, or
NULL.
network_validation_pointsPoint-level validation results, or
NULL.
network_validation_summarySummarized validation metrics by
series and gap length, or NULL.
network_validation_seasonalSeasonal validation diagnostics
by day of year, or NULL.
network_methodInterpolation method used.
network_n_bootNumber of bootstrap resamples used.
network_assessedLogical indicating whether validation was run.
network_jump_settingsList of jump-correction settings.
Smaller validation metrics such as MAE, RMSE, MAPE, and
MdAPE indicate better gap recovery. PI_coverage_95 indicates
how well the nominal 95% uncertainty interval captures the true values
under synthetic-gap validation. Seasonal diagnostics help identify periods
of the year when network interpolation is more or less reliable.
If many post-gap corrections are applied or max_abs_gap_jump is
large, it may indicate re-zeroing, sensor reset, or baseline
discontinuities after gaps.
The focal dataset df defines the output time grid.
Reference series are aligned to that grid using the datetime column.
At least two valid reference sensors are required at consecutive timestamps for interpolation.
Jump correction is a post-processing step and does not alter the core interpolation logic.
plot.network_interpolation,
dm.na.interpolation
#library(dendRoAnalyst)
#data("gf_nepa17")
## Create an artificial focal gap
#df1 <- gf_nepa17
#df1[40:50, "T2"] <- NA
## Build a small reference network
#ref <- cbind(gf_nepa17, gf_nepa17[, 2:3], gf_nepa17[, 2:3])
#colnames(ref) <- c("Time", "T1", "T2", "T3", "T4", "T5", "T6")
## Interpolate with uncertainty limits
#out <- network.interpolation(
# df1, ref,
# niMethod = "proportional",
# n_boot = 100,
# return_flags = TRUE,
# return_pi = TRUE
#)
#head(out, 10)
# Interpolate with jump correction and validation
#out2 <- network.interpolation(
# df1, ref,
# niMethod = "proportional",
# n_boot = 100,
# return_flags = TRUE,
# return_pi = TRUE,
# assess = TRUE,
# assess_lengths_steps = c(1, 2, 4),
# correct_gap_jumps = TRUE,
# jump_threshold = 0.05,
# jump_adjustment_method = "window_median",
# jump_adjust_window = 5
#)
# Plotting
#plot(out2)
#plot(out2, type = "compare")
#plot(out2, type = "seasonal_error")
# Extracting the information using attr()
#attr(out, "network_validation_summary")
#attr(out, "network_validation_points")
#attr(out, "network_validation_seasonal")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.