@@ -294,7 +294,16 @@ def test_ordinal_association(self, row_scores=None, col_scores=None):
294
294
295
295
@cache_readonly
296
296
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
+ """
298
307
299
308
n = self .table .sum ()
300
309
row = self .table .sum (1 ) / n
@@ -308,7 +317,13 @@ def marginal_probabilities(self):
308
317
309
318
@cache_readonly
310
319
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
+ """
312
327
313
328
row , col = self .marginal_probabilities
314
329
itab = np .outer (row , col )
@@ -321,37 +336,60 @@ def independence_probabilities(self):
321
336
322
337
@cache_readonly
323
338
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
+ """
325
345
326
346
probs = self .independence_probabilities
327
347
fit = self .table .sum () * probs
328
348
return fit
329
349
330
350
@cache_readonly
331
351
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
+ """
333
358
334
359
fit = self .fittedvalues
335
360
resids = (self .table - fit ) / np .sqrt (fit )
336
361
return resids
337
362
338
363
@cache_readonly
339
364
def standardized_resids (self ):
340
- # docstring for cached attributes in init above
365
+ """
366
+ Returns standardized residuals under independence.
367
+ """
341
368
342
369
row , col = self .marginal_probabilities
343
370
sresids = self .resid_pearson / np .sqrt (np .outer (1 - row , 1 - col ))
344
371
return sresids
345
372
346
373
@cache_readonly
347
374
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
+ """
349
382
350
383
return self .resid_pearson ** 2
351
384
352
385
@cache_readonly
353
386
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
+ """
355
393
356
394
ta = self .table .copy ()
357
395
a = ta [0 :- 1 , 0 :- 1 ]
@@ -371,13 +409,25 @@ def local_log_oddsratios(self):
371
409
372
410
@cache_readonly
373
411
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
+ """
375
417
376
418
return np .exp (self .local_log_oddsratios )
377
419
378
420
@cache_readonly
379
421
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
+ """
381
431
382
432
ta = self .table .cumsum (0 ).cumsum (1 )
383
433
@@ -399,7 +449,11 @@ def cumulative_log_oddsratios(self):
399
449
400
450
@cache_readonly
401
451
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
+ """
403
457
404
458
return np .exp (self .cumulative_log_oddsratios )
405
459
@@ -687,21 +741,27 @@ def from_data(cls, data, shift_zeros=True):
687
741
688
742
@cache_readonly
689
743
def log_oddsratio (self ):
690
- # docstring for cached attributes in init above
744
+ """
745
+ Returns the log odds ratio for a 2x2 table.
746
+ """
691
747
692
748
f = self .table .flatten ()
693
749
return np .dot (np .log (f ), np .r_ [1 , - 1 , - 1 , 1 ])
694
750
695
751
@cache_readonly
696
752
def oddsratio (self ):
697
- # docstring for cached attributes in init above
753
+ """
754
+ Returns the odds ratio for a 2x2 table.
755
+ """
698
756
699
757
return (self .table [0 , 0 ] * self .table [1 , 1 ] /
700
758
(self .table [0 , 1 ] * self .table [1 , 0 ]))
701
759
702
760
@cache_readonly
703
761
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
+ """
705
765
706
766
return np .sqrt (np .sum (1 / self .table ))
707
767
@@ -770,20 +830,28 @@ def oddsratio_confint(self, alpha=0.05, method="normal"):
770
830
771
831
@cache_readonly
772
832
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
+ """
774
838
775
839
p = self .table [:, 0 ] / self .table .sum (1 )
776
840
return p [0 ] / p [1 ]
777
841
778
842
@cache_readonly
779
843
def log_riskratio (self ):
780
- # docstring for cached attributes in init above
844
+ """
845
+ Returns the log od the risk ratio.
846
+ """
781
847
782
848
return np .log (self .riskratio )
783
849
784
850
@cache_readonly
785
851
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
+ """
787
855
788
856
n = self .table .sum (1 )
789
857
p = self .table [:, 0 ] / n
0 commit comments