Calculate the f2, f3, f4, and f4-ratio statistics
Usage
ts_f2(
ts,
A,
B,
mode = c("site", "branch", "node"),
span_normalise = TRUE,
windows = NULL
)
ts_f3(
ts,
A,
B,
C,
mode = c("site", "branch", "node"),
span_normalise = TRUE,
windows = NULL
)
ts_f4(
ts,
W,
X,
Y,
Z,
mode = c("site", "branch", "node"),
span_normalise = TRUE,
windows = NULL
)
ts_f4ratio(
ts,
X,
A,
B,
C,
O,
mode = c("site", "branch"),
span_normalise = TRUE
)
Arguments
- ts
Tree sequence object of the class
slendr_ts
- mode
The mode for the calculation ("sites" or "branch")
- span_normalise
Divide the result by the span of the window? Default TRUE, see the tskit documentation for more detail.
- windows
Coordinates of breakpoints between windows. The first coordinate (0) and the last coordinate (equal to
ts$sequence_length
) do not have to be specified as they are added automatically.- W, X, Y, Z, A, B, C, O
Character vectors of individual names (following the nomenclature of Patterson et al. 2021)
Examples
check_dependencies(python = TRUE) # make sure dependencies are present
init_env()
#> The interface to all required Python modules has been activated.
# load an example model with an already simulated tree sequence
slendr_ts <- system.file("extdata/models/introgression.trees", package = "slendr")
model <- read_model(path = system.file("extdata/models/introgression", package = "slendr"))
# load the tree-sequence object from disk
ts <- ts_load(slendr_ts, model, mutate = TRUE, mutation_rate = 1e-8, random_seed = 42)
# calculate f2 for two individuals in a previously loaded tree sequence
ts_f2(ts, A = "AFR_1", B = "EUR_1")
#> # A tibble: 1 × 3
#> A B f2
#> <chr> <chr> <dbl[1d]>
#> 1 AFR_1 EUR_1 0.000042
# calculate f2 for two sets of individuals
ts_f2(ts, A = c("AFR_1", "AFR_2"), B = c("EUR_1", "EUR_3"))
#> # A tibble: 1 × 3
#> A B f2
#> <chr> <chr> <dbl[1d]>
#> 1 AFR_1+AFR_2 EUR_1+EUR_3 0.0000427
# calculate f3 for two individuals in a previously loaded tree sequence
ts_f3(ts, A = "EUR_1", B = "AFR_1", C = "NEA_1")
#> # A tibble: 1 × 4
#> A B C f3
#> <chr> <chr> <chr> <dbl[1d]>
#> 1 EUR_1 AFR_1 NEA_1 0.000022
# calculate f3 for two sets of individuals
ts_f3(ts, A = c("AFR_1", "AFR_2", "EUR_1", "EUR_2"),
B = c("NEA_1", "NEA_2"),
C = "CH_1")
#> # A tibble: 1 × 4
#> A B C f3
#> <chr> <chr> <chr> <dbl[1d]>
#> 1 AFR_1+AFR_2+EUR_1+EUR_2 NEA_1+NEA_2 CH_1 0.000199
# calculate f4 for single individuals
ts_f4(ts, W = "EUR_1", X = "AFR_1", Y = "NEA_1", Z = "CH_1")
#> # A tibble: 1 × 5
#> W X Y Z f4
#> <chr> <chr> <chr> <chr> <dbl[1d]>
#> 1 EUR_1 AFR_1 NEA_1 CH_1 0
# calculate f4 for sets of individuals
ts_f4(ts, W = c("EUR_1", "EUR_2"),
X = c("AFR_1", "AFR_2"),
Y = "NEA_1",
Z = "CH_1")
#> # A tibble: 1 × 5
#> W X Y Z f4
#> <chr> <chr> <chr> <chr> <dbl[1d]>
#> 1 EUR_1+EUR_2 AFR_1+AFR_2 NEA_1 CH_1 0
# calculate f4-ratio for a given set of target individuals X
ts_f4ratio(ts, X = c("EUR_1", "EUR_2", "EUR_4", "EUR_5"),
A = "NEA_1", B = "NEA_2", C = "AFR_1", O = "CH_1")
#> # A tibble: 4 × 6
#> X A B C O alpha
#> <chr> <chr> <chr> <chr> <chr> <dbl[1d]>
#> 1 EUR_1 NEA_1 NEA_2 AFR_1 CH_1 0
#> 2 EUR_2 NEA_1 NEA_2 AFR_1 CH_1 0
#> 3 EUR_4 NEA_1 NEA_2 AFR_1 CH_1 0
#> 4 EUR_5 NEA_1 NEA_2 AFR_1 CH_1 0