<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>get started using assigner • assigner</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="get started using assigner">
<meta property="og:description" content="assigner">
<meta property="og:image" content="/logo.png">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">assigner</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.5.8</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">Installation</a>
</li>
<li>
  <a href="../FEATURES.html">Features</a>
</li>
<li>
  <a href="../articles/get_started.html">Get started</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li>
      <a href="../articles/get_started.html">Get started</a>
    </li>
    <li>
      <a href="../articles/fst_confidence_intervals.html">Fst analysis</a>
    </li>
    <li>
      <a href="../articles/web_only/fst_comparisons.html">Comparisons of Fst in 8 packages/software</a>
    </li>
    <li>
      <a href="../articles/assignment.whitelists.html">Using whitelists in assignment</a>
    </li>
    <li>
      <a href="../articles/rad_genomics_computer_setup.html">Computer setup - Installation - Troubleshooting</a>
    </li>
    <li>
      <a href="../articles/life_cycle.html">Life cycle</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">News</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/thierrygosselin/assigner">
    <span class="fa fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><script src="get_started_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>get started using assigner</h1>
                        <h4 class="author">Thierry Gosselin</h4>
            
            <h4 class="date">2020-10-26</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/thierrygosselin/assigner/blob/master/vignettes/get_started.Rmd"><code>vignettes/get_started.Rmd</code></a></small>
      <div class="hidden name"><code>get_started.Rmd</code></div>

    </div>

    
    
<div id="objectives" class="section level1">
<h1 class="hasAnchor">
<a href="#objectives" class="anchor"></a>Objectives</h1>
<p>With this vignette, you should be able to learn the basics in under 30 minutes.</p>
<p>Assumptions:</p>
<ul>
<li>You’ve read the <a href="http://thierrygosselin.github.io/assigner/reference/assignment_ngs.html">function documentation on the web</a> or with <code><a href="../reference/assignment_ngs.html">?assigner::assignment_ngs</a></code>.</li>
<li>You’ve read Eric’s paper: Anderson EC (2010) Assessing the power of informative subsets of loci for population assignment: standard methods are upwardly biased. Molecular Ecology Resources, 10, 701–710.</li>
<li>
<strong>assigner</strong> is installed. If not, follow the <a href="http://thierrygosselin.github.io/assigner/">install instructions</a>.</li>
</ul>
</div>
<div id="prepare-your-workspace" class="section level1">
<h1 class="hasAnchor">
<a href="#prepare-your-workspace" class="anchor"></a>Prepare your workspace</h1>
<ul>
<li>clean your workspace <code><a href="https://rdrr.io/r/base/rm.html">rm(list = ls())</a></code>
</li>
<li>load assigner</li>
</ul>
<div class="sourceCode" id="cb1"><pre class="downlit">
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="http://thierrygosselin.github.io/assigner/">assigner</a></span><span class="op">)</span></pre></div>
<p>By default, the working directory is where the file for this vignette is. To change: <code><a href="https://rdrr.io/r/base/getwd.html">setwd("new path here")</a></code></p>
</div>
<div id="data-1-high-structure" class="section level1">
<h1 class="hasAnchor">
<a href="#data-1-high-structure" class="anchor"></a>Data 1: high structure</h1>
<p>For this exercise, we use the first dataset included in assigner. It’s a simulated dataset generated with <a href="https://thierrygosselin.github.io/grur/reference/simulate_rad.html">grur</a>. Details of the dataset are available using: <code><a href="../reference/data_assigner_sim_01.html">?assigner::data_assigner_sim_01</a></code>.</p>
<div class="sourceCode" id="cb2"><pre class="downlit">
<span class="va">data</span> <span class="op">&lt;-</span> <span class="va">data_assigner_sim_01</span></pre></div>
</div>
<div id="analysis-using-thl-with-gsi_sim" class="section level1">
<h1 class="hasAnchor">
<a href="#analysis-using-thl-with-gsi_sim" class="anchor"></a>Analysis using THL with <code>gsi_sim</code>
</h1>
<p>The analysis below uses the <strong>cross-validation technique</strong> called <em>Training, Holdout, Leave-one-out (THL)</em>:</p>
<ul>
<li>the <em>training</em> of the model is conducted on 0.8 (80%) of the samples (per strata/pops)</li>
<li>all the markers are ranked based on <a href="http://thierrygosselin.github.io/assigner/reference/fst_WC84.html">Fst</a>, only the training samples are used to generate the Fst.</li>
<li>the holdout samples consist of 0.2 or 20% of the samples. These are the samples assigned with <a href="https://github.com/eriqande/gsi_sim">gsi_sim</a>.</li>
<li>the process of taking a subsample of individuals (holdout and training set) to train the model and conduct the assigment analysis with <strong>gsi_sim</strong> is repeated 5 times (<code>iteration.method = 5</code>).</li>
</ul>
<p><code>gsi_sim</code> is not distributed with <strong>assigner</strong>, follow the <a href="http://thierrygosselin.github.io/assigner/">install instruction</a>, here for my mac it’s:</p>
<div class="sourceCode" id="cb3"><pre class="downlit">
<span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/install_gsi_sim.html">install_gsi_sim</a></span><span class="op">(</span>fromSource <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></pre></div>
<div id="no-subsampling" class="section level2">
<h2 class="hasAnchor">
<a href="#no-subsampling" class="anchor"></a>no subsampling</h2>
<div class="sourceCode" id="cb4"><pre class="downlit">
<span class="va">test1</span> <span class="op">&lt;-</span> <span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/assignment_ngs.html">assignment_ngs</a></span><span class="op">(</span>
  data <span class="op">=</span> <span class="va">data</span>,
  assignment.analysis <span class="op">=</span> <span class="st">"gsi_sim"</span>,
  markers.sampling <span class="op">=</span> <span class="st">"ranked"</span>, 
  thl <span class="op">=</span> <span class="fl">0.2</span>,
  iteration.method <span class="op">=</span> <span class="fl">5</span>
