-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* drive by TDD (add failing tests) * implement functionality as separate properties
- Loading branch information
1 parent
9745bb1
commit a2379f7
Showing
3 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,6 +459,18 @@ def population_counts(self): | |
self.table_proportions * self._population * self._cube.population_fraction | ||
) | ||
|
||
@lazyproperty | ||
def population_moe(self): | ||
"""2D np.float64 ndarray of population margin-of-error (MoE) for table percents. | ||
The values are represented as population estimates, analogue to the `population_counts` | ||
property. This means that the values will be presented by actual estimated counts of the population | ||
The values can be np.nan when the corresponding percentage is also np.nan, which | ||
happens when the respective table margin is 0. | ||
""" | ||
total_filtered_population = self._population * self._cube.population_fraction | ||
return Z_975 * total_filtered_population * self.table_std_err | ||
|
||
@lazyproperty | ||
def pvals(self): | ||
return np.array([row.pvals for row in self._matrix.rows]) | ||
|
@@ -526,6 +538,22 @@ def rows_dimension_type(self): | |
def rows_margin(self): | ||
return np.array([row.margin for row in self._matrix.rows]) | ||
|
||
@lazyproperty | ||
def rows_percentages_moe(self): | ||
"""2D np.float64 ndarray of margin-of-error (MoE) for rows percentages. | ||
The values are represented as percentages, analogue to the `row_percentages` | ||
property. This means that the value of 3.5% will have the value 3.5 (not 0.035). | ||
The values can be np.nan when the corresponding percentage is also np.nan, which | ||
happens when the respective table margin is 0. | ||
""" | ||
return Z_975 * 100 * self.rows_std_err | ||
|
||
@lazyproperty | ||
def rows_std_err(self): | ||
"""2D np.float64 ndarray of standard errors for row percentages """ | ||
return np.sqrt(self._rows_variance / self.rows_margin[:, None]) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
scanny
Contributor
|
||
|
||
@lazyproperty | ||
def scale_mean_pairwise_indices(self): | ||
"""Sequence of column-idx tuples indicating pairwise-t result of scale-means. | ||
|
@@ -900,6 +928,12 @@ def _columns_variance(self): | |
self.counts / self.columns_margin * (1 - self.counts / self.columns_margin) | ||
) | ||
|
||
@lazyproperty | ||
def _rows_variance(self): | ||
"""ndarray of variances for row percentages""" | ||
margin = self.rows_margin[:, None] | ||
return self.counts / margin * (1 - self.counts / margin) | ||
|
||
@lazyproperty | ||
def _dimensions(self): | ||
"""tuple of (rows_dimension, columns_dimension) Dimension objects.""" | ||
|
@@ -1006,6 +1040,19 @@ def population_counts(self): | |
* self._cube.population_fraction | ||
) | ||
|
||
@lazyproperty | ||
def population_moe(self): | ||
"""1D np.float64 ndarray of population margin-of-error (MoE) for table percents. | ||
The values are represented as population estimates, analogue to the | ||
`population_counts` property. This means that the values will be presented by | ||
actual estimated counts of the population The values can be np.nan when the | ||
corresponding percentage is also np.nan, which happens when the respective | ||
table margin is 0. | ||
""" | ||
total_filtered_population = self._population * self._cube.population_fraction | ||
return Z_975 * total_filtered_population * self.standard_error | ||
|
||
@lazyproperty | ||
def row_base(self): | ||
return np.array([row.base for row in self._stripe.rows]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why does this have to be sliced
[:, None]
?We are seeing some curious behavior of row se and moe that I think could be coming from something off here.