Class AR
- All Implemented Interfaces:
Serializable
Contrary to the moving-average (MA) model, the autoregressive model is not always stationary as it may contain a unit root.
The notation AR(p)
indicates an autoregressive
model of order p. For an AR(p)
model to be weakly stationary,
the inverses of the roots of the characteristic polynomial must be less
than 1 in modulus.
Two general approaches are available for determining the order p. The first approach is to use the partial autocorrelation function, and the second approach is to use some information criteria.
Autoregression is a good start point for more complicated models. They often fit quite well (don't need the MA terms). And the fitting process is fast (MLEs require some iterations). In applications, easily fitting autoregressions is important for obtaining initial values of parameters and in getting estimates of the error process. Least squares is a popular choice, as is the Yule-Walker procedure. Unlike the Yule-Walker procedure, least squares can produce a non-stationary fitted model. Both the Yule-Walker and least squares estimators are non-iterative and consistent, so they can be used as starting values for iterative methods like MLE.
- See Also:
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns adjusted R2 statistic.double[]
ar()
Returns the linear coefficients of AR (without intercept).int
df()
Returns the degree-of-freedom of residual standard error.static AR
fit
(double[] x, int p) Fits an autoregressive model with Yule-Walker procedure.double[]
Returns the fitted values.double
forecast()
Returns 1-step ahead forecast.double[]
forecast
(int l) Returns l-step ahead forecast.double
Returns the intercept.double
mean()
Returns the mean of time series.static AR
ols
(double[] x, int p) Fits an autoregressive model with least squares method.static AR
ols
(double[] x, int p, boolean stderr) Fits an autoregressive model with least squares method.int
p()
Returns the order of AR.double
R2()
Returns R2 statistic.double[]
Returns the residuals, that is response minus fitted values.double
RSS()
Returns the residual sum of squares.toString()
double[][]
ttest()
Returns the t-test of the coefficients (including intercept).double
variance()
Returns the residual variance.double[]
x()
Returns the time series.
-
Constructor Details
-
AR
Constructor.- Parameters:
x
- the time seriesar
- the estimated weight parameters of AR(p).b
- the intercept.method
- the fitting method.
-
-
Method Details
-
x
public double[] x()Returns the time series.- Returns:
- the time series.
-
mean
public double mean()Returns the mean of time series.- Returns:
- the mean of time series.
-
p
public int p()Returns the order of AR.- Returns:
- the order of AR.
-
ttest
public double[][] ttest()Returns the t-test of the coefficients (including intercept). The first column is the coefficients, the second column is the standard error of coefficients, the third column is the t-score of the hypothesis test if the coefficient is zero, the fourth column is the p-values of test. The last row is of intercept.- Returns:
- the t-test of the coefficients.
-
ar
public double[] ar()Returns the linear coefficients of AR (without intercept).- Returns:
- the linear coefficients.
-
intercept
public double intercept()Returns the intercept.- Returns:
- the intercept.
-
residuals
public double[] residuals()Returns the residuals, that is response minus fitted values.- Returns:
- the residuals.
-
fittedValues
public double[] fittedValues()Returns the fitted values.- Returns:
- the fitted values.
-
RSS
public double RSS()Returns the residual sum of squares.- Returns:
- the residual sum of squares.
-
variance
public double variance()Returns the residual variance.- Returns:
- the residual variance.
-
df
public int df()Returns the degree-of-freedom of residual standard error.- Returns:
- the degree-of-freedom of residual standard error.
-
R2
public double R2()Returns R2 statistic. In regression, the R2 coefficient of determination is a statistical measure of how well the regression line approximates the real data points. An R2 of 1.0 indicates that the regression line perfectly fits the data.In the case of ordinary least-squares regression, R2 increases as we increase the number of variables in the model (R2 will not decrease). This illustrates a drawback to one possible use of R2, where one might try to include more variables in the model until "there is no more improvement". This leads to the alternative approach of looking at the adjusted R2.
- Returns:
- R2 statistic.
-
adjustedR2
public double adjustedR2()Returns adjusted R2 statistic. The adjusted R2 has almost same explanation as R2, but it penalizes the statistic as extra variables are included in the model.- Returns:
- Adjusted R2 statistic.
-
fit
Fits an autoregressive model with Yule-Walker procedure.- Parameters:
x
- the time series.p
- the order.- Returns:
- the model.
-
ols
Fits an autoregressive model with least squares method.- Parameters:
x
- the time series.p
- the order.- Returns:
- the model.
-
ols
Fits an autoregressive model with least squares method.- Parameters:
x
- the time series.p
- the order.stderr
- the flag if estimate the standard errors of parameters.- Returns:
- the model.
-
forecast
public double forecast()Returns 1-step ahead forecast.- Returns:
- 1-step ahead forecast.
-
forecast
public double[] forecast(int l) Returns l-step ahead forecast.- Parameters:
l
- the number of steps.- Returns:
- l-step ahead forecast.
-
toString
-