Skip to contents

Converts FBD posterior parameter table, such as those imported using combine_log, from wide to long format.

Usage

FBD_reshape(posterior, variables = NULL, log.type = c("MrBayes", "BEAST2"))

Arguments

posterior

Single posterior parameter sample dataset with skyline FBD parameters produced with combine_log.

variables

Names of FBD rate variables in the log. If NULL (default), will attempt to auto-detect the names and log type.

log.type

Name of the software which produced the log (currently supported: MrBayes or BEAST2). Has to be set if variables is not NULL.

Details

The posterior parameters log files produced by Bayesian evolutionary analyses using skyline birth-death tree models, including the skyline FBD model, result into two or more estimates for each FBD parameter, one for each time bin. This function will convert a table of parameters with skyline FBD parameters from wide to long format, with one row per generation per time bin and a new column "Time_bin" containing the respective time bins as a factor. The long format is necessary for downstream analyses using FBD_summary, FBD_dens_plot, FBD_normality_plot, FBD_tests1, or FBD_tests2, as similarly done by clock_reshape for clock rate tables.

The format of the log files can either be specified using the variables and log.type or auto-detected by the function. The "posterior" data frame can be obtained by reading in a log file directly (e.g. using the read.table function) or by combining several output log files from Mr. Bayes using combine_log.

Value

A data frame of posterior parameter estimates containing a single "Time_bin" column and one column for each FBD parameter value.

See also

vignette("fbd-params") for the use of this function as part of an analysis pipeline.

combine_log, reshape

Examples

# See vignette("fbd-params") for how to use this
# function as part of an analysis pipeline

data("posterior3p")

head(posterior3p)
#>       Gen       LnL      LnPr  TH.all.   TL.all. prop_ancfossil.all.   sigma.1.
#> 1 8750000 -1449.425 -143.1907 5.271118 11.969460                   0 0.07660715
#> 2 8761000 -1458.367 -174.9627 4.775064 11.070210                   0 0.05850396
#> 3 8771000 -1449.445 -163.9216 5.927716 12.628460                   0 0.05182430
#> 4 8782000 -1453.218 -153.2030 4.451376  9.931809                   0 0.14644520
#> 5 8792000 -1461.906 -132.1172 5.095504 11.083810                   0 0.14143120
#> 6 8803000 -1452.809 -129.3066 4.715021 10.481830                   0 0.10207230
#>     sigma.2.  sigma.3.      m.1.     m.2.     m.3. net_speciation_1.all.
#> 1 1.33351500 0.8523453 0.3695799 1.544579 1.362332            0.04987983
#> 2 0.06463618 0.1380557 0.5083868 1.495777 1.108471            0.04675159
#> 3 0.67980130 0.7776142 0.4275609 1.569911 1.144364            0.01064803
#> 4 0.65005980 0.2999867 0.6445027 1.329942 1.148377            0.07373453
#> 5 0.52745340 1.3928490 0.4993570 1.368074 1.445410            0.04990040
#> 6 1.31535200 0.7405540 0.4835195 1.359665 1.508596            0.03950198
#>   net_speciation_2.all. net_speciation_3.all. net_speciation_4.all.
#> 1           0.030036060           0.009395822            0.02637372
#> 2           0.013372350           0.021293800            0.02126325
#> 3           0.010895640           0.017047410            0.04032594
#> 4           0.007208267           0.021414940            0.03326603
#> 5           0.006333419           0.019637100            0.01893420
#> 6           0.005410397           0.026179850            0.02002429
#>   relative_extinction_1.all. relative_extinction_2.all.
#> 1                  0.6785586                  0.9373640
#> 2                  0.9174022                  0.9838011
#> 3                  0.9677827                  0.9857446
#> 4                  0.8976315                  0.9883790
#> 5                  0.7887825                  0.9883790
#> 6                  0.8675209                  0.9851012
#>   relative_extinction_3.all. relative_extinction_4.all.
#> 1                  0.9555714                0.002227504
#> 2                  0.5125231                0.028959450
#> 3                  0.9032853                0.012431660
#> 4                  0.9464226                0.011271430
#> 5                  0.9658652                0.008529459
#> 6                  0.9268501                0.026359290
#>   relative_fossilization_1.all. relative_fossilization_2.all.
#> 1                   0.055629950                    0.03741083
#> 2                   0.006523517                    0.02198622
#> 3                   0.010535440                    0.02155796
#> 4                   0.001264865                    0.02106140
#> 5                   0.036796000                    0.03160199
#> 6                   0.006094768                    0.04703950
#>   relative_fossilization_3.all. relative_fossilization_4.all. tk02var.1.
#> 1                   0.020690570                  0.0253022700  0.3197728
#> 2                   0.034472140                  0.0004126629  0.2710006
#> 3                   0.073427910                  0.0004126629  0.2853423
#> 4                   0.014086210                  0.0004126629  0.4670378
#> 5                   0.006486824                  0.0409175900  0.2115789
#> 6                   0.008285265                  0.0016655860  0.2020097
#>   tk02var.2. tk02var.3. clockrate.all.
#> 1  0.3848931  0.2075079     0.01192715
#> 2  0.3609312  0.3622265     0.01086355
#> 3  0.1831945  0.6146289     0.01349259
#> 4  0.3483061  0.4949015     0.01016002
#> 5  0.2723863  0.3463915     0.01160514
#> 6  0.2846277  0.4073166     0.01075419