<span class="op">)</span>
<span class="co">#&gt;################################################################################</span>
<span class="co">#&gt;########################## assigner::assignment_ngs ############################</span>
<span class="co">#&gt;################################################################################</span>
<span class="co">#&gt;Execution date/time: 20190501@1104</span>
<span class="co">#&gt;Assignment analysis with gsi_sim</span>
<span class="co">#&gt;Folder created: assignment_analysis_method_ranked_20190501@1104</span>
<span class="co">#&gt;Calibrating REF/ALT alleles...</span>
<span class="co">#&gt;Subsampling: not selected</span>
<span class="co">#&gt;Conducting Assignment analysis using Training, Holdout, Leave-one-out</span>
<span class="co">#&gt;Using training samples to rank markers based on Fst</span>
<span class="co">#&gt;Holdout samples saved in your folder</span>
<span class="co">#&gt;Starting parallel computations, for progress monitor activity in folder...</span>
<span class="co">#&gt;</span>
<span class="co">#&gt;Computation time, overall: 7 sec</span>
<span class="co">#&gt;########################## assignment_ngs completed ############################</span></pre></div>
<p>By default, the function uses all the markers and all my CPUs - 1, to change this last behavior use the argument <code>parallel.core</code>.</p>
<p>The most important information that you’ll probably want to see are both returned in the working directory and the object. Not much is kept in the object <code>test1</code>, because disk space is cheap, memory is not!</p>
<div class="sourceCode" id="cb5"><pre class="downlit">
<span class="fu"><a href="https://rdrr.io/r/base/names.html">names</a></span><span class="op">(</span><span class="va">test1</span><span class="op">)</span>
<span class="co">#&gt;[1] "assignment"      "assignment.plot"</span></pre></div>
<p>Written in the working directory under <code>assignment_analysis_method_ranked_date@time</code>, where <code>date@time</code> is the date and time the function was run:</p>
<div class="sourceCode" id="cb6"><pre class="downlit">
<span class="co"># 01_radiator_tidy_genomic: folder</span>
<span class="co"># assigner_assignment_ngs_args_20190501@1102.tsv: tibble, file</span>
<span class="co"># assignment_1: folder</span>
<span class="co"># assignment_2: folder</span>
<span class="co"># assignment_3: folder</span>
<span class="co"># assignment_4: folder</span>
<span class="co"># assignment_5: folder</span>
<span class="co"># assignment.plot.pdf: figure</span>
<span class="co"># assignment.ranked.results.iterations.raw.tsv: tibble, file</span>
<span class="co"># assignment.ranked.results.iterations.summary.tsv: tibble, file</span>
<span class="co"># assignment.results.summary.stats.tsv: tibble, file</span>
<span class="co"># holdout.individuals.tsv: tibble, file</span></pre></div>
<p>These folders and files are detailed in the function documentation under <a href="http://thierrygosselin.github.io/assigner/reference/assignment_ngs.html#value">value</a> returned by the function.</p>
<p>To see the figure:</p>
<div class="sourceCode" id="cb7"><pre class="downlit">
<span class="va">test1</span><span class="op">$</span><span class="va">plot.assignment</span></pre></div>
<p><img src="assignment_thl_test1.png"></p>
<p>By default, the figure display the range of the data, to change this behavior and see the full range for the y axis:</p>
<div class="sourceCode" id="cb8"><pre class="downlit">
<span class="va">test1</span><span class="op">$</span><span class="va">plot.assignment</span> <span class="op">+</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html">scale_y_continuous</a></span><span class="op">(</span>limits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">100</span><span class="op">)</span><span class="op">)</span> </pre></div>
<p><img src="assignment_thl_test1_full_range.png"></p>
<ul>
<li>assignment is very high for all populations (the points are mean values and the error bar represent the SE based on the 5 iterations).</li>
<li>the horizontal facet display a <code>1</code>, because subsampling of the samples was not used, only 1 set was calculated with all samples. An example below will show something different.</li>
<li>the x-axis display the number of marker used <code>497</code>. Using <code><a href="https://dplyr.tidyverse.org/reference/n_distinct.html">dplyr::n_distinct(data$MARKERS)</a></code> shows that the dataset contains 500 markers, as description of the dataset suggest, so why a lower number was used? By default, the function will keep only polymorphic markers in common between strata/pops (<a href="http://thierrygosselin.github.io/assigner/reference/assignment_ngs.html#assumptions">doc</a>). Removing samples from the original simulated data, and low MAC result in losing 3 markers. If you want to clean the data before running the function:</li>
</ul>
<div class="sourceCode" id="cb9"><pre class="downlit">
<span class="va">data</span> <span class="op">%&lt;&gt;%</span> 
  <span class="fu">radiator</span><span class="fu">::</span><span class="fu"><a href="https://thierrygosselin.github.io/radiator/reference/filter_monomorphic.html">filter_monomorphic</a></span><span class="op">(</span>data <span class="op">=</span> <span class="va">.</span><span class="op">)</span> <span class="op">%&gt;%</span>
  <span class="fu">radiator</span><span class="fu">::</span><span class="fu"><a href="https://thierrygosselin.github.io/radiator/reference/filter_common_markers.html">filter_common_markers</a></span><span class="op">(</span>data <span class="op">=</span> <span class="va">.</span><span class="op">)</span>
