SpatioTemporal (version 1.1.9.1)

detrendSTdata: Removes Temporal Trend from Observations in a STdata Object

Description

Removes an estimated time-trend from the observations in a STdata object. Returns a modifed STdata object with no trend; the new object can be used to fit a simpler model.

Usage

detrendSTdata(STdata, region = NULL, method = lm, ...)

Arguments

STdata

A STdata object, see mesa.data.raw.

region

Vector of the same length and order as STdata$covars$ID. Indicates region(s) in which different trends are to be fitted and removed.

method

Method for fitting the trend (set to method=lm if is.null(method)); should produce output that allows the use of predict. Possible options include lm, rlm, or lqs.

...

Additional parameters passed to method.

Value

Returns a modfied version of the input, with detrended observations and some changes:

STdata$obs

Has an additional column, removed.trend, with the amount subtracted per observation.

STdata$trend

Is reduced to only the date column, indicating a constant trend.

STdata$old.trend

The previous STdata$trend, which was used for detrending.

STdata$fit.trend

The result of method; the trend component removed for each observations can be obtained as predict(STdata$fit.trend). NOTE: Aditional functions, such as createSTmodel, might reorder STdata$obs implying that STdata$obs$removed.trend != predict(STdata$fit.trend).

Details

Sometimes there is no apparent spatial structure to the time-trend amplitude, or there is not enough identifiability in the data to properly model the structure. In that case, it is possible, at least as a sensitivity analysis, to de-trend the observations and run a model with a spatial field for the intercept only (apart from the spatio-temporal residual field).

detrendSTdata will remove the trends from the observations, using STdata$trend. 'method' is applied as metod(STdata$obs$obs ~ F,...) where F is the temporal trend from STdata$trend for each observation; or as metod(STdata$obs$obs ~ F*obs.region,...) where obs.region = factor(region[ match(STdata$obs$ID, STdata$covars$ID)]). allowing for different trends in different region (i.e. interaction between the time trend(s) and region identifiers).

predict( method(...) ) is then subtracted from STdata$obs$obs, detrending the data.

See Also

Other STdata functions: c.STmodel, createDataMatrix, createSTdata, createSTmodel, estimateBetaFields, removeSTcovarMean, updateTrend.STdata

Examples

Run this code
# NOT RUN {
##load the data
data(mesa.data.raw)
##and create STdata-object
mesa.data <- createSTdata(mesa.data.raw$obs, mesa.data.raw$X, n.basis=2,
                          SpatioTemporal=mesa.data.raw["lax.conc.1500"])

##plot time-series for the first site,
par(mfrow=c(3,2),mar=c(2.5,2.5,3,1))
plot(mesa.data, "obs", ID=1)
##And combined for all sites
plot(mesa.data, "loc.obs", legend.loc="bottomleft")

##attempt to detrend
mesa.data.detrend <- detrendSTdata(mesa.data)
##examine object, note the trends
mesa.data.detrend

##plot detrended time-series for the first site,
plot(mesa.data.detrend, "obs", ID=1)
##And combined for all sites
plot(mesa.data.detrend, "loc.obs", legend.loc="bottomleft")

##use different detrending for different types of locations
mesa.data.detrend2 <- detrendSTdata(mesa.data, region=mesa.data$covars$type)
##examine object, note the trends
mesa.data.detrend2
##plot for the first site,
plot(mesa.data.detrend2, "obs", ID=1)
plot(mesa.data.detrend2, "loc.obs", legend.loc="bottomleft")

##compare the two fitted and removed trends
print(mesa.data.detrend$fit.trend)
print(mesa.data.detrend2$fit.trend)
# }

Run the code above in your browser using DataCamp Workspace