
    (phc%                     b    S SK r S SKJr  S SKrS SKJr  SSKJr  S r	\ " S S5      5       r
S	 rg)
    N)	dataclass)ndtri   )ConfidenceIntervalc                     U SU SU < 3n [         R                  " U 5      n X:  a  [        U5      eU $ ! [         a    [        U5      S ef = f)Nz" must be an integer not less than z
, but got )operatorindex	TypeError
ValueError)nboundnamemsgs       M/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_relative_risk.py_validate_intr      s_    F4UG:aU
KC'NN1 	yoH	  'n$&'s	   5 Ac                   V    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\S'   SS jrS	r	g
)RelativeRiskResult   a  
Result of `scipy.stats.contingency.relative_risk`.

Attributes
----------
relative_risk : float
    This is::

        (exposed_cases/exposed_total) / (control_cases/control_total)

exposed_cases : int
    The number of "cases" (i.e. occurrence of disease or other event
    of interest) among the sample of "exposed" individuals.
exposed_total : int
    The total number of "exposed" individuals in the sample.
control_cases : int
    The number of "cases" among the sample of "control" or non-exposed
    individuals.
control_total : int
    The total number of "control" individuals in the sample.

Methods
-------
confidence_interval :
    Compute the confidence interval for the relative risk estimate.