## Reshape FBD table to long format
posterior3p_long <- FBD_reshape(posterior3p)

head(posterior3p_long)
#>       Gen       LnL      LnPr  TH.all.   TL.all. prop_ancfossil.all.   sigma.1.
#> 1 8750000 -1449.425 -143.1907 5.271118 11.969460                   0 0.07660715
#> 2 8761000 -1458.367 -174.9627 4.775064 11.070210                   0 0.05850396
#> 3 8771000 -1449.445 -163.9216 5.927716 12.628460                   0 0.05182430
#> 4 8782000 -1453.218 -153.2030 4.451376  9.931809                   0 0.14644520
#> 5 8792000 -1461.906 -132.1172 5.095504 11.083810                   0 0.14143120
#> 6 8803000 -1452.809 -129.3066 4.715021 10.481830                   0 0.10207230
#>     sigma.2.  sigma.3.      m.1.     m.2.     m.3. tk02var.1. tk02var.2.
#> 1 1.33351500 0.8523453 0.3695799 1.544579 1.362332  0.3197728  0.3848931
#> 2 0.06463618 0.1380557 0.5083868 1.495777 1.108471  0.2710006  0.3609312
#> 3 0.67980130 0.7776142 0.4275609 1.569911 1.144364  0.2853423  0.1831945
#> 4 0.65005980 0.2999867 0.6445027 1.329942 1.148377  0.4670378  0.3483061
#> 5 0.52745340 1.3928490 0.4993570 1.368074 1.445410  0.2115789  0.2723863
#> 6 1.31535200 0.7405540 0.4835195 1.359665 1.508596  0.2020097  0.2846277
#>   tk02var.3. clockrate.all. Time_bin net_speciation relative_extinction
#> 1  0.2075079     0.01192715        1     0.04987983           0.6785586
#> 2  0.3622265     0.01086355        1     0.04675159           0.9174022
#> 3  0.6146289     0.01349259        1     0.01064803           0.9677827
#> 4  0.4949015     0.01016002        1     0.07373453           0.8976315
#> 5  0.3463915     0.01160514        1     0.04990040           0.7887825
#> 6  0.4073166     0.01075419        1     0.03950198           0.8675209
#>   relative_fossilization
#> 1            0.055629950
#> 2            0.006523517
#> 3            0.010535440
#> 4            0.001264865
#> 5            0.036796000
#> 6            0.006094768