updateTrend.STdata {SpatioTemporal} | R Documentation

## Update Trend in `STdata` or `STmodel` Object

### Description

Updates/sets the temporal trend for `STdata` or `STmodel` objects. It also checks that the spatio-temporal covariate exists for all dates in the trend, mainly an issue if `extra.dates!=NULL` adds additional times at which to do predictions.

### Usage

    ## S3 method for class 'STdata'
    updateTrend(object, n.basis = 0, fnc = NULL,
      extra.dates = NULL, ...)

    ## S3 method for class 'STmodel'
    updateTrend(object, n.basis = 0, fnc = NULL, ...)

    updateTrend(object, n.basis = 0, fnc = NULL, ...)

    updateSTdataTrend(object, n.basis = 0, extra.dates = NULL, fnc = NULL,
      ...)

### Arguments

`object` | A `STdata` or `STmodel` object, see `mesa.data.raw`.
`n.basis` | number of basis functions for the temporal trend
`fnc` | Function that defines the trend, see Details and Example.
`extra.dates` | Additional dates for which smooth trends should be computed (otherwise only those in `object$obs$date` are used); only for `STdata`.
`...` | Additional parameters passed to `calcSmoothTrends`.

### Details

If `n.basis` is given this will use `calcSmoothTrends` to compute smoothed SVDs of data for use as temporal trends. If `fnc` is given, `n.basis` is ignored and `fnc` should be a function that, given a vector of dates, returns an object that can be coerced to a data.frame with numeric temporal trends; recall that an intercept is always added.

For a `STmodel` object the new trend must have no more components than the existing trend; if a function is given `colnames` of the new trend must match those of the existing trend. In both cases the returned `STdata` or `STmodel` object will have both a `$trend` and `$trend.fnc` field.

Function `updateSTdataTrend` is deprecated and will be removed in future versions of the package.

### Value

Returns a modfied version of the input, with an added/altered trend.

### Author(s)

Johan Lindstrom

### See Also

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

Other SVD for missing data: `SVDmiss`, `SVDsmooth`, `calcSmoothTrends`, `plot.SVDcv`, `print.SVDcv`

Other STmodel functions: `createCV`, `createDataMatrix`, `createSTmodel`, `dropObservations`, `estimateBetaFields`, `loglikeSTdim`, `loglikeST`, `predictNaive`, `processLUR`, `processLocation`, `updateCovf`

### Examples

    ##load data
    data(mesa.model)

    ##default data and time trend for one location
    par(mfrow=c(3,1), mar=c(2.5,2.5,3,1))
    plot(mesa.model)

    ##let's try with no trend
    mesa.model.0 <- updateTrend(mesa.model, n.basis=0)
    plot(mesa.model.0)

    ##...and two basis functions, based on only AQS sites and much less smooth
    subset <- mesa.model$locations$ID[mesa.model$locations$type=="AQS"]
    mesa.model.2 <- updateTrend(mesa.model, n.basis=2, subset=subset, df=100)
    plot(mesa.model.2)

    ##Compute trends based on only 10 sites (and compute the cross-validated
    ##trends leaving each of the sites out
    smooth.trend <- calcSmoothTrends(mesa.model, n.basis=2, cv=TRUE,
                                     subset=subset[1:10])

    ##update trends using the function definition
    mesa.model <- updateTrend(mesa.model, fnc=smooth.trend$trend.fnc)

    ##and create objects with each of the trends.
    mesa.model.cv <- vector("list", length(smooth.trend$trend.fnc.cv))
    for(i in 1:length(mesa.model.cv)){
      suppressMessages(mesa.model.cv[[i]] <- updateTrend(mesa.model,
                       fnc=smooth.trend$trend.fnc.cv[[i]]))
    }

    ##plot
    par(mfrow=c(1,1),mar=c(2.5,2.5,3,1))
    plot(mesa.model)
    for(i in 1:length(mesa.model.cv)){
      plot(mesa.model.cv[[i]], add=TRUE, col=i, pch=NA, lty=c(NA,2))
    }

[Package SpatioTemporal version 1.1.9.1 Index]