laggedMSR: Mean Squared Residuals and linear regression between two...

Description Usage Arguments Details Value

View source: R/thUtils.R

Description

Functions for regression two time series against one another (y ~ x), while accounting for any lag time of the pattern in y realative to similar patterns in x.

Usage

1
2
3
4
5
laggedMSR(lag, thSeriesPair, nmin)

laggedModel(lData)

laggedData(lag, thSeriesPair)

Arguments

lag

Time that time series y lags time series x.

thSeriesPair

Zoo object with two columns – the starting sine wave and ending sine wave

nmin

Minimum number of x.y pairs desired (see Details)

lData

A zoo object, typcally returned by calling laggedData()

t

A vector of times of observations of values in x and y

Details

When two time series of the same length are subjected to a lag, the number of x,y pairs is reduced in proportion to the size of the lag because the series are become more and more offset in time (analogous to the reduction of the amount of overlap between two meter-sticks, which start out aligned, but are then then slid in opposite directions). The nmin ensures that the estimate of mean squared residuals is based on at least nmin x,y pairs, once the time lag in y is accounted for.

laggedMSR() is desigend to be passed to optimize() in order to find the lag with the minimum mean squared residuals between time series x and y.

Value

laggedMSR Returns the mean squared residuals of a linear model (y ~ x) given a time series x and y, assuming that time series y lags time series x by lag time units. NOTE: When regressed agains one another, two cos waves with a lag of pi radians will yield a mean squared residual of zero and a slope of -1.0. This is an undesirable solution. The prefered solution is a lag of zero, which will yield a MSR of 0 and a slope of 1.0. This, in this function, residuals are calculated using the absolute value of the regression slope. This ensures that the prefered solution (where low MSR is associated with lags that are in phase rather than out of phase) is always returned.

laggedModel runs lm() on lData and returns the results. Usually, lData is generated by calling laggedData()

laggedData() creates a zoo object with two columns (x and y). Each row in the zoo object contains a pair of observations, after accounting for the lag – the amount of time y lags x. na.spline() is used to calculate the y column in the zoo object if lag is not an even multiple of the times between observations.


FluvialLandscapeLab/temperheic documentation built on Dec. 14, 2019, 5:47 p.m.