<span class="co">#&gt;Filter monomorphic markers</span>
<span class="co">#&gt;Number of individuals / strata / chrom / locus / SNP:</span>
<span class="co">#&gt;    Blacklisted: 0 / 0 / NA / NA / 3</span>
<span class="co">#&gt;</span>
<span class="co">#&gt;Filter common markers:</span>
<span class="co">#&gt;Number of individuals / strata / chrom / locus / SNP:</span>
<span class="co">#&gt;    Blacklisted: 0 / 0 / 0 / 0 / 0</span></pre></div>
</div>
<div id="with-subsampling" class="section level2">
<h2 class="hasAnchor">
<a href="#with-subsampling" class="anchor"></a>with subsampling</h2>
<p>For the second test, we will test several marker numbers and use the subsampling arguments to select 30 individuals in each strata (repeating this 3 times).</p>
<div class="sourceCode" id="cb10"><pre class="downlit">
<span class="va">test2</span> <span class="op">&lt;-</span> <span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/assignment_ngs.html">assignment_ngs</a></span><span class="op">(</span>
  data <span class="op">=</span> <span class="va">data</span>,
  assignment.analysis <span class="op">=</span> <span class="st">"gsi_sim"</span>,
  markers.sampling <span class="op">=</span> <span class="st">"ranked"</span>, 
  thl <span class="op">=</span> <span class="fl">0.2</span>,
  iteration.method <span class="op">=</span> <span class="fl">5</span>, 
  marker.number <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">100</span>, <span class="fl">200</span>, <span class="fl">300</span>, <span class="fl">400</span>, <span class="st">"all"</span><span class="op">)</span>,
  subsample <span class="op">=</span> <span class="fl">30</span>, 
  iteration.subsample <span class="op">=</span> <span class="fl">3</span>
