├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── admixture_graph.R ├── agraph.R ├── data.R ├── evaluate-f-statistics.R ├── export.R ├── f-statistics.R ├── f4_plotting.R ├── filter.R ├── fitted_plotting.R ├── fitting.R ├── mcmc.R ├── overlaps.R ├── paths.R ├── plot.R ├── project_and_split.R ├── propose.R ├── signs.R ├── summary-statistics.R └── symbolic-f-statistics.R ├── README-fitted_data-1.png ├── README-graph-1.png ├── README.Rmd ├── README.md ├── README_cache └── markdown_github │ ├── __packages │ ├── unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.RData │ ├── unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.rdb │ └── unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.rdx ├── admixture_graph.Rproj ├── admixture_graph.Rproj.Rcheck └── 00check.log ├── cran-comments.md ├── data ├── bears.RData ├── graphs_2_0.RData ├── graphs_3_0.RData ├── graphs_3_1.RData ├── graphs_4_0.RData ├── graphs_4_1.RData ├── graphs_4_2.RData ├── graphs_5_0.RData ├── graphs_5_1.RData ├── graphs_5_2.RData ├── graphs_6_0.RData ├── graphs_6_1.RData ├── graphs_6_2.RData ├── graphs_7_0.RData ├── graphs_7_1.RData └── graphs_8_0.RData ├── man ├── add_a_leaf.Rd ├── add_an_admixture.Rd ├── add_an_admixture2.Rd ├── add_graph_f4.Rd ├── add_graph_f4_sign.Rd ├── admix_props.Rd ├── admixture_edge.Rd ├── admixture_proportions.Rd ├── admixturegraph-package.Rd ├── agraph.Rd ├── agraph_children.Rd ├── agraph_parents.Rd ├── agraph_weights.Rd ├── all_graphs.Rd ├── all_path_overlaps.Rd ├── all_paths.Rd ├── bears.Rd ├── build_edge_optimisation_matrix.Rd ├── burn_in.Rd ├── calculate_concentration.Rd ├── canonise_expression.Rd ├── canonise_graph.Rd ├── coef.agraph_fit.Rd ├── cost_function.Rd ├── edge.Rd ├── edge_optimisation_function.Rd ├── eight_leaves_trees.Rd ├── evaluate_f4.Rd ├── examine_edge_optimisation_matrix.Rd ├── export_to_qpGraph.Rd ├── extract_admixture_proportion_parameters.Rd ├── extract_graph_parameters.Rd ├── extract_trees.Rd ├── f2.Rd ├── f3.Rd ├── f4.Rd ├── f4stats.Rd ├── fast_fit.Rd ├── fast_plot.Rd ├── filter_on_leaves.Rd ├── fit_graph.Rd ├── fit_graph_list.Rd ├── fit_permutations_and_graphs.Rd ├── fitted.agraph_fit.Rd ├── five_leaves_graphs.Rd ├── format_path.Rd ├── four_leaves_graphs.Rd ├── get_graph_f4_sign.Rd ├── graph_environment.Rd ├── graph_to_vector.Rd ├── graphs_2_0.Rd ├── graphs_3_0.Rd ├── graphs_3_1.Rd ├── graphs_4_0.Rd ├── graphs_4_1.Rd ├── graphs_4_2.Rd ├── graphs_5_0.Rd ├── graphs_5_1.Rd ├── graphs_5_2.Rd ├── graphs_6_0.Rd ├── graphs_6_1.Rd ├── graphs_6_2.Rd ├── graphs_7_0.Rd ├── graphs_7_1.Rd ├── graphs_8_0.Rd ├── is_descendant_of.Rd ├── is_negative.Rd ├── is_positive.Rd ├── is_unknown.Rd ├── is_zero.Rd ├── log_likelihood.Rd ├── log_sum_of_logs.Rd ├── make_an_outgroup.Rd ├── make_mcmc_model.Rd ├── make_permutations.Rd ├── model_bayes_factor_n.Rd ├── model_likelihood.Rd ├── model_likelihood_n.Rd ├── mynonneg.Rd ├── no_admixture_events.Rd ├── no_admixture_events.agraph.Rd ├── no_admixture_events.agraph_fit.Rd ├── no_admixture_events.agraph_fit_list.Rd ├── no_poor_fits.Rd ├── no_poor_fits.agraph_fit.Rd ├── no_poor_fits.agraph_fit_list.Rd ├── overlaps_sign.Rd ├── parent_edges.Rd ├── path_overlap.Rd ├── plot.agraph.Rd ├── plot.agraph_fit.Rd ├── plot.f4stats.Rd ├── plot_fit_1.Rd ├── plot_fit_2.Rd ├── poor_fits.Rd ├── poor_fits.agraph_fit.Rd ├── poor_fits.agraph_fit_list.Rd ├── print.agraph_fit.Rd ├── project_to_population.Rd ├── remove_duplicates.Rd ├── rename_nodes.Rd ├── residuals.agraph_fit.Rd ├── run_metropolis_hasting.Rd ├── seven_leaves_graphs.Rd ├── seven_leaves_trees.Rd ├── sf2.Rd ├── sf3.Rd ├── sf4.Rd ├── six_leaves_graphs.Rd ├── split_population.Rd ├── split_population.agraph_fit.Rd ├── split_population.data.frame.Rd ├── sum_of_squared_errors.Rd ├── sum_of_squared_errors.agraph_fit.Rd ├── sum_of_squared_errors.agraph_fit_list.Rd ├── summary.agraph_fit.Rd ├── thinning.Rd └── vector_to_graph.Rd ├── test.R ├── tests ├── testthat.R └── testthat │ ├── test_f_statistics.R │ ├── test_graph_construction.R │ ├── test_path_overlaps.R │ ├── test_paths.R │ ├── test_plots.R │ └── test_signs.R └── vignettes ├── admixturegraph.R ├── admixturegraph.Rmd ├── admixturegraph.md ├── admixturegraph_files ├── figure-html │ ├── bears_graph-1.png │ ├── new_admixtures-1.png │ ├── new_leaves-1.png │ ├── new_root-1.png │ ├── unnamed-chunk-1-1.png │ ├── unnamed-chunk-10-1.png │ ├── unnamed-chunk-11-1.png │ ├── unnamed-chunk-12-1.png │ ├── unnamed-chunk-13-1.png │ ├── unnamed-chunk-14-1.png │ ├── unnamed-chunk-15-1.png │ ├── unnamed-chunk-15-2.png │ ├── unnamed-chunk-18-1.png │ ├── unnamed-chunk-18-2.png │ ├── unnamed-chunk-19-1.png │ ├── unnamed-chunk-19-2.png │ ├── unnamed-chunk-19-3.png │ ├── unnamed-chunk-19-4.png │ ├── unnamed-chunk-3-1.png │ ├── unnamed-chunk-4-1.png │ ├── unnamed-chunk-5-1.png │ ├── unnamed-chunk-6-1.png │ ├── unnamed-chunk-7-1.png │ ├── unnamed-chunk-8-1.png │ └── unnamed-chunk-9-1.png └── figure-latex │ ├── bears_graph-1.pdf │ ├── new_admixtures-1.pdf │ ├── new_leaves-1.pdf │ ├── new_root-1.pdf │ ├── unnamed-chunk-1-1.pdf │ ├── unnamed-chunk-11-1.pdf │ ├── unnamed-chunk-12-1.pdf │ ├── unnamed-chunk-13-1.pdf │ ├── unnamed-chunk-14-1.pdf │ ├── unnamed-chunk-15-1.pdf │ ├── unnamed-chunk-15-2.pdf │ ├── unnamed-chunk-18-1.pdf │ ├── unnamed-chunk-18-2.pdf │ ├── unnamed-chunk-19-1.pdf │ ├── unnamed-chunk-19-2.pdf │ ├── unnamed-chunk-19-3.pdf │ ├── unnamed-chunk-19-4.pdf │ ├── unnamed-chunk-3-1.pdf │ ├── unnamed-chunk-4-1.pdf │ ├── unnamed-chunk-5-1.pdf │ ├── unnamed-chunk-6-1.pdf │ ├── unnamed-chunk-7-1.pdf │ └── unnamed-chunk-9-1.pdf └── bibliography.bib /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^README\.Rmd$ 4 | ^README-.*\.png$ 5 | ^NEWS\.md$ 6 | ^\.travis\.yml 7 | ^test\.R 8 | ^README_cache/*$ 9 | ^vignettes/admixturegraph_cache/*$ 10 | ^cran-comments\.md$ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Example code in package build process 6 | *-Ex.R 7 | # RStudio files 8 | .Rproj.user/ 9 | # produced vignettes 10 | vignettes/*.html 11 | vignettes/*.pdf 12 | vignettes/admixturegraph_cache 13 | .Rproj.user 14 | inst/doc 15 | 16 | README_cache/*$ 17 | .RData 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: required 3 | 4 | # Be strict when checking our package 5 | warnings_are_errors: true 6 | 7 | r_binary_packages: 8 | - testthat 9 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: admixturegraph 2 | Type: Package 3 | Title: Admixture Graph Manipulation and Fitting 4 | Version: 1.0.2 5 | Date: 2016-12-12 6 | Authors@R: c(person("Thomas", "Mailund", email = "mailund@birc.au.dk", role = c("cre", "aut")), 7 | person("Kalle", "Leppala", email = "kalle.m.leppala@gmail.com", role = c("aut")), 8 | person("Svend", "Nielsen", email = "svn@cs.au.dk", role = c("aut"))) 9 | Description: Implements tools for building and visualising admixture graphs 10 | and for extracting equations from them. These equations can be compared to f- 11 | statistics obtained from data to test the consistency of a graph against data -- 12 | for example by comparing the sign of f_4-statistics with the signs predicted by 13 | the graph -- and graph parameters (edge lengths and admixture proportions) can 14 | be fitted to observed statistics. 15 | License: GPL-2 16 | Depends: R (>= 3.2.2) 17 | Imports: doParallel, dplyr, foreach, ggplot2, graphics, MASS, methods, 18 | neldermead, parallel, pracma, stats, utils, grDevices 19 | Suggests: knitr, rmarkdown, testthat 20 | URL: https://github.com/mailund/admixture_graph 21 | BugReports: https://github.com/mailund/admixture_graph/issues 22 | VignetteBuilder: knitr 23 | LazyData: true 24 | RoxygenNote: 5.0.1 25 | NeedsCompilation: no 26 | Packaged: 2016-12-13 11:19:36 UTC; jonbe185 27 | Author: Thomas Mailund [cre, aut], 28 | Kalle Leppala [aut], 29 | Svend Nielsen [aut] 30 | Maintainer: Thomas Mailund 31 | Repository: CRAN 32 | Date/Publication: 2016-12-13 15:33:28 33 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(coef,agraph_fit) 4 | S3method(fitted,agraph_fit) 5 | S3method(no_admixture_events,agraph) 6 | S3method(no_admixture_events,agraph_fit) 7 | S3method(no_admixture_events,agraph_fit_list) 8 | S3method(no_poor_fits,agraph_fit) 9 | S3method(no_poor_fits,agraph_fit_list) 10 | S3method(plot,agraph) 11 | S3method(plot,agraph_fit) 12 | S3method(plot,f4stats) 13 | S3method(poor_fits,agraph_fit) 14 | S3method(poor_fits,agraph_fit_list) 15 | S3method(print,agraph_fit) 16 | S3method(residuals,agraph_fit) 17 | S3method(split_population,agraph_fit) 18 | S3method(split_population,data.frame) 19 | S3method(sum_of_squared_errors,agraph_fit) 20 | S3method(sum_of_squared_errors,agraph_fit_list) 21 | S3method(summary,agraph_fit) 22 | export(add_a_leaf) 23 | export(add_an_admixture) 24 | export(add_an_admixture2) 25 | export(add_graph_f4) 26 | export(add_graph_f4_sign) 27 | export(admix_props) 28 | export(admixture_edge) 29 | export(admixture_proportions) 30 | export(agraph) 31 | export(all_graphs) 32 | export(all_path_overlaps) 33 | export(all_paths) 34 | export(burn_in) 35 | export(calculate_concentration) 36 | export(canonise_graph) 37 | export(edge) 38 | export(eight_leaves_trees) 39 | export(evaluate_f4) 40 | export(export_to_qpGraph) 41 | export(extract_graph_parameters) 42 | export(extract_trees) 43 | export(f2) 44 | export(f3) 45 | export(f4) 46 | export(f4stats) 47 | export(fast_fit) 48 | export(fast_plot) 49 | export(filter_on_leaves) 50 | export(fit_graph) 51 | export(fit_graph_list) 52 | export(fit_permutations_and_graphs) 53 | export(five_leaves_graphs) 54 | export(four_leaves_graphs) 55 | export(get_graph_f4_sign) 56 | export(graph_environment) 57 | export(graph_to_vector) 58 | export(is_descendant_of) 59 | export(is_negative) 60 | export(is_positive) 61 | export(is_unknown) 62 | export(is_zero) 63 | export(log_likelihood) 64 | export(log_sum_of_logs) 65 | export(make_an_outgroup) 66 | export(make_mcmc_model) 67 | export(make_permutations) 68 | export(model_bayes_factor_n) 69 | export(model_likelihood) 70 | export(model_likelihood_n) 71 | export(no_admixture_events) 72 | export(no_poor_fits) 73 | export(overlaps_sign) 74 | export(parent_edges) 75 | export(path_overlap) 76 | export(plot_fit_1) 77 | export(plot_fit_2) 78 | export(poor_fits) 79 | export(project_to_population) 80 | export(remove_duplicates) 81 | export(rename_nodes) 82 | export(run_metropolis_hasting) 83 | export(seven_leaves_graphs) 84 | export(seven_leaves_trees) 85 | export(sf2) 86 | export(sf3) 87 | export(sf4) 88 | export(six_leaves_graphs) 89 | export(split_population) 90 | export(sum_of_squared_errors) 91 | export(thinning) 92 | export(vector_to_graph) 93 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # Version 1.0.2.9000 2 | 3 | * Export to the qpGraph format. 4 | 5 | # Version 1.0.2 6 | 7 | * Fixed a bug in the MCMC code. 8 | * Introduced admixture graph library in the data folder in the form of matrices, and new 9 | functions graph_to_vector() and vector_to_graph() to interpret the matrix data. 10 | * Added rename_nodes() for renaming graph nodes in user defined or automised manner. 11 | * Added canonise_graph() and remove_duplicates() for detecting isomorphism among graphs 12 | with labeled leaves. 13 | * Added all_graphs() although the data folder already contains a big admixture graph library. 14 | * New parallel computing fitting function fit_graph_list() that takes one list and data 15 | as an input instead of a list and permutations. 16 | * Updated the vignette. 17 | 18 | # Version 1.0.1 19 | 20 | * Updated code for laying out graphs with nodes that have more than two children. 21 | * Added options for fitting plots to make them in grayscale (Issue #11). 22 | * Updated functions for plotting the cost function and number of fits as functions of admixture 23 | proportions (Issue #12). 24 | * Changed specification of admixture proportions (Iussue #9) to avoid specifying redundant 25 | information. The changes are still backward compatible, so old analysis scripts should 26 | still work. 27 | 28 | # Version 1.0.0 29 | 30 | * A version ready for publication. 31 | 32 | # Version 0.4.1 33 | 34 | * Fixed bug that caused crossing edges for admixture events in plotting (Issue #3). 35 | * Added bears to data/ 36 | * Added syntactic suggar to graph construction 37 | * Fix plotting bug (Issue #4) 38 | * Wrote an interface to fitted data objects using the generic functions usually used 39 | for fitted models. 40 | * Added code for plotting fitted data 41 | * Added predict() function. 42 | * Added function for filtering data based on the leaves in a tree and for mapping 43 | between samples and populations (leaves). 44 | * New optimisation code based on solving linear systems for those variables that are linear. 45 | 46 | -------------------------------------------------------------------------------- /R/admixture_graph.R: -------------------------------------------------------------------------------- 1 | #' admixturegraph: Visualising and analysing admixture graphs. 2 | #' 3 | #' The package provides functionality to analyse and test admixture graphs 4 | #' against the \eqn{f} statistics described in the paper 5 | #' Ancient Admixture in Human History, 6 | #' Patterson \emph{et al.}, Genetics, Vol. 192, 1065--1093, 2012. 7 | #' 8 | #' The \eqn{f} statistics -- \eqn{f_2}, \eqn{f_3}, and \eqn{f_4} -- extract 9 | #' information about correlations between gene frequencies in different 10 | #' populations (or single diploid genome samples), which can be informative 11 | #' about patterns of gene flow between these populations in form of admixture 12 | #' events. If a graph is constructed as a hypothesis for the relationship 13 | #' between the populations, equations for the expected values of the \eqn{f} 14 | #' statistics can be extracted, as functions of edge lengths -- representing 15 | #' genetic drift -- and admixture proportions. 16 | #' 17 | #' This package provides functions for extracting these equations and for 18 | #' fitting them against computed \eqn{f} statistics. It does not currently 19 | #' provide functions for computing the \eqn{f} statistics -- for that we refer 20 | #' to the \href{https://github.com/DReichLab/AdmixTools}{ADMIXTOOLS} software 21 | #' package. 22 | #' 23 | #' @docType package 24 | #' @name admixturegraph-package 25 | NULL 26 | -------------------------------------------------------------------------------- /R/evaluate-f-statistics.R: -------------------------------------------------------------------------------- 1 | #' Extract all the parameters a graph contains. 2 | #' 3 | #' The graph is parameterized by edge lengths and admixture proportions. This 4 | #' function extracts these parameters. 5 | #' 6 | #' @param graph The admixture graph. 7 | #' 8 | #' @return A list containing two values: \code{edges}, a vector of edges and 9 | #' \code{admix_prop}, a vector containing admixture proportions. 10 | #' 11 | #' @export 12 | extract_graph_parameters <- function(graph) { 13 | edges <- c() 14 | for (node in graph$nodes) { 15 | children <- graph$nodes[graph$children[node,]] 16 | if (length(children) > 0) { 17 | edges <- c(edges, paste("edge_", node, "_", children, sep="")) 18 | } 19 | } 20 | 21 | admix_prop_variable <- function(x) nchar(x) > 0 && substr(x, 1, 1) != "(" 22 | admix_prop <- unique(Filter(admix_prop_variable, graph$probs)) 23 | 24 | list(edges = edges, admix_prop = admix_prop) 25 | } 26 | 27 | #' Build an environment in which f statistics can be evaluated. 28 | #' 29 | #' Constructs an environment in which the \eqn{f} statistics for a graph can be 30 | #' evaluted, based on the parameters in a graph and values for edge lengths and 31 | #' admixture proportions (with defaults if not specified). 32 | #' 33 | #' @param parameters The parameters of a graph as returned by 34 | #' \code{\link{extract_graph_parameters}}. 35 | #' @param edge_lengths If specified, a vector of edge lengths. Otherwise 36 | #' defaults are used. 37 | #' @param admix_prop If specified, a vector of admixture proportions. 38 | #' Otherwise defaults are used. 39 | #' 40 | #' @return A list containing two values: \code{edges}, a vector of edges and 41 | #' \code{admix_prop}, a vector containing admixture proportions. 42 | #' 43 | #' @export 44 | graph_environment <- function(parameters, 45 | edge_lengths = NULL, 46 | admix_prop = NULL) { 47 | 48 | if (is.null(edge_lengths)) { 49 | edge_lengths <- rep(0.01, length(parameters$edges)) 50 | } 51 | if (is.null(admix_prop)) { 52 | admix_prop <- rep(0.5, length(parameters$admix_prop)) 53 | } 54 | 55 | env <- new.env() 56 | for (i in seq_along(parameters$edges)) { 57 | assign(parameters$edges[i], edge_lengths[i], env) 58 | } 59 | for (i in seq_along(parameters$admix_prop)) { 60 | assign(parameters$admix_prop[i], admix_prop[i], env) 61 | } 62 | env 63 | } 64 | 65 | #' Evaluates an f_4 statistics in a given environment. 66 | #' 67 | #' Evaluates an \eqn{f_4} statistics in a given environment. 68 | #' 69 | #' @param graph The admixture graph. 70 | #' @param env The environment containing the graph parameters. 71 | #' @param W First population/sample. 72 | #' @param X Second population/sample. 73 | #' @param Y Third population/sample. 74 | #' @param Z Fourth population/sample. 75 | #' 76 | #' @return The \eqn{f_4} value specified by the graph and the environment. 77 | #' 78 | #' @export 79 | evaluate_f4 <- function(graph, env, W, X, Y, Z) { 80 | eval(sf4(graph, W, X, Y, Z), env) 81 | } 82 | 83 | #' Evalutes the f_4 statistics for all rows in a data frame and extends 84 | #' the data frame with the graph f_4. 85 | #' 86 | #' The data frame, \code{data}, must contain columns \code{W}, \code{X}, 87 | #' \code{Y}, and \code{Z}. The function then computes the \eqn{f_4(W, X; Y, Z)} 88 | #' statistics (also known as the \eqn{D} statistics) for all rows and adds these 89 | #' as a column, \code{graph_f4}, to the data frame. 90 | #' 91 | #' @param data The data frame to get the labels to compute the \eqn{f_4} statistics from. 92 | #' @param graph The admixture graph. 93 | #' @param env The environment to evaluate the \eqn{f_4} statistics in. 94 | #' 95 | #' @return A data frame identical to \code{data} except with an additional 96 | #' column, \code{graph_f4}, containing the \eqn{f_4} values as determined by 97 | #' the graph and the environment. 98 | #' 99 | #' @export 100 | add_graph_f4 <- function(data, graph, env) { 101 | data$graph_f4 <- unlist(Map(function(W,X,Y,Z) evaluate_f4(graph, env, W, X, Y, Z), 102 | data$W, data$X, data$Y, data$Z), 103 | use.names = FALSE) 104 | data 105 | } -------------------------------------------------------------------------------- /R/export.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | no_parents <- function(graph) function(node) { 4 | length(which(graph$parents[node, ])) 5 | } 6 | 7 | get_root <- function(graph) { 8 | roots <- which(Map(no_parents(graph), graph$nodes) == 0) 9 | if (length(roots) > 1) stop("Don't know how to handle more than one root") 10 | sprintf("root\t%s", names(roots[1])) 11 | } 12 | 13 | get_labels <- function(graph) { 14 | paste("label", graph$leaves, graph$leaves, sep = "\t", collapse = "\n") 15 | } 16 | 17 | mk_edge_label <- function(from, to) { 18 | paste0("edge_", from, "_", to, sep = "") 19 | } 20 | 21 | get_edges <- function(graph) { 22 | edge_statements <- c() 23 | nodes <- rownames(graph$parents) 24 | for (n in nodes) { 25 | parents <- names(which(graph$parents[n, ])) 26 | if (length(parents) == 0) next # root 27 | if (length(parents) == 1) { # normal node 28 | edge_label <- mk_edge_label(parents[1], n) 29 | edge_statements <- c(edge_statements, 30 | sprintf("edge\t%s\t%s\t%s", 31 | edge_label, parents[1], n)) 32 | next 33 | } 34 | if (length(parents) == 2) { # admixture node 35 | left <- paste0(parents[1], "_left", sep = "") 36 | right <- paste0(parents[2], "_right", sep = "") 37 | left_label <- mk_edge_label(left, n) 38 | right_label <- mk_edge_label(right, n) 39 | edge_statements <- c(edge_statements, 40 | sprintf("edge\t%s\t%s\t%s", 41 | left_label, left, n), 42 | sprintf("edge\t%s\t%s\t%s", 43 | right_label, right, n) 44 | ) 45 | next 46 | } 47 | stop(paste0("Unexpected number of parents for node ", n)) 48 | } 49 | edge_statements 50 | } 51 | 52 | get_admixtures <- function(graph) { 53 | admix_nodes <- names(which(rowSums(graph$parents) > 1)) 54 | admix_statements <- vector("character", length = length(admix_nodes)) 55 | for (i in seq_along(admix_nodes)) { 56 | node <- admix_nodes[i] 57 | parents <- names(which(graph$parents[node, ])) 58 | if (length(parents) != 2) stop(paste0("Unexpected parents for ", node)) 59 | left <- paste0(parents[1], "_left", sep = "") 60 | right <- paste0(parents[2], "_right", sep = "") 61 | admix_statements[i] <- sprintf("admix\t%s\t%s\t%s\t50\t50", node, left, right) 62 | } 63 | admix_statements 64 | } 65 | 66 | #' Export to Patterson's qpGraph format. 67 | #' 68 | #' This function writes a graph to a file-object, f, in the format used by the 69 | #' qpGraph tool. This format takes admixture proportions as part of the specification, 70 | #' but since we do not hold these proportions in our graphs, but only in fitted data, 71 | #' the export functions puts all admixture proportions as 50%/50%. Edit the output 72 | #' file by hand if you want to change this. 73 | #' 74 | #' @param f File object, e.g. stdout() 75 | #' @param graph A graph to export. 76 | #' @export 77 | export_to_qpGraph <- function(f, graph) { 78 | root <- get_root(graph) 79 | labels <- get_labels(graph) 80 | edges <- get_edges(graph) 81 | admixtures <- get_admixtures(graph) 82 | 83 | lines <- c(root, "", labels, "", edges, "", admixtures) 84 | writeLines(lines, con = f) 85 | } 86 | -------------------------------------------------------------------------------- /R/f-statistics.R: -------------------------------------------------------------------------------- 1 | #' Calculate the f_4(W, X; Y, Z) statistics. 2 | #' 3 | #' Calculate the \eqn{f_4(W, X; Y, Z)} statistics. 4 | #' 5 | #' @param graph The admixture graph. 6 | #' @param W A leaf node. 7 | #' @param X A leaf node. 8 | #' @param Y A leaf node. 9 | #' @param Z A leaf node. 10 | #' 11 | #' @return The overlaps between paths from \code{W} to \code{X} and paths from 12 | #' \code{Y} to \code{Z}. 13 | #' 14 | #' @export 15 | f4 <- function(graph, W, X, Y, Z) { 16 | if (!(W %in% graph$leaves)) stop(paste(W, "is not a leaf in the graph.")) 17 | if (!(X %in% graph$leaves)) stop(paste(X, "is not a leaf in the graph.")) 18 | if (!(Y %in% graph$leaves)) stop(paste(Y, "is not a leaf in the graph.")) 19 | if (!(Z %in% graph$leaves)) stop(paste(Z, "is not a leaf in the graph.")) 20 | 21 | WX <- all_paths(graph, W, X) 22 | YZ <- all_paths(graph, Y, Z) 23 | all_path_overlaps(WX, YZ) 24 | } 25 | 26 | #' Calculate the f_3(A; B, C) statistics. 27 | #' 28 | #' Calculate the \eqn{f_3(A; B, C)} statistics. 29 | #' 30 | #' @param graph The admixture graph. 31 | #' @param A A leaf node. 32 | #' @param B A leaf node. 33 | #' @param C A leaf node. 34 | #' 35 | #' @return A symbolic representation of the equation for the \eqn{f_3} 36 | #' statistics given by the admixture graph. 37 | #' 38 | #' @export 39 | f3 <- function(graph, A, B, C) f4(graph, A, B, A, C) 40 | 41 | #' Calculate the f_2(A, B) statistics. 42 | #' 43 | #' Calculate the \eqn{f_2(A, B)} statistics. 44 | #' 45 | #' @param graph The admixture graph. 46 | #' @param A A leaf node. 47 | #' @param B A leaf node. 48 | #' 49 | #' @return A symbolic representation of the equation for the \eqn{f_2} 50 | #' statistics given by the admixture graph. 51 | #' 52 | #' @export 53 | f2 <- function(graph, A, B) f4(graph, A, B, A, B) -------------------------------------------------------------------------------- /R/f4_plotting.R: -------------------------------------------------------------------------------- 1 | #' Make a data frame an f_4 statistics object. 2 | #' 3 | #' This is mostly just a convinience function to set the class of a data frame such that 4 | #' we plot data as error bars in a meaningful way for statistics for admixture graphs. 5 | #' 6 | #' @param x Data frame with observed \eqn{D} (\eqn{f_4}) statistics. 7 | #' 8 | #' @return Something about classes. 9 | #' 10 | #' @export 11 | f4stats <- function(x) { 12 | class(x) <- c("f4stats", class(x)) 13 | x 14 | } 15 | 16 | #' Plot the fit of a graph to data. 17 | #' 18 | #' @param x Data frame with observed \eqn{D} (\eqn{f_4}) statistics 19 | #' @param sigma How many sigmas the error bars should be wide. 20 | #' @param ... Additional parameters. 21 | #' 22 | #' @export 23 | plot.f4stats <- function(x, sigma = 6, ...) { 24 | # I know this is not the 'dplyr' way of doing it, but package check doesn't like 25 | # non standard evaluation, so this is what is needed. 26 | D <- x$D 27 | x$stderr <- with(x, D / Z.value) 28 | x$error_bar_start <- with(x, D - sigma/2*stderr) 29 | x$error_bar_end <- with(x, D + sigma/2*stderr) 30 | x$test <- with(x, paste("D(",W,",",X,";",Y,",",Z,")")) 31 | x$test <- factor(x$test, levels=dplyr::arrange(x, D)$test) 32 | 33 | ggplot2::ggplot(x) + 34 | ggplot2::geom_hline(yintercept = 0, linetype = 'dashed', color = 'gray') + 35 | ggplot2::geom_errorbar(ggplot2::aes_string(x = 'test', ymin = 'error_bar_start', ymax = 'error_bar_end'), color='black') + 36 | ggplot2::geom_point(ggplot2::aes_string(x = 'test', y = 'D'), color='black') + 37 | ggplot2::xlab('') + ggplot2::ylab('') + 38 | ggplot2::coord_flip() + 39 | ggplot2::theme_classic() + 40 | ggplot2::theme(legend.position="none") + 41 | ggplot2::theme(axis.line = ggplot2::element_blank(), 42 | axis.text.x = ggplot2::element_blank(), 43 | axis.ticks = ggplot2::element_blank()) + 44 | ggplot2::theme(panel.grid.major = ggplot2::element_line(color = 'white'), 45 | panel.grid.major.x = ggplot2::element_blank(), 46 | panel.grid.major.y = ggplot2::element_line(color = '#eeeeee')) 47 | } -------------------------------------------------------------------------------- /R/filter.R: -------------------------------------------------------------------------------- 1 | #' Filter data so all W, X, Y and Z are leaves in the graph. 2 | #' 3 | #' Filter data so all \code{W}, \code{X}, \code{Y} and \code{Z} are leaves in the graph. 4 | #' 5 | #' @param data Data frame (or similar) object containing columns \code{W}, \code{X}, 6 | #' \code{Y}, and \code{Z}. 7 | #' @param graph Admixture graph. 8 | #' 9 | #' @return Data frame with rows where \code{W}, \code{X}, \code{Y}, or \code{Z} are 10 | #' not leaves are removed. 11 | #' 12 | #' @export 13 | filter_on_leaves <- function(data, graph) { 14 | keep <- data$W %in% graph$leaves & 15 | data$X %in% graph$leaves & 16 | data$Y %in% graph$leaves & 17 | data$Z %in% graph$leaves 18 | data[keep, ] 19 | } -------------------------------------------------------------------------------- /R/overlaps.R: -------------------------------------------------------------------------------- 1 | #' Collect the postive and negative overlap between two paths. 2 | #' 3 | #' Collects the postive and negative overlap between two paths. 4 | #' 5 | #' @param path1 The first path. 6 | #' @param path2 The second path. 7 | #' 8 | #' @return The (admixture) probability of seeing the two paths together with the 9 | #' positive and negative edges in the overlap. 10 | #' 11 | #' @export 12 | path_overlap <- function(path1, path2) { 13 | rev_path2 <- data.frame(from = path2$to, to = path2$from, prob = path2$prob) 14 | list(prob = c(path_probability(path1), path_probability(path2)), 15 | positive = merge(path1, path2)[,1:2], 16 | negative = merge(path1, rev_path2)[,1:2]) 17 | } 18 | 19 | #' Get the list of overlaps of all paths. 20 | #' 21 | #' Gets the list of overlaps of all paths. 22 | #' 23 | #' @param paths1 Paths between one pair of leaves. 24 | #' @param paths2 Paths between another pair of leaves. 25 | #' @return A list of the overlaps of all combinations of paths from \code{paths1} 26 | #' and \code{paths2}. 27 | #' 28 | #' @export 29 | all_path_overlaps <- function(paths1, paths2) { 30 | n1 <- length(paths1) 31 | n2 <- length(paths2) 32 | 33 | if (n1 == 0 || n2 == 0) return(list()) 34 | 35 | overlaps <- list(rep(NA, n1 * n2)) 36 | 37 | idx <- 1 38 | for (i in 1:n1) { 39 | for (j in 1:n2) { 40 | overlaps[[idx]] <- path_overlap(paths1[[i]], paths2[[j]]) 41 | idx <- idx + 1 42 | } 43 | } 44 | overlaps 45 | } -------------------------------------------------------------------------------- /R/paths.R: -------------------------------------------------------------------------------- 1 | #' Create a path data frame from a list of nodes. 2 | #' 3 | #' Creates a path data frame from a list of nodes. 4 | #' 5 | #' @param graph The admixture graph the path is in. 6 | #' @param nodes A list of nodes on a path. 7 | #' 8 | #' @return A data frame capturing the path and the probabilities/weights on the edges. 9 | format_path <- function(graph, nodes) { 10 | path <- data.frame(from = graph$nodes[nodes[1 : length(nodes) - 1]], 11 | to = graph$nodes[nodes[2 : length(nodes)]], 12 | stringsAsFactors = FALSE) 13 | path$prob <- mapply(function(f,t) graph$probs[f, t], path$from, path$to) 14 | path 15 | } 16 | 17 | #' Compute all paths from one leaf to another. 18 | #' 19 | #' Computes all paths from one leaf to another. 20 | #' 21 | #' @param graph The admixture graph. 22 | #' @param src The starting leaf. 23 | #' @param dst The destination leaf. 24 | #' 25 | #' @return A list containing all the paths from \code{src} to \code{dst}. 26 | #' 27 | #' @export 28 | all_paths <- function(graph, src, dst) { 29 | if (!(src %in% graph$leaves)) stop(paste(src, "is not a leaf in the graph.")) 30 | if (!(dst %in% graph$leaves)) stop(paste(dst, "is not a leaf in the graph.")) 31 | 32 | src_idx <- which(src == rownames(graph$parents)) 33 | dst_idx <- which(dst == rownames(graph$parents)) 34 | PATHS <- list() 35 | X <- 1 36 | 37 | recurse_up <- function(node, path = c()) { 38 | up_edges <- which(graph$parents[node,] != 0) 39 | down_edges <- which(graph$children[node,] != 0) 40 | 41 | lapply(up_edges, function(e) recurse_up(e, c(path, node))) 42 | lapply(down_edges, function(e) recurse_down(e, c(path, node))) 43 | } 44 | 45 | recurse_down <- function(node, path) { 46 | if (node %in% path) return(NULL) 47 | if (node == dst_idx) { 48 | PATHS[[X]] <<- format_path(graph, c(path, node)) 49 | X <<- X + 1 50 | } else { 51 | down_edges <- which(graph$children[node,] != 0) 52 | lapply(down_edges, function(e) recurse_down(e, c(path, node))) 53 | } 54 | } 55 | 56 | recurse_up(src_idx) 57 | PATHS 58 | } -------------------------------------------------------------------------------- /R/project_and_split.R: -------------------------------------------------------------------------------- 1 | #' Map sample names to population names. 2 | #' 3 | #' Map sample names to population names. 4 | #' 5 | #' This function maps the sample names in \code{W}, \code{X}, \code{Y}, and 6 | #' \code{Z} to population names (typically what an admixture graph has for 7 | #' leaves) and stores the original sample names so we can map them back again 8 | #' after using the graph for making predictions. 9 | #' 10 | #' @param data The data frame to modify. 11 | #' @param f Function mapping sample names to population names. 12 | #' 13 | #' @export 14 | project_to_population <- function(data, f) { 15 | data$.W_ind <- data$W 16 | data$.X_ind <- data$X 17 | data$.Y_ind <- data$Y 18 | data$.Z_ind <- data$Z 19 | data$W <- vapply(data$.W_ind, f, "", USE.NAMES = FALSE) 20 | data$X <- vapply(data$.X_ind, f, "", USE.NAMES = FALSE) 21 | data$Y <- vapply(data$.Y_ind, f, "", USE.NAMES = FALSE) 22 | data$Z <- vapply(data$.Z_ind, f, "", USE.NAMES = FALSE) 23 | data 24 | } 25 | 26 | #' Reverse a projection of samples to populations. 27 | #' 28 | #' Reverse a projection of samples to populations. 29 | #' 30 | #' @param x The projected data or a fitted object on projected data. 31 | #' 32 | #' @export 33 | split_population <- function(x) UseMethod("split_population") 34 | 35 | #' Reverse a projection of samples to populations. 36 | #' 37 | #' Reverse a projection of samples to populations. 38 | #' 39 | #' @param x The projected data or a fitted object on projected data. 40 | #' 41 | #' @export 42 | split_population.data.frame <- function(x) { 43 | x$W = x$.W_ind 44 | x$X = x$.X_ind 45 | x$Y = x$.Y_ind 46 | x$Z = x$.Z_ind 47 | x$.W_ind <- NULL 48 | x$.X_ind <- NULL 49 | x$.Y_ind <- NULL 50 | x$.Z_ind <- NULL 51 | x 52 | } 53 | 54 | #' Reverse a projection of samples to populations. 55 | #' 56 | #' Reverse a projection of samples to populations. 57 | #' 58 | #' @param x The projected data or a fitted object on projected data. 59 | #' 60 | #' @export 61 | split_population.agraph_fit <- function(x) { 62 | x$data <- split_population(stats::fitted(x)) 63 | x 64 | } -------------------------------------------------------------------------------- /R/signs.R: -------------------------------------------------------------------------------- 1 | path_zero <- function(overlap) 2 | nrow(overlap$positive) == 0 && nrow(overlap$negative) == 0 3 | path_positive <- function(overlap) 4 | nrow(overlap$positive) > 0 && nrow(overlap$negative) == 0 5 | path_negative <- function(overlap) 6 | nrow(overlap$positive) == 0 && nrow(overlap$negative) > 0 7 | 8 | path_non_negative <- function(overlap) 9 | path_zero(overlap) || path_positive(overlap) 10 | path_non_positive <- function(overlap) 11 | path_zero(overlap) || path_negative(overlap) 12 | 13 | #' All overlaps are empty. 14 | #' 15 | #' All overlaps are empty. 16 | #' 17 | #' @param overlaps Data frame representing path overlaps, typically generated 18 | #' by \code{\link{all_path_overlaps}}. 19 | #' 20 | #' @export 21 | is_zero <- function(overlaps) { 22 | all(unlist(Map(path_zero, overlaps))) 23 | } 24 | 25 | #' All overlaps are either empty or have a positive weight. 26 | #' 27 | #' All overlaps are either empty or have a positive weight. 28 | #' 29 | #' @param overlaps Data frame representing path overlaps, typically generated 30 | #' by \code{\link{all_path_overlaps}}. 31 | #' 32 | #' @export 33 | is_positive <- function(overlaps) { 34 | !is_zero(overlaps) && all(unlist(Map(path_non_negative, overlaps))) 35 | } 36 | 37 | #' All overlaps are either empty or have a negative weight. 38 | #' 39 | #' All overlaps are either empty or have a negative weight. 40 | #' 41 | #' @param overlaps Data frame representing path overlaps, typically generated 42 | #' by \code{\link{all_path_overlaps}}. 43 | #' 44 | #' @export 45 | is_negative <- function(overlaps) { 46 | !is_zero(overlaps) && all(unlist(Map(path_non_positive, overlaps))) 47 | } 48 | 49 | #' Overlapping edges have both positive and negative contributions. 50 | #' 51 | #' Overlapping edges have both positive and negative contributions. 52 | #' 53 | #' @param overlaps Data frame representing path overlaps, typically generated 54 | #' by \code{\link{all_path_overlaps}}. 55 | #' 56 | #' @export 57 | is_unknown <- function(overlaps) { 58 | !is_zero(overlaps) && !is_positive(overlaps) && !is_negative(overlaps) 59 | } 60 | 61 | #' Get the sign of overlapping paths. 62 | #' 63 | #' Get the sign of overlapping paths. 64 | #' 65 | #' @param overlaps Data frame representing path overlaps, typically generated 66 | #' by \code{\link{all_path_overlaps}}. 67 | #' 68 | #' @export 69 | overlaps_sign <- function(overlaps) { 70 | if (is_zero(overlaps)) return(0) 71 | if (is_negative(overlaps)) return(-1) 72 | if (is_positive(overlaps)) return(+1) 73 | else return(NA) 74 | } 75 | 76 | #' Extracts the sign for the f_4 statistics predicted by the graph. 77 | #' 78 | #' Extracts the sign for the \eqn{f_4} statistics predicted by the graph. 79 | #' 80 | #' @param graph The admixture graph. 81 | #' @param W First population/sample. 82 | #' @param X Second population/sample. 83 | #' @param Y Third population/sample. 84 | #' @param Z Fourth population/sample. 85 | #' 86 | #' @return The sign of the \eqn{f_4} specified by the graph (or \code{NA} when it 87 | #' cannot be determined without knowing the graph parameters). 88 | #' 89 | #' @export 90 | get_graph_f4_sign <- function(graph, W, X, Y, Z) { 91 | overlaps_sign(f4(graph, W, X, Y, Z)) 92 | } 93 | 94 | #' Extend a data frame with f_4 statistics predicted by a graph. 95 | #' 96 | #' Extracts the sign for the \eqn{f_4} statistics predicted by the graph for all 97 | #' rows in a data frame and extends the data frame with the graph \eqn{f_4}. 98 | #' 99 | #' The data frame, \code{data}, must contain columns \code{W}, \code{X}, 100 | #' \code{Y}, and \code{Z}. The function then computes the sign of the 101 | #' \eqn{f4(W, X; Y, Z)} statistics for all rows and adds these as a column, 102 | #' \code{graph_f4_sign}, to the data frame. 103 | #' 104 | #' @param data The data frame to get the labels to compute the \eqn{f_4} 105 | #' statistics from. 106 | #' @param graph The admixture graph. 107 | #' 108 | #' @return A data frame identical to \code{data} except with an additional 109 | #' column, \code{graph_f4_sign}, containing the sign of the \eqn{f_4} 110 | #' statistics as determined by the graph. 111 | #' 112 | #' @export 113 | add_graph_f4_sign <- function(data, graph) { 114 | signs <- unlist(Map(function(W,X,Y,Z) get_graph_f4_sign(graph, W, X, Y, Z), 115 | data$W, data$X, data$Y, data$Z), 116 | use.names = FALSE) 117 | data$graph_f4_sign <- signs 118 | data 119 | } -------------------------------------------------------------------------------- /R/summary-statistics.R: -------------------------------------------------------------------------------- 1 | #' Get the number of admixture events in a graph. 2 | #' 3 | #' Get the number of admixture events in a graph. 4 | #' 5 | #' @param x The graph. 6 | #' 7 | #' @return Number of admixture events in the graph. 8 | #' 9 | #' @export 10 | no_admixture_events <- 11 | function(x) UseMethod("no_admixture_events") 12 | 13 | #' Get the number of admixture events in a graph. 14 | #' 15 | #' Get the number of admixture events in a graph. 16 | #' 17 | #' @param x The graph. 18 | #' 19 | #' @return Number of admixture events in the graph. 20 | #' 21 | #' @export 22 | no_admixture_events.agraph <- 23 | function(x) sum(rowSums(x$parents) == 2) 24 | 25 | #' Get the number of admixture events in a fitted graph. 26 | #' 27 | #' Get the number of admixture events in a fitted graph. 28 | #' 29 | #' @param x The fitted graph. 30 | #' 31 | #' @return Number of admixture events in the graph. 32 | #' 33 | #' @export 34 | no_admixture_events.agraph_fit <- 35 | function(x) no_admixture_events(x$graph) 36 | 37 | #' Get the number of admixture events in a list of fitted graph. 38 | #' 39 | #' Get the number of admixture events in a list of fitted graph. 40 | #' 41 | #' @param x The graphs. 42 | #' 43 | #' @return Number of admixture events in the graphs. 44 | #' 45 | #' @export 46 | no_admixture_events.agraph_fit_list <- 47 | function(x) unlist(Map(no_admixture_events, x)) 48 | 49 | #' Get the sum of squared errors for a fitted graph. 50 | #' 51 | #' Get the sum of squared errors for a fitted graph. 52 | #' 53 | #' @param x The fitted graph. 54 | #' 55 | #' @return SSE for the fit. 56 | #' 57 | #' @export 58 | sum_of_squared_errors <- 59 | function(x) UseMethod("sum_of_squared_errors") 60 | 61 | #' Get the sum of squared errors for a fitted graph. 62 | #' 63 | #' Get the sum of squared errors for a fitted graph. 64 | #' 65 | #' @param x The fitted graph. 66 | #' 67 | #' @return SSE for the fit. 68 | #' 69 | #' @export 70 | sum_of_squared_errors.agraph_fit <- 71 | function(x) x$best_error 72 | 73 | #' Get the sum of squared errors for a list of fitted graph. 74 | #' 75 | #' Get the sum of squared errors for a list of fitted graph. 76 | #' 77 | #' @param x The fitted graphs. 78 | #' 79 | #' @return SSE for the fits. 80 | #' 81 | #' @export 82 | sum_of_squared_errors.agraph_fit_list <- 83 | function(x) unlist(Map(sum_of_squared_errors, x)) 84 | 85 | #' Get the tests in the fit where the predictions fall outside of the error bars. 86 | #' 87 | #' Get the tests in the fit where the predictions fall outside of the error bars. 88 | #' 89 | #' @param fit The fitted graph. 90 | #' @param sigma The width of the error bars. 91 | #' 92 | #' @return The poorly fitted tests. 93 | #' 94 | #' @export 95 | poor_fits <- 96 | function(fit, sigma = 6) UseMethod("poor_fits") 97 | 98 | #' Get the tests in the fit where the predictions fall outside of the error bars. 99 | #' 100 | #' Get the tests in the fit where the predictions fall outside of the error bars. 101 | #' 102 | #' @param fit The fitted graph. 103 | #' @param sigma The width of the error bars. 104 | #' 105 | #' @return The poorly fitted tests. 106 | #' 107 | #' @export 108 | poor_fits.agraph_fit <- function(fit, sigma=6) { 109 | x <- stats::fitted(fit) 110 | x$stderr = x$D/x$Z.value 111 | x[with(x, (abs(D - graph_f4) > sigma/2*stderr)),] 112 | } 113 | 114 | #' Get the tests in the fit where the predictions fall outside of the error bars. 115 | #' 116 | #' Get the tests in the fit where the predictions fall outside of the error bars. 117 | #' 118 | #' @param fit The fitted graphs. 119 | #' @param sigma The width of the error bars. 120 | #' 121 | #' @return The poorly fitted tests. 122 | #' 123 | #' @export 124 | poor_fits.agraph_fit_list <- function(fit, sigma=6) { 125 | lapply(fit, poor_fits, sigma = sigma) 126 | } 127 | 128 | #' Get the number of tests in the fit where the predictions fall outside of the error bars. 129 | #' 130 | #' Get the number of tests in the fit where the predictions fall outside of the error bars. 131 | #' 132 | #' @param fit The fitted graph. 133 | #' @param sigma The width of the error bars. 134 | #' 135 | #' @return The poorly fitted tests. 136 | #' 137 | #' @export 138 | no_poor_fits <- 139 | function(fit, sigma=6) UseMethod("no_poor_fits") 140 | 141 | #' Get the number of tests in the fit where the predictions fall outside of the error bars. 142 | #' 143 | #' Get the number of tests in the fit where the predictions fall outside of the error bars. 144 | #' 145 | #' @param fit The fitted graph. 146 | #' @param sigma The width of the error bars. 147 | #' 148 | #' @return The poorly fitted tests. 149 | #' 150 | #' @export 151 | no_poor_fits.agraph_fit <- function(fit, sigma=6) { 152 | nrow(no_poor_fits(fit, sigma)) 153 | } 154 | 155 | #' Get the number of tests in the fit where the predictions fall outside of the error bars. 156 | #' 157 | #' Get the number of tests in the fit where the predictions fall outside of the error bars. 158 | #' 159 | #' @param fit The fitted graph. 160 | #' @param sigma The width of the error bars. 161 | #' 162 | #' @return The poorly fitted tests. 163 | #' 164 | #' @export 165 | no_poor_fits.agraph_fit_list <- function(fit, sigma=6) { 166 | vapply(poor_fits(fit, sigma = sigma), nrow, 1) 167 | } -------------------------------------------------------------------------------- /R/symbolic-f-statistics.R: -------------------------------------------------------------------------------- 1 | path_probability <- function(path) Filter(function(x) x != "", path$prob) 2 | 3 | format_edge <- function(graph) { 4 | force(graph) 5 | function(from, to) { 6 | if (graph$children[from,to]) { 7 | paste("edge_", from, "_", to, sep="") 8 | } else { 9 | paste("edge_", to, "_", from, sep="") 10 | } 11 | } 12 | } 13 | 14 | format_path_overlap <- function(graph) function(overlap) { 15 | weight <- NULL 16 | if (length(overlap$prob) > 0) { 17 | weight <- paste(overlap$prob, collapse = " * ") 18 | } 19 | 20 | positive <- unlist(Map(format_edge(graph), 21 | overlap$positive$from, overlap$positive$to), 22 | use.names = FALSE) 23 | negative <- unlist(Map(format_edge(graph), 24 | overlap$negative$from, overlap$negative$to), 25 | use.names = FALSE) 26 | 27 | format_list <- c() 28 | 29 | if (length(positive) > 0) { 30 | format_list <- c(paste(positive, collapse = " + ")) 31 | } 32 | if (length(negative) > 0) { 33 | format_list <- c(format_list, " - ", paste(negative, collapse = " - ")) 34 | } 35 | 36 | if (length(format_list) > 0 && !is.null(weight)) { 37 | format_list <- c(weight, " * ", "(", format_list, ")") 38 | } else if (length(format_list) == 0) { 39 | format_list <- c("0") 40 | } 41 | 42 | paste(format_list, collapse = "") 43 | } 44 | 45 | format_overlaps <- function(graph, overlaps) { 46 | overlaps <- vapply(overlaps, format_path_overlap(graph), character(1)) 47 | result <- paste(Filter(function(x) x != "0", overlaps), collapse = " + ") 48 | if (result != "") parse(text = result) else expression(0) 49 | } 50 | 51 | #' Calculate the f_4(W, X; Y, Z) statistics. 52 | #' 53 | #' Calculate the \eqn{f_4(W, X; Y, Z)} statistics. 54 | #' 55 | #' @param graph The admixture graph. 56 | #' @param W A leaf node. 57 | #' @param X A leaf node. 58 | #' @param Y A leaf node. 59 | #' @param Z A leaf node. 60 | #' 61 | #' @return A symbolic representation of the equation for the \eqn{f_4} 62 | #' statistics given by the admixture graph. 63 | #' 64 | #' @export 65 | sf4 <- function(graph, W, X, Y, Z) format_overlaps(graph, f4(graph, W, X, Y, Z)) 66 | 67 | #' Calculate the f_3(A; B, C) statistics. 68 | #' 69 | #' Calculate the \eqn{f_3(A; B, C)} statistics. 70 | #' 71 | #' @param graph The admixture graph. 72 | #' @param A A leaf node. 73 | #' @param B A leaf node. 74 | #' @param C A leaf node. 75 | #' 76 | #' @return A symbolic representation of the equation for the \eqn{f_3} 77 | #' statistics given by the admixture graph. 78 | #' 79 | #' @export 80 | sf3 <- function(graph, A, B, C) sf4(graph, A, B, A, C) 81 | 82 | #' Calculate the f_2(A, B) statistics. 83 | #' 84 | #' Calculate the \eqn{f_2(A, B)} statistics. 85 | #' 86 | #' @param graph The admixture graph. 87 | #' @param A A leaf node. 88 | #' @param B A leaf node. 89 | #' 90 | #' @return A symbolic representation of the equation for the \eqn{f_2} 91 | #' statistics given by the admixture graph. 92 | #' 93 | #' @export 94 | sf2 <- function(graph, A, B) sf4(graph, A, B, A, B) -------------------------------------------------------------------------------- /README-fitted_data-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/README-fitted_data-1.png -------------------------------------------------------------------------------- /README-graph-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/README-graph-1.png -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | md_document: 4 | variant: markdown_github 5 | --- 6 | 7 | 8 | 9 | ```{r, echo = FALSE, warning=FALSE} 10 | knitr::opts_chunk$set( 11 | collapse = TRUE, 12 | comment = "#>", 13 | fig.path = "README-" 14 | ) 15 | 16 | library(admixturegraph) 17 | suppressPackageStartupMessages(library(dplyr, quietly = TRUE)) 18 | suppressPackageStartupMessages(library(ggplot2, quietly = TRUE)) 19 | suppressPackageStartupMessages(library(ggthemes, quietly = TRUE)) 20 | suppressPackageStartupMessages(library(knitr, quietly = TRUE)) 21 | suppressPackageStartupMessages(library(neldermead, quietly = TRUE)) 22 | ``` 23 | 24 | # Admixture Graph Manipulation and Fitting 25 | 26 | The package provides functionality to analyse and test admixture graphs against the *f* statistics described in the paper [Ancient Admixture in Human History](http://tinyurl.com/o5a4kr4), Patternson *et al.*, Genetics, Vol. 192, 1065--1093, 2012. 27 | 28 | The *f* statistics --- *f2*, *f3*, and *f4* --- extract information about correlations between gene frequencies in different populations (or single diploid genome samples), which can be informative about patterns of gene flow between these populations in form of admixture events. If a graph is constructed as a hypothesis for the relationship between the populations, equations for the expected values of the *f* statistics can be extracted, as functions of edge lenghs --- representing genetic drift --- and admixture proportions. 29 | 30 | This package provides functions for extracting these equations and for fitting them against computed *f* statistics. It does not currently provide functions for computing the *f* statistics --- for that we refer to the [ADMIXTOOLS](https://github.com/DReichLab/AdmixTools) software package. 31 | 32 | ## Example 33 | 34 | Below is a quick example of how the package can be used. The example uses data 35 | from polar bears and brown bears with a black bear as outgroup and is taken from 36 | [Genomic evidence of geographically widespread effect of gene flow from polar 37 | bears into brown bears](http://onlinelibrary.wiley.com/doi/10.1111/mec.13038/abstract). 38 | 39 | The BLK sample is the black bear, the PB sample is a polar bear, and the rest 40 | are brown bears. 41 | 42 | I have taken the $f$ statistics from Table 1 in the paper: 43 | 44 | ```{r} 45 | data(bears) 46 | bears 47 | ``` 48 | 49 | The `D` column is the f4(W,X;Y,Z) statistic and the `Z` column is the $Z$-values 50 | obtained from a blocked jacknife (see Patterson *et al.* for details). 51 | 52 | From the statistics we can see that the ABC bears (Adm, Bar and Chi) are closer 53 | related to the polar bears compared to the other brown bears. The paper explains 54 | this with gene flow from polar bears into the ABC bears and going further out 55 | from there, but we can also explain this by several waves of admixture from 56 | ancestral polar bears into brown bears: 57 | 58 | ```{r graph} 59 | leaves <- c("BLK", "PB", 60 | "Bar", "Chi1", "Chi2", "Adm1", "Adm2", 61 | "Denali", "Kenai", "Sweden") 62 | inner_nodes <- c("R", "PBBB", 63 | "Adm", "Chi", "BC", "ABC", 64 | "x", "y", "z", 65 | "pb_a1", "pb_a2", "pb_a3", "pb_a4", 66 | "bc_a1", "abc_a2", "x_a3", "y_a4") 67 | 68 | edges <- parent_edges(c(edge("BLK", "R"), 69 | edge("PB", "pb_a1"), 70 | edge("pb_a1", "pb_a2"), 71 | edge("pb_a2", "pb_a3"), 72 | edge("pb_a3", "pb_a4"), 73 | edge("pb_a4", "PBBB"), 74 | 75 | edge("Chi1", "Chi"), 76 | edge("Chi2", "Chi"), 77 | edge("Chi", "BC"), 78 | edge("Bar", "BC"), 79 | edge("BC", "bc_a1"), 80 | 81 | edge("Adm1", "Adm"), 82 | edge("Adm2", "Adm"), 83 | 84 | admixture_edge("bc_a1", "pb_a1", "ABC", "a"), 85 | edge("Adm", "ABC"), 86 | 87 | edge("ABC", "abc_a2"), 88 | admixture_edge("abc_a2", "pb_a2", "x", "b"), 89 | 90 | edge("Denali", "x"), 91 | edge("x", "x_a3"), 92 | admixture_edge("x_a3", "pb_a3", "y", "c"), 93 | 94 | edge("Kenai", "y"), 95 | edge("y", "y_a4"), 96 | admixture_edge("y_a4", "pb_a4", "z", "d"), 97 | 98 | edge("Sweden", "z"), 99 | 100 | edge("z", "PBBB"), 101 | edge("PBBB", "R"))) 102 | 103 | bears_graph <- agraph(leaves, inner_nodes, edges) 104 | plot(bears_graph, show_admixture_labels = TRUE) 105 | ``` 106 | 107 | ## Fitting a graph to data 108 | 109 | The graph makes predictions on how the *f4* statistics should look. The graph parameters can be fit to observed statistics using the `fit_graph` function: 110 | 111 | ```{r, warning=FALSE, cache=TRUE, dependson="graph"} 112 | fit <- fit_graph(bears, bears_graph) 113 | fit 114 | ``` 115 | 116 | You can get detailsabout the fit by calling the `summary.agraph_fit` function: 117 | 118 | ```{r} 119 | summary(fit) 120 | ``` 121 | 122 | You can make a plot of the fit against the data by calling the `plot.agraph_fit` function: 123 | 124 | ```{r fitted_data} 125 | plot(fit) 126 | ``` 127 | 128 | The plot shows the observed *f4* statistics with error bars (in black) plus the predicted values from the graph. 129 | 130 | The result of this is a `ggplot2` object that you can modify by adding `ggplot2` commands in the usual way. 131 | 132 | Read the vignette `admixturegraph` for more examples. 133 | -------------------------------------------------------------------------------- /README_cache/markdown_github/__packages: -------------------------------------------------------------------------------- 1 | base 2 | methods 3 | datasets 4 | utils 5 | grDevices 6 | graphics 7 | stats 8 | admixturegraph 9 | dplyr 10 | ggplot2 11 | ggthemes 12 | knitr 13 | Matrix 14 | optimbase 15 | optimsimplex 16 | neldermead 17 | -------------------------------------------------------------------------------- /README_cache/markdown_github/unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/README_cache/markdown_github/unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.RData -------------------------------------------------------------------------------- /README_cache/markdown_github/unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/README_cache/markdown_github/unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.rdb -------------------------------------------------------------------------------- /README_cache/markdown_github/unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/README_cache/markdown_github/unnamed-chunk-3_a41d20584bc77181b0ba71b185d8e4c9.rdx -------------------------------------------------------------------------------- /admixture_graph.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace,vignette 19 | -------------------------------------------------------------------------------- /admixture_graph.Rproj.Rcheck/00check.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/admixture_graph.Rproj.Rcheck/00check.log -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ### Test environments 2 | * i686-pc-linux-gnu, R 3.3.1 (Bug In Your Hair) 3 | * x86_64-w64-mingw32, R 3.2.2 (Fire Safety) 4 | 5 | ### R CMD check results 6 | No ERRORS, WARNINGS or NOTES. -------------------------------------------------------------------------------- /data/bears.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/bears.RData -------------------------------------------------------------------------------- /data/graphs_2_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_2_0.RData -------------------------------------------------------------------------------- /data/graphs_3_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_3_0.RData -------------------------------------------------------------------------------- /data/graphs_3_1.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_3_1.RData -------------------------------------------------------------------------------- /data/graphs_4_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_4_0.RData -------------------------------------------------------------------------------- /data/graphs_4_1.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_4_1.RData -------------------------------------------------------------------------------- /data/graphs_4_2.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_4_2.RData -------------------------------------------------------------------------------- /data/graphs_5_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_5_0.RData -------------------------------------------------------------------------------- /data/graphs_5_1.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_5_1.RData -------------------------------------------------------------------------------- /data/graphs_5_2.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_5_2.RData -------------------------------------------------------------------------------- /data/graphs_6_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_6_0.RData -------------------------------------------------------------------------------- /data/graphs_6_1.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_6_1.RData -------------------------------------------------------------------------------- /data/graphs_6_2.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_6_2.RData -------------------------------------------------------------------------------- /data/graphs_7_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_7_0.RData -------------------------------------------------------------------------------- /data/graphs_7_1.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_7_1.RData -------------------------------------------------------------------------------- /data/graphs_8_0.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/data/graphs_8_0.RData -------------------------------------------------------------------------------- /man/add_a_leaf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{add_a_leaf} 4 | \alias{add_a_leaf} 5 | \title{Adds a new leaf to a graph.} 6 | \usage{ 7 | add_a_leaf(graph, leaf_name, outgroup = "") 8 | } 9 | \arguments{ 10 | \item{graph}{An admixture graph.} 11 | 12 | \item{leaf_name}{A name for the new leaf.} 13 | 14 | \item{outgroup}{An optional parameter for the preferred outgroup, which can be the new leaf.} 15 | } 16 | \value{ 17 | A list of graphs made by adding a new leaf to the input graph. The list has no 18 | duplicate elements. 19 | } 20 | \description{ 21 | Given an admixture graph, selects an edge and branches off a new edge ending at a new leaf. 22 | } 23 | \examples{ 24 | \donttest{ 25 | # Take a look at how much trees there are: 26 | leaves <- c("1", "2") 27 | inner_nodes <- c("R") 28 | edges <- parent_edges(c(edge("1", "R"), edge("2", "R"))) 29 | admixtures <- NULL 30 | Lambda <- agraph(leaves, inner_nodes, edges, admixtures) 31 | set <- list(Lambda) 32 | for (i in seq(1, 6)) { 33 | new_set <- list() 34 | for (tree in set) { 35 | new_set <- c(new_set, add_a_leaf(tree, paste(i + 2))) 36 | } 37 | set <- new_set 38 | cat("There are ") 39 | cat(length(set)) 40 | cat(" different trees with ") 41 | cat(i + 2) 42 | cat(" labeled leaves.") 43 | cat("\\n") 44 | } 45 | # In general, there are 1*3*5*...*(2n - 5) different trees with n labeled leaves 46 | # (A001147 in the online encyclopedia of integer sequences). 47 | # Exhaustive search through the graph space is hard! 48 | } 49 | 50 | } 51 | \seealso{ 52 | \code{\link{all_graphs}} 53 | 54 | \code{\link{fit_permutations_and_graphs}} 55 | 56 | \code{\link{fit_graph_list}} 57 | 58 | \code{\link{add_an_admixture}} 59 | 60 | \code{\link{add_an_admixture2}} 61 | 62 | \code{\link{make_an_outgroup}} 63 | } 64 | 65 | -------------------------------------------------------------------------------- /man/add_an_admixture.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{add_an_admixture} 4 | \alias{add_an_admixture} 5 | \title{Adds a new admixture event to a graph.} 6 | \usage{ 7 | add_an_admixture(graph, admixture_variable_name, labels_matter = FALSE, 8 | outgroup = "") 9 | } 10 | \arguments{ 11 | \item{graph}{An admixture graph.} 12 | 13 | \item{admixture_variable_name}{A name for the new admixture proportion.} 14 | 15 | \item{labels_matter}{When \code{FALSE} (the default value), we consider two admixture 16 | graphs similar when they have the same topology but permuted 17 | admixture proportion names. When \code{TRUE}, the already existing 18 | admixture events and the edges leading to them are considered 19 | labeled.} 20 | 21 | \item{outgroup}{An optional parameter for the preferred outgroup.} 22 | } 23 | \value{ 24 | A list of graphs made by adding a new admixture event to the input graph. The list has 25 | no duplicate elements (what that means depends on the value of \code{labels_matter}). 26 | } 27 | \description{ 28 | Given an admixture graph, selects a child edge and a parent edges and adds a new edge from the 29 | parent edge to the child edge with an admixture event, if possible. 30 | Thus, the resulting graph is an extension of the input graph in the sense that erasing one of 31 | the admixture edges (the new one) we get the original admixture graph. However, we know that 32 | in practice when fitting data to admixture graphs, the best graph with \eqn{k} admixture events 33 | is not always an extension like that from the best graph with \eqn{k - 1} admixture events. 34 | For a more relaxed way of adding a new admixture event, try \code{\link{add_an_admixture2}}. 35 | } 36 | \examples{ 37 | \donttest{ 38 | # To illustrate what the parameter labels_matter does, consider the following graph: 39 | 40 | leaves <- c("A", "B", "C") 41 | inner_nodes <- c("R", "x", "y", "M") 42 | edges <- parent_edges(c(edge("x", "R"), 43 | edge("y", "R"), 44 | edge("A", "x"), 45 | edge("B", "M"), 46 | edge("C", "y"), 47 | admixture_edge("M", "x", "y"))) 48 | admixtures <- admixture_proportions(c(admix_props("M", "x", "y", "p"))) 49 | graph <- agraph(leaves, inner_nodes, edges, admixtures) 50 | plot(graph, show_admixture_labels = TRUE, title = "graph") 51 | 52 | # There are 15 ways this graph can be extended to a graph with two admixture events by 53 | # adding an admixture edge, as can be seeing by having the program explicitly construct 54 | # all the cases: 55 | 56 | short_list <- add_an_admixture(graph, "q") 57 | print(length(short_list)) 58 | 59 | # However, maybe we already have a specific historical event in mind corresponding to the 60 | # original admixture event in graph, or a fixed value for the admixture proportion p. 61 | # Then, for example, it makes a difference to us whether we consider the possibility of 62 | # another admixture event occurring before that event, 63 | 64 | leaves <- c("A", "B", "C") 65 | inner_nodes <- c("R", "x", "y", "z", "M", "N") 66 | edges <- parent_edges(c(edge("x", "R"), 67 | edge("z", "R"), 68 | edge("y", "z"), 69 | edge("A", "x"), 70 | edge("B", "M"), 71 | edge("C", "y"), 72 | admixture_edge("N", "x", "z"), 73 | admixture_edge("M", "N", "y"))) 74 | admixtures <- admixture_proportions(c(admix_props("N", "x", "z", "q"), 75 | admix_props("M", "N", "y", "p"))) 76 | example1 <- agraph(leaves, inner_nodes, edges, admixtures) 77 | plot(example1, show_admixture_labels = TRUE, title = "example 1") 78 | 79 | # or after that event, 80 | 81 | leaves <- c("A", "B", "C") 82 | inner_nodes <- c("R", "x", "y", "z", "M", "N") 83 | edges <- parent_edges(c(edge("x", "R"), 84 | edge("y", "R"), 85 | edge("z", "y"), 86 | edge("A", "x"), 87 | edge("B", "N"), 88 | edge("C", "z"), 89 | admixture_edge("M", "x", "y"), 90 | admixture_edge("N", "M", "z"))) 91 | admixtures <- admixture_proportions(c(admix_props("M", "x", "y", "p"), 92 | admix_props("N", "M", "z", "q"))) 93 | example2 <- agraph(leaves, inner_nodes, edges, admixtures) 94 | plot(example2, show_admixture_labels = TRUE, title = "example 2") 95 | 96 | # even though as (acyclic) directed graphs with labeled leaves example 1 97 | # and example 2 are isomorphic. 98 | # Counting cases like that dirrerent, we get 21 possible extensions: 99 | 100 | long_list <- add_an_admixture(graph, "q", labels_matter = TRUE) 101 | print(length(long_list)) 102 | } 103 | 104 | } 105 | \seealso{ 106 | \code{\link{all_graphs}} 107 | 108 | \code{\link{fit_permutations_and_graphs}} 109 | 110 | \code{\link{fit_graph_list}} 111 | 112 | \code{\link{add_a_leaf}} 113 | 114 | \code{\link{add_an_admixture2}} 115 | 116 | \code{\link{make_an_outgroup}} 117 | } 118 | 119 | -------------------------------------------------------------------------------- /man/add_an_admixture2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{add_an_admixture2} 4 | \alias{add_an_admixture2} 5 | \title{Adds a new admixture event to a graph.} 6 | \usage{ 7 | add_an_admixture2(graph, admixture_variable_name, outgroup = "") 8 | } 9 | \arguments{ 10 | \item{graph}{An admixture graph.} 11 | 12 | \item{admixture_variable_name}{A name for the new admixture proportion.} 13 | 14 | \item{outgroup}{An optional parameter for the preferred outgroup.} 15 | } 16 | \value{ 17 | A list of graphs made by adding a new admixture event to the input graph. The list contains 18 | duplicate elements, and may even contain graphs with \emph{eyes} (two inner nodes with the 19 | property that all the paths between any two leaves visits both or neither of them). 20 | } 21 | \description{ 22 | Given an admixture graph, selects a child edge and two parent edges, disconnects the child edge 23 | from its original parent node and connects it to the two parent edges with an admixture event, 24 | if possible. Thus, contrary to \code{\link{add_an_admixture}}, the resulting graph need not be an 25 | extension of the input graph in the sense that erasing one of the admixture edges we get 26 | the original admixture graph. In practice, we know that when fitting data to admixture graphs, 27 | the best graph with \eqn{k} admixture events is not always an extension like that from the best 28 | graph with \eqn{k - 1} admixture events. Most likely it doesn't need to be an extension like 29 | this (the two new admixture edges can both go where ever) either. 30 | } 31 | \seealso{ 32 | \code{\link{all_graphs}} 33 | 34 | \code{\link{fit_permutations_and_graphs}} 35 | 36 | \code{\link{fit_graph_list}} 37 | 38 | \code{\link{add_a_leaf}} 39 | 40 | \code{\link{add_an_admixture}} 41 | 42 | \code{\link{make_an_outgroup}} 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/add_graph_f4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/evaluate-f-statistics.R 3 | \name{add_graph_f4} 4 | \alias{add_graph_f4} 5 | \title{Evalutes the f_4 statistics for all rows in a data frame and extends 6 | the data frame with the graph f_4.} 7 | \usage{ 8 | add_graph_f4(data, graph, env) 9 | } 10 | \arguments{ 11 | \item{data}{The data frame to get the labels to compute the \eqn{f_4} statistics from.} 12 | 13 | \item{graph}{The admixture graph.} 14 | 15 | \item{env}{The environment to evaluate the \eqn{f_4} statistics in.} 16 | } 17 | \value{ 18 | A data frame identical to \code{data} except with an additional 19 | column, \code{graph_f4}, containing the \eqn{f_4} values as determined by 20 | the graph and the environment. 21 | } 22 | \description{ 23 | The data frame, \code{data}, must contain columns \code{W}, \code{X}, 24 | \code{Y}, and \code{Z}. The function then computes the \eqn{f_4(W, X; Y, Z)} 25 | statistics (also known as the \eqn{D} statistics) for all rows and adds these 26 | as a column, \code{graph_f4}, to the data frame. 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/add_graph_f4_sign.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{add_graph_f4_sign} 4 | \alias{add_graph_f4_sign} 5 | \title{Extend a data frame with f_4 statistics predicted by a graph.} 6 | \usage{ 7 | add_graph_f4_sign(data, graph) 8 | } 9 | \arguments{ 10 | \item{data}{The data frame to get the labels to compute the \eqn{f_4} 11 | statistics from.} 12 | 13 | \item{graph}{The admixture graph.} 14 | } 15 | \value{ 16 | A data frame identical to \code{data} except with an additional 17 | column, \code{graph_f4_sign}, containing the sign of the \eqn{f_4} 18 | statistics as determined by the graph. 19 | } 20 | \description{ 21 | Extracts the sign for the \eqn{f_4} statistics predicted by the graph for all 22 | rows in a data frame and extends the data frame with the graph \eqn{f_4}. 23 | } 24 | \details{ 25 | The data frame, \code{data}, must contain columns \code{W}, \code{X}, 26 | \code{Y}, and \code{Z}. The function then computes the sign of the 27 | \eqn{f4(W, X; Y, Z)} statistics for all rows and adds these as a column, 28 | \code{graph_f4_sign}, to the data frame. 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/admix_props.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{admix_props} 4 | \alias{admix_props} 5 | \title{Specify the proportions in an admixture event.} 6 | \usage{ 7 | admix_props(child, parent1, parent2, prop) 8 | } 9 | \arguments{ 10 | \item{child}{The child node.} 11 | 12 | \item{parent1}{The first parent.} 13 | 14 | \item{parent2}{The second parent.} 15 | 16 | \item{prop}{The admixture proportions coming from the first parent.} 17 | } 18 | \description{ 19 | Syntactic suggar for constructing edges in an admixture graph. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/admixture_edge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{admixture_edge} 4 | \alias{admixture_edge} 5 | \title{Create an admixture edge from a child to two parents.} 6 | \usage{ 7 | admixture_edge(child, parent1, parent2, prop = NA) 8 | } 9 | \arguments{ 10 | \item{child}{The name of the child node.} 11 | 12 | \item{parent1}{The name of the parent node.} 13 | 14 | \item{parent2}{The name of the parent node.} 15 | 16 | \item{prop}{Admixture proportions from \code{parent1} to \code{child}. 17 | If this parameter is not provided, you must explicitly 18 | specify the admixture proportion parameters in the 19 | \code{agraph} function call.} 20 | } 21 | \description{ 22 | Syntactic suggar for constructing edges in an admixture graph. 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/admixture_proportions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{admixture_proportions} 4 | \alias{admixture_proportions} 5 | \title{Create the list of admixture proportions for an admixture graph.} 6 | \usage{ 7 | admixture_proportions(admix_props) 8 | } 9 | \arguments{ 10 | \item{admix_props}{The admixture proportions.} 11 | } 12 | \description{ 13 | Syntactic suggar for constructing edges in an admixture graph. 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/admixturegraph-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/admixture_graph.R 3 | \docType{package} 4 | \name{admixturegraph-package} 5 | \alias{admixturegraph-package} 6 | \title{admixturegraph: Visualising and analysing admixture graphs.} 7 | \description{ 8 | The package provides functionality to analyse and test admixture graphs 9 | against the \eqn{f} statistics described in the paper 10 | Ancient Admixture in Human History, 11 | Patterson \emph{et al.}, Genetics, Vol. 192, 1065--1093, 2012. 12 | } 13 | \details{ 14 | The \eqn{f} statistics -- \eqn{f_2}, \eqn{f_3}, and \eqn{f_4} -- extract 15 | information about correlations between gene frequencies in different 16 | populations (or single diploid genome samples), which can be informative 17 | about patterns of gene flow between these populations in form of admixture 18 | events. If a graph is constructed as a hypothesis for the relationship 19 | between the populations, equations for the expected values of the \eqn{f} 20 | statistics can be extracted, as functions of edge lengths -- representing 21 | genetic drift -- and admixture proportions. 22 | 23 | This package provides functions for extracting these equations and for 24 | fitting them against computed \eqn{f} statistics. It does not currently 25 | provide functions for computing the \eqn{f} statistics -- for that we refer 26 | to the \href{https://github.com/DReichLab/AdmixTools}{ADMIXTOOLS} software 27 | package. 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/agraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{agraph} 4 | \alias{agraph} 5 | \title{Create an admixture graph object.} 6 | \usage{ 7 | agraph(leaves, inner_nodes, parent_edges, 8 | admixture_proportions = extract_admixture_proportion_parameters(parent_edges)) 9 | } 10 | \arguments{ 11 | \item{leaves}{The names of the leaves in the admixture graph. Do not use \code{(, )} 12 | or a single \code{R}.} 13 | 14 | \item{inner_nodes}{The name of the inner nodes in the admxture graph. Do not use \code{(, )} 15 | or a single \code{R} except for the root if you wish.} 16 | 17 | \item{parent_edges}{The list of edges in the graph, created by 18 | \code{\link{parent_edges}}.} 19 | 20 | \item{admixture_proportions}{The list of admixture proportions; created by 21 | \code{\link{admixture_proportions}}. Do not use \code{+, -, *, (, )}.} 22 | } 23 | \value{ 24 | An admixture graph object. 25 | } 26 | \description{ 27 | Create an admixture graph object, an acyclic directed graph. 28 | } 29 | \examples{ 30 | leaves <- c("A", "B", "C", "D") 31 | inner_nodes <- c("ab", "b", "bc", "abc", "abcd") 32 | edges <- parent_edges(c(edge("A", "ab"), 33 | edge("B", "b"), 34 | edge("C", "bc"), 35 | edge("D", "abcd"), 36 | edge("ab", "abc"), 37 | edge("bc", "abc"), 38 | edge("abc", "abcd"), 39 | admixture_edge("b", "ab", "bc"))) 40 | admixtures <- admixture_proportions(c(admix_props("b", "ab", "bc", "x"))) 41 | 42 | graph <- agraph(leaves, inner_nodes, edges, admixtures) 43 | 44 | } 45 | \seealso{ 46 | \code{\link{edge}} 47 | 48 | \code{\link{admixture_edge}} 49 | 50 | \code{\link{admix_props}} 51 | 52 | \code{\link{parent_edges}} 53 | 54 | \code{\link{admixture_proportions}} 55 | 56 | \code{\link{plot.agraph}} 57 | } 58 | 59 | -------------------------------------------------------------------------------- /man/agraph_children.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{agraph_children} 4 | \alias{agraph_children} 5 | \title{Build the child incidene matrix from an parent edge list.} 6 | \usage{ 7 | agraph_children(nodes, parent_edges) 8 | } 9 | \arguments{ 10 | \item{nodes}{Nodes in the admxture graph.} 11 | 12 | \item{parent_edges}{An \eqn{n \times 2}{n x 2} matrix where the first column is the 13 | child node and the second is the parent.} 14 | } 15 | \value{ 16 | An incidence matrix for the child structure of an admixture graph. 17 | } 18 | \description{ 19 | Build the child incidene matrix from an parent edge list. 20 | } 21 | \seealso{ 22 | \code{\link{agraph_parents}} 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/agraph_parents.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{agraph_parents} 4 | \alias{agraph_parents} 5 | \title{Build the parent incidence matrix from an edge list.} 6 | \usage{ 7 | agraph_parents(nodes, parent_edges) 8 | } 9 | \arguments{ 10 | \item{nodes}{Nodes in the admxture graph.} 11 | 12 | \item{parent_edges}{An \eqn{n \times 2}{n x 2} matrix where the first column is the 13 | child node and the second is the parent.} 14 | } 15 | \value{ 16 | An incidence matrix for the parent structure of an admixture graph. 17 | } 18 | \description{ 19 | Build the parent incidence matrix from an edge list. 20 | } 21 | \seealso{ 22 | \code{\link{agraph_children}} 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/agraph_weights.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{agraph_weights} 4 | \alias{agraph_weights} 5 | \title{Build the matrix of admixture proportions from an edge list.} 6 | \usage{ 7 | agraph_weights(nodes, admixture_weights, parents) 8 | } 9 | \arguments{ 10 | \item{nodes}{The name of the nodes in the admxture graph.} 11 | 12 | \item{admixture_weights}{An \eqn{n \times 3}{n x 3} matrix where the first column is 13 | the child node, the second isthe parent and the third 14 | is the admixture weight on that edge.} 15 | 16 | \item{parents}{The parent edge list. Used for checking graph consistency.} 17 | } 18 | \value{ 19 | A matrix containing the admixture weights. 20 | } 21 | \description{ 22 | Build the matrix of admixture proportions from an edge list. 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/all_graphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{all_graphs} 4 | \alias{all_graphs} 5 | \title{All graphs.} 6 | \usage{ 7 | all_graphs(populations, admixture_events) 8 | } 9 | \arguments{ 10 | \item{populations}{A vector of populations (leaf names).} 11 | 12 | \item{admixture_events}{The maximum number of admixture events allowed.} 13 | } 14 | \value{ 15 | A list of admixture graphs. 16 | } 17 | \description{ 18 | Gives a list of all the graphs with at most a given number of admixture events. 19 | No duplicates. 20 | } 21 | \seealso{ 22 | \code{\link{fit_graph_list}} 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/all_path_overlaps.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/overlaps.R 3 | \name{all_path_overlaps} 4 | \alias{all_path_overlaps} 5 | \title{Get the list of overlaps of all paths.} 6 | \usage{ 7 | all_path_overlaps(paths1, paths2) 8 | } 9 | \arguments{ 10 | \item{paths1}{Paths between one pair of leaves.} 11 | 12 | \item{paths2}{Paths between another pair of leaves.} 13 | } 14 | \value{ 15 | A list of the overlaps of all combinations of paths from \code{paths1} 16 | and \code{paths2}. 17 | } 18 | \description{ 19 | Gets the list of overlaps of all paths. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/all_paths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/paths.R 3 | \name{all_paths} 4 | \alias{all_paths} 5 | \title{Compute all paths from one leaf to another.} 6 | \usage{ 7 | all_paths(graph, src, dst) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{src}{The starting leaf.} 13 | 14 | \item{dst}{The destination leaf.} 15 | } 16 | \value{ 17 | A list containing all the paths from \code{src} to \code{dst}. 18 | } 19 | \description{ 20 | Computes all paths from one leaf to another. 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/bears.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{bears} 5 | \alias{bears} 6 | \title{Statistics for populations of bears} 7 | \format{A data frame with 18 rows and 6 variables: 8 | \describe{ 9 | \item{W}{The W population} 10 | \item{X}{The X population} 11 | \item{Y}{The Y population} 12 | \item{Z}{The Z population} 13 | \item{D}{The D (f_4(W,X;Y,Z)) statistics} 14 | \item{Z.value}{The blocked jacknife Z values} 15 | }} 16 | \source{ 17 | \url{http://onlinelibrary.wiley.com/doi/10.1111/mec.13038/abstract} 18 | } 19 | \usage{ 20 | bears 21 | } 22 | \description{ 23 | Computed f_4(W,X;Y,Z) statistics for different populations of bears. 24 | } 25 | \keyword{datasets} 26 | 27 | -------------------------------------------------------------------------------- /man/build_edge_optimisation_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{build_edge_optimisation_matrix} 4 | \alias{build_edge_optimisation_matrix} 5 | \title{Build a matrix coding the linear system of edges once the admix variables 6 | have been fixed.} 7 | \usage{ 8 | build_edge_optimisation_matrix(data, graph, 9 | parameters = extract_graph_parameters(graph)) 10 | } 11 | \arguments{ 12 | \item{data}{The data set.} 13 | 14 | \item{graph}{The admixture graph.} 15 | 16 | \item{parameters}{In case one wants to tweak something in the graph.} 17 | } 18 | \value{ 19 | A list containing the full matrix (\code{full}), a version with zero 20 | columns removed (\code{column_reduced}) and parameters to pass forward 21 | (\code{parameters}). 22 | } 23 | \description{ 24 | The elements are characters containing numbers, admix variable names, 25 | parenthesis and arithmetical operations. (Transform into expressions with 26 | \code{\link{parse}} and then evaluate with \code{\link{eval}}). The default 27 | column names are the edge names from \code{\link{extract_graph_parameters}}, 28 | the rows have no names. 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/burn_in.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{burn_in} 4 | \alias{burn_in} 5 | \title{Removes the first k rows from a trace.} 6 | \usage{ 7 | burn_in(trace, k) 8 | } 9 | \arguments{ 10 | \item{trace}{A trace from an MCMC run.} 11 | 12 | \item{k}{Number of rows to discard as burn-in.} 13 | } 14 | \description{ 15 | Removes the first k rows from a trace. 16 | } 17 | 18 | -------------------------------------------------------------------------------- /man/calculate_concentration.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{calculate_concentration} 4 | \alias{calculate_concentration} 5 | \title{Building a proxy concentration matrix.} 6 | \usage{ 7 | calculate_concentration(data, Z.value) 8 | } 9 | \arguments{ 10 | \item{data}{The data containing at least the expected values of \eqn{f} statistics 11 | (column \code{D}) and possibly also products of expected values and \eqn{f} 12 | statistics divided by standard deviations of (the \eqn{Z} scores, 13 | column \code{Z.value}).} 14 | 15 | \item{Z.value}{Tells whether the \eqn{Z} scores are available or should we just use the 16 | identity matrix.} 17 | } 18 | \value{ 19 | The Cholesky decomposition of the inverted covariance matrix. 20 | } 21 | \description{ 22 | If we don't have the true concentration matrix of the data rows calculated, 23 | but at least have the \eqn{Z} scores of individual rows, (unrealistically) assuming 24 | independence and calculating the concentration matrix from those is still better 25 | than nothing (\emph{i. e.} the identity matrix). 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/canonise_expression.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{canonise_expression} 4 | \alias{canonise_expression} 5 | \title{Used to recognize similar expressions and to possibly simplify them.} 6 | \usage{ 7 | canonise_expression(x) 8 | } 9 | \arguments{ 10 | \item{x}{The input is assumed to be a \code{\link{character}} consisting of one or 11 | more terms. Each term starts with either \code{+} or \code{-} and after that 12 | contains one or more factors separated by \code{*}. Each factor is either 13 | an admix variable, a number or a clause \code{(1 - x)} (mind the spaces, 14 | this is how the function \code{\link{f4}} outputs), where \code{x} is again 15 | either an admix variable or a number. 16 | Everything is pretty much ruined if variable names are numbers or contain 17 | forbidden symbols \code{+, -, *, (, )}.} 18 | } 19 | \value{ 20 | A polynomial in a canonical form with no parenthesis or spaces and the 21 | monomials in lexicographical order. If everything is cancelled out then \code{+0}. 22 | } 23 | \description{ 24 | It's best to simplify algebraic expression a little before evaluating. 25 | } 26 | 27 | -------------------------------------------------------------------------------- /man/canonise_graph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{canonise_graph} 4 | \alias{canonise_graph} 5 | \title{Canonise graph.} 6 | \usage{ 7 | canonise_graph(graph) 8 | } 9 | \arguments{ 10 | \item{graph}{An admixture graph.} 11 | } 12 | \value{ 13 | A logical vector coding the parental matrix of a canonised version of the input graph. 14 | } 15 | \description{ 16 | Given a graph builds a unique logical vector depending only on the leaf names and the graph 17 | topology (not the inner node names, root position or the input order of edges or inner nodes). 18 | Can be used to detect graph isomorphism, that is, to weed out duplicates from a graph list. 19 | Only for comparison of graphs with the same leaf set! 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/coef.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{coef.agraph_fit} 4 | \alias{coef.agraph_fit} 5 | \title{Parameters for the fitted graph.} 6 | \usage{ 7 | \method{coef}{agraph_fit}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{The fitted object.} 11 | 12 | \item{...}{Additional parameters.} 13 | } 14 | \description{ 15 | Extracts the graph parameters for the graph fitted to data. Note that the optimal 16 | parameters are generally not unique. 17 | } 18 | \seealso{ 19 | \code{link{summary.agraph_fit}} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/cost_function.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{cost_function} 4 | \alias{cost_function} 5 | \title{The cost function fed to Nelder-Mead.} 6 | \usage{ 7 | cost_function(data, concentration, matrix, graph, 8 | parameters = extract_graph_parameters(graph), iteration_multiplier = 3) 9 | } 10 | \arguments{ 11 | \item{data}{The data set.} 12 | 13 | \item{concentration}{The Cholesky decomposition of the inverted covariance 14 | matrix.} 15 | 16 | \item{matrix}{A column reduced edge optimisation matrix (typically given 17 | by the function \code{\link{build_edge_optimisation_matrix}}).} 18 | 19 | \item{graph}{The admixture graph.} 20 | 21 | \item{parameters}{In case one wants to tweak something in the graph.} 22 | 23 | \item{iteration_multiplier}{Given to \code{\link{mynonneg}}.} 24 | } 25 | \value{ 26 | Given an input vector of admix variables, returns the smallest error 27 | regarding the edge variables. 28 | } 29 | \description{ 30 | We want Nelder-Mead to run fast so the cost function operates with the column 31 | reduced edge optimisation matrix and does not give any extra information about 32 | the fit. For the details, use \code{\link{edge_optimisation_function}} instead. 33 | } 34 | \seealso{ 35 | \code{\link{mynonneg}} 36 | 37 | \code{\link{edge_optimisation_function}} 38 | 39 | \code{\link{log_likelihood}} 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/edge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{edge} 4 | \alias{edge} 5 | \title{Create an edge from a child to a parent.} 6 | \usage{ 7 | edge(child, parent) 8 | } 9 | \arguments{ 10 | \item{child}{The name of the child node.} 11 | 12 | \item{parent}{The name of the parent node.} 13 | } 14 | \description{ 15 | Syntactic suggar for constructing edges in an admixture graph. 16 | } 17 | 18 | -------------------------------------------------------------------------------- /man/edge_optimisation_function.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{edge_optimisation_function} 4 | \alias{edge_optimisation_function} 5 | \title{More detailed edge fitting than mere cost_function.} 6 | \usage{ 7 | edge_optimisation_function(data, concentration, matrix, graph, 8 | parameters = extract_graph_parameters(graph), iteration_multiplier = 3) 9 | } 10 | \arguments{ 11 | \item{data}{The data set.} 12 | 13 | \item{concentration}{The Cholesky decomposition of the inverted covariance matrix.} 14 | 15 | \item{matrix}{A full edge optimisation matrix (typically given by the 16 | function \code{\link{build_edge_optimisation_matrix}}).} 17 | 18 | \item{graph}{The admixture graph.} 19 | 20 | \item{parameters}{In case one wants to tweak something in the graph.} 21 | 22 | \item{iteration_multiplier}{Given to \code{\link{mynonneg}}.} 23 | } 24 | \value{ 25 | Given an input vector of admix variables, returns a list containing 26 | the minimal error (\code{cost}), the graph-\eqn{f4} statistics 27 | (\code{approximation}), an example solution (\code{edge_fit}), linear 28 | relations describing all the solutions (\code{homogeneous}) and one 29 | way to choose the free (\code{free_edges}) and bounded 30 | (\code{bounded_edges}) edge variables. 31 | } 32 | \description{ 33 | Returning the cost, an example edge solution of an optimal fit, and linear 34 | relations describing the set of all edge solutions. Operating with the full 35 | edge optimisation matrix, not the column reduced one. 36 | } 37 | \seealso{ 38 | \code{\link{mynonneg}} 39 | 40 | \code{\link{cost_function}} 41 | 42 | \code{\link{log_likelihood}} 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/eight_leaves_trees.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \docType{data} 4 | \name{eight_leaves_trees} 5 | \alias{eight_leaves_trees} 6 | \title{Eight leaves trees.} 7 | \format{A list of functions on eight leaves. 8 | The outputs of these functions are \code{\link{agraph}} objects.} 9 | \usage{ 10 | eight_leaves_trees 11 | } 12 | \description{ 13 | Kind of obsolete since the introduction of \code{\link{all_graphs}}. 14 | A comprehensive listing of all the four unrooted trees with eight leaves. 15 | The position of the root can be moved later with the function 16 | \code{\link{make_an_outgroup}}. 17 | } 18 | \examples{ 19 | \donttest{ 20 | # While the usage of this function is pretty self-explanatory, let's plot all the graphs 21 | # just for browsing. 22 | for (i in seq(1, length(eight_leaves_trees))) { 23 | graph <- eight_leaves_trees[[i]](c("A", "B", "C", "D", "E", "F", "G", "H")) 24 | # This is how you include quotation marks in strings by the way: 25 | title <- paste("eight_leaves_trees[[", i, 26 | "]](c(\\"A\\", \\"B\\", \\"C\\", \\"D\\", \\"E\\", \\"F\\", \\"G\\", \\"H\\"))", sep = "") 27 | plot(graph, color = "brown", title = title) 28 | } 29 | } 30 | 31 | } 32 | \seealso{ 33 | \code{\link{all_graphs}} 34 | 35 | \code{\link{make_permutations}} 36 | 37 | \code{\link{fit_permutations_and_graphs}} 38 | 39 | \code{\link{fit_graph_list}} 40 | 41 | \code{\link{add_a_leaf}} 42 | 43 | \code{\link{add_an_admixture}} 44 | 45 | \code{\link{add_an_admixture2}} 46 | 47 | \code{\link{make_an_outgroup}} 48 | 49 | Other graphs: \code{\link{five_leaves_graphs}}, 50 | \code{\link{four_leaves_graphs}}, 51 | \code{\link{seven_leaves_graphs}}, 52 | \code{\link{six_leaves_graphs}} 53 | } 54 | \keyword{datasets} 55 | 56 | -------------------------------------------------------------------------------- /man/evaluate_f4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/evaluate-f-statistics.R 3 | \name{evaluate_f4} 4 | \alias{evaluate_f4} 5 | \title{Evaluates an f_4 statistics in a given environment.} 6 | \usage{ 7 | evaluate_f4(graph, env, W, X, Y, Z) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{env}{The environment containing the graph parameters.} 13 | 14 | \item{W}{First population/sample.} 15 | 16 | \item{X}{Second population/sample.} 17 | 18 | \item{Y}{Third population/sample.} 19 | 20 | \item{Z}{Fourth population/sample.} 21 | } 22 | \value{ 23 | The \eqn{f_4} value specified by the graph and the environment. 24 | } 25 | \description{ 26 | Evaluates an \eqn{f_4} statistics in a given environment. 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/examine_edge_optimisation_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{examine_edge_optimisation_matrix} 4 | \alias{examine_edge_optimisation_matrix} 5 | \title{Examine the edge optimisation matrix to detect unfitted admix variables.} 6 | \usage{ 7 | examine_edge_optimisation_matrix(matrix, tol = 1e-08) 8 | } 9 | \arguments{ 10 | \item{matrix}{Not really a matrix but two (should be an output of 11 | \code{\link{build_edge_optimisation_matrix}}).} 12 | 13 | \item{tol}{Calulating the rank with \code{\link{qr.solve}} sometimes crashes. 14 | Default \eqn{10^{-8}}{10^(-8)}.} 15 | } 16 | \value{ 17 | An indicator of warning (\code{complaint}), coding all the possibilities in 18 | a way that is interpreted elsewhere (in \code{\link{summary.agraph_fit}}). 19 | } 20 | \description{ 21 | If the essential number of equations is not higher than the essential number of 22 | edge variables, the quality of edge optimisation will not depend on the admix 23 | variables (expect possibly in isolated special cases where the quality can be worse), 24 | and a complaint will be given. 25 | Note: The admix variable not being fitted does not mean that there is no evidence of 26 | an admix event! Isolated values of the admix variables, possibly \eqn{0} or \eqn{1}, 27 | might give significantly worse fit than a typical value (but not the other way around). 28 | } 29 | \seealso{ 30 | \code{\link{qr.solve}} 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/export_to_qpGraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/export.R 3 | \name{export_to_qpGraph} 4 | \alias{export_to_qpGraph} 5 | \title{Export to Patterson's qpGraph format.} 6 | \usage{ 7 | export_to_qpGraph(f, graph) 8 | } 9 | \arguments{ 10 | \item{f}{File object, e.g. stdout()} 11 | 12 | \item{graph}{A graph to export.} 13 | } 14 | \description{ 15 | This function writes a graph to a file-object, f, in the format used by the 16 | qpGraph tool. This format takes admixture proportions as part of the specification, 17 | but since we do not hold these proportions in our graphs, but only in fitted data, 18 | the export functions puts all admixture proportions as 50%/50%. Edit the output 19 | file by hand if you want to change this. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/extract_admixture_proportion_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{extract_admixture_proportion_parameters} 4 | \alias{extract_admixture_proportion_parameters} 5 | \title{Extract the admixture proportion parameter from edge specifications.} 6 | \usage{ 7 | extract_admixture_proportion_parameters(parent_edges) 8 | } 9 | \arguments{ 10 | \item{parent_edges}{Matrix created with the \code{agraph_parents} function.} 11 | } 12 | \value{ 13 | The parents edges reduced to the rows with admixture proportions. 14 | } 15 | \description{ 16 | This function is simply selecting the edges with admixture proportion specifications 17 | so these can be handled when building a graph using \code{agraph}. It is not a function 18 | you would need to call explicitly, rather it is there to allow people \emph{not} to use 19 | it to provide admixture proportions explicitly (which we normally wouldn't recommend). 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/extract_graph_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/evaluate-f-statistics.R 3 | \name{extract_graph_parameters} 4 | \alias{extract_graph_parameters} 5 | \title{Extract all the parameters a graph contains.} 6 | \usage{ 7 | extract_graph_parameters(graph) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | } 12 | \value{ 13 | A list containing two values: \code{edges}, a vector of edges and 14 | \code{admix_prop}, a vector containing admixture proportions. 15 | } 16 | \description{ 17 | The graph is parameterized by edge lengths and admixture proportions. This 18 | function extracts these parameters. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/extract_trees.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{extract_trees} 4 | \alias{extract_trees} 5 | \title{Extract trees} 6 | \usage{ 7 | extract_trees(graph) 8 | } 9 | \arguments{ 10 | \item{graph}{An agraph object} 11 | } 12 | \value{ 13 | A list of trees 14 | } 15 | \description{ 16 | Extracts all the trees embedded in an agraph object 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/f2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/f-statistics.R 3 | \name{f2} 4 | \alias{f2} 5 | \title{Calculate the f_2(A, B) statistics.} 6 | \usage{ 7 | f2(graph, A, B) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{A}{A leaf node.} 13 | 14 | \item{B}{A leaf node.} 15 | } 16 | \value{ 17 | A symbolic representation of the equation for the \eqn{f_2} 18 | statistics given by the admixture graph. 19 | } 20 | \description{ 21 | Calculate the \eqn{f_2(A, B)} statistics. 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/f3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/f-statistics.R 3 | \name{f3} 4 | \alias{f3} 5 | \title{Calculate the f_3(A; B, C) statistics.} 6 | \usage{ 7 | f3(graph, A, B, C) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{A}{A leaf node.} 13 | 14 | \item{B}{A leaf node.} 15 | 16 | \item{C}{A leaf node.} 17 | } 18 | \value{ 19 | A symbolic representation of the equation for the \eqn{f_3} 20 | statistics given by the admixture graph. 21 | } 22 | \description{ 23 | Calculate the \eqn{f_3(A; B, C)} statistics. 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/f4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/f-statistics.R 3 | \name{f4} 4 | \alias{f4} 5 | \title{Calculate the f_4(W, X; Y, Z) statistics.} 6 | \usage{ 7 | f4(graph, W, X, Y, Z) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{W}{A leaf node.} 13 | 14 | \item{X}{A leaf node.} 15 | 16 | \item{Y}{A leaf node.} 17 | 18 | \item{Z}{A leaf node.} 19 | } 20 | \value{ 21 | The overlaps between paths from \code{W} to \code{X} and paths from 22 | \code{Y} to \code{Z}. 23 | } 24 | \description{ 25 | Calculate the \eqn{f_4(W, X; Y, Z)} statistics. 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/f4stats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/f4_plotting.R 3 | \name{f4stats} 4 | \alias{f4stats} 5 | \title{Make a data frame an f_4 statistics object.} 6 | \usage{ 7 | f4stats(x) 8 | } 9 | \arguments{ 10 | \item{x}{Data frame with observed \eqn{D} (\eqn{f_4}) statistics.} 11 | } 12 | \value{ 13 | Something about classes. 14 | } 15 | \description{ 16 | This is mostly just a convinience function to set the class of a data frame such that 17 | we plot data as error bars in a meaningful way for statistics for admixture graphs. 18 | } 19 | 20 | -------------------------------------------------------------------------------- /man/fast_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{fast_fit} 4 | \alias{fast_fit} 5 | \title{A fast version of graph fitting.} 6 | \usage{ 7 | fast_fit(data, graph, point = list(rep(1e-05, 8 | length(extract_graph_parameters(graph)$admix_prop)), rep(1 - 1e-05, 9 | length(extract_graph_parameters(graph)$admix_prop))), Z.value = TRUE, 10 | concentration = calculate_concentration(data, Z.value), 11 | optimisation_options = NULL, parameters = extract_graph_parameters(graph), 12 | iteration_multiplier = 3) 13 | } 14 | \arguments{ 15 | \item{data}{The data table, must contain columns \code{W}, \code{X}, 16 | \code{Y}, \code{Z} for sample names and \code{D} for the 17 | observed \eqn{f_4(W, X; Y, Z)}. May contain an optional 18 | column \code{Z.value} for the \eqn{Z} scores (the \eqn{f} 19 | statistics divided by the standard deviations).} 20 | 21 | \item{graph}{The admixture graph (an \code{\link{agraph}} object).} 22 | 23 | \item{point}{If the user wants to restrict the admixture proportions somehow, 24 | like to fix some of them. A list of two vectors: the lower and the 25 | upper bounds. As a default the bounds are just it little bit more 26 | than zero and less than one; this is because sometimes the 27 | infimum of the values of cost function is at a point of 28 | non-continuity, and zero and one have reasons to be problematic 29 | values in this respect.} 30 | 31 | \item{Z.value}{Whether we calculate the default concentration from \eqn{Z} scores 32 | (the default option \code{TRUE}) or just use the identity matrix.} 33 | 34 | \item{concentration}{The Cholesky decomposition of the inverted covariance matrix. 35 | Default matrix determined by the parameter \code{Z.value}.} 36 | 37 | \item{optimisation_options}{Options to the Nelder-Mead algorithm.} 38 | 39 | \item{parameters}{In case one wants to tweak something in the graph.} 40 | 41 | \item{iteration_multiplier}{Given to \code{\link{mynonneg}}.} 42 | } 43 | \value{ 44 | A list containing only the essentials about the fit: 45 | \code{graph} is the graph input, 46 | \code{best_error} is the minimal value of \code{\link{cost_function}}, 47 | obtained when the admixture proportions are \code{best_fit}. 48 | } 49 | \description{ 50 | Given a table of observed \eqn{f} statistics and a graph, uses Nelder-Mead algorithm to 51 | find the graph parameters (edge lengths and admixture proportions) that minimize the value 52 | of \code{\link{cost_function}}, \emph{i. e.} maximizes the likelihood of a graph with 53 | parameters given the observed data. 54 | Like \code{\link{fit_graph}} but dropping most of the analysis on the result. 55 | Intended for use in big iteration loops. 56 | } 57 | \examples{ 58 | \donttest{ 59 | # For example, let's fit the following two admixture graph to an example data on bears: 60 | 61 | data(bears) 62 | print(bears) 63 | 64 | leaves <- c("BLK", "PB", "Bar", "Chi1", "Chi2", "Adm1", "Adm2", "Denali", "Kenai", "Sweden") 65 | inner_nodes <- c("R", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "M", "N") 66 | edges <- parent_edges(c(edge("BLK", "R"), 67 | edge("PB", "v"), 68 | edge("Bar", "x"), 69 | edge("Chi1", "y"), 70 | edge("Chi2", "y"), 71 | edge("Adm1", "z"), 72 | edge("Adm2", "z"), 73 | edge("Denali", "t"), 74 | edge("Kenai", "s"), 75 | edge("Sweden", "r"), 76 | edge("q", "R"), 77 | edge("r", "q"), 78 | edge("s", "r"), 79 | edge("t", "s"), 80 | edge("u", "q"), 81 | edge("v", "u"), 82 | edge("w", "M"), 83 | edge("x", "N"), 84 | edge("y", "x"), 85 | edge("z", "w"), 86 | admixture_edge("M", "u", "t"), 87 | admixture_edge("N", "v", "w"))) 88 | admixtures <- admixture_proportions(c(admix_props("M", "u", "t", "a"), 89 | admix_props("N", "v", "w", "b"))) 90 | bears_graph <- agraph(leaves, inner_nodes, edges, admixtures) 91 | plot(bears_graph, show_admixture_labels = TRUE) 92 | 93 | fit <- fast_fit(bears, bears_graph) 94 | print(fit$best_error) 95 | 96 | # The result is just the minimal value of the cost function and the values of admixture proportions 97 | # where it's obtained, no deeper analysis of the fit. 98 | } 99 | 100 | } 101 | \seealso{ 102 | \code{\link{cost_function}} 103 | 104 | \code{\link{agraph}} 105 | 106 | \code{\link{calculate_concentration}} 107 | 108 | \code{\link[neldermead]{optimset}} 109 | 110 | \code{\link{fit_graph}} 111 | } 112 | 113 | -------------------------------------------------------------------------------- /man/fast_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{fast_plot} 4 | \alias{fast_plot} 5 | \title{Fast version of graph plotting.} 6 | \usage{ 7 | fast_plot(x, ordered_leaves = NULL, show_admixture_labels = FALSE, 8 | show_inner_node_labels = FALSE, ...) 9 | } 10 | \arguments{ 11 | \item{x}{The admixture graph.} 12 | 13 | \item{ordered_leaves}{The leaf-nodes in the left to right order they 14 | should be drawn.} 15 | 16 | \item{show_admixture_labels}{A flag determining if the plot should include 17 | the names of admixture proportions.} 18 | 19 | \item{show_inner_node_labels}{A flag determining if the plot should include 20 | the names of inner nodes.} 21 | 22 | \item{...}{Additional plotting options.} 23 | } 24 | \value{ 25 | A plot. 26 | } 27 | \description{ 28 | This is a fast, deterministic and stand-alone function for visualizing the 29 | admixture graph. Has the bad habit if sometimes drawing several nodes at the 30 | exact same coordinates; for clearer reasults try \code{\link{plot.agraph}} 31 | (which, on the other hand, relies on numerical optimising of a compicated cost 32 | function and might be unpredictable). 33 | } 34 | \examples{ 35 | # taken from the collection of all the admixture graphs with four leaves and at 36 | # most two admixture events: 37 | 38 | fast_plot(four_leaves_graphs[[24]](c("A", "B", "C", "D"))) 39 | 40 | # To be fair, here is a graph that looks all right: 41 | 42 | fast_plot(four_leaves_graphs[[25]](c("A", "B", "C", "D"))) 43 | 44 | } 45 | \seealso{ 46 | \code{\link{plot.agraph}} 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/filter_on_leaves.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/filter.R 3 | \name{filter_on_leaves} 4 | \alias{filter_on_leaves} 5 | \title{Filter data so all W, X, Y and Z are leaves in the graph.} 6 | \usage{ 7 | filter_on_leaves(data, graph) 8 | } 9 | \arguments{ 10 | \item{data}{Data frame (or similar) object containing columns \code{W}, \code{X}, 11 | \code{Y}, and \code{Z}.} 12 | 13 | \item{graph}{Admixture graph.} 14 | } 15 | \value{ 16 | Data frame with rows where \code{W}, \code{X}, \code{Y}, or \code{Z} are 17 | not leaves are removed. 18 | } 19 | \description{ 20 | Filter data so all \code{W}, \code{X}, \code{Y} and \code{Z} are leaves in the graph. 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/fit_graph_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{fit_graph_list} 4 | \alias{fit_graph_list} 5 | \title{Fit lots of graphs to data.} 6 | \usage{ 7 | fit_graph_list(data, graphs, cores) 8 | } 9 | \arguments{ 10 | \item{data}{The data table.} 11 | 12 | \item{graphs}{List of graphs.} 13 | 14 | \item{cores}{Number of cores used.} 15 | } 16 | \value{ 17 | A list of \code{\link{fast_fit}} results. 18 | } 19 | \description{ 20 | Fits a list of graphs to given data using parallel computation. This function 21 | needs \code{doParallel}, \code{foreach} and \code{parallel} installed. 22 | } 23 | \seealso{ 24 | \code{\link{all_graphs}} 25 | 26 | \code{\link{fit_permutations_and_graphs}} 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/fit_permutations_and_graphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{fit_permutations_and_graphs} 4 | \alias{fit_permutations_and_graphs} 5 | \title{Fit lots of graphs to data.} 6 | \usage{ 7 | fit_permutations_and_graphs(data, permutations, graphs, cores) 8 | } 9 | \arguments{ 10 | \item{data}{The data table.} 11 | 12 | \item{permutations}{List of population permutations.} 13 | 14 | \item{graphs}{List of functions for producing graphs.} 15 | 16 | \item{cores}{Number of cores used.} 17 | } 18 | \value{ 19 | A list of \code{\link{fast_fit}} results. 20 | } 21 | \description{ 22 | Combines a list of (population) permutations and a list of graph topologies 23 | to a big list of graphs, then fits those graphs to given data using parallel 24 | computation. This function needs \code{doParallel}, \code{foreach} and 25 | \code{parallel} installed. 26 | } 27 | \examples{ 28 | \donttest{ 29 | # Let's experiment by fitting all the graphs with five leaves and at most one admixture 30 | # event to a five population subset of the bear data. Note that with three data rows only 31 | # we do wisely by not concluding too much about the actual bear family tree; this is to 32 | # illustrate the function usage only! 33 | 34 | data(bears) 35 | data <- bears[16:18, ] 36 | print(data) 37 | permutations <- make_permutations(c("PB", "BLK", "Sweden", "Denali", "Kenai")) 38 | graphs <- five_leaves_graphs 39 | 40 | # We go with one core only as I don't know what kind of machine you are using. 41 | 42 | fitted_graphs <- fit_permutations_and_graphs(data, permutations, graphs, 1) 43 | 44 | # Now sort the fitted objects by best_error and see how the best graph looks like. 45 | 46 | errors <- sapply(fitted_graphs, function(x) x$best_error) 47 | best_graphs <- fitted_graphs[order(errors)] 48 | plot(best_graphs[[1]]$graph, color = "goldenrod", title = best_graphs[[1]]$best_error) 49 | 50 | # The same value for best_error actually occurs in the list 152 times because of our 51 | # unsufficient data. 52 | } 53 | 54 | } 55 | \seealso{ 56 | \code{\link{make_permutations}} 57 | 58 | \code{\link{four_leaves_graphs}} 59 | 60 | \code{\link{five_leaves_graphs}} 61 | 62 | \code{\link{six_leaves_graphs}} 63 | 64 | \code{\link{seven_leaves_graphs}} 65 | 66 | \code{\link{eight_leaves_trees}} 67 | 68 | \code{\link{fit_graph_list}} 69 | } 70 | 71 | -------------------------------------------------------------------------------- /man/fitted.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{fitted.agraph_fit} 4 | \alias{fitted.agraph_fit} 5 | \title{Predicted f statistics for the fitted graph.} 6 | \usage{ 7 | \method{fitted}{agraph_fit}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{The fitted object.} 11 | 12 | \item{...}{Additional parameters.} 13 | } 14 | \description{ 15 | Gets the predicted \eqn{f} statistics \eqn{F} for the fitted graph. 16 | } 17 | \seealso{ 18 | \code{link{summary.agraph_fit}} 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/five_leaves_graphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \docType{data} 4 | \name{five_leaves_graphs} 5 | \alias{five_leaves_graphs} 6 | \title{Five leaves graphs.} 7 | \format{A list of functions on five leaves and a parameter \code{permutations} which 8 | is \code{FALSE} by default. 9 | The outputs of these functions are either single \code{\link{agraph}} objects 10 | with the input vector as leaves, or if \code{permutations} is \code{TRUE}, 11 | lists of all the possible \code{\link{agraph}} objects with that leaf set up 12 | to symmetry.} 13 | \usage{ 14 | five_leaves_graphs 15 | } 16 | \description{ 17 | Kind of obsolete since the introduction of \code{\link{all_graphs}}. 18 | A comprehensive listing of all the \eqn{132} admixture graphs with five leaves and 19 | at most two admixture events. Our convention is that the position of the root does 20 | not matter (as long as it's not after an admixture event) and that graphs that have 21 | \emph{eyes}, two inner nodes with the property that all the paths between any two 22 | leaves visits both or neither of them, are excluded. The reason is that the \eqn{f} 23 | statistics can't detect the exact position of the root or distinguish between an eye 24 | and a simple branch. The position of the root can be moved later with the function 25 | \code{\link{make_an_outgroup}}. 26 | } 27 | \examples{ 28 | \donttest{ 29 | # While the usage of this function is pretty self-explanatory, let's plot all the graphs 30 | # just for browsing. 31 | for (i in seq(1, length(five_leaves_graphs))) { 32 | graph <- five_leaves_graphs[[i]](c("A", "B", "C", "D", "E")) 33 | # This is how you include quotation marks in strings by the way: 34 | title <- paste("five_leaves_graphs[[", i, "]](c(\\"A\\", \\"B\\", \\"C\\", \\"D\\", \\"E\\"))", 35 | sep = "") 36 | plot(graph, color = "purple", title = title) 37 | } 38 | } 39 | 40 | } 41 | \seealso{ 42 | \code{\link{all_graphs}} 43 | 44 | \code{\link{make_permutations}} 45 | 46 | \code{\link{fit_permutations_and_graphs}} 47 | 48 | \code{\link{fit_graph_list}} 49 | 50 | \code{\link{add_a_leaf}} 51 | 52 | \code{\link{add_an_admixture}} 53 | 54 | \code{\link{add_an_admixture2}} 55 | 56 | \code{\link{make_an_outgroup}} 57 | 58 | Other graphs: \code{\link{eight_leaves_trees}}, 59 | \code{\link{four_leaves_graphs}}, 60 | \code{\link{seven_leaves_graphs}}, 61 | \code{\link{six_leaves_graphs}} 62 | } 63 | \keyword{datasets} 64 | 65 | -------------------------------------------------------------------------------- /man/format_path.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/paths.R 3 | \name{format_path} 4 | \alias{format_path} 5 | \title{Create a path data frame from a list of nodes.} 6 | \usage{ 7 | format_path(graph, nodes) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph the path is in.} 11 | 12 | \item{nodes}{A list of nodes on a path.} 13 | } 14 | \value{ 15 | A data frame capturing the path and the probabilities/weights on the edges. 16 | } 17 | \description{ 18 | Creates a path data frame from a list of nodes. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/four_leaves_graphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \docType{data} 4 | \name{four_leaves_graphs} 5 | \alias{four_leaves_graphs} 6 | \title{Four leaves graphs.} 7 | \format{A list of functions on four leaves and a parameter \code{permutations} which 8 | is \code{FALSE} by default. 9 | The outputs of these functions are either single \code{\link{agraph}} objects 10 | with the input vector as leaves, or if \code{permutations} is \code{TRUE}, 11 | lists of all the possible \code{\link{agraph}} objects with that leaf set up 12 | to symmetry.} 13 | \usage{ 14 | four_leaves_graphs 15 | } 16 | \description{ 17 | Kind of obsolete since the introduction of \code{\link{all_graphs}}. 18 | A comprehensive listing of all the \eqn{37} admixture graphs with four leaves and 19 | at most two admixture events. Our convention is that the position of the root does 20 | not matter (as long as it's not after an admixture event) and that graphs that have 21 | \emph{eyes}, two inner nodes with the property that all the paths between any two 22 | leaves visits both or neither of them, are excluded. The reason is that the \eqn{f} 23 | statistics can't detect the exact position of the root or distinguish between an 24 | eye and a simple branch. The position of the root can be moved later with the function 25 | \code{\link{make_an_outgroup}}. 26 | } 27 | \examples{ 28 | \donttest{ 29 | # While the usage of this function is pretty self-explanatory, let's plot all the graphs 30 | # just for browsing. 31 | for (i in seq(1, length(four_leaves_graphs))) { 32 | graph <- four_leaves_graphs[[i]](c("A", "B", "C", "D")) 33 | # This is how you include quotation marks in strings by the way: 34 | title <- paste("four_leaves_graphs[[", i, "]](c(\\"A\\", \\"B\\", \\"C\\", \\"D\\"))", sep = "") 35 | plot(graph, color = "tomato3", title = title) 36 | } 37 | } 38 | 39 | } 40 | \seealso{ 41 | \code{\link{all_graphs}} 42 | 43 | \code{\link{make_permutations}} 44 | 45 | \code{\link{fit_permutations_and_graphs}} 46 | 47 | \code{\link{fit_graph_list}} 48 | 49 | \code{\link{add_a_leaf}} 50 | 51 | \code{\link{add_an_admixture}} 52 | 53 | \code{\link{add_an_admixture2}} 54 | 55 | \code{\link{make_an_outgroup}} 56 | 57 | Other graphs: \code{\link{eight_leaves_trees}}, 58 | \code{\link{five_leaves_graphs}}, 59 | \code{\link{seven_leaves_graphs}}, 60 | \code{\link{six_leaves_graphs}} 61 | } 62 | \keyword{datasets} 63 | 64 | -------------------------------------------------------------------------------- /man/get_graph_f4_sign.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{get_graph_f4_sign} 4 | \alias{get_graph_f4_sign} 5 | \title{Extracts the sign for the f_4 statistics predicted by the graph.} 6 | \usage{ 7 | get_graph_f4_sign(graph, W, X, Y, Z) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{W}{First population/sample.} 13 | 14 | \item{X}{Second population/sample.} 15 | 16 | \item{Y}{Third population/sample.} 17 | 18 | \item{Z}{Fourth population/sample.} 19 | } 20 | \value{ 21 | The sign of the \eqn{f_4} specified by the graph (or \code{NA} when it 22 | cannot be determined without knowing the graph parameters). 23 | } 24 | \description{ 25 | Extracts the sign for the \eqn{f_4} statistics predicted by the graph. 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/graph_environment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/evaluate-f-statistics.R 3 | \name{graph_environment} 4 | \alias{graph_environment} 5 | \title{Build an environment in which f statistics can be evaluated.} 6 | \usage{ 7 | graph_environment(parameters, edge_lengths = NULL, admix_prop = NULL) 8 | } 9 | \arguments{ 10 | \item{parameters}{The parameters of a graph as returned by 11 | \code{\link{extract_graph_parameters}}.} 12 | 13 | \item{edge_lengths}{If specified, a vector of edge lengths. Otherwise 14 | defaults are used.} 15 | 16 | \item{admix_prop}{If specified, a vector of admixture proportions. 17 | Otherwise defaults are used.} 18 | } 19 | \value{ 20 | A list containing two values: \code{edges}, a vector of edges and 21 | \code{admix_prop}, a vector containing admixture proportions. 22 | } 23 | \description{ 24 | Constructs an environment in which the \eqn{f} statistics for a graph can be 25 | evaluted, based on the parameters in a graph and values for edge lengths and 26 | admixture proportions (with defaults if not specified). 27 | } 28 | 29 | -------------------------------------------------------------------------------- /man/graph_to_vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{graph_to_vector} 4 | \alias{graph_to_vector} 5 | \title{Graph to vector.} 6 | \usage{ 7 | graph_to_vector(graph) 8 | } 9 | \arguments{ 10 | \item{graph}{A graph.} 11 | } 12 | \value{ 13 | The logical vector representing the graph. 14 | } 15 | \description{ 16 | Encodes an \code{\link{agraph}} object into a logical vector for saving memory. The admixture 17 | proportion names will be lost. 18 | } 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_2_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_2_0} 5 | \alias{graphs_2_0} 6 | \title{Admixture graphs of 2 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 1 row and 9 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_2_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_3_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_3_0} 5 | \alias{graphs_3_0} 6 | \title{Admixture graphs of 3 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 1 row and 25 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_3_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_3_1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_3_1} 5 | \alias{graphs_3_1} 6 | \title{Admixture graphs of 3 leaves and 1 admixture event compressed into vectors} 7 | \format{A data frame with 3 rows and 49 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_3_1 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_4_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_4_0} 5 | \alias{graphs_4_0} 6 | \title{Admixture graphs of 4 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 3 rows and 49 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_4_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_4_1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_4_1} 5 | \alias{graphs_4_1} 6 | \title{Admixture graphs of 4 leaves and 1 admixture event compressed into vectors} 7 | \format{A data frame with 30 rows and 81 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_4_1 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_4_2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_4_2} 5 | \alias{graphs_4_2} 6 | \title{Admixture graphs of 4 leaves and 2 admixture events compressed into vectors} 7 | \format{A data frame with 486 rows and 121 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_4_2 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_5_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_5_0} 5 | \alias{graphs_5_0} 6 | \title{Admixture graphs of 5 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 15 rows and 81 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_5_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_5_1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_5_1} 5 | \alias{graphs_5_1} 6 | \title{Admixture graphs of 5 leaves and 1 admixture event compressed into vectors} 7 | \format{A data frame with 315 rows and 121 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_5_1 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_5_2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_5_2} 5 | \alias{graphs_5_2} 6 | \title{Admixture graphs of 5 leaves and 2 admixture events compressed into vectors} 7 | \format{A data frame with 7710 rows and 169 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_5_2 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_6_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_6_0} 5 | \alias{graphs_6_0} 6 | \title{Admixture graphs of 6 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 105 rows and 121 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_6_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_6_1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_6_1} 5 | \alias{graphs_6_1} 6 | \title{Admixture graphs of 6 leaves and 1 admixture event compressed into vectors} 7 | \format{A data frame with 3780 rows and 169 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_6_1 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_6_2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_6_2} 5 | \alias{graphs_6_2} 6 | \title{Admixture graphs of 6 leaves and 2 admixture events compressed into vectors} 7 | \format{A data frame with 131400 rows and 225 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_6_2 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_7_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_7_0} 5 | \alias{graphs_7_0} 6 | \title{Admixture graphs of 7 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 945 rows and 169 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_7_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_7_1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_7_1} 5 | \alias{graphs_7_1} 6 | \title{Admixture graphs of 7 leaves and 1 admixture event compressed into vectors} 7 | \format{A data frame with 51975 rows and 225 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_7_1 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/graphs_8_0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{graphs_8_0} 5 | \alias{graphs_8_0} 6 | \title{Admixture graphs of 8 leaves and 0 admixture events compressed into vectors} 7 | \format{A data frame with 10395 rows and 225 variables.} 8 | \source{ 9 | Calculated using \code{\link{all_graphs}} and \code{\link{graph_to_vector}}. 10 | } 11 | \usage{ 12 | graphs_8_0 13 | } 14 | \description{ 15 | Use \code{\link{vector_to_graph}} on the \code{n}:th row to access the \code{n}:th graph 16 | as an \code{\link{agraph}} object. 17 | } 18 | \keyword{datasets} 19 | 20 | -------------------------------------------------------------------------------- /man/is_descendant_of.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{is_descendant_of} 4 | \alias{is_descendant_of} 5 | \title{Is descendant of.} 6 | \usage{ 7 | is_descendant_of(graph, offspring, ancestor) 8 | } 9 | \arguments{ 10 | \item{graph}{A graph.} 11 | 12 | \item{offspring}{Potential offspring.} 13 | 14 | \item{ancestor}{Potential ancestor.} 15 | } 16 | \value{ 17 | A truth value. 18 | } 19 | \description{ 20 | Tells whether a given node is descendant of another given node in a graph. 21 | } 22 | 23 | -------------------------------------------------------------------------------- /man/is_negative.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{is_negative} 4 | \alias{is_negative} 5 | \title{All overlaps are either empty or have a negative weight.} 6 | \usage{ 7 | is_negative(overlaps) 8 | } 9 | \arguments{ 10 | \item{overlaps}{Data frame representing path overlaps, typically generated 11 | by \code{\link{all_path_overlaps}}.} 12 | } 13 | \description{ 14 | All overlaps are either empty or have a negative weight. 15 | } 16 | 17 | -------------------------------------------------------------------------------- /man/is_positive.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{is_positive} 4 | \alias{is_positive} 5 | \title{All overlaps are either empty or have a positive weight.} 6 | \usage{ 7 | is_positive(overlaps) 8 | } 9 | \arguments{ 10 | \item{overlaps}{Data frame representing path overlaps, typically generated 11 | by \code{\link{all_path_overlaps}}.} 12 | } 13 | \description{ 14 | All overlaps are either empty or have a positive weight. 15 | } 16 | 17 | -------------------------------------------------------------------------------- /man/is_unknown.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{is_unknown} 4 | \alias{is_unknown} 5 | \title{Overlapping edges have both positive and negative contributions.} 6 | \usage{ 7 | is_unknown(overlaps) 8 | } 9 | \arguments{ 10 | \item{overlaps}{Data frame representing path overlaps, typically generated 11 | by \code{\link{all_path_overlaps}}.} 12 | } 13 | \description{ 14 | Overlapping edges have both positive and negative contributions. 15 | } 16 | 17 | -------------------------------------------------------------------------------- /man/is_zero.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{is_zero} 4 | \alias{is_zero} 5 | \title{All overlaps are empty.} 6 | \usage{ 7 | is_zero(overlaps) 8 | } 9 | \arguments{ 10 | \item{overlaps}{Data frame representing path overlaps, typically generated 11 | by \code{\link{all_path_overlaps}}.} 12 | } 13 | \description{ 14 | All overlaps are empty. 15 | } 16 | 17 | -------------------------------------------------------------------------------- /man/log_likelihood.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{log_likelihood} 4 | \alias{log_likelihood} 5 | \title{Calculate (essentially) the log likelihood of a graph with parameters, given the observation.} 6 | \usage{ 7 | log_likelihood(f, concentration, matrix, graph, 8 | parameters = extract_graph_parameters(graph)) 9 | } 10 | \arguments{ 11 | \item{f}{The observed \eqn{f} statistics (the column \code{D} from \code{data}).} 12 | 13 | \item{concentration}{The Cholesky decomposition of the inverted covariance matrix. So if \eqn{S} 14 | is the covariance matrix, this is \eqn{C = chol(S^{-1})}{C = chol(S^(-1))} satisfying 15 | \eqn{S^{-1} = C^t C}{S^(-1) = C^t*C}.} 16 | 17 | \item{matrix}{A column reduced edge optimisation matrix (typically given by the function 18 | \code{\link{build_edge_optimisation_matrix}}).} 19 | 20 | \item{graph}{The admixture graph. Here to give default value for:} 21 | 22 | \item{parameters}{Just because we need to know variable names.} 23 | } 24 | \value{ 25 | The output is a function. Given admixture proportions \code{x} and edge lengths \code{e}, the graph 26 | topology \eqn{T} implies an estimate \eqn{F} for the statistics \eqn{f}. This output function 27 | calculates 28 | \deqn{l = (F-f)^t S^{-1}(F-f)}{l = (F-f)^t*S^(-1)*(F-f)} 29 | from \code{x} and \code{e}. Up to a constant error and multiplier that is a log likelihood function, as 30 | \deqn{\det(2 \pi S)^{-1/2} e^{-l/2}}{det(2*\pi*S)^(-1/2)*exp(-l/2)} 31 | can be seen as a likelihood of a graph with parameters, given the observation, or the other way around 32 | (possibly up to a normalization constant). 33 | } 34 | \description{ 35 | Or the log likelihood of the observation, given graph with parameters, depending how things are modeled. 36 | Basically this is just \code{\link{cost_function}} that doesn't optimize the edge variables 37 | but has them as an argument instead. 38 | } 39 | \seealso{ 40 | \code{\link{cost_function}} 41 | 42 | \code{\link{edge_optimisation_function}} 43 | 44 | \code{\link{calculate_concentration}} 45 | } 46 | 47 | -------------------------------------------------------------------------------- /man/log_sum_of_logs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{log_sum_of_logs} 4 | \alias{log_sum_of_logs} 5 | \title{Computes the log of a sum of numbers all given in log-space.} 6 | \usage{ 7 | log_sum_of_logs(log_values) 8 | } 9 | \arguments{ 10 | \item{log_values}{Sequence of numbers in log space \eqn{[\log(x_1), \log(x_2), ..., \log(x_n)]}.} 11 | } 12 | \value{ 13 | \eqn{\log(\sum_{i = 1}^n x_i)}. 14 | } 15 | \description{ 16 | Given a sequence of numbers \eqn{[\log(x_1), \log(x_2), ..., \log(x_n)]}, computes \eqn{\log(\sum_{i = 1}^n x_i)}. 17 | For adding two numbers that are given in log space we use the expression \code{max(x, y) + log1p(exp(-abs(x - y)))} 18 | which is a good approximation if \code{x} and \code{y} are of the same order of magnitude, but if they 19 | are of very different sizes just returns the maximum of the two. To prevent adding numbers of very different 20 | magnitude we iteratively add the numbers pairwise. Because of numerical issues with doing this, the order 21 | of the input values can affect the result. 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/make_an_outgroup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{make_an_outgroup} 4 | \alias{make_an_outgroup} 5 | \title{Make an outgroup.} 6 | \usage{ 7 | make_an_outgroup(graph, outgroup = "", all_neutral = FALSE) 8 | } 9 | \arguments{ 10 | \item{graph}{An admixture graph.} 11 | 12 | \item{outgroup}{A leaf we want to be the outgroup.} 13 | 14 | \item{all_neutral}{For when other functions need to root graphs in a neutral way.} 15 | } 16 | \value{ 17 | An admixture graph with the given leaf as an outgroup, if possible. 18 | } 19 | \description{ 20 | Given a graph and a leaf, tries to put the root of the graph on the edge leading to the leaf. 21 | If not possible (\emph{i. e.} if the leaf has admixture in its ancestry), puts the root 22 | somewhere else. 23 | } 24 | \examples{ 25 | \donttest{ 26 | # Here is a little family tree of some dinosaur-like animals. 27 | 28 | species <- c("triceratops", "crocodile", "diplodocus", "tyrannosaurus", "chicken") 29 | graph <- five_leaves_graphs[[1]](species) 30 | plot(graph) 31 | 32 | # Of course we know that while this is correct as an undirected graph, "crocodile" 33 | # should really be the outgroup. 34 | 35 | graph <- make_an_outgroup(graph, "crocodile") 36 | plot(graph) 37 | 38 | # Strictly speaking the graph is still a little misleading because unfortunately 39 | # the (non-bird) dinosaurs are extinct :-( 40 | } 41 | 42 | } 43 | \seealso{ 44 | \code{\link{make_permutations}} 45 | 46 | \code{\link{four_leaves_graphs}} 47 | 48 | \code{\link{five_leaves_graphs}} 49 | 50 | \code{\link{six_leaves_graphs}} 51 | 52 | \code{\link{seven_leaves_graphs}} 53 | 54 | \code{\link{eight_leaves_trees}} 55 | 56 | \code{\link{fit_permutations_and_graphs}} 57 | 58 | \code{\link{fit_graph_list}} 59 | 60 | \code{\link{add_a_leaf}} 61 | 62 | \code{\link{add_an_admixture}} 63 | 64 | \code{\link{add_an_admixture2}} 65 | } 66 | 67 | -------------------------------------------------------------------------------- /man/make_mcmc_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{make_mcmc_model} 4 | \alias{make_mcmc_model} 5 | \title{Collect the information about a graph and a data set needed to run an MCMC on it.} 6 | \usage{ 7 | make_mcmc_model(graph, data) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph to analyse.} 11 | 12 | \item{data}{The data set to compute the posterior over.} 13 | } 14 | \value{ 15 | A model object wrapping functions and data needed to sample from the MCMC. 16 | } 17 | \description{ 18 | Collect the information about a graph and a data set needed to run an MCMC on it. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/make_permutations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{make_permutations} 4 | \alias{make_permutations} 5 | \title{List of permutations.} 6 | \usage{ 7 | make_permutations(populations) 8 | } 9 | \arguments{ 10 | \item{populations}{A vector (of populations for example) of length between 4 and 8.} 11 | } 12 | \value{ 13 | A list of different permutations of the elements of \code{x}. 14 | } 15 | \description{ 16 | List of permutations of given elements. 17 | } 18 | \examples{ 19 | \donttest{ 20 | # The number of permutations of n elements is n!. Take 0! = 1, 1! = 1, 2! = 2 21 | # and 3! = 6 for granted. Now we can estimate e: 22 | FOUR <- length(make_permutations(c(1, 2, 3, 4))) 23 | FIVE <- length(make_permutations(c(1, 2, 3, 4, 5))) 24 | SIX <- length(make_permutations(c(1, 2, 3, 4, 5, 6))) 25 | SEVEN <- length(make_permutations(c(1, 2, 3, 4, 5, 6, 7))) 26 | EIGHT <- length(make_permutations(c(1, 2, 3, 4, 5, 6, 7, 8))) 27 | 1/1 + 1/1 + 1/2 + 1/6 + 1/FOUR + 1/FIVE + 1/SIX + 1/SEVEN + 1/EIGHT 28 | # Hey that was pretty close! 29 | } 30 | 31 | } 32 | \seealso{ 33 | \code{\link{four_leaves_graphs}} 34 | 35 | \code{\link{five_leaves_graphs}} 36 | 37 | \code{\link{six_leaves_graphs}} 38 | 39 | \code{\link{seven_leaves_trees}} 40 | 41 | \code{\link{eight_leaves_trees}} 42 | 43 | \code{\link{fit_permutations_and_graphs}} 44 | 45 | \code{\link{add_a_leaf}} 46 | 47 | \code{\link{add_an_admixture}} 48 | 49 | \code{\link{add_an_admixture2}} 50 | } 51 | 52 | -------------------------------------------------------------------------------- /man/model_bayes_factor_n.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{model_bayes_factor_n} 4 | \alias{model_bayes_factor_n} 5 | \title{Computes the Bayes factor between two models from samples from their posterior distributions.} 6 | \usage{ 7 | model_bayes_factor_n(logL1, logL2, no_samples = 100) 8 | } 9 | \arguments{ 10 | \item{logL1}{Samples of log likelihoods from the posterior distribution of the first graph.} 11 | 12 | \item{logL2}{Samples of log likelihoods from the posterior distribution of the second graph.} 13 | 14 | \item{no_samples}{Number of permutations to sample when computing the result.} 15 | } 16 | \value{ 17 | The Bayes factor between the two graphs given as the mean and standard 18 | deviation over \code{no_samples} different permutations of the input. 19 | } 20 | \description{ 21 | The likelihood of a graph can be computed by integrating over all the graph parameters (with appropriate priors). 22 | Doing this by sampling from priors is very inefficient, so we use samples from the posteriors to importance 23 | sample the likelihood. Given two graphs, and samples from their posteriors, we can estimate the Bayes factor 24 | between them. 25 | } 26 | \details{ 27 | The numerical issues with adding a lot of numbers in log space is unstable 28 | so we get a better estimate by doing it several times on different permutations 29 | of the data. This function calculates the mean of the Bayes factors over different permutations of the 30 | input and estimates the standard deviation. 31 | } 32 | 33 | -------------------------------------------------------------------------------- /man/model_likelihood.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{model_likelihood} 4 | \alias{model_likelihood} 5 | \title{Computes the likelihood of a model from samples from its posterior distribution.} 6 | \usage{ 7 | model_likelihood(log_likelihoods) 8 | } 9 | \arguments{ 10 | \item{log_likelihoods}{Samples of log likelihoods from the posterior distribution of the graph.} 11 | } 12 | \value{ 13 | The likelihood of a graph where graph parameters are integrated out. 14 | } 15 | \description{ 16 | The likelihood of a graph can be computed by integrating over all the graph parameters (with appropriate priors). 17 | Doing this by sampling from priors is very inefficient, so we use samples from the posteriors to importance 18 | sample the likelihood. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/model_likelihood_n.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{model_likelihood_n} 4 | \alias{model_likelihood_n} 5 | \title{Computes the likelihood of a model from samples from its posterior distribution.} 6 | \usage{ 7 | model_likelihood_n(log_likelihoods, no_samples = 100) 8 | } 9 | \arguments{ 10 | \item{log_likelihoods}{Samples of log likelihoods from the posterior distribution of the graph.} 11 | 12 | \item{no_samples}{Number of permutations to sample when computing the result.} 13 | } 14 | \value{ 15 | The likelihood of a graph where graph parameters are integrated out given as the mean and standard 16 | deviation over \code{no_samples} different permutations of the input. 17 | } 18 | \description{ 19 | The likelihood of a graph can be computed by integrating over all the graph parameters (with appropriate priors). 20 | Doing this by sampling from priors is very inefficient, so we use samples from the posteriors to importance 21 | sample the likelihood. 22 | } 23 | \details{ 24 | The numerical issues with adding a lot of numbers in log space is unstable 25 | so we get a better estimate by doing it several times on different permutations 26 | of the data.This function calculates the mean of the likelihoods over different permutations of the 27 | input and estimates the standard devition. 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/mynonneg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{mynonneg} 4 | \alias{mynonneg} 5 | \title{Non negative least square solution.} 6 | \usage{ 7 | mynonneg(C, d, iteration_multiplier = 3) 8 | } 9 | \arguments{ 10 | \item{C}{The matrix.} 11 | 12 | \item{d}{The vector.} 13 | 14 | \item{iteration_multiplier}{The definition of "too many steps". Default value is \eqn{3} 15 | (times \eqn{10} times the matrix height).} 16 | } 17 | \value{ 18 | A vector (\code{x}) and the error (\code{resid.norm}). 19 | } 20 | \description{ 21 | This is the function \code{\link{lsqnonneg}} from the package \code{pracma}, 22 | I just changed \code{\link{qr.solve}} into using Moore-Penrose inverse instead 23 | (\code{\link{ginv}} from \code{MASS}) as \code{\link{qr.solve}} crashes for 24 | some singular inputs. Now it won't crash but it's sometimes running for very long 25 | time (forever?), presumably with those problematic inputs. After too many steps 26 | the function halts and lies that the fit was terrible. I don't think this will 27 | cause problems. 28 | } 29 | \seealso{ 30 | \code{\link[pracma]{lsqnonneg}} 31 | 32 | \code{\link{qr.solve}} 33 | 34 | \code{\link[MASS]{ginv}} 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/no_admixture_events.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_admixture_events} 4 | \alias{no_admixture_events} 5 | \title{Get the number of admixture events in a graph.} 6 | \usage{ 7 | no_admixture_events(x) 8 | } 9 | \arguments{ 10 | \item{x}{The graph.} 11 | } 12 | \value{ 13 | Number of admixture events in the graph. 14 | } 15 | \description{ 16 | Get the number of admixture events in a graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/no_admixture_events.agraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_admixture_events.agraph} 4 | \alias{no_admixture_events.agraph} 5 | \title{Get the number of admixture events in a graph.} 6 | \usage{ 7 | \method{no_admixture_events}{agraph}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The graph.} 11 | } 12 | \value{ 13 | Number of admixture events in the graph. 14 | } 15 | \description{ 16 | Get the number of admixture events in a graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/no_admixture_events.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_admixture_events.agraph_fit} 4 | \alias{no_admixture_events.agraph_fit} 5 | \title{Get the number of admixture events in a fitted graph.} 6 | \usage{ 7 | \method{no_admixture_events}{agraph_fit}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The fitted graph.} 11 | } 12 | \value{ 13 | Number of admixture events in the graph. 14 | } 15 | \description{ 16 | Get the number of admixture events in a fitted graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/no_admixture_events.agraph_fit_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_admixture_events.agraph_fit_list} 4 | \alias{no_admixture_events.agraph_fit_list} 5 | \title{Get the number of admixture events in a list of fitted graph.} 6 | \usage{ 7 | \method{no_admixture_events}{agraph_fit_list}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The graphs.} 11 | } 12 | \value{ 13 | Number of admixture events in the graphs. 14 | } 15 | \description{ 16 | Get the number of admixture events in a list of fitted graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/no_poor_fits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_poor_fits} 4 | \alias{no_poor_fits} 5 | \title{Get the number of tests in the fit where the predictions fall outside of the error bars.} 6 | \usage{ 7 | no_poor_fits(fit, sigma = 6) 8 | } 9 | \arguments{ 10 | \item{fit}{The fitted graph.} 11 | 12 | \item{sigma}{The width of the error bars.} 13 | } 14 | \value{ 15 | The poorly fitted tests. 16 | } 17 | \description{ 18 | Get the number of tests in the fit where the predictions fall outside of the error bars. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/no_poor_fits.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_poor_fits.agraph_fit} 4 | \alias{no_poor_fits.agraph_fit} 5 | \title{Get the number of tests in the fit where the predictions fall outside of the error bars.} 6 | \usage{ 7 | \method{no_poor_fits}{agraph_fit}(fit, sigma = 6) 8 | } 9 | \arguments{ 10 | \item{fit}{The fitted graph.} 11 | 12 | \item{sigma}{The width of the error bars.} 13 | } 14 | \value{ 15 | The poorly fitted tests. 16 | } 17 | \description{ 18 | Get the number of tests in the fit where the predictions fall outside of the error bars. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/no_poor_fits.agraph_fit_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{no_poor_fits.agraph_fit_list} 4 | \alias{no_poor_fits.agraph_fit_list} 5 | \title{Get the number of tests in the fit where the predictions fall outside of the error bars.} 6 | \usage{ 7 | \method{no_poor_fits}{agraph_fit_list}(fit, sigma = 6) 8 | } 9 | \arguments{ 10 | \item{fit}{The fitted graph.} 11 | 12 | \item{sigma}{The width of the error bars.} 13 | } 14 | \value{ 15 | The poorly fitted tests. 16 | } 17 | \description{ 18 | Get the number of tests in the fit where the predictions fall outside of the error bars. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/overlaps_sign.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/signs.R 3 | \name{overlaps_sign} 4 | \alias{overlaps_sign} 5 | \title{Get the sign of overlapping paths.} 6 | \usage{ 7 | overlaps_sign(overlaps) 8 | } 9 | \arguments{ 10 | \item{overlaps}{Data frame representing path overlaps, typically generated 11 | by \code{\link{all_path_overlaps}}.} 12 | } 13 | \description{ 14 | Get the sign of overlapping paths. 15 | } 16 | 17 | -------------------------------------------------------------------------------- /man/parent_edges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agraph.R 3 | \name{parent_edges} 4 | \alias{parent_edges} 5 | \title{Create the list of edges for an admixture graph.} 6 | \usage{ 7 | parent_edges(edges) 8 | } 9 | \arguments{ 10 | \item{edges}{List of edges.} 11 | } 12 | \description{ 13 | Syntactic suggar for constructing edges in an admixture graph. 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/path_overlap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/overlaps.R 3 | \name{path_overlap} 4 | \alias{path_overlap} 5 | \title{Collect the postive and negative overlap between two paths.} 6 | \usage{ 7 | path_overlap(path1, path2) 8 | } 9 | \arguments{ 10 | \item{path1}{The first path.} 11 | 12 | \item{path2}{The second path.} 13 | } 14 | \value{ 15 | The (admixture) probability of seeing the two paths together with the 16 | positive and negative edges in the overlap. 17 | } 18 | \description{ 19 | Collects the postive and negative overlap between two paths. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/plot.agraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot.agraph} 4 | \alias{plot.agraph} 5 | \title{Plot an admixture graph.} 6 | \usage{ 7 | \method{plot}{agraph}(x, show_leaf_labels = TRUE, draw_leaves = TRUE, 8 | color = "yellowgreen", show_inner_node_labels = FALSE, 9 | draw_inner_nodes = FALSE, inner_node_color = color, 10 | show_admixture_labels = FALSE, parent_order = list(), 11 | child_order = list(), leaf_order = NULL, fix = list(), platform = 1, 12 | title = NULL, ...) 13 | } 14 | \arguments{ 15 | \item{x}{The admixture graph.} 16 | 17 | \item{show_leaf_labels}{A flag determining if leaf names are shown.} 18 | 19 | \item{draw_leaves}{A flag determining if leaf nodes are drawn as 20 | little circles.} 21 | 22 | \item{color}{Color of all drawn nodes unless overriden by 23 | \code{inner_node_color}.} 24 | 25 | \item{show_inner_node_labels}{A flag determining if the plot should include 26 | the names of inner nodes.} 27 | 28 | \item{draw_inner_nodes}{A flag determining if inner nodes are drawn as 29 | little circles.} 30 | 31 | \item{inner_node_color}{Color of inner node circles, if drawn.} 32 | 33 | \item{show_admixture_labels}{A flag determining if the plot should include 34 | the names of admixture proportions.} 35 | 36 | \item{parent_order}{An optional list of instuctions on which order 37 | from left to right to draw the parents of nodes. 38 | The list should contain character vectors of parents 39 | with the name of the child, \emph{e.g.} 40 | \code{child = c("left_parent", "right_parent")}. 41 | Using automated heuristics for nodes not specified.} 42 | 43 | \item{child_order}{An optional list of instuctions on which order 44 | from left to right to draw the children of nodes. 45 | The list should contain character vectors of children 46 | with the name of the parent, \emph{e.g.} 47 | \code{parent = c("left_child", "right_child")}. 48 | Using automated heuristics for nodes not specified.} 49 | 50 | \item{leaf_order}{An optional vector describing in which order should 51 | the leaves be drawn. Using automated heuristic 52 | depending on \code{parent_order} and \code{child_order} 53 | if not specified. Accepts both a character vector of 54 | the leaves or a numeric vector interpreted as a 55 | permutation of the default order.} 56 | 57 | \item{fix}{If nothing else helps, the list \code{fix} can be used to 58 | correct the inner node coordinates given by the heuristics. 59 | Should contain numeric vectors of length 2 with the name 60 | of an inner node, \emph{e.g.} \code{inner_node = c(0, 10)}, 61 | moving \code{inner_node} to the right 10 units where 100 is 62 | the plot width. Non-specified inner nodes are left in peace.} 63 | 64 | \item{platform}{By default admixture nodes are drawn with a horizontal 65 | platform for proportion labels, the width of which is 66 | half the distance between any two leaves. The number 67 | \code{platform} tells how many default platform widths 68 | should the platforms be wide, \emph{i. e.} zero means no 69 | platform.} 70 | 71 | \item{title}{Optional title for the plot.} 72 | 73 | \item{...}{Additional plotting options.} 74 | } 75 | \value{ 76 | A plot. 77 | } 78 | \description{ 79 | This is a basic drawing routine for visualising the graph. Uses Nelder-Mead 80 | algorithm and complicated heuristic approach to find aestethic node coordinates, 81 | but due to bad luck or an oversight in the heuristics, especially with larger 82 | graphs, might sometimes produce a weird looking result. Usually plotting again 83 | helps and if not, use the optional parameters to help the algorithm or try the 84 | faster and deterministic function \code{\link{fast_plot}} (which unfortunately is 85 | not very good at handling multiple admixture events). 86 | } 87 | \examples{ 88 | \donttest{ 89 | leaves <- c("salmon", "sea horse", "mermaid", "horse", "human", "lobster") 90 | inner_nodes <- c("R", "s", "t", "u", "v", "w", "x", "y", "z") 91 | edges <- parent_edges(c(edge("salmon", "t"), 92 | edge("sea horse", "y"), 93 | edge("mermaid", "z"), 94 | edge("horse", "w"), 95 | edge("human", "x"), 96 | edge("lobster", "R"), 97 | edge("s", "R"), 98 | edge("t", "s"), 99 | edge("u", "t"), 100 | edge("v", "s"), 101 | edge("w", "v"), 102 | edge("x", "v"), 103 | admixture_edge("y", "u", "w"), 104 | admixture_edge("z", "u", "x"))) 105 | admixtures <- admixture_proportions(c(admix_props("y", "u", "w", "a"), 106 | admix_props("z", "u", "x", "b"))) 107 | graph <- agraph(leaves, inner_nodes, edges, admixtures) 108 | plot(graph, show_inner_node_labels = TRUE) 109 | 110 | # Suppose now that we prefer to have the outgroup "lobster" on the right side. 111 | # This is achieved by telling the algorithm that the children of "R" should be in 112 | # the order ("s", "lobster"), from left to right: 113 | 114 | plot(graph, child_order = list(R = c("s", "lobster"))) 115 | 116 | # Suppose further that we prefer to have "mermaid" and "human" next to each other, 117 | # as well as "sea horse" and "horse". This is easily achieved by rearranging the leaf 118 | # order proposed by the algorithm. We can also fine-tune by moving "y" a little bit 119 | # to the right, make the admixture platforms a bit shorter, color the nodes, show the 120 | # admixture proportions and give the plot a title: 121 | 122 | plot(graph, child_order = list(R = c("s", "lobster")), leaf_order = c(1, 2, 4, 3, 5, 6), 123 | fix = list(y = c(5, 0)), platform = 0.8, color = "deepskyblue", 124 | inner_node_color = "skyblue", show_admixture_labels = TRUE, 125 | title = "Evolution of fish/mammal hybrids") 126 | } 127 | 128 | } 129 | \seealso{ 130 | \code{\link{agraph}} 131 | 132 | \code{\link{fast_plot}} 133 | } 134 | 135 | -------------------------------------------------------------------------------- /man/plot.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitted_plotting.R 3 | \name{plot.agraph_fit} 4 | \alias{plot.agraph_fit} 5 | \title{Plot the fit of a graph to data.} 6 | \usage{ 7 | \method{plot}{agraph_fit}(x, sigma = 6, grayscale = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Fitted graph object.} 11 | 12 | \item{sigma}{How many standard deviations the error bars should be wide.} 13 | 14 | \item{grayscale}{Should the plot be in black and white?} 15 | 16 | \item{...}{Additional parameters.} 17 | } 18 | \description{ 19 | Plot the fit of a graph to data. 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/plot.f4stats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/f4_plotting.R 3 | \name{plot.f4stats} 4 | \alias{plot.f4stats} 5 | \title{Plot the fit of a graph to data.} 6 | \usage{ 7 | \method{plot}{f4stats}(x, sigma = 6, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Data frame with observed \eqn{D} (\eqn{f_4}) statistics} 11 | 12 | \item{sigma}{How many sigmas the error bars should be wide.} 13 | 14 | \item{...}{Additional parameters.} 15 | } 16 | \description{ 17 | Plot the fit of a graph to data. 18 | } 19 | 20 | -------------------------------------------------------------------------------- /man/plot_fit_1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitted_plotting.R 3 | \name{plot_fit_1} 4 | \alias{plot_fit_1} 5 | \title{A plot of the cost function or number of fitted statistics.} 6 | \usage{ 7 | plot_fit_1(object, X, resolution = 100, show_fit = FALSE, sigma = 6, ...) 8 | } 9 | \arguments{ 10 | \item{object}{The fitted object.} 11 | 12 | \item{X}{An admix variable name (remember quotation marks).} 13 | 14 | \item{resolution}{How densely is the function evaluated.} 15 | 16 | \item{show_fit}{Should the function plot the number of statistics where the graph fits 17 | the data instead of the \code{\link{cost_function}}?} 18 | 19 | \item{sigma}{If \code{show_fit} is \code{TRUE} then each statistic is considered fitted 20 | if the difference between a prediction and the observation statistics is no 21 | more than \eqn{D*\sigma/(2*Z)}. Notice that even when plotting the number of 22 | fitted statistics, we have no guarantee that the chosen variables maximize 23 | this number as the fitting function still optimizes 24 | \code{\link{cost_function}}.} 25 | 26 | \item{...}{Additional parameters.} 27 | } 28 | \value{ 29 | Values for optimal cost function for values of \code{X} between zero and one, plotted. 30 | } 31 | \description{ 32 | A plot of the cost function with respect to one admix variable specified by the user. 33 | Sorry about the name, all the good ones were taken and the fact that the word "graph" means 34 | two different things doesn't help any. 35 | } 36 | \seealso{ 37 | \code{\link{plot_fit_2}} 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/plot_fit_2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitted_plotting.R 3 | \name{plot_fit_2} 4 | \alias{plot_fit_2} 5 | \title{A contour plot of the cost function.} 6 | \usage{ 7 | plot_fit_2(object, X, Y, resolution = 10, show_fit = FALSE, sigma = 6, 8 | grayscale = FALSE, ...) 9 | } 10 | \arguments{ 11 | \item{object}{The fitted object.} 12 | 13 | \item{X}{An admix variable name (remember quotation marks).} 14 | 15 | \item{Y}{An admix variable name (remember quotation marks).} 16 | 17 | \item{resolution}{How densely is the function evaluated.} 18 | 19 | \item{show_fit}{Should the function plot the number of statistics where the graph fits 20 | the data instead of the \code{\link{cost_function}}?} 21 | 22 | \item{sigma}{If \code{show_fit} is \code{TRUE} then each statistic is considered fitted 23 | if the difference between a prediction and the observation statistics is no 24 | more than \eqn{D*\sigma/(2*Z)}. Notice that even when plotting the number of 25 | fitted statistics, we have no guarantee that the chosen variables maximize 26 | this number as the fitting function still optimizes \code{\link{cost_function}}.} 27 | 28 | \item{grayscale}{Should the figure be plotted in grayscale or in colour?} 29 | 30 | \item{...}{Additional parameters passed to the plotting function 31 | \code{\link{contour}}.} 32 | } 33 | \value{ 34 | The matrix of values computed and plotted. 35 | } 36 | \description{ 37 | A contour plot of the cost function with respect to two admix variables specified by the user. 38 | } 39 | \seealso{ 40 | \code{\link{contour}} 41 | 42 | \code{\link{plot_fit_1}} 43 | } 44 | 45 | -------------------------------------------------------------------------------- /man/poor_fits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{poor_fits} 4 | \alias{poor_fits} 5 | \title{Get the tests in the fit where the predictions fall outside of the error bars.} 6 | \usage{ 7 | poor_fits(fit, sigma = 6) 8 | } 9 | \arguments{ 10 | \item{fit}{The fitted graph.} 11 | 12 | \item{sigma}{The width of the error bars.} 13 | } 14 | \value{ 15 | The poorly fitted tests. 16 | } 17 | \description{ 18 | Get the tests in the fit where the predictions fall outside of the error bars. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/poor_fits.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{poor_fits.agraph_fit} 4 | \alias{poor_fits.agraph_fit} 5 | \title{Get the tests in the fit where the predictions fall outside of the error bars.} 6 | \usage{ 7 | \method{poor_fits}{agraph_fit}(fit, sigma = 6) 8 | } 9 | \arguments{ 10 | \item{fit}{The fitted graph.} 11 | 12 | \item{sigma}{The width of the error bars.} 13 | } 14 | \value{ 15 | The poorly fitted tests. 16 | } 17 | \description{ 18 | Get the tests in the fit where the predictions fall outside of the error bars. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/poor_fits.agraph_fit_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{poor_fits.agraph_fit_list} 4 | \alias{poor_fits.agraph_fit_list} 5 | \title{Get the tests in the fit where the predictions fall outside of the error bars.} 6 | \usage{ 7 | \method{poor_fits}{agraph_fit_list}(fit, sigma = 6) 8 | } 9 | \arguments{ 10 | \item{fit}{The fitted graphs.} 11 | 12 | \item{sigma}{The width of the error bars.} 13 | } 14 | \value{ 15 | The poorly fitted tests. 16 | } 17 | \description{ 18 | Get the tests in the fit where the predictions fall outside of the error bars. 19 | } 20 | 21 | -------------------------------------------------------------------------------- /man/print.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{print.agraph_fit} 4 | \alias{print.agraph_fit} 5 | \title{Print function for the fitted graph.} 6 | \usage{ 7 | \method{print}{agraph_fit}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{The fitted object.} 11 | 12 | \item{...}{Additional parameters.} 13 | } 14 | \description{ 15 | Prints the value of \code{\link{cost_function}} of the fitted graph, and complains 16 | if some or all of the admixture proportions aren't trurly fitted. 17 | Note: the admixture proportion not being trurly fitted does not necessarily mean that 18 | there is no evidence of an admix event! 19 | } 20 | \seealso{ 21 | \code{link{summary.agraph_fit}} 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/project_to_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/project_and_split.R 3 | \name{project_to_population} 4 | \alias{project_to_population} 5 | \title{Map sample names to population names.} 6 | \usage{ 7 | project_to_population(data, f) 8 | } 9 | \arguments{ 10 | \item{data}{The data frame to modify.} 11 | 12 | \item{f}{Function mapping sample names to population names.} 13 | } 14 | \description{ 15 | Map sample names to population names. 16 | } 17 | \details{ 18 | This function maps the sample names in \code{W}, \code{X}, \code{Y}, and 19 | \code{Z} to population names (typically what an admixture graph has for 20 | leaves) and stores the original sample names so we can map them back again 21 | after using the graph for making predictions. 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/remove_duplicates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{remove_duplicates} 4 | \alias{remove_duplicates} 5 | \title{Remove duplicate graphs from a list.} 6 | \usage{ 7 | remove_duplicates(graph_list, organise = FALSE, return_piles = FALSE) 8 | } 9 | \arguments{ 10 | \item{graph_list}{A list of graphs with the same leaf set.} 11 | 12 | \item{organise}{If \code{TRUE} also organises isomorphic graphs (now disregarding leaf names) 13 | next to each other.} 14 | 15 | \item{return_piles}{If \code{TRUE} and \code{organise} is also \code{TRUE}, the output will be a 16 | list of lists of isomorphic graphs instead of one big list.} 17 | } 18 | \value{ 19 | A list of graphs that are all different (or a list of lists of graphs if both \code{organise} 20 | and \code{return_piles} are \code{TRUE}). 21 | } 22 | \description{ 23 | Using \code{\link{canonise_graph}} to calculate unique characteristic logical vector for each 24 | graph in a given list of graphs, then sorts the list according to this attribute and remove 25 | repeated graphs. 26 | Leaf names count so that graphs with permuted leaves are considered different. 27 | Also organises similar graphs next to each other if \code{organise} is \code{TRUE}, but this 28 | is extremely slow. 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/rename_nodes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{rename_nodes} 4 | \alias{rename_nodes} 5 | \title{Rename nodes.} 6 | \usage{ 7 | rename_nodes(graph, newnames = list()) 8 | } 9 | \arguments{ 10 | \item{graph}{The graph to be renamed.} 11 | 12 | \item{newnames}{A list of new names, given in the form \code{list(old = "new")}. Nodes not listed will keep 13 | their old name, unless no list is given at all, in which case the leaves keep their old 14 | names while the inner nodes get new standardised names.} 15 | } 16 | \value{ 17 | A graph with new node names. 18 | } 19 | \description{ 20 | Changes the names of the nodes of a graph. 21 | Capable of giving new standard names to the inner nodes in a way that only depends on the graph topology 22 | (without the root) and the leaf names. This is necessary when detecting when graphs are identical up to inner 23 | node and admixture proportion names, see \code{\link{canonise_graph}} and \code{\link{remove_duplicates}}. 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/residuals.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{residuals.agraph_fit} 4 | \alias{residuals.agraph_fit} 5 | \title{Errors of prediction in the fitted graph} 6 | \usage{ 7 | \method{residuals}{agraph_fit}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{The fitted object.} 11 | 12 | \item{...}{Additional parameters.} 13 | } 14 | \description{ 15 | Gets \eqn{f - F}, the difference between predicted and observed statistics, 16 | for each data point used in the fit. 17 | } 18 | \seealso{ 19 | \code{link{summary.agraph_fit}} 20 | } 21 | 22 | -------------------------------------------------------------------------------- /man/run_metropolis_hasting.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{run_metropolis_hasting} 4 | \alias{run_metropolis_hasting} 5 | \title{Run a Metropolis-Hasting MCMC to sample graph parameters.} 6 | \usage{ 7 | run_metropolis_hasting(model, initial_state, iterations, no_temperatures = 1, 8 | cores = 1, no_flips = 1, max_tmp = 100, verbose = TRUE) 9 | } 10 | \arguments{ 11 | \item{model}{Object constructed with \code{\link{make_mcmc_model}}.} 12 | 13 | \item{initial_state}{The initial set of graph parameters.} 14 | 15 | \item{iterations}{Number of iterations to sample.} 16 | 17 | \item{no_temperatures}{Number of chains in the MC3 procedure.} 18 | 19 | \item{cores}{Number of cores to spread the chains across. Best performance is when \code{cores = no_temperatures}.} 20 | 21 | \item{no_flips}{Mean number of times a flip between two chains should be proposed after each step.} 22 | 23 | \item{max_tmp}{The highest temperature.} 24 | 25 | \item{verbose}{Logical value determining if a progress bar should be shown during the run.} 26 | } 27 | \value{ 28 | A matrix containing the trace of the chain with temperature 1. 29 | } 30 | \description{ 31 | The MCMC performs a random walk in transformed parameter space (edge lengths are log transformed 32 | and admixture proportions inverse Normal distribution transformed) and from this 33 | explores the posterior distribution of graph parameters. 34 | } 35 | \details{ 36 | Using the posterior distribution of parameters is one approach to getting parameter estimates 37 | and a sense of their variability. Credibility intervals can directly be obtained from sampled 38 | parameters; to get confidence intervals from the likelihood maximisation approach requires 39 | either estimating the Hessian matrix for the likelihood or a boot-strapping approach 40 | to the data. 41 | 42 | From sampling the likelihood values for each sample from the posterior we can also 43 | compute the model likelihood (the probability of the data when integrating over all the model 44 | parameters). This gives us a direct way of comparing graphs since the ratio of likelihoods 45 | is the Bayes factor between the models. Comparing models using maximum likelihood estimtates 46 | is more problematic since usually graphs are not nested models. 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/seven_leaves_graphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \docType{data} 4 | \name{seven_leaves_graphs} 5 | \alias{seven_leaves_graphs} 6 | \title{Seven leaves graphs.} 7 | \format{A list of functions on seven leaves and a parameter \code{permutations} which 8 | is \code{FALSE} by default. 9 | The outputs of these functions are either single \code{\link{agraph}} objects 10 | with the input vector as leaves, or if \code{permutations} is \code{TRUE}, 11 | lists of all the possible \code{\link{agraph}} objects with that leaf set up 12 | to symmetry.} 13 | \usage{ 14 | seven_leaves_graphs 15 | } 16 | \description{ 17 | Kind of obsolete since the introduction of \code{\link{all_graphs}}. 18 | A comprehensive listing of all the \eqn{48} admixture graphs with seven leaves and 19 | at most one admixture event. Our convention is that the position of the root does 20 | not matter (as long as it's not after an admixture event) and that graphs that have 21 | \emph{eyes}, two inner nodes with the property that all the paths between any two 22 | leaves visits both or neither of them, are excluded. The reason is that the \eqn{f} 23 | statistics can't detect the exact position of the root or distinguish between an 24 | eye and a simple branch. The position of the root can be moved later with the function 25 | \code{\link{make_an_outgroup}}. 26 | } 27 | \examples{ 28 | \donttest{ 29 | # While the usage of this function is pretty self-explanatory, let's plot all the graphs 30 | # just for browsing. 31 | for (i in seq(1, length(seven_leaves_graphs))) { 32 | graph <- seven_leaves_graphs[[i]](c("A", "B", "C", "D", "E", "F", "G")) 33 | # This is how you include quotation marks in strings by the way: 34 | title <- paste("seven_leaves_graphs[[", i, 35 | "]](c(\\"A\\", \\"B\\", \\"C\\", \\"D\\", \\"E\\", \\"F\\", \\"G\\"))", sep = "") 36 | plot(graph, color = "seagreen", title = title) 37 | } 38 | } 39 | 40 | } 41 | \seealso{ 42 | \code{\link{all_graphs}} 43 | 44 | \code{\link{make_permutations}} 45 | 46 | \code{\link{fit_permutations_and_graphs}} 47 | 48 | \code{\link{fit_graph_list}} 49 | 50 | \code{\link{add_a_leaf}} 51 | 52 | \code{\link{add_an_admixture}} 53 | 54 | \code{\link{add_an_admixture2}} 55 | 56 | \code{\link{make_an_outgroup}} 57 | 58 | Other graphs: \code{\link{eight_leaves_trees}}, 59 | \code{\link{five_leaves_graphs}}, 60 | \code{\link{four_leaves_graphs}}, 61 | \code{\link{six_leaves_graphs}} 62 | } 63 | \keyword{datasets} 64 | 65 | -------------------------------------------------------------------------------- /man/seven_leaves_trees.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \docType{data} 4 | \name{seven_leaves_trees} 5 | \alias{seven_leaves_trees} 6 | \title{Seven leaves trees.} 7 | \format{A list of functions on seven leaves. 8 | The outputs of these functions are \code{\link{agraph}} objects.} 9 | \usage{ 10 | seven_leaves_trees 11 | } 12 | \description{ 13 | The function \code{\link{seven_leaves_graphs}} is better than this as it also contains 14 | graphs with one admixture. (This function is only kept for legacy reasons.) 15 | Even more obsolete since the introduction of \code{\link{all_graphs}}. 16 | } 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/sf2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/symbolic-f-statistics.R 3 | \name{sf2} 4 | \alias{sf2} 5 | \title{Calculate the f_2(A, B) statistics.} 6 | \usage{ 7 | sf2(graph, A, B) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{A}{A leaf node.} 13 | 14 | \item{B}{A leaf node.} 15 | } 16 | \value{ 17 | A symbolic representation of the equation for the \eqn{f_2} 18 | statistics given by the admixture graph. 19 | } 20 | \description{ 21 | Calculate the \eqn{f_2(A, B)} statistics. 22 | } 23 | 24 | -------------------------------------------------------------------------------- /man/sf3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/symbolic-f-statistics.R 3 | \name{sf3} 4 | \alias{sf3} 5 | \title{Calculate the f_3(A; B, C) statistics.} 6 | \usage{ 7 | sf3(graph, A, B, C) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{A}{A leaf node.} 13 | 14 | \item{B}{A leaf node.} 15 | 16 | \item{C}{A leaf node.} 17 | } 18 | \value{ 19 | A symbolic representation of the equation for the \eqn{f_3} 20 | statistics given by the admixture graph. 21 | } 22 | \description{ 23 | Calculate the \eqn{f_3(A; B, C)} statistics. 24 | } 25 | 26 | -------------------------------------------------------------------------------- /man/sf4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/symbolic-f-statistics.R 3 | \name{sf4} 4 | \alias{sf4} 5 | \title{Calculate the f_4(W, X; Y, Z) statistics.} 6 | \usage{ 7 | sf4(graph, W, X, Y, Z) 8 | } 9 | \arguments{ 10 | \item{graph}{The admixture graph.} 11 | 12 | \item{W}{A leaf node.} 13 | 14 | \item{X}{A leaf node.} 15 | 16 | \item{Y}{A leaf node.} 17 | 18 | \item{Z}{A leaf node.} 19 | } 20 | \value{ 21 | A symbolic representation of the equation for the \eqn{f_4} 22 | statistics given by the admixture graph. 23 | } 24 | \description{ 25 | Calculate the \eqn{f_4(W, X; Y, Z)} statistics. 26 | } 27 | 28 | -------------------------------------------------------------------------------- /man/six_leaves_graphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \docType{data} 4 | \name{six_leaves_graphs} 5 | \alias{six_leaves_graphs} 6 | \title{Six leaves graphs.} 7 | \format{A list of functions on six leaves and a parameter \code{permutations} which 8 | is \code{FALSE} by default. 9 | The outputs of these functions are either single \code{\link{agraph}} objects 10 | with the input vector as leaves, or if \code{permutations} is \code{TRUE}, 11 | lists of all the possible \code{\link{agraph}} objects with that leaf set up 12 | to symmetry.} 13 | \usage{ 14 | six_leaves_graphs 15 | } 16 | \description{ 17 | Kind of obsolete since the introduction of \code{\link{all_graphs}}. 18 | A comprehensive listing of all the \eqn{21} admixture graphs with six leaves and 19 | at most one admixture event. Our convention is that the position of the root does 20 | not matter (as long as it's not after an admixture event) and that graphs that have 21 | \emph{eyes}, two inner nodes with the property that all the paths between any two 22 | leaves visits both or neither of them, are excluded. The reason is that the \eqn{f} 23 | statistics can't detect the exact position of the root or distinguish between an 24 | eye and a simple branch. The position of the root can be moved later with the function 25 | \code{\link{make_an_outgroup}}. 26 | } 27 | \examples{ 28 | \donttest{ 29 | # While the usage of this function is pretty self-explanatory, let's plot all the graphs 30 | # just for browsing. 31 | for (i in seq(1, length(six_leaves_graphs))) { 32 | graph <- six_leaves_graphs[[i]](c("A", "B", "C", "D", "E", "F")) 33 | # This is how you include quotation marks in strings by the way: 34 | title <- paste("six_leaves_graphs[[", i, 35 | "]](c(\\"A\\", \\"B\\", \\"C\\", \\"D\\", \\"E\\", \\"F\\"))", sep = "") 36 | plot(graph, color = "yellow4", title = title) 37 | } 38 | } 39 | 40 | } 41 | \seealso{ 42 | \code{\link{all_graphs}} 43 | 44 | \code{\link{make_permutations}} 45 | 46 | \code{\link{fit_permutations_and_graphs}} 47 | 48 | \code{\link{fit_graph_list}} 49 | 50 | \code{\link{add_a_leaf}} 51 | 52 | \code{\link{add_an_admixture}} 53 | 54 | \code{\link{add_an_admixture2}} 55 | 56 | \code{\link{make_an_outgroup}} 57 | 58 | Other graphs: \code{\link{eight_leaves_trees}}, 59 | \code{\link{five_leaves_graphs}}, 60 | \code{\link{four_leaves_graphs}}, 61 | \code{\link{seven_leaves_graphs}} 62 | } 63 | \keyword{datasets} 64 | 65 | -------------------------------------------------------------------------------- /man/split_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/project_and_split.R 3 | \name{split_population} 4 | \alias{split_population} 5 | \title{Reverse a projection of samples to populations.} 6 | \usage{ 7 | split_population(x) 8 | } 9 | \arguments{ 10 | \item{x}{The projected data or a fitted object on projected data.} 11 | } 12 | \description{ 13 | Reverse a projection of samples to populations. 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/split_population.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/project_and_split.R 3 | \name{split_population.agraph_fit} 4 | \alias{split_population.agraph_fit} 5 | \title{Reverse a projection of samples to populations.} 6 | \usage{ 7 | \method{split_population}{agraph_fit}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The projected data or a fitted object on projected data.} 11 | } 12 | \description{ 13 | Reverse a projection of samples to populations. 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/split_population.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/project_and_split.R 3 | \name{split_population.data.frame} 4 | \alias{split_population.data.frame} 5 | \title{Reverse a projection of samples to populations.} 6 | \usage{ 7 | \method{split_population}{data.frame}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The projected data or a fitted object on projected data.} 11 | } 12 | \description{ 13 | Reverse a projection of samples to populations. 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/sum_of_squared_errors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{sum_of_squared_errors} 4 | \alias{sum_of_squared_errors} 5 | \title{Get the sum of squared errors for a fitted graph.} 6 | \usage{ 7 | sum_of_squared_errors(x) 8 | } 9 | \arguments{ 10 | \item{x}{The fitted graph.} 11 | } 12 | \value{ 13 | SSE for the fit. 14 | } 15 | \description{ 16 | Get the sum of squared errors for a fitted graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/sum_of_squared_errors.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{sum_of_squared_errors.agraph_fit} 4 | \alias{sum_of_squared_errors.agraph_fit} 5 | \title{Get the sum of squared errors for a fitted graph.} 6 | \usage{ 7 | \method{sum_of_squared_errors}{agraph_fit}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The fitted graph.} 11 | } 12 | \value{ 13 | SSE for the fit. 14 | } 15 | \description{ 16 | Get the sum of squared errors for a fitted graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/sum_of_squared_errors.agraph_fit_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary-statistics.R 3 | \name{sum_of_squared_errors.agraph_fit_list} 4 | \alias{sum_of_squared_errors.agraph_fit_list} 5 | \title{Get the sum of squared errors for a list of fitted graph.} 6 | \usage{ 7 | \method{sum_of_squared_errors}{agraph_fit_list}(x) 8 | } 9 | \arguments{ 10 | \item{x}{The fitted graphs.} 11 | } 12 | \value{ 13 | SSE for the fits. 14 | } 15 | \description{ 16 | Get the sum of squared errors for a list of fitted graph. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /man/summary.agraph_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fitting.R 3 | \name{summary.agraph_fit} 4 | \alias{summary.agraph_fit} 5 | \title{Summary for the fitted graph.} 6 | \usage{ 7 | \method{summary}{agraph_fit}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{The fitted object.} 11 | 12 | \item{...}{Additional parameters.} 13 | } 14 | \description{ 15 | Prints: \cr 16 | Optimal admixture proportions and a complaint if some of them are not trurly fitted, 17 | \emph{i. e.} if after fixing a (possibly empty) subset of them, the rest have typically 18 | no effect on the cost function. Here typically means that some isolated values of the 19 | admixture proportions, like \eqn{0} or \eqn{1}, might actually give a significantly worse 20 | fit than the constant fit given by any other values (but not better). 21 | Thus, an admixture proportion not being fitted does not always mean that there is no 22 | evidence of an admix event, as fixing them at \eqn{0} or \eqn{1} could make the fit 23 | worse while the exact value won't matter otherwise. \cr 24 | The optimal edge lengths give one of the solutions for the best fit. It is generally not 25 | unique, as after fixing the admixture proportions, the best edge lengths are a non-negative 26 | least square solution for a system of linear equations. To get all the solutions one has 27 | to add any solution of the corresponding homogeneous system to the given exaple solution 28 | (and exclude possible negative values). The solutions of the homogeneous system are given 29 | as a set of free edge lengths that may obtain any non-negative value, and bounded edge 30 | lengths that linearly depend on the free ones. \cr 31 | Minimal error is the value of the \code{\link{cost_function}} at the fit. 32 | } 33 | 34 | -------------------------------------------------------------------------------- /man/thinning.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcmc.R 3 | \name{thinning} 4 | \alias{thinning} 5 | \title{Thins out an MCMC trace.} 6 | \usage{ 7 | thinning(trace, k) 8 | } 9 | \arguments{ 10 | \item{trace}{A trace from an MCMC run.} 11 | 12 | \item{k}{The number of lines to skip over per retained sample.} 13 | } 14 | \description{ 15 | Thins out an MCMC trace. 16 | } 17 | 18 | -------------------------------------------------------------------------------- /man/vector_to_graph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/propose.R 3 | \name{vector_to_graph} 4 | \alias{vector_to_graph} 5 | \title{Vector to graph.} 6 | \usage{ 7 | vector_to_graph(vector) 8 | } 9 | \arguments{ 10 | \item{vector}{A logical vector.} 11 | } 12 | \value{ 13 | The graph corresponding to the vector. 14 | } 15 | \description{ 16 | Interprets a logical vector back to an \code{\link{agraph}} object. The admixture 17 | proportion names are now lost. 18 | } 19 | 20 | -------------------------------------------------------------------------------- /test.R: -------------------------------------------------------------------------------- 1 | 2 | data(bears) 3 | 4 | leaves <- c("BLK", "PB", "AK", "ABC_A", "ABC_BC", "YB", "EBB") 5 | inner_nodes <- c("R", "a", "b", "c", "d", "e", "f", "g", "h", 6 | "abc_a", "G", "E") 7 | 8 | edges <- parent_edges(c(edge("BLK", "R"), 9 | edge("PB", "h"), 10 | edge("AK", "h"), 11 | edge("ABC_A", "abc_a"), 12 | admixture_edge("abc_a", "f", "g"), 13 | edge("ABC_BC", "g"), 14 | edge("YB", "e"), 15 | edge("EBB", "c"), 16 | edge("h", "f"), 17 | edge("f", "d"), 18 | edge("g", "G"), 19 | admixture_edge("G", "d", "e"), 20 | edge("d", "b"), 21 | edge("e", "E"), 22 | admixture_edge("E", "b", "c"), 23 | edge("b", "a"), 24 | edge("c", "a"), 25 | edge("a", "R"))) 26 | 27 | 28 | admixtures <- admixture_proportions(c(admix_props("abc_a", "f", "g", "alpha"), 29 | admix_props("G", "d", "e", "beta"), 30 | admix_props("E", "b", "c", "gamma"))) 31 | 32 | bears_graph <- agraph(leaves, inner_nodes, edges, admixtures) 33 | plot(bears_graph, show_inner_node_labels = TRUE, show_admixture_labels = TRUE) 34 | 35 | (x <- fit_graph(bears, bears_graph)) 36 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(admixturegraph) 3 | 4 | test_check("admixturegraph") -------------------------------------------------------------------------------- /tests/testthat/test_f_statistics.R: -------------------------------------------------------------------------------- 1 | context("f statistics") 2 | 3 | test_that("that the f statistics computes the correct paths overlaps.", { 4 | leaves <- c("A", "B", "C", "D") 5 | inner_nodes <- c("AC", "BC", "ABC") 6 | edges <- parent_edges(c(edge("A", "AC"), 7 | edge("B", "BC"), 8 | admixture_edge("C", "AC", "BC"), 9 | edge("AC", "ABC"), 10 | edge("BC", "ABC"), 11 | edge("D", "ABC"))) 12 | admix <- admixture_proportions(c(admix_props("C", "AC", "BC", "a"))) 13 | graph <- agraph(leaves, inner_nodes, edges, admix) 14 | 15 | AB_paths <- all_paths(graph, "A", "B") 16 | CB_paths <- all_paths(graph, "C", "B") 17 | CD_paths <- all_paths(graph, "C", "D") 18 | 19 | expect_equal(all_path_overlaps(AB_paths, AB_paths), f2(graph, "A", "B")) 20 | expect_equal(all_path_overlaps(CB_paths, CD_paths), f3(graph, "C", "B", "D")) 21 | expect_equal(all_path_overlaps(AB_paths, CD_paths), f4(graph, "A", "B", "C", "D")) 22 | }) 23 | 24 | test_that("we get the right symbolic representation of f statistics.", { 25 | leaves <- c("A", "B", "C", "D") 26 | inner_nodes <- c("AC", "BC", "ABC") 27 | edges <- parent_edges(c(edge("A", "AC"), 28 | edge("B", "BC"), 29 | admixture_edge("C", "AC", "BC"), 30 | edge("AC", "ABC"), 31 | edge("BC", "ABC"), 32 | edge("D", "ABC"))) 33 | admix <- admixture_proportions(c(admix_props("C", "AC", "BC", "a"))) 34 | graph <- agraph(leaves, inner_nodes, edges, admix) 35 | 36 | expect_equal(toString(sf2(graph, "A", "B")), "edge_AC_A + edge_ABC_BC + edge_ABC_AC + edge_BC_B") 37 | expect_equal(toString(sf3(graph, "A", "B", "D")), "edge_AC_A + edge_ABC_AC") 38 | expect_equal(toString(sf3(graph, "C", "B", "D")), 39 | "a * a * (edge_ABC_AC + edge_AC_C) + a * (1 - a) * (-edge_ABC_BC) + (1 - a) * (1 - a) * (edge_BC_C)") 40 | expect_equal(toString(sf4(graph, "A", "B", "C", "D")), 41 | "a * (edge_ABC_AC) + (1 - a) * (-edge_ABC_BC)") 42 | expect_equal(toString(sf4(graph, "B", "D", "A", "C")), "(1 - a) * (-edge_ABC_BC)") 43 | expect_equal(toString(sf4(graph, "B", "D", "C", "A")), "(1 - a) * (edge_ABC_BC)") 44 | }) -------------------------------------------------------------------------------- /tests/testthat/test_graph_construction.R: -------------------------------------------------------------------------------- 1 | context("Graph construction") 2 | 3 | test_that("we can build a simple tree.", { 4 | leaves <- c("A", "B", "C") 5 | inner_nodes <- c("AB", "ABC") 6 | edges <- parent_edges(c(edge("A", "AB"), 7 | edge("B", "AB"), 8 | edge("AB", "ABC"), 9 | edge("C", "ABC"))) 10 | graph <- agraph(leaves, inner_nodes, edges, NULL) 11 | 12 | expect_equal(graph$leaves, leaves) 13 | expect_equal(graph$inner_nodes, inner_nodes) 14 | expect_equal(graph$nodes, c(leaves, inner_nodes)) 15 | 16 | expect_equal(names(which(graph$children["A",])), character(0)) 17 | expect_equal(names(which(graph$children["B",])), character(0)) 18 | expect_equal(names(which(graph$children["C",])), character(0)) 19 | expect_equal(names(which(graph$children["AB",])), c("A", "B")) 20 | expect_equal(names(which(graph$children["ABC",])), c("C", "AB")) 21 | 22 | expect_equal(names(which(graph$parents["A",])), c("AB")) 23 | expect_equal(names(which(graph$parents["B",])), c("AB")) 24 | expect_equal(names(which(graph$parents["C",])), c("ABC")) 25 | expect_equal(names(which(graph$parents["AB",])), c("ABC")) 26 | expect_equal(names(which(graph$parents["ABC",])), character(0)) 27 | }) 28 | 29 | test_that("we can build an unresolved simple tree.", { 30 | leaves <- c("A", "B", "C") 31 | inner_nodes <- c("ABC") 32 | edges <- parent_edges(c(edge("A", "ABC"), 33 | edge("B", "ABC"), 34 | edge("C", "ABC"))) 35 | graph <- agraph(leaves, inner_nodes, edges, NULL) 36 | 37 | expect_equal(graph$leaves, leaves) 38 | expect_equal(graph$inner_nodes, inner_nodes) 39 | expect_equal(graph$nodes, c(leaves, inner_nodes)) 40 | 41 | expect_equal(names(which(graph$children["A",])), character(0)) 42 | expect_equal(names(which(graph$children["B",])), character(0)) 43 | expect_equal(names(which(graph$children["C",])), character(0)) 44 | expect_equal(names(which(graph$children["ABC",])), c("A", "B", "C")) 45 | 46 | expect_equal(names(which(graph$parents["A",])), c("ABC")) 47 | expect_equal(names(which(graph$parents["B",])), c("ABC")) 48 | expect_equal(names(which(graph$parents["C",])), c("ABC")) 49 | expect_equal(names(which(graph$parents["ABC",])), character(0)) 50 | }) 51 | 52 | test_that("we can build a simple graph.", { 53 | leaves <- c("A", "B", "C") 54 | inner_nodes <- c("AC", "BC", "ABC") 55 | edges <- parent_edges(c(edge("A", "AC"), 56 | edge("B", "BC"), 57 | admixture_edge("C", "AC", "BC"), 58 | edge("AC", "ABC"), 59 | edge("BC", "ABC"))) 60 | admixtures <- admixture_proportions(c(admix_props("C", "AC", "BC", "a"))) 61 | 62 | graph <- agraph(leaves, inner_nodes, edges, admixtures) 63 | 64 | expect_equal(graph$leaves, leaves) 65 | expect_equal(graph$inner_nodes, inner_nodes) 66 | expect_equal(graph$nodes, c(leaves, inner_nodes)) 67 | 68 | expect_equal(names(which(graph$children["A",])), character(0)) 69 | expect_equal(names(which(graph$children["B",])), character(0)) 70 | expect_equal(names(which(graph$children["C",])), character(0)) 71 | expect_equal(names(which(graph$children["AC",])), c("A", "C")) 72 | expect_equal(names(which(graph$children["BC",])), c("B", "C")) 73 | expect_equal(names(which(graph$children["ABC",])), c("AC", "BC")) 74 | 75 | expect_equal(names(which(graph$parents["A",])), c("AC")) 76 | expect_equal(names(which(graph$parents["B",])), c("BC")) 77 | expect_equal(names(which(graph$parents["C",])), c("AC", "BC")) 78 | expect_equal(names(which(graph$parents["AC",])), c("ABC")) 79 | expect_equal(names(which(graph$parents["BC",])), c("ABC")) 80 | expect_equal(names(which(graph$parents["ABC",])), character(0)) 81 | 82 | expect_equal(graph$probs["C","AC"], c("a")) 83 | expect_equal(graph$probs["C","BC"], c("(1 - a)")) 84 | expect_equal(graph$probs["AC","C"], c("a")) 85 | expect_equal(graph$probs["BC","C"], c("(1 - a)")) 86 | 87 | }) 88 | 89 | test_that("we get errors when specifying an edge between non-existing nodes.", { 90 | leaves <- c("A", "B", "C") 91 | inner_nodes <- c("AC", "BC", "ABC") 92 | edges <- parent_edges(c(edge("A", "AC"), 93 | edge("B", "BC"), 94 | admixture_edge("C", "AC", "BC"), 95 | edge("AC", "x"), 96 | edge("BC", "ABC"))) 97 | admixtures <- admixture_proportions(c(admix_props("C", "AC", "BC", "a"))) 98 | 99 | expect_that(agraph(leaves, inner_nodes, edges, admixtures), throws_error()) 100 | }) 101 | 102 | test_that("we get errors when specifying admixture proportions for non-existing edges.", { 103 | leaves <- c("A", "B", "C") 104 | inner_nodes <- c("AC", "BC", "ABC") 105 | edges <- parent_edges(c(edge("A", "AC"), 106 | edge("B", "BC"), 107 | admixture_edge("C", "AC", "BC"), 108 | edge("AC", "ABC"), 109 | edge("BC", "ABC"))) 110 | admixtures <- admixture_proportions(c(admix_props("C", "ABC", "BC", "a"))) 111 | 112 | expect_that(agraph(leaves, inner_nodes, edges, admixtures), throws_error()) 113 | }) 114 | 115 | 116 | -------------------------------------------------------------------------------- /tests/testthat/test_path_overlaps.R: -------------------------------------------------------------------------------- 1 | context("Path overlaps") 2 | 3 | test_that("we can compute the overlap between paths.", { 4 | leaves <- c("A", "B", "C") 5 | inner_nodes <- c("AC", "BC", "ABC") 6 | edges <- matrix(ncol = 2, byrow=TRUE, 7 | data = c("A", "AC", 8 | "B", "BC", 9 | "C", "AC", "C", "BC", 10 | "AC", "ABC", 11 | "BC", "ABC")) 12 | admixture_proportions <- matrix(ncol = 3, byrow=TRUE, 13 | data = c("C", "AC", "a", "C", "BC", "(1-a)")) 14 | graph <- agraph(leaves, inner_nodes, edges, admixture_proportions) 15 | 16 | AB_paths <- all_paths(graph, "A", "B") 17 | CB_paths <- all_paths(graph, "C", "B") 18 | 19 | 20 | expect_equal(length(AB_paths), 1) 21 | expect_equal(length(CB_paths), 2) 22 | 23 | overlaps1 <- path_overlap(AB_paths[[1]], CB_paths[[1]]) 24 | overlaps2 <- path_overlap(AB_paths[[1]], CB_paths[[2]]) 25 | 26 | expect_equal(overlaps1$prob, c("a")) 27 | expect_equal(nrow(overlaps1$positive), 3) 28 | expect_equal(overlaps1$positive$from, c("ABC", "AC", "BC")) 29 | expect_equal(overlaps1$positive$to, c("BC", "ABC", "B")) 30 | expect_equal(nrow(overlaps1$negative), 0) 31 | 32 | expect_equal(overlaps2$prob, c("(1-a)")) 33 | expect_equal(nrow(overlaps2$positive), 1) 34 | expect_equal(overlaps2$positive$from, c("BC")) 35 | expect_equal(overlaps2$positive$to, c("B")) 36 | expect_equal(nrow(overlaps2$negative), 0) 37 | 38 | all_overlaps <- all_path_overlaps(AB_paths, CB_paths) 39 | 40 | expect_equal(all_overlaps[[1]], overlaps1) 41 | expect_equal(all_overlaps[[2]], overlaps2) 42 | }) 43 | 44 | -------------------------------------------------------------------------------- /tests/testthat/test_paths.R: -------------------------------------------------------------------------------- 1 | context("Paths") 2 | 3 | test_that("we can extract paths from a graph.", { 4 | 5 | leaves <- c("A", "B", "C") 6 | inner_nodes <- c("AC", "BC", "ABC") 7 | edges <- matrix(ncol = 2, byrow=TRUE, 8 | data = c("A", "AC", 9 | "B", "BC", 10 | "C", "AC", "C", "BC", 11 | "AC", "ABC", 12 | "BC", "ABC")) 13 | admixture_proportions <- matrix(ncol = 3, byrow=TRUE, 14 | data = c("C", "AC", "a", "C", "BC", "(1-a)")) 15 | graph <- agraph(leaves, inner_nodes, edges, admixture_proportions) 16 | 17 | AB_paths <- all_paths(graph, "A", "B") 18 | CB_paths <- all_paths(graph, "C", "B") 19 | 20 | expect_equal(length(AB_paths), 1) 21 | expect_equal(AB_paths[[1]]$from, c("A", "AC", "ABC", "BC")) 22 | expect_equal(AB_paths[[1]]$to, c("AC", "ABC", "BC", "B")) 23 | 24 | expect_equal(length(CB_paths), 2) 25 | expect_equal(CB_paths[[1]]$from, c("C", "AC", "ABC", "BC")) 26 | expect_equal(CB_paths[[1]]$to, c("AC", "ABC", "BC", "B")) 27 | expect_equal(CB_paths[[1]]$prob, c("a", "", "", "")) 28 | 29 | expect_equal(CB_paths[[2]]$from, c("C", "BC")) 30 | expect_equal(CB_paths[[2]]$to, c("BC", "B")) 31 | expect_equal(CB_paths[[2]]$prob, c("(1-a)", "")) 32 | 33 | }) 34 | -------------------------------------------------------------------------------- /tests/testthat/test_plots.R: -------------------------------------------------------------------------------- 1 | context("Graph plotting") 2 | 3 | test_that("trees plot fine.", { 4 | leaves <- c("A") 5 | inner_nodes <- c("Root") 6 | edges <- parent_edges(c(edge("A", "Root"))) 7 | admix <- NULL 8 | graph <- agraph(leaves, inner_nodes, edges, admix) 9 | plot(graph) 10 | 11 | leaves <- c("A", "B", "C") 12 | inner_nodes <- c("Root", "z", "y") 13 | edges <- parent_edges(c(edge("z", "Root"), 14 | edge("y", "z"), 15 | edge("A", "y"), 16 | edge("B", "y"), 17 | edge("C", "y"))) 18 | admix <- NULL 19 | graph <- agraph(leaves, inner_nodes, edges, admix) 20 | plot(graph) 21 | }) 22 | 23 | test_that("complex non-planar grahs plot fine.", { 24 | leaves <- c("A", "B") 25 | inner_nodes <- c("Root", "L", "R") 26 | edges <- parent_edges(c(edge("L", "Root"), 27 | edge("R", "Root"), 28 | admixture_edge("A", "L", "R"), 29 | admixture_edge("B", "L", "R"))) 30 | admix <- admixture_proportions(c(admix_props("A", "L", "R", "a"), 31 | admix_props("B", "L", "R", "b"))) 32 | graph <- agraph(leaves, inner_nodes, edges, admix) 33 | plot(graph) 34 | 35 | leaves <- c("A") 36 | inner_nodes <- c("Root", "L1", "R1", "L2", "R2") 37 | edges <- parent_edges(c(edge("L1", "Root"), 38 | edge("R1", "Root"), 39 | admixture_edge("L2", "L1", "R1"), 40 | admixture_edge("R2", "L1", "R1"), 41 | admixture_edge("A", "L2", "R2"))) 42 | admix <- admixture_proportions(c(admix_props("L2", "L1", "R1", "l"), 43 | admix_props("R2", "L1", "R1", "r"), 44 | admix_props("A", "L2", "R2", "a"))) 45 | graph <- agraph(leaves, inner_nodes, edges, admix) 46 | plot(graph, platform = 0) 47 | 48 | leaves <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J") 49 | inner_nodes <- c("Root", "L1", "R1", "L2", "R2", "Z") 50 | edges <- parent_edges(c(edge("L1", "Root"), 51 | edge("R1", "Root"), 52 | admixture_edge("L2", "L1", "R1"), 53 | admixture_edge("R2", "L1", "R1"), 54 | admixture_edge("Z", "L2", "R2"), 55 | edge("A", "Root"), 56 | edge("B", "Root"), 57 | edge("C", "Root"), 58 | edge("D", "L1"), 59 | edge("E", "R1"), 60 | edge("F", "L2"), 61 | edge("G", "R2"), 62 | edge("H", "Z"), 63 | edge("I", "Z"), 64 | edge("J", "Z"))) 65 | admix <- admixture_proportions(c(admix_props("L2", "L1", "R1", "l"), 66 | admix_props("R2", "L1", "R1", "r"), 67 | admix_props("Z", "L2", "R2", "z"))) 68 | graph <- agraph(leaves, inner_nodes, edges, admix) 69 | plot(graph) 70 | }) -------------------------------------------------------------------------------- /tests/testthat/test_signs.R: -------------------------------------------------------------------------------- 1 | context("Signs") 2 | 3 | test_that("we extract the right sign for f statistics.", { 4 | leaves <- c("A", "B", "C", "D") 5 | inner_nodes <- c("AC", "BC", "ABC") 6 | edges <- parent_edges(c(edge("A", "AC"), 7 | edge("B", "BC"), 8 | admixture_edge("C", "AC", "BC"), 9 | edge("AC", "ABC"), 10 | edge("BC", "ABC"), 11 | edge("D", "ABC"))) 12 | admix <- admixture_proportions(c(admix_props("C", "AC", "BC", "a"))) 13 | graph <- agraph(leaves, inner_nodes, edges, admix) 14 | 15 | expect_equal(overlaps_sign(f2(graph, "A", "B")), +1) 16 | expect_equal(overlaps_sign(f3(graph, "A", "B", "D")), +1) 17 | expect_that(overlaps_sign(f4(graph, "A", "B", "C", "D")), equals(NA)) 18 | expect_equal(overlaps_sign(f4(graph, "B", "D", "A", "C")), -1) 19 | expect_equal(overlaps_sign(f4(graph, "B", "D", "C", "A")), +1) 20 | }) 21 | -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/bears_graph-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/bears_graph-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/new_admixtures-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/new_admixtures-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/new_leaves-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/new_leaves-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/new_root-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/new_root-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-15-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-15-2.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-18-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-18-2.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-2.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-3.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-19-4.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/bears_graph-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/bears_graph-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/new_admixtures-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/new_admixtures-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/new_leaves-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/new_leaves-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/new_root-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/new_root-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-1-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-1-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-11-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-11-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-12-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-12-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-13-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-13-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-14-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-14-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-15-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-15-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-15-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-15-2.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-18-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-18-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-18-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-18-2.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-2.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-3.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-19-4.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-3-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-3-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-4-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-4-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-5-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-5-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-6-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-6-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-7-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-7-1.pdf -------------------------------------------------------------------------------- /vignettes/admixturegraph_files/figure-latex/unnamed-chunk-9-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mailund/admixture_graph/3ff9f1b7efb7ca9145d5f4ff40898469251940f7/vignettes/admixturegraph_files/figure-latex/unnamed-chunk-9-1.pdf -------------------------------------------------------------------------------- /vignettes/bibliography.bib: -------------------------------------------------------------------------------- 1 | @article{Patterson:ADMIXTOOLS, 2 | author = {Patterson, Nick and Moorjani, Priya and Luo, Yontao and Mallick, Swapan and Rohland, Nadin and Zhan, Yiping and Genschoreck, Teri and Webster, Teresa and Reich, David}, 3 | title = {{Ancient admixture in human history.}}, 4 | journal = {Genetics}, 5 | year = {2012}, 6 | volume = {192}, 7 | number = {3}, 8 | pages = {1065--1093}, 9 | month = sep, 10 | } 11 | 12 | @article{Cahill:2013ig, 13 | author = {Cahill, James A and Green, Richard E and Fulton, Tara L and Stiller, Mathias and Jay, Flora and Ovsyanikov, Nikita and Salamzade, Rauf and St John, John and Stirling, Ian and Slatkin, Montgomery and Shapiro, Beth}, 14 | title = {{Genomic evidence for island population conversion resolves conflicting theories of polar bear evolution.}}, 15 | journal = {PLoS Genet}, 16 | year = {2013}, 17 | volume = {9}, 18 | number = {3}, 19 | pages = {e1003345--e1003345}, 20 | month = mar 21 | } 22 | 23 | @article{Cahill:2014fo, 24 | author = {Cahill, James A and Stirling, Ian and Kistler, Logan and Salamzade, Rauf and Ersmark, Erik and Fulton, Tara L and Stiller, Mathias and Green, Richard E and Shapiro, Beth}, 25 | title = {{Genomic evidence of geographically widespread effect of gene flow from polar bears into brown bears.}}, 26 | journal = {Molecular Ecology}, 27 | year = {2015}, 28 | volume = {24}, 29 | number = {6}, 30 | pages = {1205--1217}, 31 | month = mar 32 | } 33 | 34 | --------------------------------------------------------------------------------