BARFIMA.functions {BTSR} | R Documentation |
Functions to simulate, extract components and fit BARFIMA models
Description
These functions can be used to simulate, extract components
and fit any model of the class barfima
. A model with
class barfima
is a special case of a model with class btsr
.
See ‘The BTSR structure’ in btsr.functions
for
more details on the general structure.
The \beta
ARMA model, the beta regression and a i.i.d. sample
from a beta distribution can be obtained as special cases.
See ‘Details’.
Usage
BARFIMA.sim(n = 1, burn = 0, xreg = NULL, coefs = list(alpha = 0, beta
= NULL, phi = NULL, theta = NULL, d = 0, nu = 20), y.start = NULL,
xreg.start = NULL, xregar = TRUE, error.scale = 1, complete = FALSE,
inf = 1000, linkg = c("logit", "logit"), seed = NULL, rngtype = 2,
debug = FALSE)
BARFIMA.extract(yt, xreg = NULL, nnew = 0, xnew = NULL, p, q,
coefs = list(), lags = list(), fixed.values = list(),
fixed.lags = list(), y.start = NULL, xreg.start = NULL,
xregar = TRUE, error.scale = 1, inf = 1000, m = 0,
linkg = c("logit", "logit"), llk = TRUE, sco = FALSE, info = FALSE,
extra = FALSE, debug = FALSE)
BARFIMA.fit(yt, xreg = NULL, nnew = 0, xnew = NULL, p = 0, d = TRUE,
q = 0, m = 0, inf = 1000, start = list(), ignore.start = FALSE,
lags = list(), fixed.values = list(), fixed.lags = list(),
lower = list(nu = 0), upper = list(nu = Inf), linkg = c("logit",
"logit"), sco = FALSE, info = FALSE, extra = FALSE, xregar = TRUE,
y.start = NULL, xreg.start = NULL, error.scale = 1, control = list(),
report = TRUE, debug = FALSE, ...)
Arguments
n |
a strictly positive integer. The sample size of yt (after burn-in). Default is 1. |
burn |
a non-negative integer. The length of the "burn-in" period. Default is 0. |
xreg |
optionally, a vector or matrix of external regressors.
For simulation purposes, the length of xreg must be |
coefs |
a list with the coefficients of the model. An empty list will result in an error. The arguments that can be passed through this list are:
|
y.start |
optionally, an initial value for yt (to be used
in the recursions). Default is |
xreg.start |
optionally, a vector of initial value for xreg
(to be used in the recursions). Default is |
xregar |
logical; indicates if xreg is to be included in the
AR part of the model. See ‘The BTSR structure’. Default is |
error.scale |
the scale for the error term. See ‘The BTSR structure’
in |
complete |
logical; if |
inf |
the truncation point for infinite sums. Default is 1,000.
In practice, the Fortran subroutine uses |
linkg |
character or a two character vector indicating which
links must be used in the model. See ‘The BTSR structure’
in |
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. |
rngtype |
optionally, an integer indicating which random number generator
is to be used. Default is 2: the Mersenne Twister algorithm. See ‘Common Arguments’
in |
debug |
logical, if |
yt |
a numeric vector with the observed time series. If missing, an error message is issued. |
nnew |
optionally, the number of out-of sample predicted values required. Default is 0. |
xnew |
a vector or matrix, with |
p |
a non-negative integer. The order of AR polynomial.
If missing, the value of |
q |
a non-negative integer. The order of the MA polynomial.
If missing, the value of |
lags |
optionally, a list with the lags that the values in |
fixed.values |
optionally, a list with the values of the coefficients
that are fixed. By default, if a given vector (such as the vector of AR coefficients)
has fixed values and the corresponding entry in this list is empty, the fixed values
are set as zero. The names of the entries in this list must match the ones
in |
fixed.lags |
optionally, a list with the lags that the fixed values
in |
m |
a non-negative integer indicating the starting time for the sum of the
partial log-likelihoods, that is |
llk |
logical, if |
sco |
logical, if |
info |
logical, if |
extra |
logical, if |
d |
logical, if |
start |
a list with the starting values for the non-fixed coefficients
of the model. If an empty list is provided, the function |
ignore.start |
logical, if starting values are not provided, the
function uses the default values and |
lower |
optionally, list with the lower bounds for the
parameters. The names of the entries in these lists must match the ones
in |
upper |
optionally, list with the upper bounds for the
parameters. The names of the entries in these lists must match the ones
in |
control |
a list with configurations to be passed to the optimization subroutines. Missing arguments will receive default values. See fit.control. |
report |
logical, if |
... |
further arguments passed to the internal functions. |
Details
The \beta
ARMA model and the beta regression can be
obtained as special cases of the \beta
ARFIMA model.
-
\beta
ARFIMA: the model from Pumi et al. (2019) is obtained by settingerror.scale = 1
(predictive scale) andxregar = TRUE
(so that the regressors are included in the AR part of the model). Variations of this model are obtained by changingerror.scale
,xregar
and/or by using different links fory[t]
(in the AR part of the model) and\mu[t]
. -
\beta
ARMA: the model from Rocha and Cribari-Neto (2009, 2017) is obtained by settingcoefs$d = 0
andd = FALSE
anderror.scale = 1
(predictive scale). Variations of this model are obtained by changing the error scale and/or by using a different link fory[t]
in the AR part of the model. beta regression: the model from Ferrari and Cribari-Neto (2004) is obtained by setting
p = 0
,q = 0
andcoefs$d = 0
andd = FALSE
. Theerror.scale
is irrelevant. The second argument inlinkg
is irrelevant.an i.i.d. sample from a Beta distribution with parameters
shape1
andshape2
(compatible with the one fromrbeta
) is obtained by settinglinkg = "linear"
,p = 0
,q = 0
,d = FALSE
and, in the coefficient list,alpha = shape1/(shape1+shape2)
andnu = shape1+shape2
. (error.scale
andxregar
are irrelevant)
The function BARFIMA.sim
generates a random sample from a \beta
ARFIMA(p,d,q)
model.
The function BARFIMA.extract
allows the user to extract the
components y_t
, \mu_t
, \eta_t = g(\mu_t)
, r_t
,
the log-likelihood, and the vectors and matrices used to calculate the
score vector and the information matrix associated to a given set of parameters.
This function can be used by any user to create an objective function that can be passed to optimization algorithms not available in the BTSR Package.
The function BARFIMA.fit
fits a BARFIMA model to a given univariate time
series. For now, available optimization algorithms are "L-BFGS-B"
and
"Nelder-Mead"
. Both methods accept bounds for the parameters. For
"Nelder-Mead"
, bounds are set via parameter transformation.
Value
The function BARFIMA.sim
returns the simulated time series yt by default.
If complete = TRUE
, a list with the following components
is returned instead:
-
model
: string with the text"BARFIMA"
-
yt
: the simulated time series -
mut
: the conditional mean -
etat
: the linear predictorg(\mu_t)
-
error
: the error termr_t
-
xreg
: the regressors (if included in the model). -
debug
: the output from FORTRAN (if requested).
The function BARFIMA.extract
returns a list with the following components.
-
model
: string with the text"BARFIMA"
-
coefs
: the coefficients of the model passed through thecoefs
argument -
yt
: the observed time series -
gyt
: the transformed time seriesg_2(y_t)
-
mut
: the conditional mean -
etat
: the linear predictorg_1(\mu_t)
-
error
: the error termr_t
-
xreg
: the regressors (if included in the model). -
sll
: the sum of the conditional log-likelihood (if requested) -
sco
: the score vector (if requested) -
info
: the information matrix (if requested) -
Drho
,T
,E
,h
: additional matrices and vectors used to calculate the score vector and the information matrix. (if requested) -
yt.new
: the out-of-sample forecast (if requested) -
out.Fortran
: FORTRAN output (if requested)
The function btsr.fit
returns a list with the following components.
Each particular model can have additional components in this list.
-
model
: string with the text"BARFIMA"
-
convergence
: An integer code. 0 indicates successful completion. The error codes depend on the algorithm used. -
message
: A character string giving any additional information returned by the optimizer, or NULL. -
counts
: an integer giving the number of function evaluations. -
control
: a list of control parameters. -
start
: the starting values used by the algorithm. -
coefficients
: The best set of parameters found. -
n
: the sample size used for estimation. -
series
: the observed time series -
gyt
: the transformed time seriesg_2(y_t)
-
fitted.values
: the conditional mean, which corresponds to the in-sample forecast, also denoted fitted values -
etat
: the linear predictorg_1(\mu_t)
-
error.scale
: the scale for the error term. -
error
: the error termr_t
-
residual
: the observed minus the fitted values. The same as theerror
term iferror.scale = 0
. -
forecast
: the out-of-sample forecast (if requested). -
xnew
: the observations of the regressors observed/predicted values corresponding to the period of out-of-sample forecast. Only inlcudes ifxreg
is notNULL
andnnew > 0
. -
sll
: the sum of the conditional log-likelihood (if requested) -
info.Matrix
: the information matrix (if requested) -
configs
: a list with the configurations adopted to fit the model. This information is used by the prediction function. -
out.Fortran
: FORTRAN output (if requested) -
call
: a string with the description of the fitted model.
References
Ferrari, S.L.P. and Cribari-Neto, F. (2004). Beta regression for modelling rates and proportions. J. Appl. Stat. 31 (7), 799-815.
Pumi, G.; Valk, M.; Bisognin, C.; Bayer, F.M. and Prass, T.S. (2019). Beta autoregressive fractionally integrated moving average models. Journal of Statistical Planning and Inference (200), 196-212.
Rocha, A.V. and Cribari-Neto, F. (2009). Beta autoregressive moving average models. Test 18 (3), 529–545.
Rocha, A.V. and Cribari-Neto, F. (2017). Erratum to: Beta autoregressive moving average models. Test 26 (2), 451-459.
See Also
Examples
# Generating a Beta model were mut does not vary with time
# yt ~ Beta(a,b), a = mu*nu, b = (1-mu)*nu
y <- BARFIMA.sim(linkg = "linear", n = 1000, seed = 2021,
coefs = list(alpha = 0.2, nu = 20))
hist(y)
#------------------------------------------------------------
# Generating a Beta model were mut does not vary with time
# yt ~ Beta(a,b), a = mu*nu, b = (1-mu)*nu
#------------------------------------------------------------
m1 <- BARFIMA.sim(linkg = "linear",n = 100,
complete = TRUE, seed = 2021,
coefs = list(alpha = 0.2, nu = 20))
#------------------------------------------------------------
# Extracting the conditional time series given yt and
# a set of parameters
#------------------------------------------------------------
# Assuming that all coefficients are non-fixed
e1 = BARFIMA.extract(yt = m1$yt, coefs = list(alpha = 0.2, nu = 20),
link = "linear", llk = TRUE,
sco = TRUE, info = TRUE)
#----------------------------------------------------
# comparing the simulated and the extracted values
#----------------------------------------------------
cbind(head(m1$mut), head(e1$mut))
#---------------------------------------------------------
# the log-likelihood, score vector and information matrix
#---------------------------------------------------------
e1$sll
e1$score
e1$info.Matrix
# Generating a Beta model were mut does not vary with time
# yt ~ Beta(a,b), a = mu*nu, b = (1-mu)*nu
y <- BARFIMA.sim(linkg = "linear", n = 100, seed = 2021,
coefs = list(alpha = 0.2, nu = 20))
# fitting the model
f <- BARFIMA.fit(yt = y, report = TRUE,
start = list(alpha = 0.5, nu = 10),
linkg = "linear", d = FALSE)