<span class="op">)</span>
<span class="co">#&gt; ################################################################################</span>
<span class="co">#&gt; ########################## assigner::assignment_ngs ############################</span>
<span class="co">#&gt; ################################################################################</span>
<span class="co">#&gt; Execution date/time: 20190501@1158</span>
<span class="co">#&gt; Assignment analysis with gsi_sim</span>
<span class="co">#&gt; Folder created: assignment_analysis_method_ranked_20190501@1158</span>
<span class="co">#&gt; Calibrating REF/ALT alleles...</span>
<span class="co">#&gt; Subsampling: selected</span>
<span class="co">#&gt;     using subsample size of: 30</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Analyzing subsample: 1</span>
<span class="co">#&gt; Conducting Assignment analysis using Training, Holdout, Leave-one-out</span>
<span class="co">#&gt; Using training samples to rank markers based on Fst</span>
<span class="co">#&gt; Holdout samples saved in your folder</span>
<span class="co">#&gt; Starting parallel computations, for progress monitor activity in folder...</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Analyzing subsample: 2</span>
<span class="co">#&gt; Conducting Assignment analysis using Training, Holdout, Leave-one-out</span>
<span class="co">#&gt; Using training samples to rank markers based on Fst</span>
<span class="co">#&gt; Holdout samples saved in your folder</span>
<span class="co">#&gt; Starting parallel computations, for progress monitor activity in folder...</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Analyzing subsample: 3</span>
<span class="co">#&gt; Conducting Assignment analysis using Training, Holdout, Leave-one-out</span>
<span class="co">#&gt; Using training samples to rank markers based on Fst</span>
<span class="co">#&gt; Holdout samples saved in your folder</span>
<span class="co">#&gt; Starting parallel computations, for progress monitor activity in folder...</span>
<span class="co">#&gt; </span>
<span class="co">#&gt; Computation time, overall: 19 sec</span>
<span class="co">#&gt; ########################## assignment_ngs completed ############################</span></pre></div>
<p>The object generated is similar to the analysis witout subsampling. The output folder is different. The subsample folders have the same content as the output of the analysis witout subsampling.</p>
<div class="sourceCode" id="cb11"><pre class="downlit">
<span class="co"># 01_radiator_tidy_genomic: folder</span>
<span class="co"># assigner_assignment_ngs_args_20190501@1540.tsv: tibble, file</span>
<span class="co"># assignment.plot.pdf: figure</span>
<span class="co"># assignment.ranked.results.summary.stats.all.subsamples.tsv: tibble, file</span>
<span class="co"># assignment.results.summary.stats.tsv: tibble, file</span>
<span class="co"># subsample_1: folder</span>
<span class="co"># subsample_2: folder</span>
<span class="co"># subsample_3: folder</span>
<span class="co"># subsampling_individuals.tsv: tibble, file</span></pre></div>
<p>To view the figure:</p>
<div class="sourceCode" id="cb12"><pre class="downlit">
<span class="va">test2</span><span class="op">$</span><span class="va">plot.assignment</span> <span class="op">+</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html">scale_y_continuous</a></span><span class="op">(</span>limits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">100</span><span class="op">)</span><span class="op">)</span> </pre></div>
<p><img src="assignment_thl_test2.png"></p>
<ul>
<li>The last vertical and horizontal facets are the mean assignment for all the subsampling iterations and mean assignment over populations, respectively.</li>
<li>With the last plot, in the lower right corner, corresponding to the overall average (subsampling and strata/pops).</li>
<li>the number of markers doesn’t affect the assignment analysis, the top 100 markers are as good as using all the 497 markers. Keep in mind that this is rarely the case with real datasets…</li>
</ul>
<p>This dataset as a high overall Fst value:</p>
<div class="sourceCode" id="cb13"><pre class="downlit">
<span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/fst_WC84.html">fst_WC84</a></span><span class="op">(</span><span class="va">data</span><span class="op">)</span> <span class="op">%$%</span> <span class="va">fst.overall</span><span class="op">$</span><span class="va">FST</span>
<span class="co">#&gt;[1] 0.39603</span></pre></div>
<p>The look of the membership probabilities with <code>adegenet</code> dapc analysis would show something similar to this:</p>
<p><img src="membership_dataset1.png"></p>
</div>
</div>
<div id="data-2-low-structure" class="section level1">
<h1 class="hasAnchor">
<a href="#data-2-low-structure" class="anchor"></a>Data 2: low structure</h1>
<p>Let’s try the same analysis, but this time with a dataset with lower Fst. It’s a simulated dataset generated with <a href="https://thierrygosselin.github.io/grur/reference/simulate_rad.html">grur</a>. Details of the dataset are available using: <code><a href="../reference/data_assigner_sim_02.html">?assigner::data_assigner_sim_02</a></code>.</p>
<div class="sourceCode" id="cb14"><pre class="downlit">
<span class="va">data</span> <span class="op">&lt;-</span> <span class="va">data_assigner_sim_02</span></pre></div>
</div>
<div id="analysis-using-thl-with-gsi_sim-1" class="section level1">
<h1 class="hasAnchor">
<a href="#analysis-using-thl-with-gsi_sim-1" class="anchor"></a>Analysis using THL with <code>gsi_sim</code>
</h1>
<div class="sourceCode" id="cb15"><pre class="downlit">
<span class="va">test3</span> <span class="op">&lt;-</span> <span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/assignment_ngs.html">assignment_ngs</a></span><span class="op">(</span>
  data <span class="op">=</span> <span class="va">data</span>,
  assignment.analysis <span class="op">=</span> <span class="st">"gsi_sim"</span>,
  markers.sampling <span class="op">=</span> <span class="st">"ranked"</span>, 
  thl <span class="op">=</span> <span class="fl">0.2</span>,
  iteration.method <span class="op">=</span> <span class="fl">5</span>, 
  marker.number <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">100</span>, <span class="fl">200</span>, <span class="fl">300</span>, <span class="fl">400</span>, <span class="st">"all"</span><span class="op">)</span>,
  subsample <span class="op">=</span> <span class="fl">30</span>, 
  iteration.subsample <span class="op">=</span> <span class="fl">3</span>
