The bifurcating autiegressive (BAR) model is a useful tool for studying binary tree-structured data, often seen in cell-lineage studies. The “bifurcatingr” R package makes it easier to work with these models. It can estimate different orders of BAR models and improve accuracy through various correction methods. These methods include bootstrap-based corrections and linear bias functions. The package also helps generate and visualize data from BAR models and offers eight ways to estimate confidence intervals for the model’s coefficients, with or without bias correction.
To use bifurcatingr in your R code, you must first load the library:
To generate binary tree data based on a the bifurcating autoregressive model (BAR) model, you can use the “bfa.tree.gen” function. Generating a binary tree with 127 observations based on a first-order BAR model with errors that follow a contaminated bivariate normal distribution with 20% contamination. A zero mean vector is used and the standard deviations are 1 and 2, respectively. The intercept is set to 10 and the autoregressive coefficient is 0.7.
dat<-bfa_tree_gen(n=127,p=1,s1=1,s2=2,r1=0.5,r2=0.5,g=0.2,intercept=10,ar_coef=c(0.7))
dat <- round(dat,1)
dat
#> [1] 30.1 31.7 30.3 31.4 31.6 32.0 31.1 32.4 30.9 32.2 31.2 31.3 32.0 31.8 29.9
#> [16] 32.9 31.7 30.7 31.7 31.1 30.6 32.9 32.9 31.3 31.9 31.7 31.3 32.2 32.9 29.9
#> [31] 30.4 32.5 33.2 28.4 31.7 29.8 31.5 31.3 32.3 33.1 33.7 30.9 31.7 32.4 32.3
#> [46] 31.3 32.5 31.5 31.1 32.2 32.4 33.3 32.0 32.2 29.6 32.9 32.9 33.7 32.9 31.9
#> [61] 32.1 32.5 30.6 32.8 33.7 32.2 33.1 29.6 30.1 32.9 31.7 30.6 31.3 32.1 32.7
#> [76] 30.4 31.4 31.0 28.3 36.8 32.7 33.5 34.6 33.3 31.5 32.2 32.2 32.2 32.9 32.2
#> [91] 32.3 34.0 33.2 31.7 31.9 31.3 32.1 33.8 34.4 32.4 34.4 32.5 32.8 32.4 32.9
#> [106] 32.4 31.5 32.6 32.1 30.0 30.3 32.3 33.7 33.8 32.6 33.4 32.6 32.3 31.0 33.0
#> [121] 32.6 33.8 32.4 34.3 33.8 30.7 31.1
The function “bfa.tree.plot” is designed to represent the binary tree data usong igraph library. By making use of the cell lineage dataset found in Cowan and Staudte (1986) and stored in the bifurcatingr package as “ecoli”, executing the following command will generate the tree.
The BAR model can be visualized using a scatterplot depicting the relationship between observations at time “t” and their lagged observations. This is done through the “bfa.scatterplot” function. This function requires two inputs: the binary tree data as a numeric vector “z” and the lag order “p”. The following command generates a scatterplot for the genrated binary tree above based on the BAR(1) model:
The following command generat scatterplot based on the BAR(2) model for the same data above.