Gapfill_nls: Gap-fill using NLS

View source: R/Gapf_NLS.R

Gapfill_nlsR Documentation

Gap-fill using NLS

Description

This function automatically gap-fills the missing data points (marked as "NA") in the soil respiration dataset using the non-linear Levenberg-Marquardt algorithm as a function of the soil temperature. A Lloyd-Taylor model is used to formulate the relationship (Lloyd & Taylor, 1994). In cases when Lloyd-Taylor model yields large residuals, a basic exponential function is used instead ("Flux~a*exp(b*Ts)").

Usage

Gapfill_nls(
  data,
  Flux = "Flux",
  Ts = "Ts",
  win = 5,
  interval = 10,
  R10 = 10,
  E0 = 400,
  fail = "ave"
)

Arguments

data

a data frame that includes the flux (with NA indicating the missing data) and soil temperature

Flux

a string indicates the column name for the flux variable to be gap-filled

Ts

a string indicates the column name for the soil temperature

win

a number indicates the required sampling window length around each gap (total number in two sides), unit: days (default: 5)

interval

a number indicates the temporal resolution of the measurements in the dataset, unit: minutes (default: 10)

R10

the start value for the parameter R10 in the Lloyd-Taylor model (default: 10)

E0

the start value for the parameter E0 in the Lloyd-Taylor model (default: 400)

fail

a string or a number, what to do when model fails to converge: 1. use the mean value in the sampling window to fill the gap ("ave", default), or 2. use any value assigned here to fill the gap (e.g., 9999, NA, etc.)

Value

A data frame that includes the original data, gap-filled data ("filled") and a "mark" column that indicates the value in each row of the "filled" is either: 0. original, 1. gap-filled, or 2. failed to converge

References

Lloyd J., Taylor, J.A., 1994. On the Temperature Dependence of Soil Respiration. Functional Ecology. 8, 315-323.

Examples

# read example data
df <- read.csv(file = system.file("extdata", "Soil_resp_example.csv", package = "FluxGapsR"),header = T)
df_filled <- Gapfill_nls(data = df)
# visualize the gapfilled results
plot(df_filled$filled,col="red")
points(df_filled$Flux)

junbinzhao/FluxGapsR documentation built on Nov. 19, 2022, 9:17 p.m.