<span class="op">)</span></pre></div>
<p>To view the figure:</p>
<div class="sourceCode" id="cb16"><pre class="downlit">
<span class="va">test3</span><span class="op">$</span><span class="va">plot.assignment</span> <span class="op">+</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html">scale_y_continuous</a></span><span class="op">(</span>limits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">100</span><span class="op">)</span><span class="op">)</span> 
<span class="co"># &lt;img src="assignment_thl_test3.png"&gt;: works</span>
<span class="co">#![](assignment_thl_test3.png): works</span>
<span class="co">#knitr::include_graphics("assignment_thl_test3.png"):works</span></pre></div>
<p><img src="assignment_thl_test3.png" width="282"></p>
<ul>
<li>Very different overall results…</li>
<li>For the assignment analysis of species exhibiting overall low structure, using more markers will, generally, help the assingnment (if the data is filtered correctly…)</li>
</ul>
<p>This is the overall Fst value:</p>
<div class="sourceCode" id="cb17"><pre class="downlit">
<span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/fst_WC84.html">fst_WC84</a></span><span class="op">(</span><span class="va">data</span><span class="op">)</span> <span class="op">%$%</span> <span class="va">fst.overall</span><span class="op">$</span><span class="va">FST</span>
<span class="co">#&gt;[1] 0.001320833</span></pre></div>
<p>This is the membership probabilities with <code>adegenet</code> dapc analysis:</p>
<p><img src="membership_dataset2.png"></p>
<p>The populations are very admixed because of the high migration rate used during the simulations.</p>
</div>
<div id="analysis-using-loo-with-gsi_sim" class="section level1">
<h1 class="hasAnchor">
<a href="#analysis-using-loo-with-gsi_sim" class="anchor"></a>Analysis using LOO with gsi_sim</h1>
<p>Let’s try using the <em>Leave-One-Out</em> cross-validation technique with dataset2. With this method, there is no potential bias during marker selection, you can used all the markers with <code>marker.number = "all"</code> or a string of marker numbers like the example above, but here, there’s no point in using less markers randomly.</p>
<p>The <em>Leave-One-Out</em> method means that the allele frequencies are calculated without the sample being assigned. This is repeated for each sample.</p>
<div class="sourceCode" id="cb18"><pre class="downlit">
<span class="va">test4</span> <span class="op">&lt;-</span> <span class="fu">assigner</span><span class="fu">::</span><span class="fu"><a href="../reference/assignment_ngs.html">assignment_ngs</a></span><span class="op">(</span>
  data <span class="op">=</span> <span class="va">data</span>,
  assignment.analysis <span class="op">=</span> <span class="st">"gsi_sim"</span>,
  markers.sampling <span class="op">=</span> <span class="st">"random"</span>, 
  marker.number <span class="op">=</span> <span class="st">"all"</span>
<span class="op">)</span>
<span class="co">#&gt; ################################################################################</span>
<span class="co">#&gt; ########################## assigner::assignment_ngs ############################</span>
<span class="co">#&gt; ################################################################################</span>
<span class="co">#&gt; Execution date/time: 20190501@1317</span>
<span class="co">#&gt; Assignment analysis with gsi_sim</span>
<span class="co">#&gt; Folder created: assignment_analysis_method_random_20190501@1317</span>
<span class="co">#&gt; Calibrating REF/ALT alleles...</span>
<span class="co">#&gt; Subsampling: not selected</span>
<span class="co">#&gt; Conducting Assignment analysis with markers selected randomly</span>
<span class="co">#&gt; Making a list containing all the markers combinations</span>
<span class="co">#&gt; Starting parallel computations, for progress monitor activity in folder...</span>
<span class="co">#&gt; Summarizing the assignment analysis results by iterations and marker group</span>
<span class="co">#&gt; Compiling results</span>
<span class="co">#&gt; ########################## assignment_ngs completed ############################</span></pre></div>
<p>To view the figure:</p>
<div class="sourceCode" id="cb19"><pre class="downlit">
<span class="va">test4</span><span class="op">$</span><span class="va">plot.assignment</span> <span class="op">+</span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html">scale_y_continuous</a></span><span class="op">(</span>limits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">100</span><span class="op">)</span><span class="op">)</span> </pre></div>
<p><img src="assignment_loo_test4.png" width="329"></p>
<p>Conclusion: not much to gain here by using the LOO…</p>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

        <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
    </nav>
</div>

</div>



      <footer><div class="copyright">
  <p>Developed by Thierry Gosselin.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>

      </footer>
</div>

  


  </body>
</html>
