rohitsanj / doex
Showing 4 of 8 files from the diff.
Other files ignored by Codecov

@@ -1,11 +1,22 @@
 1 + `import numpy as np` 1 2 `import scipy.stats` 3 + `from statsmodels.stats.libqsturng import qsturng` 2 4 `from prettytable import PrettyTable` 5 + `from itertools import combinations` 3 6 4 7 5 8 `def p_value(f, dfn, dfd):` 6 9 ` return 1 - scipy.stats.f.cdf(f, dfn, dfd)` 7 10 8 11 12 + `def get_q_crit(k, df, alpha=0.05):` 13 + ` return qsturng(1 - alpha, k, df)` 14 + 15 + 16 + `def get_t_value(y1, y2, sigma, n1, n2):` 17 + ` return (y2 - y1) / (sigma * np.sqrt((1 / n1) + (1 / n2)))` 18 + 19 + 9 20 `def create_anova_table():` 10 21 ` float_format = ".4"` 11 22
@@ -24,3 +35,38 @@
 24 35 ` "p value",` 25 36 ` ]` 26 37 ` return table` 38 + 39 + 40 + `def create_multi_comparisons_table():` 41 + ` float_format = " .4"` 42 + 43 + ` table = PrettyTable()` 44 + ` table.float_format["t statistic"] = float_format` 45 + 46 + ` table.field_names = ["Treatment", "t statistic", ""]` 47 + ` return table` 48 + 49 + 50 + `def multiple_comparisons(treatments, treatments_data, error_dof, sigma_error, alpha=0.05):` 51 + ` treatment_map = {t: d for t, d in zip(treatments, treatments_data)}` 52 + ` treatment_means = {t: (np.average(d), len(d)) for t, d in treatment_map.items()}` 53 + 54 + ` k = len(treatment_means)` 55 + 56 + ` q_crit = get_q_crit(k, error_dof, alpha) / np.sqrt(2)` 57 + 58 + ` comparisons_list = list(combinations(treatments, 2))` 59 + 60 + ` t_values = {}` 61 + ` for pair in comparisons_list:` 62 + ` value1, degree1 = treatment_means[pair[0]]` 63 + ` value2, degree2 = treatment_means[pair[1]]` 64 + ` t = get_t_value(value1, value2, sigma_error, degree1, degree2)` 65 + ` t_values[pair] = (t, "Significant" if abs(t) > q_crit else "Not Significant")` 66 + 67 + ` table = create_multi_comparisons_table()` 68 + ` sorted_t_values = {k: v for k, v in sorted(t_values.items(), key=lambda item: item[0])}` 69 + ` for comp, t in sorted_t_values.items():` 70 + ` table.add_row(["{} vs {}".format(*comp), *t])` 71 + 72 + ` return table`

@@ -1,6 +1,6 @@
 1 1 `import numpy as np` 2 2 3 - `from .utils import p_value, create_anova_table` 3 + `from .utils import p_value, create_anova_table, multiple_comparisons` 4 4 5 5 6 6 `class CompletelyRandomizedDesign:`
@@ -35,6 +35,17 @@
 35 35 ` self.table = self._create_table()` 36 36 ` print(self.table)` 37 37 38 + ` def multiple_comparisons(self):` 39 + ` # Display multiple comparisons result` 40 + ` print(` 41 + ` multiple_comparisons(` 42 + ` list(range(1, len(self.entries) + 1)),` 43 + ` self.entries,` 44 + ` self.dof_error,` 45 + ` np.sqrt(self.mss_error),` 46 + ` )` 47 + ` )` 48 + 38 49 ` def _create_table(self):` 39 50 ` table = create_anova_table()` 40 51

@@ -1,6 +1,6 @@
 1 1 `import numpy as np` 2 2 3 - `from .utils import p_value, create_anova_table` 3 + `from .utils import p_value, create_anova_table, multiple_comparisons` 4 4 5 5 6 6 `class RandomizedCompleteBlockDesign:`
@@ -49,6 +49,19 @@
 49 49 ` self.table = self._create_table()` 50 50 ` print(self.table)` 51 51 52 + ` def multiple_comparisons(self):` 53 + ` # Multiple comparisons` 54 + ` n_treatments, _ = self.data.shape` 55 + 56 + ` print(` 57 + ` multiple_comparisons(` 58 + ` list(range(1, n_treatments + 1)),` 59 + ` self.data,` 60 + ` self.dof_error,` 61 + ` np.sqrt(self.mss_error),` 62 + ` )` 63 + ` )` 64 + 52 65 ` def _create_table(self):` 53 66 ` table = create_anova_table()` 54 67

@@ -1,10 +1,15 @@
 1 1 `import numpy as np` 2 2 3 - `from .utils import p_value, create_anova_table` 3 + `from .utils import (` 4 + ` p_value,` 5 + ` create_anova_table,` 6 + ` multiple_comparisons,` 7 + `)` 4 8 5 9 6 10 `class LatinSquare:` 7 - ` def __init__(self, treatments_order, treatments_values):` 11 + ` def __init__(self, treatments_order, treatments_values, alpha=0.05):` 12 + ` self.alpha = alpha` 8 13 ` self.treatments = list()` 9 14 ` self.treatments_order = np.array(treatments_order)` 10 15 ` self.treatments_values = np.array(treatments_values)`
@@ -80,6 +85,14 @@
 80 85 ` self.table = self._create_table()` 81 86 ` print(self.table)` 82 87 88 + ` def multiple_comparisons(self):` 89 + ` # Display multiple comparisons result` 90 + ` print(` 91 + ` multiple_comparisons(` 92 + ` self.treatments, self.treatments_data, self.dof_error, np.sqrt(self.mss_error)` 93 + ` )` 94 + ` )` 95 + 83 96 ` def _validate_treatments_order(self):` 84 97 ` for row in self.treatments_order:` 85 98 ` self.treatments = list(set(self.treatments + list(row)))`
Files Coverage
doex 100.00%
Project Totals (6 files) 100.00%
codecov-umbrella
Build #317381988 -
unittests
codecov-umbrella
Build #317381988 -
unittests
codecov-umbrella
Build #317381988 -
unittests