Learn R Programming

waterData (version 1.0.8)

fillMiss: Fill-in missing hydrological values

Description

Function to fill in missing time series data.

Usage

fillMiss(dataset, block = 30, pmiss = 40, model = "trend",
  smooth = TRUE, ...)

Arguments

dataset
is a data frame in the format of the data frame returned by importDVs, with missing values indicated by NA.
block
is the size of the largest block of missing data that the function will fill-in.
pmiss
is the maximum amount of the missing data that can be missing in the dataset for fill-in procedure to be performed.
model
is the type of structural time series model, see StructTS. The default value is trend. If level is used, the results of fillMiss, which by default applies a fixed-interval smoothing to the time series, tsSmooth, will be very close to linear interpolation.
smooth
a logical that indicates whether or not to apply tsSmooth to the structured time series.
...
further arguments to be passed to plotting method (see par).

Value

a data frame with NAs in the "val" column replaced by estimated values and a plot showing observed and estimated data. If there are too many missing values, based on default or user defined limits, the unaltered dataset is returned as well as a message, such as "Error in fillMiss(misQ05054000) : Too much missing data. Cannot fill in missing values."

Format

The returned data frame has the following columns:
Name Type Description
staid factor USGS station identification number
val numeric The value of the hydrologic variable
dates Date Date of daily value

Details

This function will check the percent of missing values and the size of the largest missing block of data. By default, if less than 40 percent of the data are missing and the largest block is less than 30 days, the data will be filled-in by using a structural time series, StructTS from the base stats package in R (R Development Core Team, 2012). The fitted structural time series is then smoothed via a state-space model, tsSmooth from the base stats package in R.

References

Beauchamp, J.J., 1989, Comparison of regression and time-series methods for synthesizing missing streamflow records: Water Resources Bulletin, v. 25, no. 5, p. 961--975. Elshorbagy, A.A., Panu, U.S., Simonovic, S.P., 2000, Group-based estimation of missing hydrological data---I. Approach and general methodology: Hydrological Sciences Journal, v. 45, no. 6, p. 849--866. R Development Core Team, 2012, R---A language and environment for statistical computing: Vienna, Austria, R Foundation for Statistical Computing, [ISBN 3-900051-07-0]. (Also available at https://www.r-project.org.)

See Also

StructTS, tsSmooth, cleanUp

Examples

Run this code
data(exampleWaterData)
my.newdata <- fillMiss(misQ05054000, block=30, pmiss=50, log="y")
summary(misQ05054000)
summary(my.newdata)
# ph example
 ## Not run: ------------------------------------
# pH05082500<-importDVs("05082500", code="00400", stat="00008", 
# sdate="2000-01-01", edate="2011-12-31")
# plotParam(pH05082500)
# pHfilled<-fillMiss(pH05082500, block=45, ylim=c(7.5,9), yaxs="i")
#  
## ---------------------------------------------

Run the code above in your browser using DataLab