2

我正在尝试在 Oracle 中复制 Excel 工作簿的功能。工作表上的一个公式使用 CHIDIST,它“返回卡方分布的单尾概率”。我在 Oracle 的任何地方都看不到类似的功能!我将不得不编写自己的 CHIDIST 函数吗?

以下是关于 CHIDIST 的 Excel 文档的链接:http: //office.microsoft.com/en-gb/excel-help/chidist-HP005209010.aspx

我已经计算出卡方和自由度。

谢谢

4

2 回答 2

0

右尾概率...不错...

在 oracle 中,您可以将 java 代码嵌入到存储过程和函数中。最好的方法是使用正确的 java 类并从 oracle 的函数中调用它。这并不难:

http://docs.oracle.com/cd/B19306_01/java.102/b14187/chfive.htm http://jwork.org/scavis/api/doc.php/umontreal/iro/lecuyer/probdist/ChiDist.html

这就是我能为你做的一切:

DECLARE
    l_value_to_evaluate NUMBER (10, 3) := 18.307;  /* X; Value at which you want to evaluate the distribution */
    l_degrees_freedom   NUMBER := 10;              /* Degrees of freedom */
    l_number NUMBER;

    FUNCTION is_number(str_in IN VARCHAR2) RETURN NUMBER
    IS
        n NUMBER;
    BEGIN
        n := TO_NUMBER(str_in);

        RETURN 1;
    EXCEPTION
        WHEN VALUE_ERROR THEN
            RETURN 0;
    END;
BEGIN
    -- If either argument is nonnumeric, CHIDIST returns the #VALUE! error value.
    l_number := is_number(l_value_to_evaluate);
    l_number := is_number(l_degrees_freedom);

    -- If x is negative, CHIDIST returns the #NUM! error value.
    IF SIGN(l_value_to_evaluate) = -1 THEN
        RAISE_APPLICATION_ERROR(-20998, '#NUM!');
    END IF;

    -- If degrees_freedom is not an integer, it is truncated.
    l_degrees_freedom := TRUNC(l_degrees_freedom);

    -- If degrees_freedom < 1 or degrees_freedom > 10^10, CHIDIST returns the #NUM! error value.
    IF l_degrees_freedom < 1
    OR l_degrees_freedom > POWER(10, 10) THEN
        RAISE_APPLICATION_ERROR(-20997, '#NUM!');
    END IF;

    -- CHIDIST is calculated as CHIDIST = P(X>x), where X is a χ2 random variable.
    /* Here the integral's implementation */
EXCEPTION
    WHEN VALUE_ERROR THEN
        RAISE_APPLICATION_ERROR(-20999, '#VALUE!');
END;
于 2013-06-11T16:15:57.270 回答
0

如果您使用 CHIDIST 进行卡方检验,则该STATS_CROSSTAB函数可能是达到同一目的的不同方法。它将计算两组成对观察的卡方值、显着性或自由度。

于 2013-06-11T16:50:47.100 回答