relative_riskexposed_casesexposed_totalcontrol_casescontrol_totalc                    SUs=::  a  S::  d  O  [        S5      eU R                  S:X  a6  U R                  S:X  a&  [        [        R
                  [        R
                  S9$ U R                  S:X  a  [        S[        R
                  S9$ U R                  S:X  a&  [        [        R
                  [        R                  S9$ SU-
  n[        SUS-  -
  5      nU R                  n[        R                  " SU R                  -  SU R                  -  -
  SU R                  -  -   SU R                  -  -
  5      nX5-  nU[        R                  " U* 5      -  nU[        R                  " U5      -  n[        XxS9$ )a\  
Compute the confidence interval for the relative risk.

The confidence interval is computed using the Katz method
(i.e. "Method C" of [1]_; see also [2]_, section 3.1.2).

Parameters
----------
confidence_level : float, optional
    The confidence level to use for the confidence interval.
    Default is 0.95.

Returns
-------
ci : ConfidenceInterval instance
    The return value is an object with attributes ``low`` and
    ``high`` that hold the confidence interval.

References
----------
.. [1] D. Katz, J. Baptista, S. P. Azen and M. C. Pike, "Obtaining
       confidence intervals for the risk ratio in cohort studies",
       Biometrics, 34, 469-474 (1978).
.. [2] Hardeo Sahai and Anwer Khurshid, Statistics in Epidemiology,
       CRC Press LLC, Boca Raton, FL, USA (1996).


Examples
--------
>>> from scipy.stats.contingency import relative_risk
>>> result = relative_risk(exposed_cases=10, exposed_total=75,
...                        control_cases=12, control_total=225)
>>> result.relative_risk
2.5
>>> result.confidence_interval()
ConfidenceInterval(low=1.1261564003469628, high=5.549850800541033)
r   r   z0confidence_level must be in the interval [0, 1].)lowhigh           )r   r   r   r   npnaninfr   r   sqrtr   r   exp)	selfconfidence_levelalphazrrsedeltakatz_lokatz_his	            r   confidence_interval&RelativeRiskResult.confidence_interval6   sN   L $)) ' ( ( "t'9'9Q'>%"&&rvv>>1$%#BFF;;1$%"&&rvv>>$$!eAg+ WWQt)))Ad.@.@,@@t)))*,-d.@.@,@A BRVVUF^#RVVE]"!g<<     N)gffffff?)
__name__
__module____qualname____firstlineno____doc__float__annotations__intr-   __static_attributes__r0   r/   r   r   r      s-    6 D=r/   r   c                 V   [        U SS5      n [        USS5      n[        USS5      n[        USS5      nX:  a  [        S5      eX#:  a  [        S5      eU S:X  a  US:X  a  [        R                  nO,U S:X  a  S	nO#US:X  a  [        R                  nOX-  nX#-  nXV-  n[        UU UUUS
9$ )a6  
Compute the relative risk (also known as the risk ratio).

This function computes the relative risk associated with a 2x2
contingency table ([1]_, section 2.2.3; [2]_, section 3.1.2). Instead
of accepting a table as an argument, the individual numbers that are
used to compute the relative risk are given as separate parameters.
This is to avoid the ambiguity of which row or column of the contingency
table corresponds to the "exposed" cases and which corresponds to the
"control" cases.  Unlike, say, the odds ratio, the relative risk is not
invariant under an interchange of the rows or columns.

Parameters
----------
exposed_cases : nonnegative int
    The number of "cases" (i.e. occurrence of disease or other event
    of interest) among the sample of "exposed" individuals.
exposed_total : positive int
    The total number of "exposed" individuals in the sample.
control_cases : nonnegative int
    The number of "cases" among the sample of "control" or non-exposed
    individuals.
control_total : positive int
    The total number of "control" individuals in the sample.

Returns
-------
result : instance of `~scipy.stats._result_classes.RelativeRiskResult`
    The object has the float attribute ``relative_risk``, which is::

        rr = (exposed_cases/exposed_total) / (control_cases/control_total)

    The object also has the method ``confidence_interval`` to compute
    the confidence interval of the relative risk for a given confidence
    level.

See Also
--------
odds_ratio

Notes
-----
The R package epitools has the function `riskratio`, which accepts
a table with the following layout::

                    disease=0   disease=1
    exposed=0 (ref)    n00         n01
    exposed=1          n10         n11

With a 2x2 table in the above format, the estimate of the CI is
computed by `riskratio` when the argument method="wald" is given,
or with the function `riskratio.wald`.

For example, in a test of the incidence of lung cancer among a
sample of smokers and nonsmokers, the "exposed" category would
correspond to "is a smoker" and the "disease" category would
correspond to "has or had lung cancer".

To pass the same data to ``relative_risk``, use::

    relative_risk(n11, n10 + n11, n01, n00 + n01)

.. versionadded:: 1.7.0

References
----------
.. [1] Alan Agresti, An Introduction to Categorical Data Analysis
       (second edition), Wiley, Hoboken, NJ, USA (2007).
.. [2] Hardeo Sahai and Anwer Khurshid, Statistics in Epidemiology,
       CRC Press LLC, Boca Raton, FL, USA (1996).

Examples
--------
>>> from scipy.stats.contingency import relative_risk

This example is from Example 3.1 of [2]_.  The results of a heart
disease study are summarized in the following table::

             High CAT   Low CAT    Total
             --------   -------    -----
    CHD         27         44        71
    No CHD      95        443       538

    Total      122        487       609

CHD is coronary heart disease, and CAT refers to the level of
circulating catecholamine.  CAT is the "exposure" variable, and
high CAT is the "exposed" category. So the data from the table
to be passed to ``relative_risk`` is::

    exposed_cases = 27
    exposed_total = 122
    control_cases = 44
    control_total = 487

>>> result = relative_risk(27, 122, 44, 487)
>>> result.relative_risk
2.4495156482861398

Find the confidence interval for the relative risk.

>>> result.confidence_interval(confidence_level=0.95)
ConfidenceInterval(low=1.5836990926700116, high=3.7886786315466354)

The interval does not contain 1, so the data supports the statement
that high CAT is associated with greater risk of CHD.
r   r   r   r   r   r   z,exposed_cases must not exceed exposed_total.z,control_cases must not exceed control_total.r   )r   r   r   r   r   )r   r   r   r    r!   r   )r   r   r   r   r(   p1p2s          r   r   r   }   s    ^ "-ODM!-ODM!-ODM!-ODM$GHH$GHHmq0VV	!		!	VV**WB,9,9,9,9	; ;r/   )r   dataclassesr   numpyr   scipy.specialr   _commonr   r   r   r   r0   r/   r   <module>rA      s<     !   ' f= f= f=RJ;r/   