Title: | Positive Time Series Regression |
---|---|
Description: | A collection of functions to simulate, estimate and forecast a wide range of regression based dynamic models for positive time series. This package implements the results presented in Prass, T.S.; Carlos, J.H.; Taufemback, C.G. and Pumi, G. (2022). "Positive Time Series Regression" <arXiv:2201.03667>. |
Authors: | Taiane Schaedler Prass [aut, cre, com] , Jonas Hendler Carlos [aut], Cleiton Guollo Taufemback [aut] |
Maintainer: | Taiane Schaedler Prass <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.2 |
Built: | 2025-01-20 03:55:07 UTC |
Source: | https://github.com/cran/PTSR |
Density function and random numbers generation for models with support on the positive real line.
d.betap(x, mu, varphi, log = FALSE) r.betap(n, mu, varphi) d.F(x, mu, varphi, log = FALSE) r.F(n, mu, varphi) d.gamma(x, mu, varphi, log = FALSE) r.gamma(n, mu, varphi) d.invGauss(x, mu, varphi, log = FALSE) r.invGauss(n, mu, varphi) d.logLogis(x, mu, varphi, log = FALSE) r.logLogis(n, mu, varphi) d.logNorm(x, mu, varphi, log = FALSE) r.logNorm(n, mu, varphi) d.chi(x, mu, log = FALSE, ...) r.chi(n, mu, ...) d.ray(x, mu, log = FALSE, ...) r.ray(n, mu, ...)
d.betap(x, mu, varphi, log = FALSE) r.betap(n, mu, varphi) d.F(x, mu, varphi, log = FALSE) r.F(n, mu, varphi) d.gamma(x, mu, varphi, log = FALSE) r.gamma(n, mu, varphi) d.invGauss(x, mu, varphi, log = FALSE) r.invGauss(n, mu, varphi) d.logLogis(x, mu, varphi, log = FALSE) r.logLogis(n, mu, varphi) d.logNorm(x, mu, varphi, log = FALSE) r.logNorm(n, mu, varphi) d.chi(x, mu, log = FALSE, ...) r.chi(n, mu, ...) d.ray(x, mu, log = FALSE, ...) r.ray(n, mu, ...)
x |
vector of real values |
mu |
non-negative parameter (the distribution's mean. See ‘Details’) |
varphi |
non-negative parameter |
log |
logical; if TRUE, probabilities |
n |
sample size |
... |
for compatibility with other functions |
For the reparametrized Beta-Prime distribution, the functions dbetapr and rbetapr are imported from the package extraDistr
. The following holds
For the reparametrized F distribution, the functions df and rf are imported from stats
. The following holds
so that the parameter must satisfy
.
For the reparametrized Gamma distribution, the functions dgamma and rgamma are imported from stats
. The following holds
For the reparametrized Inverse Gaussian distribution, the functions dinvGauss and rinvGauss are imported from SuppDists
. The following holds
For the reparametrized Log-logistic distribution, the functions dllogis and rllogis a are imported from actuar
. The following holds
For the reparametrized Log-Normal distribution, the functions dlnorm and rlnorm are imported from stats
. The following holds
For the reparametrized Chi-squared F distribution, the functions dchisq and rchisq are imported from stats
. The following holds
For the reparametrized Rayleigh distribution, the functions drayleigh and rrayleigh are imported from extraDistr
. The following holds
For any avaliable dist
, ddist
gives the density and rdist
generates random deviates.
The length of the result is determined by n
for rdist
, and is the maximum of the lengths of the numerical arguments for rdist
.
The numerical arguments other than n
are recycled to the length of the result. Only the first elements of the logical arguments are used.
Predicted values based on ptsr object.
## S3 method for class 'ptsr' predict(object, newdata, nnew = 0, ...)
## S3 method for class 'ptsr' predict(object, newdata, nnew = 0, ...)
object |
Object of class inheriting from |
newdata |
A matrix with new values for the regressors. If omitted
and |
nnew |
number of out-of-sample forecasts required. If |
... |
further arguments passed to or from other methods. |
predict.ptsr
produces predicted values, obtained by evaluating
the regression function in the frame newdata
.
If newdata
is omitted the predictions are based on the data
used for the fit.
For now, prediction intervals are not provided.
A list with the following arguments
series |
The original time series yt. |
xreg |
The original regressors (if any). |
fitted.values |
The in-sample forecast given by |
etat |
In-sample values of |
error |
The error term |
residuals |
The (in-sample) residuals, that is, the observed minus the predicted values. |
forecast |
The predicted values for yt. |
Print method for objects of class ptsr
.
## S3 method for class 'ptsr' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'ptsr' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
object of class |
digits |
minimal number of significant digits, see
|
... |
further arguments to be passed to or from other methods. They are ignored in this function |
Users are not encouraged to call these internal functions directly. Internal functions for package PTSR.
Invisibly returns its argument, x
.
Title Function to fit a PTSR model
ptsr.fit(start, yt, xreg = NULL, xregar = TRUE, fit.alpha = TRUE, p = 0, q = 0, arlag = NULL, malag = NULL, ddist = d.gamma, link1 = "log", link2 = "identity", g1 = NULL, g1.inv = NULL, g2 = NULL, method = "L-BFGS-B", ...)
ptsr.fit(start, yt, xreg = NULL, xregar = TRUE, fit.alpha = TRUE, p = 0, q = 0, arlag = NULL, malag = NULL, ddist = d.gamma, link1 = "log", link2 = "identity", g1 = NULL, g1.inv = NULL, g2 = NULL, method = "L-BFGS-B", ...)
start |
a vector with the starting values for the non-fixed coefficients of the model. |
yt |
the time series |
xreg |
optionally, a vector or matrix of external regressors. Default is |
xregar |
logical, if |
fit.alpha |
logical, if FALSE, alpha is set to zero. Default is |
p |
order of the AR polinomial |
q |
order of the MA polinomial |
arlag |
the lags to be included in the AR polinomial. Default is |
malag |
the lags to be included in the MA polinomial. Default is |
ddist |
function, the density function to be used |
link1 |
character indicating which link must be used for |
link2 |
character indicating which link must be used for |
g1 |
optionally, a link function to be used for |
g1.inv |
optionally, a the inverse link function to be used for |
g2 |
optionally, a link function to be used for |
method |
The method to be used. See [optim][stats::optim] for details. |
... |
Further arguments to be passed to |
The same arguments return by optim
plus a the following arguments
coefficients
: a vector with the estimated coefficients;
sll
: the sum of the log-likelihood for the fitted model;
series
: the original time series;
xreg
: the regressors (if any);
fitted.values
: the conditional mean, which corresponds to
the in-sample forecast, also denoted fitted values;
residuals
: the observed minus the fitted values;
model
: a list with the configurations used to fit the model.
#------------------------------------------------------------------- # Gamma-ARMA(1,1) model with no regressors #------------------------------------------------------------------- simu = ptsr.sim(n = 3000, burn = 50, varphi = 20, alpha = 0, phi = 0.35, theta = 0.2, seed = 1234, rdist = r.gamma, link1 = "log", link2 = "log") fit1 = ptsr.fit(start = c(0,0,0,10), yt = simu$yt, fit.alpha = TRUE, p = 1, q = 1, ddist = d.gamma, link1 = "log", link2 = "log", method = "L-BFGS-B") summary(fit1) # removing alpha from the model fit2 = ptsr.fit(start = c(0,0,10), yt = simu$yt, fit.alpha = FALSE, p = 1, q = 1, ddist = d.gamma, link1 = "log", link2 = "log", method = "L-BFGS-B") summary(fit2)
#------------------------------------------------------------------- # Gamma-ARMA(1,1) model with no regressors #------------------------------------------------------------------- simu = ptsr.sim(n = 3000, burn = 50, varphi = 20, alpha = 0, phi = 0.35, theta = 0.2, seed = 1234, rdist = r.gamma, link1 = "log", link2 = "log") fit1 = ptsr.fit(start = c(0,0,0,10), yt = simu$yt, fit.alpha = TRUE, p = 1, q = 1, ddist = d.gamma, link1 = "log", link2 = "log", method = "L-BFGS-B") summary(fit1) # removing alpha from the model fit2 = ptsr.fit(start = c(0,0,10), yt = simu$yt, fit.alpha = FALSE, p = 1, q = 1, ddist = d.gamma, link1 = "log", link2 = "log", method = "L-BFGS-B") summary(fit2)
Given the name of a link, this function returns a link function,
an inverse link function, the derivative
and the derivative
.
ptsr.link(link = "log")
ptsr.link(link = "log")
link |
character; one of |
The available links are:
log:
log1:
An object of class "link-ptsr"
, a list with components
linkfun |
Link function |
linkinv |
Inverse link function |
linkdif |
Derivative |
mu.eta |
Derivative |
name |
a name to be used for the link |
Function to simulate a PTSR model
ptsr.sim(n = 1, burn = 0, xreg = NULL, xregar = TRUE, varphi = 1, alpha = 0, beta = NULL, phi = NULL, theta = NULL, seed = stats::runif(1, 1000, 10000), rdist = r.gamma, link1 = "log", link2 = "identity", g1 = NULL, g1.inv = NULL, g2 = NULL)
ptsr.sim(n = 1, burn = 0, xreg = NULL, xregar = TRUE, varphi = 1, alpha = 0, beta = NULL, phi = NULL, theta = NULL, seed = stats::runif(1, 1000, 10000), rdist = r.gamma, link1 = "log", link2 = "identity", g1 = NULL, g1.inv = NULL, g2 = NULL)
n |
a strictly positive integer. The sample size of yt (after burn-in). Default is 1. |
burn |
a non-negative integer. length of "burn-in" period. Default is 0. |
xreg |
optionally, a vector or matrix of external regressors.
For simulation purposes, the length of xreg must be |
xregar |
logical, if |
varphi |
non-negative parameter. Default is 1. |
alpha |
a numeric value corresponding to the intercept. Default is 0. |
beta |
optionally, a vector of coefficients corresponding to the
regressors in |
phi |
optionally, for the simulation function this must be a vector
of size |
theta |
optionally, for the simulation function this must be a vector
of size |
seed |
optionally, an integer which gives the value of the fixed seed to be used by the random number generator. If missing, a random integer is chosen uniformly from 1,000 to 10,000. |
rdist |
function, the random number generator to be used |
link1 |
character indicating which link must be used for |
link2 |
character indicating which link must be used for |
g1 |
optionally, a link function to be used for |
g1.inv |
optionally, a the inverse link function to be used for |
g2 |
optionally, a link function to be used for |
The function ptsr.sim
generates a random sample from a positive time
series regression model, with a given distribution.
Returns a list with the following components
yt
: the simulated time series
mut
: the conditional mean
etat
: the linear predictor
error
: the error term.
#------------------------------------------------------------------- # Generating a sample of a Gamma-ARMA(1,1) model with no regressors #------------------------------------------------------------------- simu = ptsr.sim(n = 300, burn = 50, varphi = 20, alpha = 0, phi = 0.35, theta = 0.2, seed = 1234, rdist = r.gamma, link1 = "log", link2 = "log") names(simu) plot.ts(simu$yt) lines(simu$mut, col= "red")
#------------------------------------------------------------------- # Generating a sample of a Gamma-ARMA(1,1) model with no regressors #------------------------------------------------------------------- simu = ptsr.sim(n = 300, burn = 50, varphi = 20, alpha = 0, phi = 0.35, theta = 0.2, seed = 1234, rdist = r.gamma, link1 = "log", link2 = "log") names(simu) plot.ts(simu$yt) lines(simu$mut, col= "red")
summary
method for class "ptsr"
.
## S3 method for class 'ptsr' summary(object, ...) ## S3 method for class 'summary.ptsr' print(x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ...)
## S3 method for class 'ptsr' summary(object, ...) ## S3 method for class 'summary.ptsr' print(x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ...)
object |
object of class |
... |
further arguments passed to or from other methods. |
x |
an object of class |
digits |
minimal number of significant digits, see
|
signif.stars |
logical. If |
print.summary.btsr
tries to be smart about formatting the
coefficients, standard errors, etc. and additionally provides
‘significance stars’.
The function summary.ptsr
computes and returns a list
of summary statistics of the fitted model given in object
.
Returns a list of class summary.ptsr
, which contains the
following components:
residuals |
the residuals of the model. |
coefficients |
a |
sigma.res |
the square root of the estimated variance of the random error
where |
df |
degrees of freedom, a 3-vector |
vcov |
a |
loglik |
the sum of the log-likelihood values |
aic |
the AIC value. |
bic |
the BIC value. |
hqc |
the HQC value. |