Skip to content

Commit

Permalink
rfctr: change std_dev and std_err to table_std_dev and table_std_err
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed May 7, 2020
1 parent 2aa5409 commit 3e04803
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 153 deletions.
109 changes: 58 additions & 51 deletions src/cr/cube/cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,6 @@ def pairwise_indices(self):
self, alpha=alpha, only_larger=only_larger
).pairwise_indices

@lazyproperty
def scale_mean_pairwise_indices(self):
alpha = self._transforms_dict.get("pairwise_indices", {}).get("alpha", 0.05)
only_larger = self._transforms_dict.get("pairwise_indices", {}).get(
"only_larger", True
)
return NewPairwiseSignificance(
self, alpha=alpha, only_larger=only_larger
).scale_mean_pairwise_indices

@lazyproperty
def pairwise_significance_tests(self):
"""tuple of _ColumnPairwiseSignificance tests.
Expand Down Expand Up @@ -360,20 +350,14 @@ def scale_means_column(self):
return inner / denominator

@lazyproperty
def var_scale_means_column(self):
if np.all(np.isnan(self._columns_dimension_numeric)):
return None

not_a_nan_index = ~np.isnan(self._columns_dimension_numeric)
col_dim_numeric = self._columns_dimension_numeric[not_a_nan_index]

numerator = self.counts[:, not_a_nan_index] * pow(
np.broadcast_to(col_dim_numeric, self.counts[:, not_a_nan_index].shape)
- self.scale_means_column.reshape(-1, 1),
2,
def scale_mean_pairwise_indices(self):
alpha = self._transforms_dict.get("pairwise_indices", {}).get("alpha", 0.05)
only_larger = self._transforms_dict.get("pairwise_indices", {}).get(
"only_larger", True
)
denominator = np.sum(self.counts[:, not_a_nan_index], axis=1)
return np.nansum(numerator, axis=1) / denominator
return NewPairwiseSignificance(
self, alpha=alpha, only_larger=only_larger
).scale_mean_pairwise_indices

@lazyproperty
def scale_means_columns_margin(self):
Expand All @@ -400,26 +384,6 @@ def scale_means_row(self):
denominator = np.sum(self.counts[not_a_nan_index, :], axis=0)
return inner / denominator

@lazyproperty
def var_scale_means_row(self):
if np.all(np.isnan(self._rows_dimension_numeric)):
return None

not_a_nan_index = ~np.isnan(self._rows_dimension_numeric)
row_dim_numeric = self._rows_dimension_numeric[not_a_nan_index]
numerator = (
self.counts[not_a_nan_index, :]
* pow(
np.broadcast_to(
row_dim_numeric, self.counts[not_a_nan_index, :].T.shape
)
- self.scale_means_row.reshape(-1, 1),
2,
).T
)
denominator = np.sum(self.counts[not_a_nan_index, :], axis=0)
return np.nansum(numerator, axis=0) / denominator

@lazyproperty
def scale_means_rows_margin(self):
if np.all(np.isnan(self._rows_dimension_numeric)):
Expand All @@ -440,14 +404,6 @@ def scale_means_rows_margin(self):
def shape(self):
return self.counts.shape

@lazyproperty
def standard_deviation(self):
return np.array([row.standard_deviation for row in self._matrix.rows])

@lazyproperty
def standard_error(self):
return np.array([row.standard_error for row in self._matrix.rows])

@lazyproperty
def summary_pairwise_indices(self):
alpha = self._transforms_dict.get("pairwise_indices", {}).get("alpha", 0.05)
Expand Down Expand Up @@ -529,6 +485,50 @@ def table_percentages(self):
def table_proportions(self):
return np.array([row.table_proportions for row in self._matrix.rows])

@lazyproperty
def table_std_dev(self):
return np.array([row.table_std_dev for row in self._matrix.rows])

@lazyproperty
def table_std_err(self):
return np.array([row.table_std_err for row in self._matrix.rows])

@lazyproperty
def var_scale_means_column(self):
if np.all(np.isnan(self._columns_dimension_numeric)):
return None

not_a_nan_index = ~np.isnan(self._columns_dimension_numeric)
col_dim_numeric = self._columns_dimension_numeric[not_a_nan_index]

numerator = self.counts[:, not_a_nan_index] * pow(
np.broadcast_to(col_dim_numeric, self.counts[:, not_a_nan_index].shape)
- self.scale_means_column.reshape(-1, 1),
2,
)
denominator = np.sum(self.counts[:, not_a_nan_index], axis=1)
return np.nansum(numerator, axis=1) / denominator

@lazyproperty
def var_scale_means_row(self):
if np.all(np.isnan(self._rows_dimension_numeric)):
return None

not_a_nan_index = ~np.isnan(self._rows_dimension_numeric)
row_dim_numeric = self._rows_dimension_numeric[not_a_nan_index]
numerator = (
self.counts[not_a_nan_index, :]
* pow(
np.broadcast_to(
row_dim_numeric, self.counts[not_a_nan_index, :].T.shape
)
- self.scale_means_row.reshape(-1, 1),
2,
).T
)
denominator = np.sum(self.counts[not_a_nan_index, :], axis=0)
return np.nansum(numerator, axis=0) / denominator

@lazyproperty
def zscore(self):
return np.array([row.zscore for row in self._matrix.rows])
Expand Down Expand Up @@ -590,6 +590,13 @@ def _transforms_dict(self):
"""
return self._transforms_arg if self._transforms_arg is not None else {}

@lazyproperty
def _variance(self):
"""Returns the variance for cell percentages
`variance = p * (1-p)`
"""
return self.counts / self.table_margin * (1 - self.counts / self.table_margin)


class _Strand(CubePartition):
"""1D cube-partition.
Expand Down
Loading

0 comments on commit 3e04803

Please sign in to comment.