Title: | Bifurcating Autoregressive Models |
---|---|
Description: | Estimation of bifurcating autoregressive models of any order, p, BAR(p) as well as several types of bias correction for the least squares estimators of the autoregressive parameters as described in Zhou and Basawa (2005) <doi:10.1016/j.spl.2005.04.024> and Elbayoumi and Mostafa (2020) <doi:10.1002/sta4.342>. Currently, the bias correction methods supported include bootstrap (single, double and fast-double) bias correction and linear-bias-function-based bias correction. Functions for generating and plotting bifurcating autoregressive data from any BAR(p) model are also included. This new version includes calculating several type of bias-corrected and -uncorrected confidence intervals for the least squares estimators of the autoregressive parameters as described in Elbayoumi and Mostafa (2023) <doi:10.6339/23-JDS1092>. |
Authors: | Tamer Elbayoumi [aut, cre], Sayed Mostafa [aut] |
Maintainer: | Tamer Elbayoumi <[email protected]> |
License: | AGPL (>= 3) |
Version: | 2.1.0 |
Built: | 2024-11-05 06:34:08 UTC |
Source: | CRAN |
This function calculates the standard normal bootstrap CI for the least squares estimator of the bifurcating autoregressive model.
bfa_boot_ci(a1_ls, a1_ls_star, conf_level = 0.95)
bfa_boot_ci(a1_ls, a1_ls_star, conf_level = 0.95)
a1_ls |
A numeric value of the least squares estimator of bifurcating autoregressive model |
a1_ls_star |
A numeric vector representing B replicates of the least squares estimator |
conf_level |
A numeric value representing the confidence level. Defaults to 0.95. |
A numeric vector representing the lower and upper limits of the confidence interval
a1_ls <- 0.7 a1_ls_star <- c(rnorm(100,0.7,0.05)) bfa_boot_ci(a1_ls, a1_ls_star, conf_level= 0.95)
a1_ls <- 0.7 a1_ls_star <- c(rnorm(100,0.7,0.05)) bfa_boot_ci(a1_ls, a1_ls_star, conf_level= 0.95)
This function performs linear-bias-function bias-correction (LBC), single
bootstrap, double bootstrap, fast-double bootstrap of the bias-correction
least squares estimators of the autoregressive coefficients in a bifurcating
autoregressive (BAR) model of any order p
as described in Elbayoumi &
Mostafa (2020).
bfa_boot_ls_bc( z, p, method = "boot1", burn = 5, B, boot_est = TRUE, boot_data = FALSE )
bfa_boot_ls_bc( z, p, method = "boot1", burn = 5, B, boot_est = TRUE, boot_data = FALSE )
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
method |
method of bias correction. Currently, "boot1", "boot2", "boot2fast" and "LBC" are supported and they implement single bootstrap, double bootstrap, fast-double bootstrap, and linear-bias-function bias-correction, respectively. |
burn |
number of tree generations to discard before starting the bootstrap sample (replicate) |
B |
number of bootstrap samples (replicates) |
boot_est |
a logical that determines whether the bootstrapped least squares estimates of the autoregressive coefficients should be returned. Defaults to TRUE. |
boot_data |
a logical that determines whether the bootstrap samples should be returned. Defaults to FALSE. |
boot_bcest |
a matrix containing the bootstrapped bias-correction least squares estimates of the autoregressive coefficients |
boot_data |
a matrix containing the bootstrap samples used |
Elbayoumi, T. M. & Mostafa, S. A. (2020). On the estimation bias in bifurcating autoregressive models. Stat, 1-16.
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot_ls_bc(z, p=1, method="LBC", B=500) hist(bfa_boot_ls_bc(z, p=1, method="LBC", B=500)$boot_bcest)
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot_ls_bc(z, p=1, method="LBC", B=500) hist(bfa_boot_ls_bc(z, p=1, method="LBC", B=500)$boot_bcest)
This function performs single bootstrapping of the least squares estimators
of the autoregressive coefficients in a bifurcating autoregressive (BAR)
model of any order p
as described in Elbayoumi and Mostafa (2020).
bfa_boot1_ls(z, p, burn = 5, B, boot_est = TRUE, boot_data = FALSE)
bfa_boot1_ls(z, p, burn = 5, B, boot_est = TRUE, boot_data = FALSE)
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
burn |
number of tree generations to discard before starting the bootstrap sample (replicate) |
B |
number of bootstrap samples (replicates) |
boot_est |
a logical that determines whether the bootstrapped least squares estimates of the autoregressive coefficients should be returned. Defaults to TRUE. |
boot_data |
a logical that determines whether the bootstrap samples should be returned. Defaults to FALSE. |
boot_est |
a matrix containing the bootstrapped least squares estimates of the autoregressive coefficients |
boot_data |
a matrix containing the bootstrap samples used |
Elbayoumi, T. M. & Mostafa, S. A. (2020). On the estimation bias in bifurcating autoregressive models. Stat, 1-16.
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot1_ls(z, p=1, B=999)
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot1_ls(z, p=1, B=999)
This function performs double bootstrapping of the least squares estimators
of the autoregressive coefficients in a bifurcating autoregressive (BAR)
model of any order p
as described in Elbayoumi and Mostafa (2020).
bfa_boot2_ls(z, p, burn = 5, B1, B2)
bfa_boot2_ls(z, p, burn = 5, B1, B2)
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
burn |
number of tree generations to discard before starting the bootstrap sample (replicate) |
B1 |
number of bootstrap samples (replicates) used in first round of bootstrapping |
B2 |
number of bootstrap samples (replicates) used in second round of bootstrapping |
boot_est |
a matrix containing the first-stage bootstrapped least squares estimates of the autoregressive coefficients |
boot2 |
a matrix containing the second-stage bootstrapped least squares estimates of the autoregressive coefficients |
Elbayoumi, T. M. & Mostafa, S. A. (2020). On the estimation bias in bifurcating autoregressive models. Stat, 1-16.
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot2_ls(z, p=1, B1=99, B2=9)
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot2_ls(z, p=1, B1=99, B2=9)
This function performs fast double bootstrapping of the least squares
estimators of the autoregressive coefficients in a bifurcating autoregressive
(BAR) model of any order p
as described in Elbayoumi and Mostafa (2020).
bfa_boot2fast_ls(z, p, burn = 5, B)
bfa_boot2fast_ls(z, p, burn = 5, B)
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
burn |
number of tree generations to discard before starting the bootstrap sample (replicate) |
B |
number of bootstrap samples (replicates) used in first round of bootstrapping |
boot_est |
a matrix containing the first-stage bootstrapped least squares estimates of the autoregressive coefficients |
boot2 |
a matrix containing the second-stage bootstrapped least squares estimates of the autoregressive coefficients |
Elbayoumi, T. M. & Mostafa, S. A. (2020). On the estimation bias in bifurcating autoregressive models. Stat, 1-16.
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot2fast_ls(z, p=1, B=499)
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_boot2fast_ls(z, p=1, B=499)
This function performs bias correction on the least squares estimators of the autoregressive coefficients in a BAR(p) model based on the assumption that the bias of the least squares estimator is approximately linear as a function of the parameter as described in Elbayoumi and Mostafa (2020).
bfa_lbc_ls(z, p)
bfa_lbc_ls(z, p)
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
coef_lbc |
linear-bias-function-based bias-corrected least squares estimates of the autoregressive coefficients |
Elbayoumi, T. M. & Mostafa, S. A. (2020). On the estimation bias in bifurcating autoregressive models. Stat, 1-16.
z <- bfa_tree_gen(127, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_lbc_ls(z, p=1) z <- bfa_tree_gen(127, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) bfa_lbc_ls(z, p=2)
z <- bfa_tree_gen(127, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_lbc_ls(z, p=1) z <- bfa_tree_gen(127, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) bfa_lbc_ls(z, p=2)
This function performs Least Squares estimation of bifurcating autoregressive (BFA) models of any order as described in Zhou and Basawa (2005).
bfa_ls( z, p, x_data = FALSE, y_data = FALSE, resids = FALSE, error_cor = TRUE, error_var = FALSE, cov_matrix = FALSE, conf = FALSE, conf_level = 0.95, B = 49, p_value = FALSE )
bfa_ls( z, p, x_data = FALSE, y_data = FALSE, resids = FALSE, error_cor = TRUE, error_var = FALSE, cov_matrix = FALSE, conf = FALSE, conf_level = 0.95, B = 49, p_value = FALSE )
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
x_data |
a logical that determines whether the x data used in fitting the model should be returned. Defaults to FALSE. |
y_data |
a logical that determines whether the y data used in fitting the model should be returned. Defaults to FALSE. |
resids |
a logical that determines whether the model residuals should be returned. Defaults to FALSE. |
error_cor |
a logical that determines whether the estimated correlation
between pairs of model errors |
error_var |
a logical that determines whether the estimated variance of the model errors should be returned. Defaults to FALSE. |
cov_matrix |
a logical that determines whether the estimated variance-covariance matrix of the least squares estimates should be returned. Defaults to FALSE. |
conf |
a logical that determines whether confidence intervals for model
coefficients should be returned. Defaults to FALSE. If TRUE, asymptotic normal
confidence intervals for the intercept and the slops are calculated using
|
conf_level |
confidence level to be used in computing the normal
confidence intervals for model coefficients when |
B |
number of bootstrap samples (replicates) |
p_value |
a logical that determines whether p-values for model
coefficients should be returned. Defaults to FALSE. If TRUE, p-values are
computed from normal distribution using estimated coefficients and
|
coef |
a matrix containing the least squares estimates of the autoregressive coefficients |
error_cor |
the least squares estimate of
the correlation between pairs of model errors |
x |
a matrix containing the x
data used in fitting the model. Only returned if |
y |
a vector containing the y data used in fitting the model. Only
returned if |
resids |
the model residuals. Only
returned if |
error_var |
the estimated variance of
the model errors. Only returned if |
cov_matrix |
the estimated variance-covariance matrix of the least
squares coefficients. Only returned if |
conf |
a
matrix of normal confidence intervals for model coefficients. Only returned
if |
p_value |
a matrix of two-sided p-values for
testing the significance of model coefficients. Computed from normal
distribution and using the estimated covariance matrix |
Zhou, J. & Basawa, I. V. (2005). Least squares estimation for bifurcating autoregressive processes. Statistics & Probability Letters, 74(1):77-88.
z <- bfa_tree_gen(127, 1, 1, 1, -0.9, -0.9, 0, 10, c(0.7)) bfa_ls(z, p=1) bfa_ls(z,p=1,conf=TRUE,cov_matrix = TRUE,conf_level = 0.9,p_value=TRUE)
z <- bfa_tree_gen(127, 1, 1, 1, -0.9, -0.9, 0, 10, c(0.7)) bfa_ls(z, p=1) bfa_ls(z,p=1,conf=TRUE,cov_matrix = TRUE,conf_level = 0.9,p_value=TRUE)
This function performs bias correction on the least squares estimators of the autoregressive coefficients in a BAR(p) model using single, double and fast-double bootstrapping, and the linear-bias-function approach as described in Elbayoumi and Mostafa (2021).
bfa_ls_bc( z, p, method = "boot1", burn = 5, B1 = 999, B2 = 499, boot_est = TRUE, boot_data = FALSE )
bfa_ls_bc( z, p, method = "boot1", burn = 5, B1 = 999, B2 = 499, boot_est = TRUE, boot_data = FALSE )
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
method |
method of bias correction. Currently, "boot1", "boot2", "boot2fast" and "LBC" are supported and they implement single bootstrap, double bootstrap, fast-double bootstrap, and linear-bias-function bias-correction, respectively. |
burn |
number of tree generations to discard before starting the bootstrap sample (replicate) |
B1 |
number of bootstrap samples (replicates) used in first round of bootstrapping |
B2 |
number of bootstrap samples (replicates) used in second round of bootstrapping |
boot_est |
a logical that determines whether the bootstrapped least squares estimates of the autoregressive coefficients should be returned. Defaults to TRUE. |
boot_data |
a logical that determines whether the bootstrap samples should be returned. Defaults to FALSE. |
coef_ls_bc |
bias-corrected least squares estimates of the autoregressive coefficients |
Elbayoumi, T. M. & Mostafa, S. A. (2021). On the estimation bias in bifurcating autoregressive models. Stat, e342.
z <- bfa_tree_gen(63, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_ls_bc(z, p=2, method="boot1") z <- bfa_tree_gen(63, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) bfa_ls_bc(z, p=2, method="LBC")
z <- bfa_tree_gen(63, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_ls_bc(z, p=2, method="boot1") z <- bfa_tree_gen(63, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) bfa_ls_bc(z, p=2, method="LBC")
This function performs bias correction confidence intervals on the least squares estimators of the autoregressive coefficients in a BAR(p) model using single, fast-double, and the Bias-corrected and accelerated bootstrapping as described in Elbayoumi and Mostafa (2023).
bfa_ls_bc_ci( z, p, method = "BCa", conf_int = "standard_normal_bc", conf_level = 0.95, B = 5, burn = 5 )
bfa_ls_bc_ci( z, p, method = "BCa", conf_int = "standard_normal_bc", conf_level = 0.95, B = 5, burn = 5 )
z |
a numeric vector containing the tree data |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data |
method |
method of bias correction. Currently, "boot1", "boot2fast", and "BCa" are supported and they implement single bootstrap, fast-double bootstrap, and bias-corrected and accelerated bootstrap, respectively. Defaults to "BCa". |
conf_int |
type of the confidence interval. Currently, "standard_normal_bc", "percentile", and "percentile_bc" are supported and they implement corrected standard normal bootstrap CI, uncorrected percentile bootstrap CI, and corrected percentile bootstrap CI, respectively. If "boot1" method is selected, the "standard_normal_bc", "percentile", "percentile_bc" confidence intervals can be obtained. If "boot2fast" method is selected, the "standard_normal_bc" and "percentile_bc" confidence intervals can be obtained. No effect for conf_int, the "BCa" method is selected. Defaults to standard_normal_bc". |
conf_level |
confidence level to be used in computing confidence intervals
for model coefficients. Defaults to |
B |
number of bootstrap samples (replicates). |
burn |
number of tree generations to discard before starting the bootstrap sample (replicate). Defaults to 5. |
Bias_corrected_coef |
a matrix containing the bias-correction least squares estimates of the autoregressive coefficients |
BCa_ci |
a matrix containing the lower and upper limits of corrected BCa
confidence intervals,if |
standard_normal_bc_ci |
a matrix containing the lower and upper limits of
corrected confidence intervals, if |
percentile_ci |
a matrix containing the lower and upper limits of uncorrected
percentile confidence intervals, if |
percentile_bc_ci |
a matrix containing the lower and upper limits of corrected
percentile confidence intervals, if |
standard_normal_bc_ci |
a matrix containing the lower and upper limits of corrected
confidence intervals, if |
percentile_bc_ci |
a matrix containing the lower and upper limits of corrected percentile
confidence intervals, if |
Elbayoumi, T. M. & Mostafa, S. A. (2023). Impact of Bias Correction of the Least Squares Estimation on Bootstrap Confidence Intervals for Bifurcating Autoregressive Models. Journal of Data Science, 1-20, doi.org/10.6339/23-JDS1092.
# Generating Non-contaminated normal BAR(1) tree and calculating the bias corrected # standard normal CI for the autoregressive coefficients of the BAR(1) model # Note that in this example (B=2) for speeding up the calculations. # B must be set to 499 or more for calculation accuracy. z <- bfa_tree_gen(15, 1, 1, 1, -0.9, -0.9, 0, 10, c(-0.5)) bfa_ls_bc_ci(z, p=1, method="boot1", B=2)
# Generating Non-contaminated normal BAR(1) tree and calculating the bias corrected # standard normal CI for the autoregressive coefficients of the BAR(1) model # Note that in this example (B=2) for speeding up the calculations. # B must be set to 499 or more for calculation accuracy. z <- bfa_tree_gen(15, 1, 1, 1, -0.9, -0.9, 0, 10, c(-0.5)) bfa_ls_bc_ci(z, p=1, method="boot1", B=2)
This function calculates the Bias-Corrected percentile CI for the least squares estimator of the bifurcating autoregressive model.
bfa_perc_bc_ci(z, a1_ls, a1_ls_star, conf_level = 0.95)
bfa_perc_bc_ci(z, a1_ls, a1_ls_star, conf_level = 0.95)
z |
a numeric vector containing the tree data. |
a1_ls |
A numeric value of the least squares estimator of bifurcating autoregressive model |
a1_ls_star |
A numeric vector representing B replicates of the least squares estimator |
conf_level |
A numeric value representing the confidence level. Defaults to 0.95. |
A numeric vector representing the lower and upper limits of the bias corrected percentile confidence interval for the autoregressive coefficients of BAR model.
# Generating Non-contaminated normal BAR(1) tree and calculating the bias # corrected percentile CI for the autoregressive coefficients of the BAR(1) model z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) a1_ls <- bfa_ls(z,1)$coef[2] a1_ls_star <- (rnorm(100,0.7,0.05)) bfa_perc_bc_ci(z, a1_ls, a1_ls_star, conf_level=0.95)
# Generating Non-contaminated normal BAR(1) tree and calculating the bias # corrected percentile CI for the autoregressive coefficients of the BAR(1) model z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) a1_ls <- bfa_ls(z,1)$coef[2] a1_ls_star <- (rnorm(100,0.7,0.05)) bfa_perc_bc_ci(z, a1_ls, a1_ls_star, conf_level=0.95)
This function calculates the percentile bootstrap CI for the least squares estimator of the bifurcating autoregressive model.
bfa_perc_ci(a1_ls_star, conf_level = 0.95)
bfa_perc_ci(a1_ls_star, conf_level = 0.95)
a1_ls_star |
A numeric vector representing B replicates of the least squares estimator. |
conf_level |
A numeric value representing the confidence level. Defaults to 0.95. |
A numeric vector representing the lower and upper limits of the confidence interval.
a1_ls_star <- c(rnorm(100,0.7,0.05)) bfa_perc_ci(a1_ls_star, conf_level= 0.95)
a1_ls_star <- c(rnorm(100,0.7,0.05)) bfa_perc_ci(a1_ls_star, conf_level= 0.95)
Draw scatterplots between observations at time t
and the lagged
observations from the given bifurcating autoregressive tree data.
bfa_scatterplot(z, p, ...)
bfa_scatterplot(z, p, ...)
z |
a numeric vector containing the tree data |
p |
an integer determining the order of the bifurcating autoregressive model that is believed to best fit the data |
... |
other graphical parameters that can be passed to |
A single scatterplot when p=1
or a matrix of scatterplots when
p>1
.
z <- bfa_tree_gen(63, 1, 1, 2, 0.5, 0.5, 0.2, 10, c(0.7)) bfa_scatterplot(z,1) z<-bfa_tree_gen(63, 2, 1, 2, 0.5, 0.5, 0.2, 10, c(0.7,0.2)) bfa_scatterplot(z,2) bfa_scatterplot(z,2,lower.panel=NULL)
z <- bfa_tree_gen(63, 1, 1, 2, 0.5, 0.5, 0.2, 10, c(0.7)) bfa_scatterplot(z,1) z<-bfa_tree_gen(63, 2, 1, 2, 0.5, 0.5, 0.2, 10, c(0.7,0.2)) bfa_scatterplot(z,2) bfa_scatterplot(z,2,lower.panel=NULL)
This function extracts subtree of size from the end of a given
bifurcating autoregressive tree (model) of order p.
bfa_subtree(n, p)
bfa_subtree(n, p)
n |
subtree size (integer) |
p |
an integer determining the order of bifurcating autoregressive model |
A numeric vector representing a subtree of size from
the end of a given bifurcating autoregressive tree.
bfa_subtree(31, 1) bfa_subtree(31, 2)
bfa_subtree(31, 1) bfa_subtree(31, 2)
This function generate bifurcating autoregressive (BFA) trees of any size based on a BFA model of any order.
bfa_tree_gen(n, p, s1, s2, r1, r2, g, intercept, ar_coef, dist = "cnorm", a)
bfa_tree_gen(n, p, s1, s2, r1, r2, g, intercept, ar_coef, dist = "cnorm", a)
n |
tree size (integer) |
p |
an integer determining the order of bifurcating autoregressive model |
s1 |
standard deviation of the errors distribution |
s2 |
standard deviation of the second component of the mixture normal distribution generating contaminated errors. s2 should be greater than s1. s2 is only effective when g>0. |
r1 |
correlation between pairs of errors |
r2 |
is used in combination with |
g |
proportion of contamination when contaminated normal distribution is selected, or a positive value representing the degrees of freedom when skew t-student distribution is selected. Defaults to zero producing non-contaminated multivariate normal errors. |
intercept |
the intercept in the BAR model generating the tree |
ar_coef |
a vector of length p giving the autoregressive coefficients in the BAR model generating the tree |
dist |
determine the distribution of the error. Three distributions are available; Contaminated normal distribution "cnorm", Skew normal distribution "snorm", and Skew t-student distribution "st". |
a |
an integer which regulates the the slant of the density when skew normal distribution or skew t-student distribution is selected. Defaults to zero producing non-skewed multivariate normal errors, and non-skewed multivariate t-student errors for the tree generation. |
A numeric vector representing a bifurcating autoregressive (BAR) tree
with n
observations.
# Non-contaminated normal BAR(1) tree: bfa_tree_gen(127, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) # Non-contaminated normal BAR(2) tree: bfa_tree_gen(127, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) # Contaminated normal BAR(1) tree: bfa_tree_gen(127, 1, 1, 2, 0.5, 0.5, 0.2, 10, c(0.7)) # BAR(1) tree with error generated from skewed normal distribution with skewness equals to -3: bfa_tree_gen(127, 1, 1, 2, 0.5, 0.5, 0, 10, c(0.7),dist="snorm",-3) # BAR(2) tree with error generated from skewed normal distribution with skewness equals to 3: bfa_tree_gen(127, 2, 1, 2, 0.5, 0.5, 0, 10, c(0.7,0.5),dist="snorm",3) # BAR(1) tree with error generated from skewed-t distribution with skewness equals # to -3 and df equals to 10: bfa_tree_gen(127, 1, 1, 2, 0.5, 0.5, 10, 10, c(0.7),dist="st",-3) # BAR(2) tree with error generated from skewed-t distribution with skewness equals # to 3 and df equals to 1: bfa_tree_gen(127, 2, 1, 2, 0.5, 0.5, 10, 10, c(0.7,0.5),dist="st",3)
# Non-contaminated normal BAR(1) tree: bfa_tree_gen(127, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) # Non-contaminated normal BAR(2) tree: bfa_tree_gen(127, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) # Contaminated normal BAR(1) tree: bfa_tree_gen(127, 1, 1, 2, 0.5, 0.5, 0.2, 10, c(0.7)) # BAR(1) tree with error generated from skewed normal distribution with skewness equals to -3: bfa_tree_gen(127, 1, 1, 2, 0.5, 0.5, 0, 10, c(0.7),dist="snorm",-3) # BAR(2) tree with error generated from skewed normal distribution with skewness equals to 3: bfa_tree_gen(127, 2, 1, 2, 0.5, 0.5, 0, 10, c(0.7,0.5),dist="snorm",3) # BAR(1) tree with error generated from skewed-t distribution with skewness equals # to -3 and df equals to 10: bfa_tree_gen(127, 1, 1, 2, 0.5, 0.5, 10, 10, c(0.7),dist="st",-3) # BAR(2) tree with error generated from skewed-t distribution with skewness equals # to 3 and df equals to 1: bfa_tree_gen(127, 2, 1, 2, 0.5, 0.5, 10, 10, c(0.7,0.5),dist="st",3)
This function graphs bifurcating autoregressive (BFA) tree data.
bfa_tree_plot( z, digits, shape = "none", vertex.size = 10, text.size = 1, text.color = "black", vertex.color = "gold", vertex.asp = 0.25, arrow.size = 0.5, arrow.width = 0.5, arrow.color = "black", plot.margin = -0.3 )
bfa_tree_plot( z, digits, shape = "none", vertex.size = 10, text.size = 1, text.color = "black", vertex.color = "gold", vertex.asp = 0.25, arrow.size = 0.5, arrow.width = 0.5, arrow.color = "black", plot.margin = -0.3 )
z |
a numeric vector containing the tree data |
digits |
an integer indicating the number of decimal places to be displayed in vertex labels |
shape |
the shape of the vertex. Currently “circle”, “square”, “csquare”, “rectangle”, “crectangle”, “vrectangle”, and “none” are supported. Defaults to “none” which does not display the vertices at all. |
vertex.size |
a numeric scalar or vector defining the size of the vertex or vertices. If a vector is supplied, vertex sizes may differ. Defaults to 10. |
text.size |
the font size of vertex labels. Defaults to 1. |
text.color |
the color of vertex labels. If it is a character vector, then it may either contain integer values, named colors or RGB specified colors with three or four bytes. Defaults to "black". |
vertex.color |
the fill color of the vertex. If you don't want some or
all vertices to have any color, supply NA. The default is "gold". See also
the options in |
vertex.asp |
a parameter that controls the aspect ratio of the plot, The default value is 0.25. |
arrow.size |
the size of the arrows. The default value is 0.5. |
arrow.width |
the width of the arrows. The default value is 0.5. |
arrow.color |
the color of the arrows. The default is "black". See also
the options in |
plot.margin |
the amount of empty space around the plot, it is a numeric vector of length four. Usually values between 0 and 0.5 are meaningful, but negative values are also possible and in that case it will make the plot zoom in to a part of the graph. If it is shorter than four, recycling will occur. The default value is -0.3. |
For more details about the graph options see
igraph.plotting
.
A binary tree displaying the BFA data.
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_tree_plot(z) bfa_tree_plot(z,shape= "circle") bfa_tree_plot(z,shape= "circle", text.color="white", vertex.color = "darkgrey",plot.margin = 0)
z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) bfa_tree_plot(z) bfa_tree_plot(z,shape= "circle") bfa_tree_plot(z,shape= "circle", text.color="white", vertex.color = "darkgrey",plot.margin = 0)
This function calculates the Bias-Corrected and Accelerated bootstrap (BCa) CI for the least squares estimator of the bifurcating autoregressive model.
boot_bca_ci(z, p, B = 99, J = 2, conf_level = 0.95)
boot_bca_ci(z, p, B = 99, J = 2, conf_level = 0.95)
z |
a numeric vector containing the tree data. |
p |
an integer determining the order of bifurcating autoregressive model to be fit to the data. |
B |
number of bootstrap samples (replicates). Defaults to 99. |
J |
an integer determining the number of vectors of bootstrap replicates. Defaults to 2. |
conf_level |
A numeric value representing the confidence level. Defaults to 0.95. |
coef |
a matrix containing the least squares estimates of the autoregressive coefficients |
limits |
A numeric vector representing the lower and upper limits of the BCa confidence interval for the autoregressive coefficients of BAR model |
# Generating Non-contaminated normal BAR(1) tree and calculating the BCa CI for # the autoregressive coefficients of the BAR(1) model z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) boot_bca_ci(z,p=1,B=99,J=2,conf_level=0.95) # Generating Non-contaminated normal BAR(2) tree and calculating the BCa CI for # the autoregressive coefficients of the BAR(2) model z <- bfa_tree_gen(127, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) boot_bca_ci(z,p=2,B=99,J=2,conf_level=0.95)
# Generating Non-contaminated normal BAR(1) tree and calculating the BCa CI for # the autoregressive coefficients of the BAR(1) model z <- bfa_tree_gen(31, 1, 1, 1, 0.5, 0.5, 0, 10, c(0.7)) boot_bca_ci(z,p=1,B=99,J=2,conf_level=0.95) # Generating Non-contaminated normal BAR(2) tree and calculating the BCa CI for # the autoregressive coefficients of the BAR(2) model z <- bfa_tree_gen(127, 2, 1, 1, 0.5, 0.5, 0, 10, c(0.5, 0.3)) boot_bca_ci(z,p=2,B=99,J=2,conf_level=0.95)
A real cell lineage dataset taken from Cowan and Staudte (1986). The values represent the lifetimes in minutes of lineage E. coli cells. It contains 31 observations making which can be described by a bifurcating autoregressive tree with 4 generations.
ecoli
ecoli
A data frame with 31 rows and 1 variable:
E. coli cells lifetime, in minutes
Cowan, R. and Staudte, R. (1986). The Bifurcating Autoregression Model in Cell Lineage Studies. Biometrics, 42(4):769-783.
A real cell lineage dataset taken from Staudte et al. (1984). The values represent the mean lifetimes in tenths of hours obtained from averaging observations from 41 bifurcating trees. The averaging of observations and the tree are made by Elbayoumi and Mostafa (2023).
emt6
emt6
A data frame with 63 rows and 1 variable:
EMT6 cells lifetime, in tenths of hours
Elbayoumi, T. and Mostafa, S. (2023). Impact of Bias Correction of the Least Squares Estimation on Bootstrap Confidence Intervals for Bifurcating Autoregressive Models. Journal of Data Science, doi.org/10.6339/23-JDS1092.
This function generates contaminated multivariate normal errors that are used in the generation of the Bifurcating autoregressive tree.
rcontmnorm( n, d = 2, mu1 = rep(0, d), sigma1 = diag(d), mu2 = rep(0, d), sigma2 = diag(d), g )
rcontmnorm( n, d = 2, mu1 = rep(0, d), sigma1 = diag(d), mu2 = rep(0, d), sigma2 = diag(d), g )
n |
sample size |
d |
dimension. Defaults to 2 for bivariate normal errors. |
mu1 |
mean vector for first multivariate normal distribution. Defaults to the zero vector. |
sigma1 |
variance-covariance matrix for first multivariate normal distribution. Defaults to the d by d identity matrix, where d is the dimension. |
mu2 |
mean vector for second multivariate normal distribution. Defaults to the zero vector. |
sigma2 |
variance-covariance matrix for second multivariate normal distribution. Defaults to the d by d identity matrix, where d is the dimension. |
g |
proportion of contamination. Defaults to zero producing non-contaminated multivariate normal data. |
An n
by d
contaminated multivariate normal matrix.
#Non-contaminated bivariate normal: rcontmnorm(10, sigma2=2^2*matrix(c(1,0,0,1),nrow=2) , g=0) #Contaminated bivariate normal with 20% contamination: rcontmnorm(10, sigma2=2^2*matrix(c(1,0,0,1),nrow=2) , g=0.2)
#Non-contaminated bivariate normal: rcontmnorm(10, sigma2=2^2*matrix(c(1,0,0,1),nrow=2) , g=0) #Contaminated bivariate normal with 20% contamination: rcontmnorm(10, sigma2=2^2*matrix(c(1,0,0,1),nrow=2) , g=0.2)
This function generates multivariate normal errors that are used in the generation of the Bifurcating autoregressive tree.
rmnorm(n, d = 2, mu = rep(0, d), sigma = diag(d))
rmnorm(n, d = 2, mu = rep(0, d), sigma = diag(d))
n |
sample size |
d |
dimension. Defaults to 2 for bivariate normal errors. |
mu |
mean vector. Defaults to the zero vector. |
sigma |
variance-covariance matrix. Defaults to the |
An n
by d
multivariate normal matrix.
rmnorm(10) rmnorm(10, 3)
rmnorm(10) rmnorm(10, 3)