Learn R Programming

sptemExp (version 0.1.4)

fillNASVDSer: SVD to Interpolate the Missing Values in the Time Series Data

Description

Function to Use SVD to Interpolate the Missing Values in the Time Series Data

Usage

fillNASVDSer(dset, idF, dateF, valF, k)

Arguments

dset

The data frame for time series. Data format: siteid, date, obs dataframe.

idF

The unique location id like siteid.

dateF

The time column name.

valF

The target variable column name.

k

the priciple component, default 1

Value

The data frame similar to the input dset's structure but with filled values.

Details

This function can be used to fill the missing values in time series for many locations.

Examples

Run this code
# NOT RUN {
#Using the 2014 PM2.5 time series as an example
data("shdSeries2014")
n=nrow(shdSeries2014)
p=0.1 # Set the proportion of missing values
np=as.integer(n*p)
index=sample(n,np)
shdSeries2014missed=shdSeries2014
shdSeries2014missed[index,"obs"]=NA
shdSeries2014filled=fillNASVDSer(shdSeries2014missed,"siteid","date","obs",k=1)

#Exmine the accuracy:
cor(shdSeries2014filled[index,"obs"],shdSeries2014[index,"obs"])
rmse(shdSeries2014filled[index,"obs"],shdSeries2014[index,"obs"])

# }

Run the code above in your browser using DataLab