| barma | R Documentation |
Fits a Beta Autoregressive Moving Average (BARMA) model to time series data valued in (0, 1) using Maximum Likelihood Estimation (MLE). The function performs complete model estimation including parameter estimation, hypothesis testing infrastructure, and model diagnostics.
barma(y, ar = NA, ma = NA, link = "logit", xreg = NULL)
y |
A time series object ('ts') with values strictly in the open interval (0, 1).
Must have at least |
ar |
A numeric vector specifying autoregressive (AR) lags (e.g., 'c(1, 2)' for AR(2)). Set to 'NA' for models without AR component. Default is 'NA'. |
ma |
A numeric vector specifying moving average (MA) lags (e.g., '1' for MA(1)). Set to 'NA' for models without MA component. Default is 'NA'. |
link |
The link function connecting the mean
|
xreg |
A matrix or data frame of external regressors (covariates), optional. Must have the same number of rows as 'y'. If provided, its columns are included in the linear predictor with associated coefficients in 'beta'. |
Fit Beta Autoregressive Moving Average (BARMA) Models
This function fits the BARMA(p,q) model as proposed by Rocha & Cribari-Neto (2009, with erratum 2017). It serves as the main wrapper for the optimization process, calling specialized helper functions for likelihood computation, gradient calculation, and Fisher Information Matrix estimation.
**Model Specification**: The BARMA model is defined as:
g(\mu_t) = \alpha + X_t\beta + \sum_{i=1}^{p} \varphi_i
(g(y_{t-i}) - X_{t-i}\beta) + \sum_{j=1}^{q} \theta_j \epsilon_{t-j}
where y_t | F_{t-1} \sim Beta(\mu_t\phi, (1-\mu_t)\phi),
g(\cdot) is the link function, and F_{t-1} is the information
set at time t-1.
**Model Types** (specified via 'ar' and 'ma' arguments):
**BARMA(p,q):** Both 'ar' and 'ma' are specified.
**BAR(p):** Only 'ar' is specified; set 'ma = NA'.
**BMA(q):** Only 'ma' is specified; set 'ar = NA'.
**External Regressors**: Covariates can be included via 'xreg'. The model becomes a regression BARMA, where the mean depends on current covariates and lagged responses/errors.
**Optimization**: The function uses the BFGS quasi-Newton algorithm via
optim with analytic gradients for efficiency. Initial values
are obtained from the 'start_values()' function.
**Implementation Notes**:
- The conditional log-likelihood is computed, conditioning on the first
m = \max(p,q) observations (burn-in period).
- The 2017 Erratum corrections are implemented for correct handling of
moving average components in the score vector and Fisher Information Matrix.
- All computations are vectorized where possible for efficiency.
An object of class '"barma"' containing:
coef |
Named vector of all estimated parameters, ordered as: alpha, AR parameters, MA parameters, beta parameters, phi. |
vcov |
The variance-covariance matrix of the estimators, computed as the inverse of the observed Fisher Information Matrix. |
model |
A summary table with coefficients, standard errors, z-statistics,
and p-values for hypothesis tests |
fitted |
Fitted conditional mean values as a 'ts' object (NA-padded for burn-in period). |
muhat |
Alias for 'fitted' (fitted mean values). |
etahat |
Estimated linear predictor values (full vector, NA-padded). |
errorhat |
Estimated errors on predictor scale (full vector, 0-padded). |
loglik |
The conditional log-likelihood at the MLE. |
fisher_info_mat |
The observed Fisher Information Matrix. |
conv |
Convergence code from 'optim' (0 = success). |
alpha, beta, varphi, theta, phi |
Individual parameter estimates. |
start_values |
Initial parameter values used in optimization. |
call |
The original function call. |
opt |
Raw output object from 'optim()' call. |
The original version of this function was developed by Fabio M. Bayer (Federal University of Santa Maria, bayer@ufsm.br). It has been substantially modified and improved by Everton da Costa, with suggestions and contributions from Francisco Cribari-Neto.
Everton da Costa (Federal University of Pernambuco, everto.cost@gmail.com); Francisco Cribari-Neto (Federal University of Pernambuco, francisco.cribari@ufpe.br)
Rocha, A.V., & Cribari-Neto, F. (2009). Beta autoregressive moving average models. TEST, 18(3), 529-545. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s11749-008-0112-z")}
Rocha, A.V., & Cribari-Neto, F. (2017). Erratum to: Beta autoregressive moving average models. TEST, 26, 451-459. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s11749-017-0528-4")}
simu_barma for simulation,
loglik_barma for likelihood computation,
score_vector_barma for gradient computation,
fim_barma for Fisher Information Matrix
# Example 1: Fit a BAR(1) model
set.seed(2025)
y_sim_bar <- simu_barma(
n = 250,
alpha = 0.0,
varphi = 0.6,
phi = 25.0,
link = "logit",
freq = 12
)
# Fit the model
fit_bar <- barma(y_sim_bar, ar = 1, link = "logit")
# View results
summary(fit_bar)
coef(fit_bar)
# Example 2: Fit a BARMA(1,1) model
set.seed(2025)
y_sim_barma <- simu_barma(
n = 250,
alpha = 0.0,
varphi = 0.6,
theta = 0.3,
phi = 25.0,
link = "logit",
freq = 12
)
# Fit ARMA structure
fit_barma <- barma(y_sim_barma, ar = 1, ma = 1, link = "logit")
summary(fit_barma)
# Example 3: BARMA(1,1) model with harmonic seasonal regressors
hs <- sin(2 * pi * seq_along(y_sim_barma) / 12)
hc <- cos(2 * pi * seq_along(y_sim_barma) / 12)
# Create regressor matrix
X <- cbind(hs = hs,
hc = hc)
fit_barma_xreg <- barma(
y_sim_barma,
ar = 1, ma = 1,
link = "logit", xreg = X
)
summary(fit_barma_xreg)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.