This vignette will introduce you to how the package mixIndependR
will build and compare the observed and expected distributions for number of heterozygous loci (K) and number of shared alleles (X).
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(mixIndependR) library(ggplot2)
With required parameters obtained from "basic genetics" part, observed and expected distributions can be built:
x <- mixexample p <- AlleleFreq(x) h <-Heterozygous(x) H <- RxpHetero(h,p,HWE=FALSE) AS<-AlleleShare(x,replacement =FALSE) e <-RealProAlleleShare(AS)
FreqHetero
and DistHetero
build the observed and expected distribution for number of heterozygous loci (K).
ObsDist_K<-FreqHetero(h) ExpDist_K<- DistHetero(H)
FreqAlleleShare
and DistAlleleShare
build the observed and expected distribution for number of shared alleles (X).
ObsDist_X<-FreqAlleleShare(AS) ExpDist_X<-DistAlleleShare(e)
ComposPare
s convert the above distributions into a format suitable for visualization. With the trans=TRUE
, the observed frequencies and the expected density would be in separate columns. If trans=FALSE
, two variables would be “OvE” (denoting the status of “observed or expected”) and “frequencies”.
df_K <- ComposPare_K(h,ExpDist_K,trans = F) df_X <- ComposPare_X(AS,ExpDist_X,trans = F)
ggplot(df_K,aes(x=freq))+ geom_histogram(aes(y=..density..,color=OvE,fill=OvE),alpha=0.5,binwidth = 1,position = "identity")+ ggtitle("No. of Heterozyous loci")+ xlab("No. of Heterozygous Loci(K)")+ylab("Density/Probability")+ stat_function(data=ExpDist_K,mapping = aes(x=K,y=Density),fun = splinefun(ExpDist_K$K,ExpDist_K$Density),color="Red") ggplot(df_X,aes(x=freq))+ geom_histogram(aes(y=..density..,color=OvE,fill=OvE),alpha=0.5,binwidth = 1,position = "identity")+ ggtitle("No. of Shared Alleles")+ xlab("No. of Shared Alleles(X)")+ylab("Density/Probability")+ stat_function(data=ExpDist_X,mapping = aes(x=X,y=Density),fun = splinefun(ExpDist_X$X,ExpDist_X$Density),color="Red")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.