Skip to content

Commit f3e8b03

Browse files
committed
Work on docstrings
1 parent 77d93c3 commit f3e8b03

File tree

1 file changed

+84
-16
lines changed

1 file changed

+84
-16
lines changed

statsmodels/stats/contingency_tables.py

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,16 @@ def test_ordinal_association(self, row_scores=None, col_scores=None):
294294

295295
@cache_readonly
296296
def marginal_probabilities(self):
297-
# docstring for cached attributes in init above
297+
"""
298+
Estimate marginal probability distributions for the rows and columns.
299+
300+
Returns
301+
-------
302+
row : ndarray
303+
Marginal row probabilities
304+
col : ndarray
305+
Marginal column probabilities
306+
"""
298307

299308
n = self.table.sum()
300309
row = self.table.sum(1) / n
@@ -308,7 +317,13 @@ def marginal_probabilities(self):
308317

309318
@cache_readonly
310319
def independence_probabilities(self):
311-
# docstring for cached attributes in init above
320+
"""
321+
Returns fitted joint probabilities under independence.
322+
323+
The returned table is outer(row, column), where row and
324+
column are the estimated marginal distributions
325+
of the rows and columns.
326+
"""
312327

313328
row, col = self.marginal_probabilities
314329
itab = np.outer(row, col)
@@ -321,37 +336,60 @@ def independence_probabilities(self):
321336

322337
@cache_readonly
323338
def fittedvalues(self):
324-
# docstring for cached attributes in init above
339+
"""
340+
Returns fitted cell counts under independence.
341+
342+
The returned cell counts are estimates under a model
343+
where the rows and columns of the table are independent.
344+
"""
325345

326346
probs = self.independence_probabilities
327347
fit = self.table.sum() * probs
328348
return fit
329349

330350
@cache_readonly
331351
def resid_pearson(self):
332-
# docstring for cached attributes in init above
352+
"""
353+
Returns Pearson residuals.
354+
355+
The Pearson residuals are calculated under a model where
356+
the rows and columns of the table are independent.
357+
"""
333358

334359
fit = self.fittedvalues
335360
resids = (self.table - fit) / np.sqrt(fit)
336361
return resids
337362

338363
@cache_readonly
339364
def standardized_resids(self):
340-
# docstring for cached attributes in init above
365+
"""
366+
Returns standardized residuals under independence.
367+
"""
341368

342369
row, col = self.marginal_probabilities
343370
sresids = self.resid_pearson / np.sqrt(np.outer(1 - row, 1 - col))
344371
return sresids
345372

346373
@cache_readonly
347374
def chi2_contribs(self):
348-
# docstring for cached attributes in init above
375+
"""
376+
Returns the contributions to the chi^2 statistic for independence.
377+
378+
The returned table contains the contribution of each cell to the chi^2
379+
test statistic for the null hypothesis that the rows and columns
380+
are independent.
381+
"""
349382

350383
return self.resid_pearson**2
351384

352385
@cache_readonly
353386
def local_log_oddsratios(self):
354-
# docstring for cached attributes in init above
387+
"""
388+
Returns local log odds ratios.
389+
390+
The local log odds ratios are the log odds ratios
391+
calculated for contiguous 2x2 sub-tables.
392+
"""
355393

356394
ta = self.table.copy()
357395
a = ta[0:-1, 0:-1]
@@ -371,13 +409,25 @@ def local_log_oddsratios(self):
371409

372410
@cache_readonly
373411
def local_oddsratios(self):
374-
# docstring for cached attributes in init above
412+
"""
413+
Returns local odds ratios.
414+
415+
See documentation for local_log_oddsratios.
416+
"""
375417

376418
return np.exp(self.local_log_oddsratios)
377419

378420
@cache_readonly
379421
def cumulative_log_oddsratios(self):
380-
# docstring for cached attributes in init above
422+
"""
423+
Returns cumulative log odds ratios.
424+
425+
The cumulative log odds ratios for a contingency table
426+
with ordered rows and columns are calculated by collapsing
427+
all cells to the left/right and above/below a given point,
428+
to obtain a 2x2 table from which a log odds ratio can be
429+
calculated.
430+
"""
381431

382432
ta = self.table.cumsum(0).cumsum(1)
383433

@@ -399,7 +449,11 @@ def cumulative_log_oddsratios(self):
399449

400450
@cache_readonly
401451
def cumulative_oddsratios(self):
402-
# docstring for cached attributes in init above
452+
"""
453+
Returns the cumulative odds ratios for a contingency table.
454+
455+
See documentation for cumulative_log_oddsratio.
456+
"""
403457

404458
return np.exp(self.cumulative_log_oddsratios)
405459

@@ -687,21 +741,27 @@ def from_data(cls, data, shift_zeros=True):
687741

688742
@cache_readonly
689743
def log_oddsratio(self):
690-
# docstring for cached attributes in init above
744+
"""
745+
Returns the log odds ratio for a 2x2 table.
746+
"""
691747

692748
f = self.table.flatten()
693749
return np.dot(np.log(f), np.r_[1, -1, -1, 1])
694750

695751
@cache_readonly
696752
def oddsratio(self):
697-
# docstring for cached attributes in init above
753+
"""
754+
Returns the odds ratio for a 2x2 table.
755+
"""
698756

699757
return (self.table[0, 0] * self.table[1, 1] /
700758
(self.table[0, 1] * self.table[1, 0]))
701759

702760
@cache_readonly
703761
def log_oddsratio_se(self):
704-
# docstring for cached attributes in init above
762+
"""
763+
Returns the standard error for the log odds ratio.
764+
"""
705765

706766
return np.sqrt(np.sum(1 / self.table))
707767

@@ -770,20 +830,28 @@ def oddsratio_confint(self, alpha=0.05, method="normal"):
770830

771831
@cache_readonly
772832
def riskratio(self):
773-
# docstring for cached attributes in init above
833+
"""
834+
Returns the risk ratio for a 2x2 table.
835+
836+
The risk ratio is calcuoated with respec to the rows.
837+
"""
774838

775839
p = self.table[:, 0] / self.table.sum(1)
776840
return p[0] / p[1]
777841

778842
@cache_readonly
779843
def log_riskratio(self):
780-
# docstring for cached attributes in init above
844+
"""
845+
Returns the log od the risk ratio.
846+
"""
781847

782848
return np.log(self.riskratio)
783849

784850
@cache_readonly
785851
def log_riskratio_se(self):
786-
# docstring for cached attributes in init above
852+
"""
853+
Returns the standard error of the log of the risk ratio.
854+
"""
787855

788856
n = self.table.sum(1)
789857
p = self.table[:, 0] / n

0 commit comments

Comments
 (0)