title: Correct formula for summation in R, calculating polymorphism information content (PIC)
body: <p>(Genomics data jargon warning!) I am calculating the polymorphism information content (PIC) in R from a dataset of thousands of single nucleotide polymorphisms (SNPs). The data needed to make the calculation is allele frequencies. Each observation has two (rarely three) allele types either the reference or the 1st alternative. I have a small number with a 2nd alternative allele. This is the formula I am trying to code in R: <a href="https://i.stack.imgur.com/umMkR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/umMkR.png" alt="PIC formula" /></a> <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1686077/?page=7" rel="nofollow noreferrer">original publication</a></p>
  <p>where Pi and Pj are the frequencies of ith and jth alleles for the selected SNP marker. This is my current formulation in R</p>
  <pre><code>var_freq$PIC &lt;- (1-(var_freq$a2^2)-(1-var_freq$a2)^2)-(2*(var_freq$a2^2)*(1-(var_freq$a2^2))))
  </code></pre>
  <p>Where the variable <code>a2</code> is the alternative allele frequency.</p>
  <p>The test dataset: a1 is reference allele, a2 is the alternative (still ignoring the a3 the 2nd alternative allele)</p>
  <pre><code>library(tidyverse)
  set.seed(123)
  testdata &lt;- data.frame(a1=rnorm(n=10000, mean = .99, sd=0.15)) %&gt;% 
    filter(., a1&lt;1&amp;a1&gt;0) %&gt;% 
    mutate(., a2=1-a1)
  </code></pre>
  <p>Is this the correct R code formulation for the PIC value, i.e. am I interpreting the formula right?</p>