.. Source code docs ##################### Source Code Reference ##################### .. contents:: :depth: 5 src.language.utils ================== The NIAID Stats Calculator supports I18n internationalization. It currently provides English and Spanish translations. The translation files are stored in the locales folder. .. js:autofunction:: setLocale .. js:autofunction:: getCurrentLocale .. js:autofunction:: isRTL .. js:autofunction:: translateHeaderText src.components ============== The React Native components that comprise the views in the application. ************************* src.components.Navigation ************************* The Navigation component that defines the top NavBar. ******************************* src.components.ResultsContainer ******************************* The component that will display the results of the equations. *************************** src.components.fishersExact *************************** The components that define the input form area and input form for the Fishers Exact Test. src.components.fishersExact.FishersExactContainer ------------------------------------------------- The form container. src.components.fishersExact.FishersInputForm -------------------------------------------- The component that defines the input form for the Fishers Exact Test. *********************** src.components.studentT *********************** The components that define the input form area and input form for the Fishers Exact Test. src.components.studentT.StudentTContainer ----------------------------------------- The form container. src.components.studentT.StudentTInputForm ----------------------------------------- The component that defines the input form for the Student's t-test. src.lib ======= The JavaScript code that does all of the math and related heavy lifting lives here. ************* src.lib.utils ************* A utilities file containing generic functions used by the stats package. It exports asVector and toScientific. .. js:autofunction:: flattenArray .. js:autofunction:: asVector .. js:autofunction:: round .. js:autofunction:: toScientific ***************** src.lib.studentst ***************** Calculates the Student's t-test statistic, degrees of freedom, and p-value. .. js:autofunction:: calcTStatistic .. js:autofunction:: calcDf .. js:autofunction:: calcPvalue *************** src.lib.fishers *************** Calculates the Fishers Exact two tailed, left tailed, and right tailed tests using the equation .. math:: p= \frac {( a + b )! ( c + d )! ( a + c )! ( b + d )!} {a ! b ! c ! d ! N !} where a, b, c, d are the individual frequencies and N is the total frequency .. list-table:: :widths: 3 7 7 30 :header-rows: 1 * - - group 1 - group 2 - * - pos - a - b - a+b * - neg - c - d - c+d * - - a+c - b+d - N = (a+b)+(c+d) = (a+c)+(b+d) to calculate the probability of a given matrix. Based on the gist by Sukumaran, J. and M. T. Holder at https://gist.github.com/jeetsukumaran/2189099. References related to the calculation of the Fishers Exact test and when to use it: https://software.broadinstitute.org/gatk/documentation/article.php?id=8056 http://www.biostathandbook.com/fishers.html https://onlinecourses.science.psu.edu/stat504/node/89/ http://vassarstats.net/tab2x2.html .. js:autofunction:: binomialCoefficient .. js:autofunction:: hypergeometricPMF .. js:autofunction:: rotateCW .. js:autofunction:: minRotation .. js:autofunction:: shallowCopy .. js:autofunction:: getLeftTailProbs .. js:autofunction:: getRightTailProbs .. js:autofunction:: calcSingleTailP .. js:autofunction:: calcTwoTailP .. js:autofunction:: calcOddsAndCI ************* src.lib.chiSq ************* Calculates `Pearson's Chi-squared with Yates correction`_ using the equation .. math:: X^2_{Yates} = \frac {N(|ad-bc|-\frac {N} {2})^2} {NsNfNaNb} for a 2x2 table of observed values like: .. list-table:: :widths: 1 2 2 2 :header-rows: 1 * - - S - F - * - A - a - b - Na * - B - c - d - Nb * - - Ns - Nf - N where :math:`Na = a + b, Nb = c + d, Ns = a + c, Nf = b + d, N = Na + Nb = Ns + Nf` The degrees of freedom, which is equal to the number of rows minus one times the number of columns minus one (e.g. :math:`(R-1)*(C-1)`), is fixed at 1 for a 2x2 table. The p-value calculation is taken from https://www.codeproject.com/Articles/432194/How-to-Calculate-the-Chi-Squared-P-Value and translated into JS. .. js:autofunction:: calcChiSqYatesValue .. js:autofunction:: computePvalue ************* src.lib.stats ************* These libraries contain the generic math functions needed to perform the statistical tests. Many of these functions were translated from `R`_ or borrowed from the `jStat`_ library. Exports jStat and mle modules. src.lib.stats.jstatFunc ----------------------- These are mostly generic statistical functions. .. js:autofunction:: gammaln .. js:autofunction:: igamma .. js:autofunction:: betaln .. js:autofunction:: betacf .. js:autofunction:: ibeta .. js:autofunction:: pnorm The final two methods in jStatFunc are submethods required by the pnorm calculation. .. js:autofunction:: doDel .. js:autofunction:: swapTail src.lib.stats.mle ----------------- Defines all functions needed to calculate the Maximum Likelihood Estimate and confidence interval for the Fisher's Exact Test. These calculations are translations from `R`_ for use in React Native. The Maximum Likelihood Estimate is used to approximate the odds ratio. There are two distinct groupings of methods in the mle file. The first are the statistical calculations that the odds ratio and confidence interval calculations depend on: .. js:autofunction:: bd0 .. js:autofunction:: stirlerr .. js:autofunction:: dbinom .. js:autofunction:: dhyper .. js:autofunction:: dnhyper .. js:autofunction:: mnhyper .. js:autofunction:: pdhyper .. js:autofunction:: phyper .. js:autofunction:: pnhyper .. js:autofunction:: zeroin2 .. js:autofunction:: sign .. js:autofunction:: uniroot The second grouping contains the actual calculations of the odds ratio and confidence interval: .. js:autofunction:: calcOddsRatio .. js:autofunction:: calcNCPUpper .. js:autofunction:: calcNCPLower src.styles ========== Contains the style definitions for the components. ****************************** src.styles.formContainerStyles ****************************** Defines the styles for the Container components. ********************* src.styles.formStyles ********************* Defines the styles for the input forms components. ********************************* src.styles.resultsContainerStyles ********************************* Defines the styles for the ResultsContainer component. src.templates ============= Contains the templates used by the components. *************************** src.templates.horizontalrow *************************** The template used by the input forms components that allows for a side-by-side layout of the input fields. References ========== .. target-notes:: .. _`Pearson's Chi-squared with Yates correction`: https://en.wikipedia.org/wiki/Yates%27s_correction_for_continuity .. _`R`: https://www.r-project.org/ .. _`jStat`: https://github.com/jstat/jstat