fitCLS {remotePARTS}R Documentation

CLS for time series

Description

fitCLS is used to fit conditional least squares regression to time series data.

Usage

fitCLS(
  formula,
  data = NULL,
  lag.y = 1,
  lag.x = 1,
  debug = FALSE,
  model = FALSE,
  y = FALSE
)

Arguments

formula

a model formula, as used by stats::lm()

data

optional data environment to search for variables in formula. As used by lm()

lag.y

an integer indicating the lag (in time steps) between y and y.0

lag.x

an integer indicating the lag (in time steps) between y and the independent variables (except y.0).

debug

logical debug mode

model

logical, should the used model matrix be returned? As used by lm()

y

logical, should the used response variable be returned? As used by lm()

Details

This function regresses the response variable (y) at time t, conditional on the response at time t-lag.y and the specified dependent variables (X) at time t-lag.x:

y(t) = y(t - lag.y) + X(t - lag.x) + \varepsilon

where y(t) is the response at time t;

X(t) is a model matrix containing covariates;

\beta is a vector of effects of X(t);

and \varepsilon(t) is a temporally independent Gaussian random variable with mean zero and standard deviation \sigma

stats::lm() is then called, using the above equation.

Value

fitCLS returns a list object of class "remoteTS", which inherits from "lm". In addition to the default "lm" components, the output contains these additional list elements:

tstat

the t-statistics for coefficients

pval

the p-values corresponding to t-tests of coefficients

MSE

the model mean squared error

logLik

the log-likelihood of the model fit

See Also

fitCLS_map to easily apply fitCLS to many pixels; fitAR and fitAR_map for AR time series analyses.

Other remoteTS: fitAR_map(), fitAR(), fitCLS_map()

Examples


# simulate dummy data
t = 1:30 # times series
Z = rnorm(30) # random independent variable
x = .2*Z + (.05*t) # generate dependent effects
x[2:30] = x[2:30] + .2*x[1:29] # add autocorrelation
x = x + rnorm(30, 0, .01)
df = data.frame(x, t, Z) # collect in data frame

# fit a CLS model with previous x, t, and Z as predictors
## note, this model does not follow the underlying process.
### See below for a better fit.
(CLS <- fitCLS(x ~ t + Z, data = df))

# extract other values
CLS$MSE #MSE
CLS$logLik #log-likelihood

# fit with no lag in independent variables (as simulated):
(CLS2 <- fitCLS(x ~ t + Z, df, lag.x = 0))
summary(CLS2)

# no lag in x
fitCLS(x ~ t + Z, df, lag.y = 0)

# visualize the lag
## large lag in x
fitCLS(x ~ t + Z, df, lag.y = 2, lag.x = 0, debug = TRUE)$lag
## large lag in Z
fitCLS(x ~ t + Z, df, lag.y = 0, lag.x = 2, debug = TRUE)$lag

# # throws errors (NOT RUN)
# fitCLS(x ~ t + Z, df, lag.y = 28) # longer lag than time
# fitCLS(cbind(x, rnorm(30)) ~ t + Z, df) # matrix response

## Methods
summary(CLS)
residuals(CLS)


[Package remotePARTS version 1.0.4 Index]