--- title: "Hypothesis Test" description: output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Hypothesis Test} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- This vignette will introduce you to find the critical value for comparison of observed and expected obtained last step. ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r load package,include = FALSE} library(mixIndependR) library(ggplot2) ``` ```{r preparation, include=FALSE} x <- mixexample p <- AlleleFreq(x) h <-Heterozygous(x) H <- RxpHetero(h,p,HWE=FALSE) AS<-AlleleShare(x,replacement=FALSE) e <-RealProAlleleShare(AS) ObsDist_K<-FreqHetero(h) ExpDist_K<- DistHetero(H) ObsDist_X<-FreqAlleleShare(AS) ExpDist_X<-DistAlleleShare(e) ``` `Simulate_DistK` and `Simulate_DistX` simulate bundles of expected distributions for number of heterozygous loci and number of shared alleles respectively. ```{r Simulation} Simu_K <- Simulate_DistK(H,100,500) Simu_X <- Simulate_DistX(e,100,500) ``` `Dist_SimuChisq` generates a bundle of chi-square values which can be distributed. `ecdf` build the cumulative probability functions for the chi-square values. ```{r Chi-square} x2_K<-Dist_SimuChisq(Simu_K,ExpDist_K$Density,200) x2_X<-Dist_SimuChisq(Simu_X,ExpDist_X$Density,200) P1<-ecdf(x2_K) P2<-ecdf(x2_X) ``` ```{r Last plot, echo=FALSE, fig.height=4, fig.show='hold', fig.width=3} x <- c(0:200) dfX2 <- data.frame(x=x,y=P1(x)) ggplot(dfX2,aes(x=x,y=P1(x)))+ geom_line()+ geom_hline(yintercept = 0.95,color="Red")+ ggtitle("CPF No. of Heterozygous Loci")+ xlab("Chi-square")+ylab("1-p-value") dfX22 <- data.frame(x=x,y=P2(x)) ggplot(dfX22,aes(x=x,y=P2(x)))+ geom_line()+ geom_hline(yintercept = 0.95,color="Red")+ ggtitle("CPF No. of Shared Alleles")+ xlab("Chi-square")+ylab("1-p-value") ```