Title: | Stationary Linear Models |
---|---|
Description: | Provides statistical procedures for linear regression in the general context where the errors are assumed to be correlated. Different ways to estimate the asymptotic covariance matrix of the least squares estimators are available. Starting from this estimation of the covariance matrix, the confidence intervals and the usual tests on the parameters are modified. The functions of this package are very similar to those of 'lm': it contains methods such as summary(), plot(), confint() and predict(). The 'slm' package is described in the paper by E. Caron, J. Dedecker and B. Michel (2019), "Linear regression with stationary errors: the R package slm", arXiv preprint <arXiv:1906.06583>. |
Authors: | Emmanuel Caron, Jérôme Dedecker, Bertrand Michel |
Maintainer: | Emmanuel Caron <[email protected]> |
License: | GPL-3 |
Version: | 1.2.0 |
Built: | 2024-11-22 03:35:35 UTC |
Source: | https://github.com/cran/slm |
The slm
package enables to fit linear models on datasets considering the dependence between the observations.
Most of the functions are based on the functions and methods of lm
, with the same arguments and the same format for the outputs.
slm
function, in "slm-main.R"The slm
function is the main function of this package. Its architecture is the same as the lm
function
but it takes into account the possible correlation between the observations. To estimate the asymptotic covariance matrix of
the least squares estimator, several approaches are available: "fitAR" calls the
cov_AR
function, "spectralproj" the cov_spectralproj
function, "kernel" the cov_kernel
function,
"efromovich" the cov_efromovich
function and "select" the cov_select
function. The "hac" method uses the sandwich
package,
and more precisely, the method described by Andrews (1991) and Zeileis (2004).
slm
, in "slm-method.R"The slm
function has several associated methods, which are the same as for the lm
function.
The available methods are: summary
, confint
, predict
, plot
and vcov
.
The package has some auxiliary functions, in particular some predefined kernels for the kernel method of slm
function: the
trapeze kernel, the triangle kernel and the rectangular kernel. The user can also define his own kernel and put it in the argument
kernel_fonc
in the slm
function.
The generative_process
function generates some stationary processes.
The generative_model
function generates some designs.
The package contains a dataset "shan". This dataset comes from a study about fine particle pollution in the city of Shanghai. The data are available on the following website https://archive.ics.uci.edu/ml/datasets/PM2.5+Data+of+Five+Chinese+Cities#.
D. Andrews (1991). Heteroskedasticity and autocorrelation consistent covariant matrix estimation. Econometrica, 59(3), 817-858.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
A. Zeileis (2004). Econometric computing with HC and HAC covariance matrix estimators.
Computes confidence intervals for the model parameters.
## S3 method for class 'slm' confint(object, parm = NULL, level = 0.95, ...)
## S3 method for class 'slm' confint(object, parm = NULL, level = 0.95, ...)
object |
a fitted model object of class |
parm |
a vector of integer. Specifies the coordinates of the vector of parameters for which a confidence interval will be given. If missing, all parameters are considered. |
level |
a number between 0 and 1; the confidence level required. |
... |
additional argument(s) for methods. |
This function returns the confidence intervals for the parameters of the model.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
data("shan") reg1 = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) confint(reg1, level = 0.8) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1, plot = TRUE) confint(reg2, level = 0.9)
data("shan") reg1 = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) confint(reg1, level = 0.8) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1, plot = TRUE) confint(reg2, level = 0.9)
Fit an autoregressive model to the process and compute the theoretical autocovariances of the fitted AR process.
By default, the order is chosen by using the AIC criterion (model_selec = -1
).
cov_AR(epsilon, model_selec = -1, plot = FALSE)
cov_AR(epsilon, model_selec = -1, plot = FALSE)
epsilon |
numeric vector. An univariate process. |
model_selec |
integer or |
plot |
logical. By default, |
The function returns the vector of the theoretical autocovariances of the AR process fitted on the process epsilon
.
model_selec |
the order selected. |
cov_st |
the vector of theoretical autocovariances of the fitted AR process. |
P.J. Brockwell and R.A. Davis (1991). Time Series: Theory and Methods. Springer Science & Business Media.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
x = arima.sim(list(ar=c(0.4,0.2)),1000) cov_AR(x, model_selec = 2, plot = TRUE)
x = arima.sim(list(ar=c(0.4,0.2)),1000) cov_AR(x, model_selec = 2, plot = TRUE)
This method estimates the spectral density and the autocovariances of the error process via a lag-window estimator based on the rectangular kernel (see P.J. Brockwell and R.A. Davis (1991). Time Series: Theory and Methods. Springer Science & Business Media, page 330). The lag is computed according to Efromovich's algorithm (Efromovich (1998)).
cov_efromovich(epsilon, plot = FALSE)
cov_efromovich(epsilon, plot = FALSE)
epsilon |
numeric vector. An univariate process. |
plot |
logical. By default, |
The function returns the estimated autocovariances of the process, that is the Fourier coefficients of the spectral density estimates, and the order chosen by the algorithm.
model_selec |
the number of selected autocovariance terms. |
cov_st |
the estimated autocovariances. |
P.J. Brockwell and R.A. Davis (1991). Time Series: Theory and Methods. Springer Science & Business Media.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
S. Efromovich (1998). Data-driven efficient estimation of the spectral density. Journal of the American Statistical Association, 93(442), 762-769.
x = arima.sim(list(ar=c(0.4,0.2)),1000) cov_efromovich(x)
x = arima.sim(list(ar=c(0.4,0.2)),1000) cov_efromovich(x)
This method estimates the spectral density and the autocovariances of the error process via a lag-window
(or kernel) estimator (see P.J. Brockwell and R.A. Davis (1991). Time Series: Theory and Methods. Springer Science & Business Media,
page 330). The weights are computed according to a kernel and a bandwidth
(or a lag),
to be chosen by the user. The lag can be computed automatically by using a bootstrap technique (as in Wu and Pourahmadi (2009)), via the
Rboot
function.
cov_kernel(epsilon, model_selec = -1, model_max = min(50,length(epsilon)/2), kernel_fonc = triangle, block_size = length(epsilon)/2, block_n = 100, plot = FALSE)
cov_kernel(epsilon, model_selec = -1, model_max = min(50,length(epsilon)/2), kernel_fonc = triangle, block_size = length(epsilon)/2, block_n = 100, plot = FALSE)
epsilon |
numeric vector. An univariate process. |
model_selec |
integer or |
model_max |
integer. The maximal order. |
kernel_fonc |
function. Defines the kernel to use in the method. The user can give his own kernel function. |
block_size |
integer. If |
block_n |
integer. If |
plot |
logical. By default, |
The method returns the tapered autocovariance vector with model_selec
autocovariance terms.
model_selec |
the number of selected autocovariance terms. |
cov_st |
the estimated autocovariances. |
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
W.B. Wu, M. Pourahmadi (2009). Banding sample autocovariance matrices of stationary processes. Statistica Sinica, pp. 1755–1768.
x = arima.sim(list(ar=c(0.7)),1000) cov_kernel(x, model_selec = -1, block_n = 10, plot = TRUE)
x = arima.sim(list(ar=c(0.7)),1000) cov_kernel(x, model_selec = -1, block_n = 10, plot = TRUE)
This function gives the estimation of the asymptotic covariance matrix of the normalized least squares estimator in the case of the linear regression model with strictly stationary errors.
cov_matrix_estimator(object)
cov_matrix_estimator(object)
object |
an object of class |
The function computes the covariance matrix estimator of the normalized least squares estimator from the vector cov_st
of a slm
object. If the user has given the argument Cov_ST
in the slm
object, then it is used
to compute the final covariance matrix. If the method used is the "hac" method, then the final covariance matrix is computed via
the kernHAC
function of the sandwich
package, by using the Quadratic Spectral kernel and the bandwidth described in Andrews (1991).
For the methods "efromovich", "kernel" and "select", the covariance matrix estimator may not be positive definite. Then we apply the
"Positive definite projection" algorithm, which consists in replacing all eigenvalues lower or equal to zero with the smallest
positive eigenvalue of the covariance matrix.
This function returns the estimation of the asymptotic covariance matrix of the normalized least squares estimator.
D. Andrews (1991). Heteroskedasticity and autocorrelation consistent covariant matrix estimation. Econometrica, 59(3), 817-858.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
A. Zeileis (2004). Econometric computing with HC and HAC covariance matrix estimators.
The R package sandwich
.
kernHAC
for HAC methods.
This function gives the estimation of the autocovariances of the error process, with the method chosen by the user. Five methods are available: "fitAR", "spectralproj", "efromovich", "kernel" and "select".
cov_method(epsilon, method_cov_st = "fitAR", model_selec = -1, model_max = NULL, kernel_fonc = NULL, block_size = NULL, block_n = NULL, plot = FALSE)
cov_method(epsilon, method_cov_st = "fitAR", model_selec = -1, model_max = NULL, kernel_fonc = NULL, block_size = NULL, block_n = NULL, plot = FALSE)
epsilon |
numeric vector. An univariate process. |
method_cov_st |
the method chosen by the user to estimate the autocovariances of the error process. The user has the choice between the methods "fitAR", "spectralproj", "efromovich", "kernel", "select" or "hac". By default, the "fitAR" method is used. |
model_selec |
integer or |
model_max |
integer. Maximal dimension of the method. |
kernel_fonc |
function. Use this argument if |
block_size |
integer. Size of the bootstrap blocks if |
block_n |
integer. Blocks number to use for the bootstrap if |
plot |
logical. By default, |
The function returns the autocovariances computed with the chosen method.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
x = arima.sim(list(ar=c(0.4,0.2)),1000) cov_method(x, method_cov_st = "fitAR", model_selec = -1)
x = arima.sim(list(ar=c(0.4,0.2)),1000) cov_method(x, method_cov_st = "fitAR", model_selec = -1)
Allows the user to select the lags of the autocovariance terms of the process to be kept.
cov_select(epsilon, model_selec, plot = FALSE)
cov_select(epsilon, model_selec, plot = FALSE)
epsilon |
numeric vector. An univariate process. |
model_selec |
a vector with the positive lags of the selected autocovariance terms. The variance (lag = 0) is automatically selected. |
plot |
logical. By default, |
In the framework of slm
, this is a manual method for estimating the covariance matrix of the error process
by only selecting some autocovariance terms from the residual autocovariances.
This function returns the estimated autocovariance terms.
model_selec |
the vector with the positive lag of the selected autocovariance terms. |
cov_st |
the vector of the selected autocovariances. |
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
x = arima.sim(list(ar=c(0.2,0.1,0.25)),1000) cov_select(x, c(1,3,5))
x = arima.sim(list(ar=c(0.2,0.1,0.25)),1000) cov_select(x, c(1,3,5))
Computes a data-driven histogram estimator of the spectral density of a process and compute its Fourier coefficients,
that is the associated autocovariances. For a dimension , the estimator of the spectral density is an histogram on a regular basis of
size
. Then we use a penalized criterion in order to choose the dimension which balance the bias and the variance, as proposed in Comte (2001). The penalty
is of the form
, where
is the constant and
the sample size. The dimension and the constant of the penalty are
chosen with the slope heuristic method, with the dimension jump algorithm (from package "
capushe
").
cov_spectralproj(epsilon, model_selec = -1, model_max = min(100,length(epsilon)/2), plot = FALSE)
cov_spectralproj(epsilon, model_selec = -1, model_max = min(100,length(epsilon)/2), plot = FALSE)
epsilon |
numeric vector. An univariate process. |
model_selec |
integer. The dimension of the method. If |
model_max |
integer. The maximal dimension. By default, it is equal to the minimum between 100 and the length of the process divided by 2. |
plot |
logical. By default, |
The function returns the estimated autocovariances of the process, that is the Fourier coefficients of the spectral density estimate, and the dimension chosen by the algorithm.
model_selec |
the dimension selected. |
cov_st |
the estimated autocovariances. |
J.P. Baudry, C. Maugis B. and Michel (2012). Slope heuristics: overview and implementation. Statistics and Computing, 22(2), 455–470.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
F. Comte (2001). Adaptive estimation of the spectrum of a stationary Gaussian sequence. Bernoulli, 7(2), 267-298.
The R package capushe
.
Slope heuristic algorithm DDSE
.
Dimension jump algorithm Djump
.
x = arima.sim(list(ar=c(0.2), ma=c(0.3,0.05)), n=100) cov_spectralproj(x, model_selec = -1)
x = arima.sim(list(ar=c(0.2), ma=c(0.3,0.05)), n=100) cov_spectralproj(x, model_selec = -1)
This function returns a design for the regression linear model, without the intercept. The user can choose one of the two models:
"mod1" or "mod2". The first model "mod1" contains just one column, equal to ,
, where
is an AR(1)
process with
phi_1 = 0.5
.
The second model "mod2" contains two columns, the first equal to and the second equal to
, for
.
The process
is again an AR(1) process with
phi_1 = 0.5
. More information about "mod2" is available in the paper of
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm.
generative_model(n, model = "mod1")
generative_model(n, model = "mod1")
n |
integer. The sample size. |
model |
a list of character "mod1" or "mod2" to choose the model. |
This function returns a data-frame which contains a simulated random design.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
generative_model(500,"mod1")
generative_model(500,"mod1")
This is a generative function. The user chooses one of the process
: "iid", "AR1", "AR12", "MA12", "Nonmixing", "sysdyn", and it
generates the chosen process. These processes are fully described in the paper of
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583.
https://arxiv.org/abs/1906.06583.
generative_process(n, process = "AR1", phi = "numeric", theta = "numeric")
generative_process(n, process = "AR1", phi = "numeric", theta = "numeric")
n |
integer. The sample size. |
process |
a list of character to choose the process. |
phi |
a numeric vector with AR parameters if the process is "AR1" or "AR12". |
theta |
a numeric vector with MA parameters if the process is "MA12". |
This function returns a vector of observations drawn according to the selected process.
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
generative_process(200,"Nonmixing")
generative_process(200,"Nonmixing")
Same function as the plot.lm
function.
## S3 method for class 'slm' plot(x, ...)
## S3 method for class 'slm' plot(x, ...)
x |
|
... |
other parameters to be passed through to plotting functions. |
This function returns the graphics of plot.lm(x)
.
data("shan") reg = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) plot(reg)
data("shan") reg = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) plot(reg)
Predicted values based on slm
object.
## S3 method for class 'slm' predict(object, newdata = NULL, interval = "confidence", level = 0.95, ...)
## S3 method for class 'slm' predict(object, newdata = NULL, interval = "confidence", level = 0.95, ...)
object |
an object of class |
newdata |
an optional data frame in which to look for variables with which to predict.
|
interval |
type of interval calculation. It can be only |
level |
a number between 0 and 1, which indicates the tolerance/confidence level. |
... |
further arguments passed to or from other methods. |
This function produces predicted values, obtained by evaluating the regression function in the frame newdata
(which defaults to model.frame(object)
). If newdata
is omitted the predictions are based on the data used for the fit.
This function produces a vector of predictions or a matrix of predictions and bounds with column names fit
, lwr
,
and upr
if interval
is set.
data("shan") reg1 = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) predict(reg1) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1) predict(reg2)
data("shan") reg1 = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) predict(reg1) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1) predict(reg2)
This function computes an estimation of the risk for the tapered covariance matrix estimator of a process via a bootstrap method, for a specified treshold and a specified kernel.
Rboot(epsilon, treshold, block_size, block_n, model_max, kernel_fonc)
Rboot(epsilon, treshold, block_size, block_n, model_max, kernel_fonc)
epsilon |
numeric vector. An univariate process. |
treshold |
integer. Number of estimated autocovariance terms that we consider for the estimation of the covariance matrix. |
block_size |
integer. The size of the bootstrap blocks. |
block_n |
integer. Blocks number used for the bootstrap. |
model_max |
integer. The maximal dimension, that is the maximal number of terms available to estimate the covariance matrix. |
kernel_fonc |
function. The kernel to use. The user can define his own kernel and put it in the argument. |
This function returns a list with:
risk |
for one treshold, the value of the estimated risk. |
SE |
the standard-error due to the bootstrap. |
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
Rectangular kernel
rectangle(x)
rectangle(x)
x |
a vector of real numbers. |
This function computes the values of the rectangular kernel at points x
.
x = seq(-2,2,length=1000) y = rectangle(x) plot(x,y)
x = seq(-2,2,length=1000) y = rectangle(x) plot(x,y)
This dataset comes from a study about fine particle pollution in five Chinese cities. The data are available on the following website https://archive.ics.uci.edu/ml/datasets/PM2.5+Data+of+Five+Chinese+Cities#. The present dataset concerns the city of Shanghai. From the initial dataset, we have removed the lines that contain NA observations and we then extract the first 5000 observations. Then we consider only pollution variables and weather variables.
data("shan")
data("shan")
A data frame with 5000 rows and 10 variables:
PM2.5 concentration in the Xuhui district ().
PM2.5 concentration in the Jing’an district ().
PM2.5 concentration in the U.S diplomatic post ().
Dew Point ().
Temperature ().
Humidity (%).
Pressure ().
Cumulated wind speed ().
hourly precipitation ().
Cumulated precipitation ().
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
X. Liang, S. Li, S. Zhang, H. Huang, S.X. Chen (2016). PM2.5 data reliability, consistency, and air quality assessment in five Chinese cities. Journal of Geophysical Research: Atmospheres, 121(17), 10–220.
slm
is used to fit linear models when the error process is assumed to be strictly stationary.
slm(myformula, data = NULL, model = TRUE, x = FALSE, y = FALSE, qr = TRUE, method_cov_st = "fitAR", cov_st = NULL, Cov_ST = NULL, model_selec = -1, model_max = 50, kernel_fonc = NULL, block_size = NULL, block_n = NULL, plot = FALSE)
slm(myformula, data = NULL, model = TRUE, x = FALSE, y = FALSE, qr = TRUE, method_cov_st = "fitAR", cov_st = NULL, Cov_ST = NULL, model_selec = -1, model_max = 50, kernel_fonc = NULL, block_size = NULL, block_n = NULL, plot = FALSE)
myformula |
an object of class " |
data |
an optional data frame, list or environment (or object coercible by |
model , x , y , qr
|
logicals. If |
method_cov_st |
the method chosen by the user to estimate the autocovariances of the error process. The user has the choice between the methods "fitAR", "spectralproj", "efromovich", "kernel", "select" or "hac". By default, the "fitAR" method is used. |
cov_st |
numeric vector. The estimated autocovariances of the error process. The user can give his own vector. |
Cov_ST |
matrix. It is an argument given by the user if he wants to use his own covariance matrix estimator. |
model_selec |
integer or |
model_max |
integer. Maximal order of the method. |
kernel_fonc |
function. Use this argument if |
block_size |
integer. Size of the bootstrap blocks if |
block_n |
integer. Blocks number to use for the bootstrap if |
plot |
logical. By default, |
The slm
function is based on the architecture of the lm
function.
Models for slm
are specified symbolically.
A typical model has the form response ~ terms
where response
is the (numeric)
response vector and terms
is a series of terms which specifies a linear predictor for response
.
See the documentation of lm
for more details.
slm
returns an object of class
"slm
". The function
summary
is used to obtain and print a summary of the results. The generic accessor functions
coefficients
, effects
, fitted.values
and residuals
extract various
useful features of the value returned by slm
.
An object of class "slm
" is a list containing at least the following components:
method_cov_st |
print the method chosen. |
cov_st |
the estimated autocovariances of the error process. NA if "hac" is used. |
Cov_ST |
if given by the user, the estimated covariance matrix of the error process. NA if "hac" is used. |
model_selec |
the order of the method. |
norm_matrix |
the normalization matrix of the least squares estimator. |
design_qr |
the matrix |
coefficients |
a named vector of the estimated coefficients. |
residuals |
the residuals, that is response minus fitted values. |
fitted.values |
the fitted values. |
rank |
the numeric rank of the fitted linear model. |
df.residual |
the number of observations minus the number of variables. |
call |
the matched call. |
terms |
the |
xlevels |
(only where relevant) a record of the levels of the factors used in fitting. |
y |
if requested, the response used. |
x |
if requested, the model matrix used. |
model |
if requested (the default), the model frame used. |
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
summary
for summaries.
The generic functions coef
, effects
,
residuals
, fitted
, vcov
.
predict
for prediction, including confidence intervals for , where
is a new observation of the design.
confint
for confidence intervals of parameters.
data("shan") slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg1 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1, plot = TRUE) reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "kernel", model_selec = -1, model_max = 50, kernel_fonc = triangle, block_size = 100, block_n = 100)
data("shan") slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg1 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1, plot = TRUE) reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "kernel", model_selec = -1, model_max = 50, kernel_fonc = triangle, block_size = 100, block_n = 100)
An S4 class to create an slm
object.
method_cov_st
the method used to compute the autocovariance vector of the error process. The user has the choice between the methods "fitAR", "spectralproj", "efromovich", "kernel", "select" or "hac". By default, the "fitAR" method is used.
cov_st
a numeric vector with the estimated autocovariances of the error process, computed from
the method_cov_st
method.
Cov_ST
the estimated covariance matrix of the error process, computed from the method_cov_st
method.
model_selec
integer. The order of the chosen method. If model_selec = -1
, the method works automatically.
norm_matrix
the normalization matrix of the design X.
design_qr
the matrix .
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
Summary method for class "slm
".
## S3 method for class 'slm' summary(object, correlation = FALSE, symbolic.cor = FALSE, ...)
## S3 method for class 'slm' summary(object, correlation = FALSE, symbolic.cor = FALSE, ...)
object |
an object of class " |
correlation |
logical. If |
symbolic.cor |
logical. If |
... |
further arguments passed to or from other methods. |
The function summary.slm
computes and returns a list of summary statistics of the fitted linear model
given in object
, using the components (list elements) "call
" and "terms
" from its argument, plus:
residuals |
the residuals, that is response minus fitted values. |
coefficients |
a |
aliased |
named logical vector showing if the original coefficients are aliased. |
sigma |
the square root of the estimated variance of the error process. |
df |
degrees of freedom, a 3-vector |
chi2statistic |
a 2-vector with the value of the chi2-statistic with its degree of freedom. |
r.squared |
|
cov.unscaled |
the matrix |
correlation |
the correlation matrix corresponding to the above |
symbolic.cor |
(only if |
E. Caron, J. Dedecker and B. Michel (2019). Linear regression with stationary errors: the R package slm. arXiv preprint arXiv:1906.06583. https://arxiv.org/abs/1906.06583.
The model fitting function slm
, summary
.
The function coef
extracts the matrix of coefficients with standard errors, z-statistics and p-values.
data("shan") reg1 = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) summary(reg1) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1) summary(reg2)
data("shan") reg1 = slm(shan$PM_Xuhui ~ . , data = shan, method_cov_st = "fitAR", model_selec = -1) summary(reg1) data("co2") y = as.vector(co2) x = as.vector(time(co2)) - 1958 reg2 = slm(y ~ x + I(x^2) + I(x^3) + sin(2*pi*x) + cos(2*pi*x) + sin(4*pi*x) + cos(4*pi*x) + sin(6*pi*x) + cos(6*pi*x) + sin(8*pi*x) + cos(8*pi*x), method_cov_st = "fitAR", model_selec = -1) summary(reg2)
Trapeze kernel
trapeze(x, width = 0.8)
trapeze(x, width = 0.8)
x |
a vector of real numbers. |
width |
a number between 0 and 1. |
This function computes the values of the trapeze kernel at points x
.
x = seq(-2,2,length=1000) y = trapeze(x, width=0.5) plot(x,y)
x = seq(-2,2,length=1000) y = trapeze(x, width=0.5) plot(x,y)
Kernel triangle
triangle(x)
triangle(x)
x |
a vector of real numbers. |
This function computes the values of the triangle kernel at points x
.
x = seq(-2,2,length=1000) y = triangle(x) plot(x,y)
x = seq(-2,2,length=1000) y = triangle(x) plot(x,y)
Returns the variance-covariance matrix of the (non-normalized) least squares estimators for an object of class slm.
## S3 method for class 'slm' vcov(object, ...)
## S3 method for class 'slm' vcov(object, ...)
object |
a fitted model object of class slm. |
... |
additional arguments for method functions. |
The variance-covariance matrix of the (non-normalized) least squares estimators for an object of class slm.
The generic function vcov
.
The function cov_matrix_estimator
.
n = 500 eps = generative_process(n,"AR1",c(0.7)) X = as.matrix(generative_model(n,"mod2")) Y = 3 + 2*X[,2] + eps reg = slm(Y ~ X, method_cov_st = "fitAR", model_selec = -1) vcov(reg)
n = 500 eps = generative_process(n,"AR1",c(0.7)) X = as.matrix(generative_model(n,"mod2")) Y = 3 + 2*X[,2] + eps reg = slm(Y ~ X, method_cov_st = "fitAR", model_selec = -1) vcov(reg)