fitAR {remotePARTS} | R Documentation |
AR regressions by REML
Description
fitAR
is used to fit AR(1) time series regression
analysis using restricted maximum likelihood
Usage
fitAR(formula, data = NULL)
AR_fun(par, y, X, logLik.only = TRUE)
Arguments
formula |
a model formula, as used by |
data |
optional data environment to search for variables in |
par |
AR parameter value |
y |
vector of time series (response) |
X |
model matrix (predictors) |
logLik.only |
logical: should only the partial log-likelihood be computed |
Details
This function finds the restricted maximum likelihood (REML) to estimate parameters for the regression model with AR(1) random error terms
y(t) = X(t) \beta + \varepsilon(t)
\varepsilon(t) = \rho \varepsilon(t-1) + \delta(t)
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)
;
\varepsilon(t)
is the autocorrelated random error;
\delta \sim N(0, \sigma)
is a temporally independent
Gaussian random variable with mean zero and standard deviation
\sigma
;
and \rho
is the AR(1) autoregression parameter
fitAR
estimates the parameter via mathematical optimization
of the restricted log-likelihood function.
AR_fun
is the work horse behind fitAR
that is called
by optim
to estimate the autoregression parameter \rho
.
Value
fitAR
returns a list object of class "remoteTS", which contains
the following elements.
- call
the function call
- coefficients
a named vector of coefficients
- SE
the standard errors of parameter estimates
- 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
- residuals
the residuals: response minus fitted values
- fitted.values
the fitted mean values
- rho
The AR parameter, determined via REML
- rank
the numeric rank of the fitted model
- df.residual
the residual degrees of freedom
- terms
the
stats::terms
object used
Output is structured similarly to an "lm" object.
When logLik.only == F
, AR_fun
returns the output described in
?fitAR
. When logLik.only == T
, it returns a quantity that is
linearly and negatively related to the restricted log likelihood
(i.e., partial log-likelihood).
References
Ives, A. R., K. C. Abbott, and N. L. Ziebarth. 2010. Analysis of ecological
time series with ARMA(p,q) models. Ecology 91:858-871.
See Also
fitAR_map
to easily apply fit_AR
to many pixels;
fitCLS
and fitCLS_map
for conditional least squares
time series analyses.
Other remoteTS:
fitAR_map()
,
fitCLS_map()
,
fitCLS()
Other remoteTS:
fitAR_map()
,
fitCLS_map()
,
fitCLS()
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
# fit the AR model, using Z as a covariate
(AR = fitAR(x ~ Z))
# get specific components
AR$residuals
AR$coefficients
AR$pval
# now using time as a covariate
(AR.time <- fitAR(x ~ t))
# source variable from a dataframe
df = data.frame(y = x, t.scaled = t/30, Z = Z)
fitAR(y ~ t.scaled + Z, data = df)
## Methods
summary(AR)
residuals(AR)
coefficients(AR)