Skip to content

Commit

Permalink
v0.2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
yh202109 committed Jul 12, 2024
1 parent 413064c commit fae2139
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/statlab_corr_spearman_rho.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ Let :math:`(Y_{i1}, Y_{i2})` be a pair of random variables corresponding to the
Let :math:`(R_{i1}, R_{i2})` be the rank of :math:`Y_{i1}` and the rank of :math:`Y_{i2}`.
In the case of ties, one method is to assign the tied group with the average of unique ranks corresponding the tied group.
For the :math:`i` th sample, let
:math:`s_1` be the number of observed values less than :math:`Y_{i1}`,
:math:`s_2` be the number of observed values equal to :math:`Y_{i1}`,
and :math:`s_3` be the number of observed values greater to :math:`Y_{i1}`.
:math:`S_1` be the number of observed values less than :math:`Y_{i1}`,
:math:`S_2` be the number of observed values equal to :math:`Y_{i1}`,
and :math:`S_3` be the number of observed values greater to :math:`Y_{i1}`.
We can calculate the rank of a single sample as

.. math::
:label: eq_rank
R_{i^*1} = s_1 + \frac{s_2+1}{2} = n - s3 - \frac{s_2-1}{2}.
R_{i^*1} = S_1 + \frac{S_2+1}{2} = n - S_3 - \frac{S_2-1}{2}.
For a vector, ``pandas.DataFrame`` has the ``rank`` function with ``method='average'`` option to calculate rank as defined in :eq:`eq_rank`.
In ``R``, that can be calculated using the ``rank`` function with ``ties.method='average'`` option.
Expand All @@ -80,10 +80,10 @@ The Spearman's :math:`\rho` can be calculated as:
.. math::
:label: eq_rho
\rho = \frac{\frac{1}{n}\sum_i R_{i1}R_{i2} - \frac{1}{4}(n+1)^2}{t_1 t_2},
\rho = \frac{\frac{1}{n}\sum_i R_{i1}R_{i2} - \frac{1}{4}(n+1)^2}{s_1 s_2},
where :math:`t_1 = \sum_i Y_{i1}^2 - \frac{1}{4}(n+1)^2`,
and :math:`t_2 = \sum_i Y_{i2}^2 - \frac{1}{4}(n+1)^2`.
where :math:`s_1 = \sum_i Y_{i1}^2 - \frac{1}{4}(n+1)^2`,
and :math:`s_2 = \sum_i Y_{i2}^2 - \frac{1}{4}(n+1)^2`.

*************
Example - Group-1
Expand Down

0 comments on commit fae2139

Please sign in to comment.