btsr.functions {BTSR}R Documentation

Generic functions to simulate, extract components and fit BTSR models

Description

These generic functions can be used to simulate, extract components and fit any model of the class btsr. All functions are wrappers for the corresponding function associated to the chosen model. See ‘The BTSR structure’ and ‘Common Arguments’.

Usage

btsr.sim(model, complete = FALSE, ...)

btsr.extract(model, ...)

btsr.fit(model, ...)

Arguments

model

character; one of "BARFIMA", "GARFIMA", "KARFIMA", "BARC".

complete

logical; if FALSE the function returns only the simulated time series yt, otherwise, additional time series are provided. Default is FALSE for all models.

...

further arguments passed to the functions, according to the model selected in the argument model. See ‘Common Arguments’

Details

The function btsr.sim is used to generate random samples from BTSR models. See ‘The BTSR structure’.

The function btsr.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 functions not available in BTSR Package. At this point, there is no other use for which this function was intended.

The function btsr.fit fits a BTSR 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 btsr.sim returns the simulated time series yt by default. If complete = TRUE, a list with the following components is returned instead:

The function btsr.extract returns a list with the following components. Each particular model can have additional components in this list.

The function btsr.fit returns a list with the following components. Each particular model can have additional components in this list.

The BTSR structure

The general structure of the deterministic part of a BTSR model is

g_1(\mu_t) = \alpha + X_t\beta + \sum_{j=1}^p \phi_j[g_2(y_{t-j}) - I_{xregar}X_{t-j}\beta] + h_t

where

Common Arguments

In what follows we describe some of the arguments that are commom to all BTSR models. For more details on extra arguments, see the corresponding function associated to the selected model.

Simulation Function

Common arguments passed through "..." in btsr.sim are:

Extracting Function

Common arguments passed through "..." in btsr.extract are:

Fitting Function

Common arguments passed through "..." in btsr.fit are the same as in btsr.extract plus the following:

References

Knuth, D. E. (2002). The Art of Computer Programming. Volume 2, third edition, ninth printing.

L'Ecuyer, P. (1999). Good parameters and implementations for combined multiple recursive random number generators. Operations Research, 47, 159-164. doi:10.1287/opre.47.1.159.

Matsumoto, M. and Nishimura, T. (1998). Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator, ACM Transactions on Modeling and Computer Simulation, 8, 3-30.

Wichmann, B. A. and Hill, I. D. (1982). Algorithm AS 183: An Efficient and Portable Pseudo-random Number Generator. Applied Statistics, 31, 188-190; Remarks: 34, 198 and 35, 89. doi:10.2307/2347988.

See Also

BARFIMA.sim, GARFIMA.sim, KARFIMA.sim, BARC.sim

BARFIMA.extract, GARFIMA.extract, KARFIMA.extract, BARC.extract

BARFIMA.fit, GARFIMA.fit, KARFIMA.fit, BARC.fit

Examples

# Generating a Beta model were mut does not vary with time
# yt ~ Beta(a,b), a = mu*nu, b = (1-mu)*nu

y <- btsr.sim(model= "BARFIMA", 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 <- btsr.sim(model= "BARFIMA", linkg = "linear",
                n = 100, seed = 2021, complete = TRUE,
                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 = btsr.extract(model = "BARFIMA", yt = m1$yt,
                  coefs = list(alpha = 0.2, nu = 20),
                  link = "linear", llk = TRUE,
                  sco = TRUE, info = TRUE)

 # Assuming that all coefficients are fixed
 e2 = btsr.extract(model = "BARFIMA", yt = m1$yt,
                  fixed.values = list(alpha = 0.2, nu = 20),
                  link = "linear", llk = TRUE,
                  sco = TRUE, info = TRUE)

 # Assuming at least one fixed coefficient and one non-fixed
 e3 = btsr.extract(model = "BARFIMA", yt = m1$yt,
                  fixed.values = list(alpha = 0.2, nu = 20),
                  link = "linear", llk = TRUE,
                  sco = TRUE, info = TRUE)
 e4 = btsr.extract(model = "BARFIMA", yt = m1$yt,
                  fixed.values = 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), head(e2$mut), head(e3$mut), head(e4$mut))

 #----------------------------------------------------
 # comparing the log-likelihood values obtained (must be the all equal)
 #----------------------------------------------------
 c(e1$sll, e2$sll, e3$sll, e4$sll)

 #----------------------------------------------------
 # comparing the score vectors:
 #----------------------------------------------------
 # - e1 must have 2 values: dl/dmu and dl/dnu
 # - e2 must be empty
 # - e3 and e4 must have one value corresponding
 #    to the non-fixed coefficient
 #----------------------------------------------------
  e1$score
  e2$score
  e3$score
  e4$score

 #----------------------------------------------------
 # comparing the information matrices.
 #----------------------------------------------------
 # - e1 must be a 2x2 matrix
 # - e2 must be empty
 # - e3 and e4 must have one value corresponding
 #    to the non-fixed coefficient
 #----------------------------------------------------
  e1$info.Matrix
  e2$info.Matrix
  e3$info.Matrix
  e4$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 <- btsr.sim(model= "BARFIMA", linkg = "linear",
               n = 100, seed = 2021,
               coefs = list(alpha = 0.2, nu = 20))

# fitting the model
f <- btsr.fit(model = "BARFIMA", yt = y, report = TRUE,
             start = list(alpha = 0.5, nu = 10),
             linkg = "linear", d = FALSE)


[Package BTSR version 0.1.5 Index]