1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192
|
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* fn-stat.c: Built in statistical functions and functions registration
*
* Authors:
* Jukka-Pekka Iivonen <jiivonenhutcs.cs.hut.fi>
* Michael Meeks <micheal@ximian.com>
* Morten Welinder <terra@gnome.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gnumeric-config.h>
#include <gnumeric.h>
#include <func.h>
#include <mathfunc.h>
#include <rangefunc.h>
#include <regression.h>
#include <sheet.h>
#include <collect.h>
#include <value.h>
#include <expr.h>
#include <expr-impl.h>
#include <gnm-i18n.h>
#include <goffice/goffice.h>
#include <gnm-plugin.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <tools/analysis-tools.h>
GNM_PLUGIN_MODULE_HEADER;
#define HELP_DESCRIPTION_TEXT_INCLUSION { GNM_FUNC_HELP_DESCRIPTION, F_("Numbers, text and logical values are included in the calculation too. If the cell contains text or the argument evaluates to FALSE, it is counted as value zero (0). If the argument evaluates to TRUE, it is counted as one (1). Note that empty cells are not counted.")}
/***************************************************************************/
static GnmFuncHelp const help_varp[] = {
{ GNM_FUNC_HELP_NAME, F_("VARP:variance of an entire population")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("VARP is also known as the N-variance.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain number 11.4, 17.3, 21.3, 25.9, and 40.1.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then VARP(A1:A5) equals 94.112")},
{ GNM_FUNC_HELP_SEEALSO, ("AVERAGE,DVAR,DVARP,STDEV,VAR")},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Variance") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:Variance.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_varp (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_var_pop,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_var[] = {
{ GNM_FUNC_HELP_NAME, F_("VAR:sample variance of the given sample")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("VAR is also known as the N-1-variance.")},
{ GNM_FUNC_HELP_NOTE, F_("Since the N-1-variance includes Bessel's correction, whereas the N-variance calculated by VARPA or VARP does not, "
"under reasonable conditions the N-1-variance is an unbiased estimator of the variance of the population "
"from which the sample is drawn.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then VAR(A1:A5) equals 117.64.")},
{ GNM_FUNC_HELP_SEEALSO, ("VARP,STDEV,VARA")},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Variance") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:Variance.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_var (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_var_est,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_stdev[] = {
{ GNM_FUNC_HELP_NAME, F_("STDEV:sample standard deviation of the given sample")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("STDEV is also known as the N-1-standard deviation.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("To obtain the population standard deviation of a whole population use STDEVP.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then STDEV(A1:A5) equals 10.84619749.")},
{ GNM_FUNC_HELP_SEEALSO, ("AVERAGE,DSTDEV,DSTDEVP,STDEVA,STDEVPA,VAR")},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Standard_deviation") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:StandardDeviation.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_stdev (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_stddev_est,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_stdevp[] = {
{ GNM_FUNC_HELP_NAME, F_("STDEVP:population standard deviation of the given population")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("This is also known as the N-standard deviation")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then STDEVP(A1:A5) equals 9.701133954.")},
{ GNM_FUNC_HELP_SEEALSO, ("STDEV,STDEVA,STDEVPA")},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Standard_deviation") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:StandardDeviation.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_stdevp (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_stddev_pop,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_rank[] = {
{ GNM_FUNC_HELP_NAME, F_("RANK:rank of a number in a list of numbers")},
{ GNM_FUNC_HELP_ARG, F_("x:number whose rank you want to find")},
{ GNM_FUNC_HELP_ARG, F_("ref:list of numbers")},
{ GNM_FUNC_HELP_ARG, F_("order:0 (descending order) or non-zero (ascending order); defaults to 0")},
{ GNM_FUNC_HELP_NOTE, F_("In case of a tie, RANK returns the largest possible rank.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, \xe2\x80\xa6, A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 25.9.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then RANK(17.3,A1:A5) equals 4.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then RANK(25.9,A1:A5) equals 1.")},
{ GNM_FUNC_HELP_SEEALSO, ("PERCENTRANK,RANK.AVG")},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_rank (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs;
int i, r, n;
GnmValue *result = NULL;
gnm_float x;
gboolean increasing;
x = value_get_as_float (argv[0]);
xs = collect_floats_value (argv[1], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
increasing = argv[2] ? value_get_as_checked_bool (argv[2]) : FALSE;
if (result)
goto out;
for (i = 0, r = 1; i < n; i++) {
gnm_float y = xs[i];
if (increasing ? y < x : y > x)
r++;
}
result = value_new_int (r);
out:
g_free (xs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_rank_avg[] = {
{ GNM_FUNC_HELP_NAME, F_("RANK.AVG:rank of a number in a list of numbers")},
{ GNM_FUNC_HELP_ARG, F_("x:number whose rank you want to find")},
{ GNM_FUNC_HELP_ARG, F_("ref:list of numbers")},
{ GNM_FUNC_HELP_ARG, F_("order:0 (descending order) or non-zero (ascending order); defaults to 0")},
{ GNM_FUNC_HELP_NOTE, F_("In case of a tie, RANK returns the average rank.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel 2010 compatible.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 25.9.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then RANK.AVG(17.3,A1:A5) equals 4.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then RANK.AVG(25.9,A1:A5) equals 1.5.")},
{ GNM_FUNC_HELP_SEEALSO, ("PERCENTRANK,RANK")},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_rank_avg (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs;
int i, r, n, t;
GnmValue *result = NULL;
gnm_float x;
gboolean increasing;
x = value_get_as_float (argv[0]);
xs = collect_floats_value (argv[1], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
increasing = argv[2] ? value_get_as_checked_bool (argv[2]) : FALSE;
if (result)
goto out;
for (i = 0, r = 1, t = 0; i < n; i++) {
gnm_float y = xs[i];
if (increasing ? y < x : y > x)
r++;
if (x == y)
t++;
}
if (t > 1)
result = value_new_float (r + (t - 1)/2.);
else
result = value_new_int (r);
out:
g_free (xs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_trimmean[] = {
{ GNM_FUNC_HELP_NAME, F_("TRIMMEAN:mean of the interior of a data set")},
{ GNM_FUNC_HELP_ARG, F_("ref:list of numbers whose mean you want to calculate")},
{ GNM_FUNC_HELP_ARG, F_("fraction:fraction of the data set excluded from the mean")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("If @{fraction}=0.2 and the data set contains 40 numbers, 8 numbers are trimmed from the data set (40 x 0.2): "
"the 4 largest and the 4 smallest. To avoid a bias, the number of points to be excluded is always rounded down to the nearest even number.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Then TRIMMEAN(A1:A5,0.2) equals 23.2 and TRIMMEAN(A1:A5,0.4) equals 21.5.")},
{ GNM_FUNC_HELP_SEEALSO, ("AVERAGE,GEOMEAN,HARMEAN,MEDIAN,MODE")},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_trimmean (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
int c, tc, n;
GnmValue *result = NULL;
gnm_float *xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
&n, &result);
gnm_float p = value_get_as_float (argv[1]);
gnm_float res;
if (result)
goto out;
if (p < 0 || p >= 1) {
result = value_new_error_NUM (ei->pos);
goto out;
}
tc = (int)gnm_fake_floor ((n * p) / 2);
c = n - 2 * tc;
if (gnm_range_average (xs + tc, c, &res))
result = value_new_error_VALUE (ei->pos);
else
result = value_new_float (res);
g_free (xs);
out:
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_covar[] = {
{ GNM_FUNC_HELP_NAME, F_("COVAR:covariance of two data sets")},
{ GNM_FUNC_HELP_ARG, F_("array1:first data set")},
{ GNM_FUNC_HELP_ARG, F_("array2:set data set")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.") },
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then COVAR(A1:A5,B1:B5) equals 65.858.") },
{ GNM_FUNC_HELP_SEEALSO, "CORREL,FISHER,FISHERINV"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Covariance") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:Covariance.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_covar (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return float_range_function2 (argv[0], argv[1],
ei,
gnm_range_covar,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_correl[] = {
{ GNM_FUNC_HELP_NAME, F_("CORREL:Pearson correlation coefficient of two data sets")},
{ GNM_FUNC_HELP_ARG, F_("array1:first data set")},
{ GNM_FUNC_HELP_ARG, F_("array2:second data set")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then CORREL(A1:A5,B1:B5) equals 0.996124788.") },
{ GNM_FUNC_HELP_SEEALSO, "COVAR,FISHER,FISHERINV"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:CorrelationCoefficient.html") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:Covariance.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_correl (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return float_range_function2 (argv[0], argv[1],
ei,
gnm_range_correl_pop,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_negbinomdist[] = {
{ GNM_FUNC_HELP_NAME, F_("NEGBINOMDIST:probability mass function of the negative binomial distribution")},
{ GNM_FUNC_HELP_ARG, F_("f:number of failures")},
{ GNM_FUNC_HELP_ARG, F_("t:threshold number of successes")},
{ GNM_FUNC_HELP_ARG, F_("p:probability of a success")},
{ GNM_FUNC_HELP_NOTE, F_("If @{f} or @{t} is a non-integer it is truncated.")},
{ GNM_FUNC_HELP_NOTE, F_("If (@{f} + @{t} -1) <= 0 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this functions returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=NEGBINOMDIST(2,5,0.55)" },
{ GNM_FUNC_HELP_SEEALSO, "BINOMDIST,COMBIN,FACT,HYPGEOMDIST,PERMUT"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_negbinomdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float r = gnm_fake_floor (value_get_as_float (argv[1]));
gnm_float p = value_get_as_float (argv[2]);
if ((x + r - 1) <= 0 || p < 0 || p > 1)
return value_new_error_NUM (ei->pos);
return value_new_float (dnbinom (x, r, p, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_normsdist[] = {
{ GNM_FUNC_HELP_NAME, F_("NORMSDIST:cumulative density function of the standard normal distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("NORMSDIST is the OpenFormula function LEGACY.NORMSDIST.") },
{ GNM_FUNC_HELP_EXAMPLES, "=NORMSDIST(2)" },
{ GNM_FUNC_HELP_SEEALSO, "NORMDIST"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Normal_distribution") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:NormalDistribution.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_normsdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x;
x = value_get_as_float (argv[0]);
return value_new_float (pnorm (x, 0, 1, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_normsinv[] = {
{ GNM_FUNC_HELP_NAME, F_("NORMSINV:inverse of the cumulative density function of the standard normal distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:given probability")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("NORMSINV is the OpenFormula function LEGACY.NORMSINV.") },
{ GNM_FUNC_HELP_EXAMPLES, "=NORMSINV(0.2)" },
{ GNM_FUNC_HELP_SEEALSO, "NORMDIST,NORMINV,NORMSDIST,STANDARDIZE,ZTEST"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Normal_distribution") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:NormalDistribution.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_normsinv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p;
p = value_get_as_float (argv[0]);
if (p < 0 || p > 1)
return value_new_error_NUM (ei->pos);
return value_new_float (qnorm (p, 0, 1, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_lognormdist[] = {
{ GNM_FUNC_HELP_NAME, F_("LOGNORMDIST:cumulative distribution function of the lognormal distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("mean:mean")},
{ GNM_FUNC_HELP_ARG, F_("stddev:standard deviation")},
{ GNM_FUNC_HELP_NOTE, F_("If @{stddev} = 0 LOGNORMDIST returns a #DIV/0! error.")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} <= 0, @{mean} < 0 or @{stddev} <= 0 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=LOGNORMDIST(3,1,2)" },
{ GNM_FUNC_HELP_SEEALSO, "NORMDIST"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Log-normal_distribution") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:LogNormalDistribution.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_lognormdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gnm_float stddev = value_get_as_float (argv[2]);
if (x <= 0 || mean < 0 || stddev <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (plnorm (x, mean, stddev, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_loginv[] = {
{ GNM_FUNC_HELP_NAME, F_("LOGINV:inverse of the cumulative distribution function of the lognormal distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("mean:mean")},
{ GNM_FUNC_HELP_ARG, F_("stddev:standard deviation")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 or @{stddev} <= 0 this function returns #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=LOGINV(0.5,2,3)" },
{ GNM_FUNC_HELP_SEEALSO, ("EXP,LN,LOG,LOG10,LOGNORMDIST")},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Log-normal_distribution") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:LogNormalDistribution.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_loginv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p, mean, stddev;
p = value_get_as_float (argv[0]);
mean = value_get_as_float (argv[1]);
stddev = value_get_as_float (argv[2]);
if (p < 0 || p > 1 || stddev <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (qlnorm (p, mean, stddev, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_fisherinv[] = {
{ GNM_FUNC_HELP_NAME, F_("FISHERINV:inverse of the Fisher transformation")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} is a non-number this function returns a #VALUE! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=FISHERINV(2)" },
{ GNM_FUNC_HELP_SEEALSO, "FISHER,TANH"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_fisherinv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return value_new_float (gnm_tanh (value_get_as_float (argv[0])));
}
/***************************************************************************/
static GnmFuncHelp const help_mode[] = {
{ GNM_FUNC_HELP_NAME, F_("MODE:first most common number in the dataset")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("If the data set does not contain any duplicates this function returns a #N/A error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 11.4, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then MODE(A1:A5) equals 11.4.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,MEDIAN"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Mode_(statistics)") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:Mode.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_mode (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_mode,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NA);
}
/***************************************************************************/
static GnmFuncHelp const help_harmean[] = {
{ GNM_FUNC_HELP_NAME, F_("HARMEAN:harmonic mean")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The harmonic mean of N data points is N divided by the sum of the reciprocals of the data points).")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then HARMEAN(A1:A5) equals 19.529814427.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,GEOMEAN,MEDIAN,MODE,TRIMMEAN"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Harmonic_mean") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:HarmonicMean.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_harmean (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_harmonic_mean,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static GnmFuncHelp const help_geomean[] = {
{ GNM_FUNC_HELP_NAME, F_("GEOMEAN:geometric mean")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The geometric mean is equal to the Nth root of the product of the N values.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then GEOMEAN(A1:A5) equals 21.279182482.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,HARMEAN,MEDIAN,MODE,TRIMMEAN"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Geometric_mean") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:GeometricMean.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_geomean (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_geometric_mean,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static GnmFuncHelp const help_count[] = {
{ GNM_FUNC_HELP_NAME, F_("COUNT:total number of integer or floating point arguments passed")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then COUNT(A1:A5) equals 5.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
callback_function_count (GnmEvalPos const *ep, GnmValue const *value, void *closure)
{
int *result = closure;
if (value && VALUE_IS_FLOAT (value))
(*result)++;
return NULL;
}
static GnmValue *
gnumeric_count (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
int i = 0;
/* no need to check for error, this is not strict */
function_iterate_argument_values
(ei->pos, callback_function_count, &i,
argc, argv, FALSE, CELL_ITER_IGNORE_BLANK);
return value_new_int (i);
}
/***************************************************************************/
static GnmFuncHelp const help_counta[] = {
{ GNM_FUNC_HELP_NAME, F_("COUNTA:number of arguments passed not including empty cells")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings 11.4, \"missing\", \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then COUNTA(A1:A5) equals 5.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,COUNT,DCOUNT,DCOUNTA,PRODUCT,SUM"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
callback_function_counta (GnmEvalPos const *ep, GnmValue const *value, void *closure)
{
int *result = closure;
(*result)++;
return NULL;
}
static GnmValue *
gnumeric_counta (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
int i = 0;
/* no need to check for error, this is not strict */
function_iterate_argument_values
(ei->pos, callback_function_counta, &i,
argc, argv, FALSE, CELL_ITER_IGNORE_BLANK);
return value_new_int (i);
}
/***************************************************************************/
static GnmFuncHelp const help_average[] = {
{ GNM_FUNC_HELP_NAME, F_("AVERAGE:average of all the numeric values and cells")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then AVERAGE(A1:A5) equals 23.2.")},
{ GNM_FUNC_HELP_SEEALSO, ("SUM, COUNT")},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Arithmetic_mean") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:ArithmeticMean.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_average (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_average,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_min[] = {
{ GNM_FUNC_HELP_NAME, F_("MIN:smallest value, with negative numbers considered smaller than positive numbers")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then MIN(A1:A5) equals 11.4.") },
{ GNM_FUNC_HELP_SEEALSO, "MAX,ABS"},
{ GNM_FUNC_HELP_END }
};
static int
range_min0 (gnm_float const *xs, int n, gnm_float *res)
{
if (n == 0) {
*res = 0;
return 0;
} else
return gnm_range_min (xs, n, res);
}
static GnmValue *
gnumeric_min (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
range_min0,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_max[] = {
{ GNM_FUNC_HELP_NAME, F_("MAX:largest value, with negative numbers considered smaller than positive numbers")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then MAX(A1:A5) equals 40.1.") },
{ GNM_FUNC_HELP_SEEALSO, "MIN,ABS"},
{ GNM_FUNC_HELP_END }
};
static int
range_max0 (gnm_float const *xs, int n, gnm_float *res)
{
if (n == 0) {
*res = 0;
return 0;
} else
return gnm_range_max (xs, n, res);
}
static GnmValue *
gnumeric_max (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
range_max0,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_skew[] = {
{ GNM_FUNC_HELP_NAME, F_("SKEW:unbiased estimate for skewness of a distribution")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_NOTE, F_("This is only meaningful if the underlying "
"distribution really has a third moment. The skewness of a "
"symmetric (e.g., normal) distribution is zero.")},
{ GNM_FUNC_HELP_NOTE, F_("If less than three numbers are given, this function returns a #DIV/0! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then SKEW(A1:A5) equals 0.976798268.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,VAR,SKEWP,KURT"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_skew (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_skew_est,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_skewp[] = {
{ GNM_FUNC_HELP_NAME, F_("SKEWP:population skewness of a data set")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_NOTE, F_("If less than two numbers are given, SKEWP returns a #DIV/0! error.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then SKEWP(A1:A5) equals 0.655256198.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,VARP,SKEW,KURTP"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_skewp (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_skew_pop,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_expondist[] = {
{ GNM_FUNC_HELP_NAME, F_("EXPONDIST:porbaility density or cumulative distribution function of the exponential distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("y:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the density function or the cumulative distribution function")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("If @{cumulative} is false it will return:\t"
"@{y} * exp (-@{y}*@{x}),otherwise it will return\t"
"1 - exp (-@{y}*@{x}).")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < 0 or @{y} <= 0 this will return an error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=EXPONDIST(2,4,0)" },
{ GNM_FUNC_HELP_SEEALSO, "POISSON"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_expondist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float y = value_get_as_float (argv[1]);
gboolean cuml = value_get_as_checked_bool (argv[2]);
if (x < 0.0 || y <= 0.0)
return value_new_error_NUM (ei->pos);
if (cuml)
return value_new_float (pexp (x, 1 / y, TRUE, FALSE));
else
return value_new_float (dexp (x, 1 / y, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_bernoulli[] = {
{ GNM_FUNC_HELP_NAME, F_("BERNOULLI:probability mass function of a Bernoulli distribution")},
{ GNM_FUNC_HELP_ARG, F_("k:integer")},
{ GNM_FUNC_HELP_ARG, F_("p:probability of success")},
{ GNM_FUNC_HELP_NOTE, F_("If @{k} != 0 and @{k} != 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXAMPLES, "=BERNOULLI(0,0.5)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDBERNOULLI"},
{ GNM_FUNC_HELP_END }
};
static gnm_float
random_bernoulli_pdf (gnm_float k, gnm_float p)
{
if (k == 0)
return 1 - p;
else if (k == 1)
return p;
else
return 0;
}
static GnmValue *
gnumeric_bernoulli (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float k = value_get_as_float (argv[0]);
gnm_float p = value_get_as_float (argv[1]);
if (p < 0 || p > 1 || (k != 0 && k != 1))
return value_new_error_NUM (ei->pos);
return value_new_float (random_bernoulli_pdf (k, p));
}
/***************************************************************************/
static GnmFuncHelp const help_gammadist[] = {
{ GNM_FUNC_HELP_NAME, F_("GAMMADIST:probability density or cumulative distribution function of the gamma distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("alpha:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("beta:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the density function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < 0 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_NOTE, F_("If @{alpha} <= 0 or @{beta} <= 0, this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=GAMMADIST(1,2,3,0)" },
{ GNM_FUNC_HELP_SEEALSO, "GAMMAINV"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_gammadist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float alpha = value_get_as_float (argv[1]);
gnm_float beta = value_get_as_float (argv[2]);
gboolean cum = value_get_as_checked_bool (argv[3]);
if (x < 0 || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
if (cum)
return value_new_float (pgamma (x, alpha, beta, TRUE, FALSE));
else
return value_new_float (dgamma (x, alpha, beta, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_gammainv[] = {
{ GNM_FUNC_HELP_NAME, F_("GAMMAINV:inverse of the cumulative gamma distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("alpha:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("beta:scale parameter")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{alpha} <= 0 or @{beta} <= 0 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=GAMMAINV(0.34,2,4)" },
{ GNM_FUNC_HELP_SEEALSO, "GAMMADIST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_gammainv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p, alpha, beta;
p = value_get_as_float (argv[0]);
alpha = value_get_as_float (argv[1]);
beta = value_get_as_float (argv[2]);
if (p < 0 || p > 1 || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (qgamma (p, alpha, beta, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_chidist[] = {
{ GNM_FUNC_HELP_NAME, F_("CHIDIST:survival function of the chi-squared distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("dof:number of degrees of freedom")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{dof} is non-integer it is truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{dof} < 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("CHIDIST(@{x},@{dof}) is the OpenFormula function LEGACY.CHIDIST(@{x},@{dof}).") },
{ GNM_FUNC_HELP_EXAMPLES, "=CHIDIST(5.3,2)" },
{ GNM_FUNC_HELP_SEEALSO, "CHIINV,CHITEST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_chidist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float dof = gnm_fake_floor (value_get_as_float (argv[1]));
if (dof < 1)
return value_new_error_NUM (ei->pos);
return value_new_float (pchisq (x, dof, FALSE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_chiinv[] = {
{ GNM_FUNC_HELP_NAME, F_("CHIINV:inverse of the survival function of the chi-squared distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("dof:number of degrees of freedom")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 or @{dof} < 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("CHIINV(@{p},@{dof}) is the OpenFormula function LEGACY.CHIDIST(@{p},@{dof}).") },
{ GNM_FUNC_HELP_EXAMPLES, "=CHIINV(0.98,7)" },
{ GNM_FUNC_HELP_SEEALSO, "CHIDIST,CHITEST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_chiinv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p = value_get_as_float (argv[0]);
gnm_float dof = gnm_fake_floor (value_get_as_float (argv[1]));
if (p < 0 || p > 1 || dof < 1)
return value_new_error_NUM (ei->pos);
return value_new_float (qchisq (p, dof, FALSE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_chitest[] = {
{ GNM_FUNC_HELP_NAME, F_("CHITEST:p value of the Goodness of Fit Test")},
{ GNM_FUNC_HELP_ARG, F_("actual_range:observed data")},
{ GNM_FUNC_HELP_ARG, F_("theoretical_range:expected values")},
{ GNM_FUNC_HELP_NOTE, F_("If the actual range is not an n by 1 or 1 by n range, "
"but an n by m range, then CHITEST uses (n-1) times (m-1) as "
"degrees of freedom. This is useful if the expected values "
"were calculated from the observed value in a test of "
"independence or test of homogeneity.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("CHITEST is the OpenFormula function LEGACY.CHITEST.") },
{ GNM_FUNC_HELP_SEEALSO, "CHIDIST,CHIINV"},
{ GNM_FUNC_HELP_END }
};
static int
calc_chisq (gnm_float const *xs, gnm_float const *ys, int n, gnm_float *res)
{
gnm_float sum = 0;
int i;
gboolean has_neg = FALSE;
if (n == 0)
return 1;
for (i = 0; i < n; i++) {
gnm_float a = xs[i];
gnm_float e = ys[i];
if (e == 0)
return 1;
else if (e < 0)
has_neg = TRUE;
else
sum += (a - e) / e * (a - e);
}
if (has_neg) {
/* Hack: return -1 as a flag. */
*res = -1;
return 0;
}
*res = sum;
return 0;
}
static GnmValue *
gnumeric_chitest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
int w0 = value_area_get_width (argv[0], ei->pos);
int h0 = value_area_get_height (argv[0], ei->pos);
int w1 = value_area_get_width (argv[1], ei->pos);
int h1 = value_area_get_height (argv[1], ei->pos);
GnmValue *v;
gnm_float chisq;
int df;
/* Size error takes precedence over everything else. */
if (w0 * h0 != w1 * h1)
return value_new_error_NA (ei->pos);
v = float_range_function2 (argv[0], argv[1],
ei,
calc_chisq,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_DIV0);
if (!VALUE_IS_NUMBER (v))
return v;
chisq = value_get_as_float (v);
value_release (v);
/* See calc_chisq. */
if (chisq == -1)
return value_new_error_NUM (ei->pos);
df = (w0-1) * (h0-1);
df = (df == 0 ? w0 * h0 - 1 : df);
return value_new_float (pchisq (chisq, df, FALSE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_betadist[] = {
{ GNM_FUNC_HELP_NAME, F_("BETADIST:cumulative distribution function of the beta distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("alpha:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("beta:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("a:optional lower bound, defaults to 0")},
{ GNM_FUNC_HELP_ARG, F_("b:optional upper bound, defaults to 1")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < @{a} or @{x} > @{b} this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{alpha} <= 0 or @{beta} <= 0, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{a} >= @{b} this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=BETADIST(0.12,2,3)" },
{ GNM_FUNC_HELP_SEEALSO, "BETAINV"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_betadist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x, alpha, beta, a, b;
x = value_get_as_float (argv[0]);
alpha = value_get_as_float (argv[1]);
beta = value_get_as_float (argv[2]);
a = argv[3] ? value_get_as_float (argv[3]) : 0;
b = argv[4] ? value_get_as_float (argv[4]) : 1;
if (x < a || x > b || a >= b || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (pbeta ((x - a) / (b - a), alpha, beta, TRUE, FALSE));
}
/***************************************************************************/
/* Note: Excel's this function returns a #NUM! for various values where it
simply gives up computing the result. */
static GnmFuncHelp const help_betainv[] = {
{ GNM_FUNC_HELP_NAME, F_("BETAINV:inverse of the cumulative distribution function of the beta distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("alpha:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("beta:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("a:optional lower bound, defaults to 0")},
{ GNM_FUNC_HELP_ARG, F_("b:optional upper bound, defaults to 1")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{alpha} <= 0 or @{beta} <= 0, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{a} >= @{b} this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=BETAINV(0.45,1.6,1)" },
{ GNM_FUNC_HELP_SEEALSO, "BETADIST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_betainv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p, alpha, beta, a, b;
p = value_get_as_float (argv[0]);
alpha = value_get_as_float (argv[1]);
beta = value_get_as_float (argv[2]);
a = argv[3] ? value_get_as_float (argv[3]) : 0;
b = argv[4] ? value_get_as_float (argv[4]) : 1;
if (p < 0 || p > 1 || a >= b || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float ((b - a) * qbeta (p, alpha, beta, TRUE, FALSE) + a);
}
/***************************************************************************/
static GnmFuncHelp const help_tdist[] = {
{ GNM_FUNC_HELP_NAME, F_("TDIST:survival function of the Student t-distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("dof:number of degrees of freedom")},
{ GNM_FUNC_HELP_ARG, F_("tails:1 or 2")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{dof} < 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{tails} is neither 1 or 2 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("The parameterization of this function is different from "
"what is used for, e.g., NORMSDIST. This is a common source of "
"mistakes, but necessary for compatibility.") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function is Excel compatible for non-negative @{x}.") },
{ GNM_FUNC_HELP_EXAMPLES, "=TDIST(2,5,1)" },
{ GNM_FUNC_HELP_EXAMPLES, "=TDIST(-2,5,1)" },
{ GNM_FUNC_HELP_EXAMPLES, "=TDIST(0,5,2)" },
{ GNM_FUNC_HELP_SEEALSO, "TINV,TTEST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_tdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float dof = value_get_as_float (argv[1]);
gnm_float tails = value_get_as_float (argv[2]);
gnm_float p;
if (dof < 1)
goto bad;
if (tails == 1) {
gboolean lower_tail = FALSE;
if (x < 0) {
lower_tail = TRUE;
x = -x;
}
p = pt (x, dof, lower_tail, FALSE);
} else if (tails == 2) {
if (x < 0)
goto bad;
p = 2 * pt (x, dof, FALSE, FALSE);
} else
goto bad;
return value_new_float (p);
bad:
return value_new_error_NUM (ei->pos);
}
/***************************************************************************/
static GnmFuncHelp const help_tinv[] = {
{ GNM_FUNC_HELP_NAME, F_("TINV:inverse of the survival function of the Student t-distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("dof:number of degrees of freedom")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 or @{dof} < 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_NOTE, F_("The parameterization of this function is different from "
"what is used for, e.g., NORMSINV. This is a common source of "
"mistakes, but necessary for compatibility.") },
{ GNM_FUNC_HELP_EXAMPLES, "=TINV(0.4,32)" },
{ GNM_FUNC_HELP_SEEALSO, "TDIST,TTEST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_tinv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p = value_get_as_float (argv[0]);
gnm_float dof = value_get_as_float (argv[1]);
gnm_float result;
if (p < 0 || p > 1 || dof < 1)
return value_new_error_NUM (ei->pos);
result = qt (p / 2, dof, FALSE, FALSE);
if (result < 0)
return value_new_error_NUM (ei->pos);
return value_new_float (result);
}
/***************************************************************************/
static GnmFuncHelp const help_fdist[] = {
{ GNM_FUNC_HELP_NAME, F_("FDIST:survival function of the F distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("dof_of_num:numerator degrees of freedom")},
{ GNM_FUNC_HELP_ARG, F_("dof_of_denom:denominator degrees of freedom")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{dof_of_num} < 1 or @{dof_of_denom} < 1, this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("FDIST is the OpenFormula function LEGACY.FDIST.") },
{ GNM_FUNC_HELP_EXAMPLES, "=FDIST(2,5,5)" },
{ GNM_FUNC_HELP_SEEALSO, "FINV"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_fdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float dof1 = gnm_fake_floor (value_get_as_float (argv[1]));
gnm_float dof2 = gnm_fake_floor (value_get_as_float (argv[2]));
if (x < 0 || dof1 < 1 || dof2 < 1)
return value_new_error_NUM (ei->pos);
return value_new_float (pf (x, dof1, dof2, FALSE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_landau[] = {
{ GNM_FUNC_HELP_NAME, F_("LANDAU:approximate probability density function of the Landau distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_EXAMPLES, "=LANDAU(0.34)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDLANDAU"},
{ GNM_FUNC_HELP_END }
};
/* From the GNU Scientific Library 1.1.1 (randist/landau.c)
*
* Copyright (C) 2001 David Morrison
*/
static gnm_float
random_landau_pdf (gnm_float x)
{
static gnm_float P1[5] = {
0.4259894875E0, -0.1249762550E0, 0.3984243700E-1,
-0.6298287635E-2, 0.1511162253E-2
};
static gnm_float P2[5] = {
0.1788541609E0, 0.1173957403E0, 0.1488850518E-1,
-0.1394989411E-2, 0.1283617211E-3
};
static gnm_float P3[5] = {
0.1788544503E0, 0.9359161662E-1, 0.6325387654E-2,
0.6611667319E-4, -0.2031049101E-5
};
static gnm_float P4[5] = {
0.9874054407E0, 0.1186723273E3, 0.8492794360E3,
-0.7437792444E3, 0.4270262186E3
};
static gnm_float P5[5] = {
0.1003675074E1, 0.1675702434E3, 0.4789711289E4,
0.2121786767E5, -0.2232494910E5
};
static gnm_float P6[5] = {
0.1000827619E1, 0.6649143136E3, 0.6297292665E5,
0.4755546998E6, -0.5743609109E7
};
static gnm_float Q1[5] = {
1.0, -0.3388260629E0, 0.9594393323E-1,
-0.1608042283E-1, 0.3778942063E-2
};
static gnm_float Q2[5] = {
1.0, 0.7428795082E0, 0.3153932961E0,
0.6694219548E-1, 0.8790609714E-2
};
static gnm_float Q3[5] = {
1.0, 0.6097809921E0, 0.2560616665E0,
0.4746722384E-1, 0.6957301675E-2
};
static gnm_float Q4[5] = {
1.0, 0.1068615961E3, 0.3376496214E3,
0.2016712389E4, 0.1597063511E4
};
static gnm_float Q5[5] = {
1.0, 0.1569424537E3, 0.3745310488E4,
0.9834698876E4, 0.6692428357E5
};
static gnm_float Q6[5] = {
1.0, 0.6514101098E3, 0.5697473333E5,
0.1659174725E6, -0.2815759939E7
};
static gnm_float A1[3] = {
0.4166666667E-1, -0.1996527778E-1, 0.2709538966E-1
};
static gnm_float A2[2] = {
-0.1845568670E1, -0.4284640743E1
};
gnm_float U, V, DENLAN;
V = x;
if (V < -5.5) {
U = gnm_exp (V + 1.0);
DENLAN = 0.3989422803 * (gnm_exp ( -1 / U) / gnm_sqrt (U)) *
(1 + (A1[0] + (A1[1] + A1[2] * U) * U) * U);
} else if (V < -1) {
U = gnm_exp (-V - 1);
DENLAN = gnm_exp ( -U) * gnm_sqrt (U) *
(P1[0] + (P1[1] + (P1[2] + (P1[3] + P1[4] * V) * V)
* V) * V) /
(Q1[0] + (Q1[1] + (Q1[2] + (Q1[3] + Q1[4] * V) * V)
* V) * V);
} else if (V < 1) {
DENLAN = (P2[0] + (P2[1] + (P2[2] + (P2[3] + P2[4] * V) * V)
* V) * V) /
(Q2[0] + (Q2[1] + (Q2[2] + (Q2[3] + Q2[4] * V) * V)
* V) * V);
} else if (V < 5) {
DENLAN = (P3[0] + (P3[1] + (P3[2] + (P3[3] + P3[4] * V) * V)
* V) * V) /
(Q3[0] + (Q3[1] + (Q3[2] + (Q3[3] + Q3[4] * V) * V)
* V) * V);
} else if (V < 12) {
U = 1 / V;
DENLAN = U * U *
(P4[0] + (P4[1] + (P4[2] + (P4[3] + P4[4] * U) * U)
* U) * U) /
(Q4[0] + (Q4[1] + (Q4[2] + (Q4[3] + Q4[4] * U) * U)
* U) * U);
} else if (V < 50) {
U = 1 / V;
DENLAN = U * U *
(P5[0] + (P5[1] + (P5[2] + (P5[3] + P5[4] * U) * U)
* U) * U) /
(Q5[0] + (Q5[1] + (Q5[2] + (Q5[3] + Q5[4] * U) * U)
* U) * U);
} else if (V < 300) {
U = 1 / V;
DENLAN = U * U *
(P6[0] + (P6[1] + (P6[2] + (P6[3] + P6[4] * U) * U)
* U) * U) /
(Q6[0] + (Q6[1] + (Q6[2] + (Q6[3] + Q6[4] * U) * U)
* U) * U);
} else {
U = 1 / (V - V * log(V) / (V + 1));
DENLAN = U * U * (1 + (A2[0] + A2[1] * U) * U);
}
return DENLAN;
}
static GnmValue *
gnumeric_landau (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
return value_new_float (random_landau_pdf (x));
}
/***************************************************************************/
static GnmFuncHelp const help_finv[] = {
{ GNM_FUNC_HELP_NAME, F_("FINV:inverse of the survival function of the F distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("dof_of_num:numerator degrees of freedom")},
{ GNM_FUNC_HELP_ARG, F_("dof_of_denom:denominator degrees of freedom")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{dof_of_num} < 1 or @{dof_of_denom} < 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("FINV is the OpenFormula function LEGACY.FINV.") },
{ GNM_FUNC_HELP_EXAMPLES, "=FINV(0.2,2,4)" },
{ GNM_FUNC_HELP_SEEALSO, "FDIST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_finv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p = value_get_as_float (argv[0]);
gnm_float dof1 = gnm_fake_floor (value_get_as_float (argv[1]));
gnm_float dof2 = gnm_fake_floor (value_get_as_float (argv[2]));
if (p < 0 || p > 1 || dof1 < 1 || dof2 < 1)
return value_new_error_NUM (ei->pos);
return value_new_float (qf (p, dof1, dof2, FALSE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_binomdist[] = {
{ GNM_FUNC_HELP_NAME, F_("BINOMDIST:probability mass of cumulative distribution function of the binomial distribution")},
{ GNM_FUNC_HELP_ARG, F_("n:number of successes")},
{ GNM_FUNC_HELP_ARG, F_("trials:number of trials")},
{ GNM_FUNC_HELP_ARG, F_("p:probability of success in each trial")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the mass function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{n} or @{trials} are non-integer they are truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{n} < 0 or @{trials} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{n} > @{trials} this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=BINOMDIST(3,5,0.8,0)" },
{ GNM_FUNC_HELP_SEEALSO, "POISSON"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_binomdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float n = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float trials = gnm_fake_floor (value_get_as_float (argv[1]));
gnm_float p = value_get_as_float (argv[2]);
gboolean cuml = value_get_as_checked_bool (argv[3]);
if (n < 0 || trials < 0 || p < 0 || p > 1 || n > trials)
return value_new_error_NUM (ei->pos);
if (cuml)
return value_new_float (pbinom (n, trials, p, TRUE, FALSE));
else
return value_new_float (dbinom (n, trials, p, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_binom_dist_range[] = {
{ GNM_FUNC_HELP_NAME, F_("BINOM.DIST.RANGE:probability of the binomial distribution over an interval")},
{ GNM_FUNC_HELP_ARG, F_("trials:number of trials")},
{ GNM_FUNC_HELP_ARG, F_("p:probability of success in each trial")},
{ GNM_FUNC_HELP_ARG, F_("start:start of the interval")},
{ GNM_FUNC_HELP_ARG, F_("end:end of the interval, defaults to @{start}")},
{ GNM_FUNC_HELP_NOTE, F_("If @{start}, @{end} or @{trials} are non-integer they are truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{trials} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_NOTE, F_("If @{start} > @{end} this function returns 0.")},
{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=BINOM.DIST.RANGE(5,0.8,3,4)" },
{ GNM_FUNC_HELP_SEEALSO, "BINOMDIST,R.PBINOM"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_binom_dist_range (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float trials = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float p = value_get_as_float (argv[1]);
gnm_float start = gnm_fake_floor (value_get_as_float (argv[2]));
gnm_float end = argv[3] ? gnm_fake_floor (value_get_as_float (argv[3])) : start;
if (trials < 0 || p < 0 || p > 1)
return value_new_error_NUM (ei->pos);
return value_new_float (pbinom2 (start, end, trials, p));
}
/***************************************************************************/
static GnmFuncHelp const help_cauchy[] = {
{ GNM_FUNC_HELP_NAME, F_("CAUCHY:probability density or cumulative distribution function of the Cauchy, "
"Lorentz or Breit-Wigner distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("a:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the density function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{a} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{cumulative} is neither TRUE nor FALSE this function returns a #VALUE! error.") },
{ GNM_FUNC_HELP_EXAMPLES, "=CAUCHY(0.43,1,TRUE)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDCAUCHY"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_cauchy (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
gboolean cuml = value_get_as_checked_bool (argv[2]);
if (a < 0)
return value_new_error_NUM (ei->pos);
if (cuml)
return value_new_float (pcauchy (x, 0, a, FALSE, FALSE));
else
return value_new_float (dcauchy (x, 0, a, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_critbinom[] = {
{ GNM_FUNC_HELP_NAME, F_("CRITBINOM:right-tailed critical value of the binomial distribution")},
{ GNM_FUNC_HELP_ARG, F_("trials:number of trials")},
{ GNM_FUNC_HELP_ARG, F_("p:probability of success in each trial")},
{ GNM_FUNC_HELP_ARG, F_("alpha:significance level (area of the tail)")},
{ GNM_FUNC_HELP_NOTE, F_("If @{trials} is a non-integer it is truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{trials} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{alpha} < 0 or @{alpha} > 1 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=CRITBINOM(10,0.5,0.75)" },
{ GNM_FUNC_HELP_SEEALSO, "BINOMDIST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_critbinom (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float trials = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float p = value_get_as_float (argv[1]);
gnm_float alpha = value_get_as_float (argv[2]);
if (trials < 0 || p < 0 || p > 1 || alpha < 0 || alpha > 1)
return value_new_error_NUM (ei->pos);
return value_new_float (qbinom (alpha, trials, p, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_permut[] = {
{ GNM_FUNC_HELP_NAME, F_("PERMUT:number of @{k}-permutations of a @{n}-set")},
{ GNM_FUNC_HELP_ARG, F_("n:size of the base set")},
{ GNM_FUNC_HELP_ARG, F_("k:number of elements in each permutation")},
{ GNM_FUNC_HELP_NOTE, F_("If @{n} = 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{n} < @{k} this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=PERMUT(7,3)" },
{ GNM_FUNC_HELP_SEEALSO, "COMBIN"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_permut (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float n = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float k = gnm_fake_floor (value_get_as_float (argv[1]));
if (0 <= k && k <= n)
return value_new_float (permut (n, k));
else
return value_new_error_NUM (ei->pos);
}
/***************************************************************************/
static GnmFuncHelp const help_hypgeomdist[] = {
{ GNM_FUNC_HELP_NAME, F_("HYPGEOMDIST:probability mass or cumulative distribution function of the hypergeometric distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number of successes")},
{ GNM_FUNC_HELP_ARG, F_("n:sample size")},
{ GNM_FUNC_HELP_ARG, F_("M:number of possible successes in the population")},
{ GNM_FUNC_HELP_ARG, F_("N:population size")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the mass function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x},@{n},@{M} or @{N} is a non-integer it is truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x},@{n},@{M} or @{N} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} > @{M} or @{n} > @{N} this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=HYPGEOMDIST(1,2,3,10)" },
{ GNM_FUNC_HELP_SEEALSO, "BINOMDIST,POISSON"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_hypgeomdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float n = gnm_fake_floor (value_get_as_float (argv[1]));
gnm_float M = gnm_fake_floor (value_get_as_float (argv[2]));
gnm_float N = gnm_fake_floor (value_get_as_float (argv[3]));
gboolean cum = argv[4] ? value_get_as_checked_bool (argv[4]) : FALSE;
if (x < 0 || n < 0 || M < 0 || N < 0 || x > M || n > N)
return value_new_error_NUM (ei->pos);
if (cum)
return value_new_float (phyper (x, M, N - M, n, TRUE, FALSE));
else
return value_new_float (dhyper (x, M, N - M, n, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_confidence[] = {
{ GNM_FUNC_HELP_NAME, F_("CONFIDENCE:margin of error of a confidence interval for the population mean")},
{ GNM_FUNC_HELP_ARG, F_("alpha:significance level")},
{ GNM_FUNC_HELP_ARG, F_("stddev:population standard deviation")},
{ GNM_FUNC_HELP_ARG, F_("size:sample size")},
{ GNM_FUNC_HELP_NOTE, F_("This function requires the usually unknown population standard deviation.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{size} is non-integer it is truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{size} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{size} is 0 this function returns a #DIV/0! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=CONFIDENCE(0.05,1,33)" },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_confidence (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float stddev = value_get_as_float (argv[1]);
gnm_float size = gnm_fake_floor (value_get_as_float (argv[2]));
if (size <= 0 || stddev <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (-qnorm (x / 2, 0, 1, TRUE, FALSE) * (stddev / gnm_sqrt (size)));
}
/***************************************************************************/
static GnmFuncHelp const help_standardize[] = {
{ GNM_FUNC_HELP_NAME, F_("STANDARDIZE:z-score of a value")},
{ GNM_FUNC_HELP_ARG, F_("x:value")},
{ GNM_FUNC_HELP_ARG, F_("mean:mean of the original distribution")},
{ GNM_FUNC_HELP_ARG, F_("stddev:standard deviation of the original distribution")},
{ GNM_FUNC_HELP_NOTE, F_("If @{stddev} is 0 this function returns a #DIV/0! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=STANDARDIZE(3,2,4)" },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_standardize (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gnm_float stddev = value_get_as_float (argv[2]);
if (stddev <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float ((x - mean) / stddev);
}
/***************************************************************************/
static GnmFuncHelp const help_weibull[] = {
{ GNM_FUNC_HELP_NAME, F_("WEIBULL:probability density or cumulative distribution function of the Weibull distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("alpha:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("beta:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the density function or the cumulative distribution function")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("If the @{cumulative} boolean is true it will return: "
"1 - exp (-(@{x}/@{beta})^@{alpha}),otherwise it will return "
"(@{alpha}/@{beta}^@{alpha}) * @{x}^(@{alpha}-1) * exp(-(@{x}/@{beta}^@{alpha})).") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{alpha} <= 0 or @{beta} <= 0 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=WEIBULL(3,2,4,0)" },
{ GNM_FUNC_HELP_SEEALSO, "POISSON"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_weibull (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float alpha = value_get_as_float (argv[1]);
gnm_float beta = value_get_as_float (argv[2]);
gboolean cuml = value_get_as_checked_bool (argv[3]);
if (x < 0 || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
if (cuml)
return value_new_float (pweibull (x, alpha, beta, TRUE, FALSE));
else
return value_new_float (dweibull (x, alpha, beta, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_normdist[] = {
{ GNM_FUNC_HELP_NAME, F_("NORMDIST:probability density or cumulative distribution function of a normal distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("mean:mean of the distribution")},
{ GNM_FUNC_HELP_ARG, F_("stddev:standard deviation of the distribution")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the density function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{stddev} is 0 this function returns a #DIV/0! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=NORMDIST(2,1,2,0)" },
{ GNM_FUNC_HELP_SEEALSO, "POISSON"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_normdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gnm_float stddev = value_get_as_float (argv[2]);
gboolean cuml = value_get_as_checked_bool (argv[3]);
if (stddev <= 0)
return value_new_error_NUM (ei->pos);
if (cuml)
return value_new_float (pnorm (x, mean, stddev, TRUE, FALSE));
else
return value_new_float (dnorm (x, mean, stddev, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_norminv[] = {
{ GNM_FUNC_HELP_NAME, F_("NORMINV:inverse of the cumulative distribution function of a normal distribution")},
{ GNM_FUNC_HELP_ARG, F_("p:probability")},
{ GNM_FUNC_HELP_ARG, F_("mean:mean of the distribution")},
{ GNM_FUNC_HELP_ARG, F_("stddev:standard deviation of the distribution")},
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 or @{stddev} <= 0 this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=NORMINV(0.76,2,3)" },
{ GNM_FUNC_HELP_SEEALSO, "NORMDIST,NORMSDIST,NORMSINV,STANDARDIZE,ZTEST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_norminv (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p = value_get_as_float (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gnm_float stddev = value_get_as_float (argv[2]);
if (p < 0 || p > 1 || stddev <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (qnorm (p, mean, stddev, TRUE, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_kurt[] = {
{ GNM_FUNC_HELP_NAME, F_("KURT:unbiased estimate of the kurtosis of a data set")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.") },
{ GNM_FUNC_HELP_NOTE, F_("This is only meaningful if the underlying "
"distribution really has a fourth moment. The kurtosis is "
"offset by three such that a normal distribution will have zero "
"kurtosis.") },
{ GNM_FUNC_HELP_NOTE, F_("If fewer than four numbers are given or all of them are equal "
"this function returns a #DIV/0! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then KURT(A1:A5) equals 1.234546305.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,VAR,SKEW,KURTP"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_kurt (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_kurtosis_m3_est,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_kurtp[] = {
{ GNM_FUNC_HELP_NAME, F_("KURTP:population kurtosis of a data set")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.") },
{ GNM_FUNC_HELP_NOTE, F_("If fewer than two numbers are given or all of them are equal "
"this function returns a #DIV/0! error.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then KURTP(A1:A5) equals -0.691363424.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,VARP,SKEWP,KURT"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_kurtp (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_kurtosis_m3_pop,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_avedev[] = {
{ GNM_FUNC_HELP_NAME, F_("AVEDEV:average of the absolute deviations of a data set")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then AVEDEV(A1:A5) equals 7.84.") },
{ GNM_FUNC_HELP_SEEALSO, "STDEV"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_avedev (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_avedev,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_NUM);
}
/***************************************************************************/
static GnmFuncHelp const help_devsq[] = {
{ GNM_FUNC_HELP_NAME, F_("DEVSQ:sum of squares of deviations of a data set")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then DEVSQ(A1:A5) equals 470.56.") },
{ GNM_FUNC_HELP_SEEALSO, "STDEV"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_devsq (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_devsq,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_fisher[] = {
{ GNM_FUNC_HELP_NAME, F_("FISHER:Fisher transformation")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} is not a number, this function returns a #VALUE! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} <= -1 or @{x} >= 1, this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=FISHER(0.332)" },
{ GNM_FUNC_HELP_SEEALSO, "FISHERINV,ATANH"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_fisher (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x;
if (!VALUE_IS_NUMBER (argv[0]))
return value_new_error_VALUE (ei->pos);
x = value_get_as_float (argv[0]);
if (x <= -1.0 || x >= 1.0)
return value_new_error_NUM (ei->pos);
return value_new_float (gnm_atanh (x));
}
/***************************************************************************/
static GnmFuncHelp const help_poisson[] = {
{ GNM_FUNC_HELP_NAME, F_("POISSON:probability mass or cumulative distribution function of the Poisson distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number of events")},
{ GNM_FUNC_HELP_ARG, F_("mean:mean of the distribution")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the mass function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{x} is a non-integer it is truncated.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{mean} <= 0 POISSON returns the #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=POISSON(3,6,0)"},
{ GNM_FUNC_HELP_SEEALSO, ("NORMDIST,WEIBULL")},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_poisson (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float mean = value_get_as_float (argv[1]);
gboolean cuml = value_get_as_checked_bool (argv[2]);
if (x < 0 || mean <= 0)
return value_new_error_NUM (ei->pos);
if (cuml)
return value_new_float (ppois (x, mean, TRUE, FALSE));
else
return value_new_float (dpois (x, mean, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_pearson[] = {
{ GNM_FUNC_HELP_NAME, F_("PEARSON:Pearson correlation coefficient of the paired set of data")},
{ GNM_FUNC_HELP_ARG, F_("array1:first component values")},
{ GNM_FUNC_HELP_ARG, F_("array2:second component values")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_SEEALSO, "INTERCEPT,LINEST,RSQ,SLOPE,STEYX"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_pearson (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return gnumeric_correl (ei, argv);
}
/***************************************************************************/
static GnmFuncHelp const help_rsq[] = {
{ GNM_FUNC_HELP_NAME, F_("RSQ:square of the Pearson correlation coefficient of the paired set of data")},
{ GNM_FUNC_HELP_ARG, F_("array1:first component values")},
{ GNM_FUNC_HELP_ARG, F_("array2:second component values")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_SEEALSO, ("CORREL,COVAR,INTERCEPT,LINEST,LOGEST,PEARSON,SLOPE,STEYX,TREND")},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_rsq (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return float_range_function2 (argv[0], argv[1],
ei,
gnm_range_rsq_pop,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_median[] = {
{ GNM_FUNC_HELP_NAME, F_("MEDIAN:median of a data set")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("Strings and empty cells are simply ignored.") },
{ GNM_FUNC_HELP_NOTE, F_("If even numbers are given MEDIAN returns the average of the two "
"numbers in the center.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then MEDIAN(A1:A5) equals 21.3.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE,COUNT,COUNTA,DAVERAGE,MODE,SSMEDIAN,SUM"},
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Median") },
{ GNM_FUNC_HELP_EXTREF, F_("wolfram:StatisticalMedian.html") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_median (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_median_inter_sorted,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
GNM_ERROR_NUM);
}
/***************************************************************************/
static GnmFuncHelp const help_ssmedian[] = {
{ GNM_FUNC_HELP_NAME, F_("SSMEDIAN:median for grouped data as commonly determined in the social sciences")},
{ GNM_FUNC_HELP_ARG, F_("array:data set")},
{ GNM_FUNC_HELP_ARG, F_("interval:length of each grouping interval, defaults to 1")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The data points given in @{array} are assumed to be the result of "
"grouping data into intervals of length @{interval}") },
{ GNM_FUNC_HELP_NOTE, F_("If @{array} is empty, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{interval} <= 0, this function returns a #NUM! error."
"SSMEDIAN does not check whether the data points are "
"at least @{interval} apart.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, A3 contain numbers 7, 8, 8.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then SSMEDIAN(A1:A3, 1) equals 7.75.") },
{ GNM_FUNC_HELP_SEEALSO, "MEDIAN"},
{ GNM_FUNC_HELP_END }
};
static gnm_float
gnumeric_ssmedian_calc (gnm_float const *sorted_data, int len,
gnm_float mid_val, gnm_float interval)
{
gnm_float L_lower = mid_val - interval / 2;
gnm_float L_upper = mid_val + interval / 2;
int f_below = 0;
int f_within = 0;
int i;
for (i = 0; i < len; i++) {
if (*sorted_data < L_lower)
f_below++;
else if (*sorted_data <= L_upper)
f_within++;
else
break;
sorted_data++;
}
return L_lower + (len / 2e0 - f_below) * interval / f_within;
}
static GnmValue *
gnumeric_ssmedian (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *data;
GnmValue *result = NULL;
gnm_float interval;
int n;
data = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
&n, &result);
if (result)
goto done;
interval = argv[1] ? value_get_as_float (argv[1]) : 1.0;
if (interval <= 0 || n == 0) {
result = value_new_error_NUM (ei->pos);
goto done;
}
switch (n) {
case (1):
result = value_new_float (data[0]);
break;
case (2):
result = value_new_float ((data[0] + data[1]) / 2);
break;
default:
if (n % 2 == 0) {
gnm_float m1 = data[n / 2];
gnm_float m0 = data[n / 2 - 1];
result = value_new_float
(m1 == m1
? gnumeric_ssmedian_calc (data, n,
m1, interval)
: (m0 + m1) / 2);
} else {
result = value_new_float
(gnumeric_ssmedian_calc
(data, n, data[n / 2], interval));
}
}
done:
g_free (data);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_large[] = {
{ GNM_FUNC_HELP_NAME, F_("LARGE:@{k}-th largest value in a data set")},
{ GNM_FUNC_HELP_ARG, F_("data:data set")},
{ GNM_FUNC_HELP_ARG, F_("k:which value to find")},
{ GNM_FUNC_HELP_NOTE, F_("If data set is empty this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{k} <= 0 or @{k} is greater than the number of data items given "
"this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then LARGE(A1:A5,2) equals 25.9."
"LARGE(A1:A5,4) equals 17.3.") },
{ GNM_FUNC_HELP_SEEALSO, "PERCENTILE,PERCENTRANK,QUARTILE,SMALL"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_large (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
int n;
GnmValue *res = NULL;
gnm_float *xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
&n, &res);
gnm_float k = value_get_as_float (argv[1]);
if (res)
return res;
k = gnm_fake_ceil (k);
if (k >= 1 && k <= n)
res = value_new_float (xs[n - (int)k]);
else
res = value_new_error_NUM (ei->pos);
g_free (xs);
return res;
}
/***************************************************************************/
static GnmFuncHelp const help_small[] = {
{ GNM_FUNC_HELP_NAME, F_("SMALL:@{k}-th smallest value in a data set")},
{ GNM_FUNC_HELP_ARG, F_("data:data set")},
{ GNM_FUNC_HELP_ARG, F_("k:which value to find")},
{ GNM_FUNC_HELP_NOTE, F_("If data set is empty this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{k} <= 0 or @{k} is greater than the number of data items given "
"this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then SMALL(A1:A5,2) equals 17.3."
"SMALL(A1:A5,4) equals 25.9.") },
{ GNM_FUNC_HELP_SEEALSO, "PERCENTILE,PERCENTRANK,QUARTILE,LARGE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_small (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
int n;
GnmValue *res = NULL;
gnm_float *xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
&n, &res);
gnm_float k = value_get_as_float (argv[1]);
if (res)
return res;
k = gnm_fake_ceil (k);
if (k >= 1 && k <= n)
res = value_new_float (xs[(int)k - 1]);
else
res = value_new_error_NUM (ei->pos);
g_free (xs);
return res;
}
/***********************************************************************/
static GnmFuncHelp const help_prob[] = {
{ GNM_FUNC_HELP_NAME, F_("PROB:probability of an interval for a discrete (and finite) probability distribution")},
{ GNM_FUNC_HELP_ARG, F_("x_range:possible values")},
{ GNM_FUNC_HELP_ARG, F_("prob_range:probabilities of the corresponding values")},
{ GNM_FUNC_HELP_ARG, F_("lower_limit:lower interval limit")},
{ GNM_FUNC_HELP_ARG, F_("upper_limit:upper interval limit, defaults to @{lower_limit}")},
{ GNM_FUNC_HELP_NOTE, F_("If the sum of the probabilities in @{prob_range} is not equal to 1 "
"this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If any value in @{prob_range} is <=0 or > 1, this function returns a #NUM! "
"error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x_range} and @{prob_range} contain a different number of data "
"entries, this function returns a #N/A error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_SEEALSO, "BINOMDIST,CRITBINOM"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_prob (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmValue *res;
GnmValue *error = NULL;
int i, prob_n, x_n;
gnm_float *prob_vals = NULL, *x_vals = NULL;
gnm_float lower_limit, upper_limit;
gnm_float total_sum = 0, sum = 0;
lower_limit = value_get_as_float (argv[2]);
upper_limit = argv[3] ? value_get_as_float (argv[3]) : lower_limit;
x_vals = collect_floats_value
(argv[0], ei->pos,
COLLECT_IGNORE_STRINGS | COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
&x_n, &error);
if (error) {
res = error;
goto out;
}
prob_vals = collect_floats_value
(argv[1], ei->pos,
COLLECT_IGNORE_STRINGS | COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
&prob_n, &error);
if (error) {
res = error;
goto out;
}
if (x_n != prob_n) {
res = value_new_error_NA (ei->pos);
goto out;
}
for (i = 0; i < x_n; i++) {
gnm_float x = x_vals[i];
gnm_float prob = prob_vals[i];
/* FIXME: Check "0" behaviour with Excel and comment. */
if (prob <= 0 || prob > 1) {
res = value_new_error_NUM (ei->pos);
goto out;
}
total_sum += prob;
if (x >= lower_limit && x <= upper_limit)
sum += prob;
}
if (gnm_abs (total_sum - 1) > x_n * 2 * GNM_EPSILON) {
res = value_new_error_NUM (ei->pos);
goto out;
}
res = value_new_float (sum);
out:
g_free (x_vals);
g_free (prob_vals);
return res;
}
/***************************************************************************/
static GnmFuncHelp const help_steyx[] = {
{ GNM_FUNC_HELP_NAME, F_("STEYX:standard error of the predicted y-value in the regression")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values")},
{ GNM_FUNC_HELP_NOTE, F_("If @{known_ys} and @{known_xs} are empty or have a different "
"number of arguments then this function returns a #N/A error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then STEYX(A1:A5,B1:B5) equals 1.101509979.") },
{ GNM_FUNC_HELP_SEEALSO, "PEARSON,RSQ,SLOPE"},
{ GNM_FUNC_HELP_END }
};
static int
range_steyx (gnm_float const *xs, gnm_float const *ys, int n, gnm_float *res)
{
gnm_float linres[2];
int dim = 1;
GORegressionResult regres;
gnm_regression_stat_t *extra_stat;
gboolean affine = TRUE;
extra_stat = gnm_regression_stat_new ();
regres = gnm_linear_regression ((gnm_float **)&xs, dim,
ys, n, affine, linres, extra_stat);
*res = gnm_sqrt (extra_stat->var);
gnm_regression_stat_destroy (extra_stat);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
return 0;
default:
return 1;
}
}
static GnmValue *
gnumeric_steyx (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return float_range_function2 (argv[1], argv[0],
ei,
range_steyx,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_ztest[] = {
{ GNM_FUNC_HELP_NAME, F_("ZTEST:the probability of observing a sample mean as large as "
"or larger than the mean of the given sample")},
{ GNM_FUNC_HELP_ARG, F_("ref:data set (sample)")},
{ GNM_FUNC_HELP_ARG, F_("x:population mean")},
{ GNM_FUNC_HELP_ARG, F_("stddev:population standard deviation, defaults to the sample standard deviation")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("ZTEST calulates the probability of observing a sample mean as large as "
"or larger than the mean of the given sample for samples drawn "
"from a normal distribution with mean @{x} and standard deviation @{stddev}.")},
{ GNM_FUNC_HELP_NOTE, F_("If @{ref} contains less than two data items ZTEST "
"returns #DIV/0! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then ZTEST(A1:A5,20) equals 0.254717826.")},
{ GNM_FUNC_HELP_SEEALSO, ("CONFIDENCE,NORMDIST,NORMINV,NORMSDIST,NORMSINV,STANDARDIZE")},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_ztest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
int n;
gnm_float *xs;
GnmValue *result = NULL;
gnm_float x, s, m, p;
xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS,
&n, &result);
if (result)
goto done;
x = value_get_as_float (argv[1]);
if (gnm_range_average (xs, n, &m)) {
result = value_new_error_DIV0 (ei->pos);
goto done;
}
if (argv[2])
s = value_get_as_float (argv[2]);
else if (gnm_range_stddev_est (xs, n, &s)) {
result = value_new_error_DIV0 (ei->pos);
goto done;
}
if (s <= 0) {
result = value_new_error_DIV0 (ei->pos);
goto done;
}
p = pnorm (x, m, s / gnm_sqrt (n), TRUE, FALSE);
result = value_new_float (p);
done:
g_free (xs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_averagea[] = {
{ GNM_FUNC_HELP_NAME, F_("AVERAGEA:average of all the values and cells")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings 11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then AVERAGEA(A1:A5) equals 18.94.") },
{ GNM_FUNC_HELP_SEEALSO, "AVERAGE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_averagea (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_average,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_DIV0);
}
/***************************************************************************/
static GnmFuncHelp const help_maxa[] = {
{ GNM_FUNC_HELP_NAME, F_("MAXA:largest value, with negative numbers considered smaller than positive numbers")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings "
"11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then MAXA(A1:A5) equals 40.1.") },
{ GNM_FUNC_HELP_SEEALSO, "MAX,MINA"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_maxa (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_max,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_mina[] = {
{ GNM_FUNC_HELP_NAME, F_("MINA:smallest value, with negative numbers considered smaller than positive numbers")},
{ GNM_FUNC_HELP_ARG, F_("number1:first value")},
{ GNM_FUNC_HELP_ARG, F_("number2:second value")},
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings "
"11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then MINA(A1:A5) equals 0.") },
{ GNM_FUNC_HELP_SEEALSO, "MIN,MAXA"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_mina (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_min,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_vara[] = {
{ GNM_FUNC_HELP_NAME, F_("VARA:sample variance of the given sample")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("VARA is also known as the N-1-variance.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("To get the true variance of a complete population use VARPA.") },
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_NOTE, F_("Since the N-1-variance includes Bessel's correction, whereas the N-variance calculated by VARPA or VARP does not, "
"under reasonable conditions the N-1-variance is an unbiased estimator of the variance of the population "
"from which the sample is drawn.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings "
"11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then VARA(A1:A5) equals 228.613.") },
{ GNM_FUNC_HELP_SEEALSO, "VAR,VARPA"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_vara (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_var_est,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_varpa[] = {
{ GNM_FUNC_HELP_NAME, F_("VARPA:variance of an entire population")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("VARPA is also known as the N-variance.") },
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings "
"11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then VARPA(A1:A5) equals 182.8904.") },
{ GNM_FUNC_HELP_SEEALSO, "VARA,VARP"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_varpa (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_var_pop,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_stdeva[] = {
{ GNM_FUNC_HELP_NAME, F_("STDEVA:sample standard deviation of the given "
"sample")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("STDEVA is also known as the N-1-standard deviation.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("To obtain the population standard deviation of a whole population "
"use STDEVPA.")},
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings "
"11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then STDEVA(A1:A5) equals 15.119953704.") },
{ GNM_FUNC_HELP_SEEALSO, "STDEV,STDEVPA"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_stdeva (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_stddev_est,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_stdevpa[] = {
{ GNM_FUNC_HELP_NAME, F_("STDEVPA:population standard deviation of an entire population")},
{ GNM_FUNC_HELP_ARG, F_("area1:first cell area")},
{ GNM_FUNC_HELP_ARG, F_("area2:second cell area")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("This is also known as the N-standard deviation")},
HELP_DESCRIPTION_TEXT_INCLUSION,
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers and strings "
"11.4, 17.3, \"missing\", 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then STDEVPA(A1:A5) equals 13.523697719.") },
{ GNM_FUNC_HELP_SEEALSO, "STDEVA,STDEVP"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_stdevpa (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
return float_range_function (argc, argv, ei,
gnm_range_stddev_pop,
COLLECT_ZERO_STRINGS |
COLLECT_ZEROONE_BOOLS |
COLLECT_IGNORE_BLANKS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_percentrank[] = {
{ GNM_FUNC_HELP_NAME, F_("PERCENTRANK:rank of a data point in a data set")},
{ GNM_FUNC_HELP_ARG, F_("array:range of numeric values")},
{ GNM_FUNC_HELP_ARG, F_("x:data point to be ranked")},
{ GNM_FUNC_HELP_ARG, F_("significance:number of significant digits, defaults to 3")},
{ GNM_FUNC_HELP_NOTE, F_("If @{array} contains no data points, this function returns a #NUM! "
"error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{significance} is less than one, this function returns a #NUM! "
"error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} exceeds the largest value or is less than the smallest "
"value in @{array}, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} does not match any of the values in @{array} or @{x} matches "
"more than once, this function interpolates the returned value.") },
{ GNM_FUNC_HELP_SEEALSO, "LARGE,MAX,MEDIAN,MIN,PERCENTILE,QUARTILE,SMALL"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_percentrank (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *data, x, significance, r;
GnmValue *result = NULL;
int i, n;
int n_equal, n_smaller, n_larger;
gnm_float x_larger, x_smaller;
data = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
x = value_get_as_float (argv[1]);
significance = argv[2] ? value_get_as_float (argv[2]) : 3;
if (result)
goto done;
n_equal = n_smaller = n_larger = 0;
x_larger = x_smaller = 42;
for (i = 0; i < n; i++) {
gnm_float y = data[i];
if (y < x) {
if (n_smaller == 0 || x_smaller < y)
x_smaller = y;
n_smaller++;
} else if (y > x) {
if (n_larger == 0 || x_larger > y)
x_larger = y;
n_larger++;
} else
n_equal++;
}
if (n_smaller + n_equal == 0 || n_larger + n_equal == 0) {
result = value_new_error_NA (ei->pos);
goto done;
}
if (n == 1)
r = 1;
else {
gnm_float s10;
if (n_equal > 0)
r = n_smaller / (gnm_float)(n - 1);
else {
gnm_float r1 = (n_smaller - 1) / (gnm_float)(n - 1);
gnm_float r2 = n_smaller / (gnm_float)(n - 1);
r = (r1 * (x_larger - x) +
r2 * (x - x_smaller)) / (x_larger - x_smaller);
}
/* A strange place to check, but n==1 is special. */
if (significance < 0) {
result = value_new_error_NUM (ei->pos);
goto done;
}
s10 = gnm_pow10 (-significance);
if (s10 <= 0) {
result = value_new_error_DIV0 (ei->pos);
goto done;
}
r = gnm_fake_trunc (r / s10) * s10;
}
result = value_new_float (r);
done:
g_free (data);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_percentile[] = {
{ GNM_FUNC_HELP_NAME, F_("PERCENTILE:determines the 100*@{k}-th percentile of the given data points")},
{ GNM_FUNC_HELP_ARG, F_("array:data points")},
{ GNM_FUNC_HELP_ARG, F_("k:which percentile to calculate")},
{ GNM_FUNC_HELP_NOTE, F_("If @{array} is empty, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{k} < 0 or @{k} > 1, this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then PERCENTILE(A1:A5,0.42) equals 20.02.") },
{ GNM_FUNC_HELP_SEEALSO, "QUARTILE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_percentile (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *data;
GnmValue *result = NULL;
int n;
data = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
&n, &result);
if (!result) {
gnm_float p = value_get_as_float (argv[1]);
gnm_float res;
if (gnm_range_fractile_inter_sorted (data, n, &res, p))
result = value_new_error_NUM (ei->pos);
else
result = value_new_float (res);
}
g_free (data);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_quartile[] = {
{ GNM_FUNC_HELP_NAME, F_("QUARTILE:the @{k}-th quartile of the data points")},
{ GNM_FUNC_HELP_ARG, F_("array:data points")},
{ GNM_FUNC_HELP_ARG, F_("quart:a number from 0 to 4, indicating which quartile to calculate")},
{ GNM_FUNC_HELP_NOTE, F_("If @{array} is empty, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{quart} < 0 or @{quart} > 4, this function returns a #NUM! error. If @{quart} = 0, the smallest value of @{array} to be returned.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{quart} is not an integer, it is truncated.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 11.4, 17.3, 21.3, 25.9, and 40.1.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then QUARTILE(A1:A5,1) equals 17.3.") },
{ GNM_FUNC_HELP_SEEALSO, "LARGE,MAX,MEDIAN,MIN,PERCENTILE,SMALL"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_quartile (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *data;
GnmValue *result = NULL;
int n;
data = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_SORT,
&n, &result);
if (!result) {
gnm_float q = gnm_fake_floor (value_get_as_float (argv[1]));
gnm_float res;
if (gnm_range_fractile_inter_sorted (data, n, &res, q / 4.0))
result = value_new_error_NUM (ei->pos);
else
result = value_new_float (res);
}
g_free (data);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_ftest[] = {
{ GNM_FUNC_HELP_NAME, F_("FTEST:p-value for the two-tailed hypothesis test comparing the "
"variances of two populations")},
{ GNM_FUNC_HELP_ARG, F_("array1:sample from the first population")},
{ GNM_FUNC_HELP_ARG, F_("array2:sample from the second population")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then FTEST(A1:A5,B1:B5) equals 0.510815017.") },
{ GNM_FUNC_HELP_SEEALSO, "FDIST,FINV"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_ftest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
CollectFlags flags = COLLECT_IGNORE_STRINGS | COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS;
gnm_float *xs = NULL, *ys = NULL;
int nx, ny;
GnmValue *res = NULL;
gnm_float p, varx, vary;
xs = collect_floats_value (argv[0], ei->pos, flags, &nx, &res);
if (res)
goto out;
ys = collect_floats_value (argv[1], ei->pos, flags, &ny, &res);
if (res)
goto out;
if (gnm_range_var_est (xs, nx, &varx) ||
gnm_range_var_est (ys, ny, &vary) ||
vary == 0) {
res = value_new_error_DIV0 (ei->pos);
goto out;
}
p = pf (varx / vary, nx - 1, ny - 1, FALSE, FALSE);
if (p > 0.5) {
/*
* We need the other tail and 1-p might not be very accurate.
*/
p = pf (varx / vary, nx - 1, ny - 1, TRUE, FALSE);
}
res = value_new_float (2 * p);
out:
g_free (xs);
g_free (ys);
return res;
}
/***************************************************************************/
static GnmFuncHelp const help_ttest[] = {
{ GNM_FUNC_HELP_NAME, F_("TTEST:p-value for a hypothesis test comparing the means of two populations using "
"the Student t-distribution")},
{ GNM_FUNC_HELP_ARG, F_("array1:sample from the first population")},
{ GNM_FUNC_HELP_ARG, F_("array2:sample from the second population")},
{ GNM_FUNC_HELP_ARG, F_("tails:number of tails to consider")},
{ GNM_FUNC_HELP_ARG, F_("type:Type of test to perform. 1 indicates a test for paired variables, "
"2 a test of unpaired variables with equal variances, and "
"3 a test of unpaired variables with unequal variances")},
{ GNM_FUNC_HELP_NOTE, F_("If the data sets contain a different number of data points and "
"the test is paired (@{type} one), TTEST returns the #N/A error.") },
{ GNM_FUNC_HELP_NOTE, F_("@{tails} and @{type} are truncated to integers.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{tails} is not one or two, this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{type} is any other than one, two, or three, this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then TTEST(A1:A5,B1:B5,1,1) equals 0.003127619."
"TTEST(A1:A5,B1:B5,2,1) equals 0.006255239."
"TTEST(A1:A5,B1:B5,1,2) equals 0.111804322."
"TTEST(A1:A5,B1:B5,1,3) equals 0.113821797.") },
{ GNM_FUNC_HELP_SEEALSO, "FDIST,FINV"},
{ GNM_FUNC_HELP_END }
};
static int barf_ttest_dof;
static int
calc_ttest_paired (gnm_float const *xs, gnm_float const *ys, int n,
gnm_float *res)
{
gnm_float *zs, zm, zsig;
gboolean err;
int i;
if (n == 0)
return 1;
/* zs = xs - ys */
zs = g_memdup (xs, n * sizeof (*xs));
for (i = 0; i < n; i++)
zs[i] -= ys[i];
err = (gnm_range_average (zs, n, &zm) ||
gnm_range_stddev_est (zs, n, &zsig) ||
zsig == 0);
g_free (zs);
if (err)
return 1;
else {
*res = gnm_sqrt (n) * (zm / zsig);
/* We need this n out of here. For now, hack it. */
barf_ttest_dof = n - 1;
return 0;
}
}
static GnmValue *
ttest_paired (GnmFuncEvalInfo *ei,
GnmValue const *r0, GnmValue const *r1, int tails)
{
int w0 = value_area_get_width (r0, ei->pos);
int h0 = value_area_get_height (r0, ei->pos);
int w1 = value_area_get_width (r1, ei->pos);
int h1 = value_area_get_height (r1, ei->pos);
GnmValue *v;
gnm_float x;
/* Size error takes precedence over everything else. */
if (w0 * h0 != w1 * h1)
return value_new_error_NA (ei->pos);
v = float_range_function2 (r0, r1, ei, calc_ttest_paired,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_DIV0);
if (!VALUE_IS_NUMBER (v))
return v;
x = value_get_as_float (v);
value_release (v);
return value_new_float (tails * pt (gnm_abs (x), barf_ttest_dof,
FALSE, FALSE));
}
static GnmValue *
ttest_equal_unequal (GnmFuncEvalInfo *ei,
GnmValue const *rx, GnmValue const *ry, int tails,
gboolean unequal)
{
CollectFlags flags = COLLECT_IGNORE_STRINGS | COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS;
gnm_float *xs = NULL, *ys = NULL;
int nx, ny;
GnmValue *res = NULL;
gnm_float mx, vx, my, vy, dof, t;
xs = collect_floats_value (rx, ei->pos, flags, &nx, &res);
if (res)
goto out;
ys = collect_floats_value (ry, ei->pos, flags, &ny, &res);
if (res)
goto out;
if (gnm_range_average (xs, nx, &mx) ||
gnm_range_var_est (xs, nx, &vx) ||
gnm_range_average (ys, ny, &my) ||
gnm_range_var_est (ys, ny, &vy)) {
res = value_new_error_DIV0 (ei->pos);
goto out;
}
if (vx == 0 && vy == 0) {
/* Note sure here. */
res = value_new_error_DIV0 (ei->pos);
goto out;
}
if (unequal) {
gnm_float S = (vx / nx + vy / ny);
gnm_float c = (vx / nx) / S;
gnm_float cC = (vy / ny) / S;
dof = 1.0 / (c * c / (nx - 1) + cC * cC / (ny - 1));
t = gnm_abs (mx - my) / gnm_sqrt (S);
} else {
dof = nx + ny - 2;
t = (gnm_abs (mx - my) *
gnm_sqrt (dof * nx * ny /
((nx + ny) * ((nx - 1) * vx + (ny - 1) * vy))));
}
res = value_new_float (tails * pt (t, dof, FALSE, FALSE));
out:
g_free (xs);
g_free (ys);
return res;
}
static GnmValue *
gnumeric_ttest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float tails = value_get_as_float (argv[2]);
gnm_float type = value_get_as_float (argv[3]);
int itails;
if (tails != 1 && tails != 2)
return value_new_error_NUM (ei->pos);
itails = (int)tails;
if (type != 1 && type != 2 && type != 3)
return value_new_error_NUM (ei->pos);
switch ((int)type) {
case 1:
return ttest_paired (ei, argv[0], argv[1], itails);
case 2:
return ttest_equal_unequal (ei, argv[0], argv[1], itails, FALSE);
case 3:
return ttest_equal_unequal (ei, argv[0], argv[1], itails, TRUE);
default:
return value_new_error_NUM (ei->pos);
}
}
/***************************************************************************/
static GnmFuncHelp const help_frequency[] = {
{ GNM_FUNC_HELP_NAME, F_("FREQUENCY:frequency table")},
{ GNM_FUNC_HELP_ARG, F_("data_array:data values")},
{ GNM_FUNC_HELP_ARG, F_("bins_array:array of cutoff values")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The results are given as an array.") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("If the @{bin_array} is empty, this function "
"returns the number of data points "
"in @{data_array}.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_frequency (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
CollectFlags flags = COLLECT_IGNORE_STRINGS | COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS;
GnmValue *error = NULL, *res;
int *counts;
int i, nvalues, nbins;
gnm_float *values = NULL, *bins = NULL;
values = collect_floats_value (argv[0], ei->pos, flags,
&nvalues, &error);
if (error) {
res = error;
goto out;
}
bins = collect_floats_value (argv[1], ei->pos, flags | COLLECT_SORT,
&nbins, &error);
if (error) {
res = error;
goto out;
}
/* Special case. */
if (nbins == 0) {
res = value_new_int (nvalues);
goto out;
}
counts = g_new0 (int, nbins + 1);
/* Stupid code. */
for (i = 0; i < nvalues; i++) {
int j;
for (j = 0; j < nbins; j++)
if (values[i] <= bins[j])
break;
counts[j]++;
}
res = value_new_array_non_init (1, nbins + 1);
res->v_array.vals[0] = g_new (GnmValue *, nbins + 1);
for (i = 0; i < nbins + 1; i++)
res->v_array.vals[0][i] = value_new_float (counts[i]);
g_free (counts);
out:
g_free (values);
g_free (bins);
return res;
}
/***************************************************************************/
/* Notes for now, to be incorporated into help when it actually works:
*
* Entered as linest(Yrange, [Xrange, [Intercept, [Stat]]]). Intercept and Stat
* work as above. According to playing with Excel, if Yrange is an array, Xrange
* must be an array. They claim that you can use semicolons to separate rows in
* an array, but I've never gotten that to work. If Yrange is a single column,
* every column in the Xrange (which must be a cell range) is interpreted as a
* separate variable. Similar for a single row. If Y is a blob, X is interpreted
* as a single variable blob. Experiments suggest that multivariable blobs don't work.
* Currently everything should be implemented except for inputting arrays. X's must
* be contiguous so far as I can tell.
*/
typedef struct {
gnm_float *ys;
int n;
gnm_float **xss;
int dim;
} GnmRegData;
static void
gnm_reg_data_free (GnmRegData *data)
{
int i;
g_free (data->ys);
for (i = 0; i < data->dim; i++)
g_free (data->xss[i]);
g_free (data->xss);
memset (data, 0, sizeof (*data));
}
static gnm_float *
gnm_reg_get_var (GnmValue const *xval, int x, int y, int dx, int dy,
int n, GnmEvalPos const *ep)
{
gnm_float *res = g_new (gnm_float, n);
int i;
for (i = 0; i < n; i++) {
GnmValue const *v = value_area_fetch_x_y (xval, x, y, ep);
if (!VALUE_IS_FLOAT (v)) {
/* Anything else is an error. */
g_free (res);
return NULL;
}
res[i] = value_get_as_float (v);
x += dx;
y += dy;
}
return res;
}
static GnmValue *
gnm_reg_data_collect (GnmValue const *yval, GnmValue const *xval,
GnmRegData *data, GnmEvalPos const *ep)
{
int yh = value_area_get_height (yval, ep);
int yw = value_area_get_width (yval, ep);
int ny;
GnmValue *result = NULL;
memset (data, 0, sizeof (*data));
/* Blanks, bools, strings, errors all are forbidden. */
data->ys = collect_floats_value (yval, ep, 0,
&ny, &result);
if (result || ny <= 0)
goto error;
data->n = ny;
if (VALUE_IS_EMPTY (xval)) {
int i;
data->dim = 1;
data->xss = g_new (gnm_float *, data->dim);
data->xss[0] = g_new (gnm_float, ny);
for (i = 0; i < ny; i++)
data->xss[0][i] = i + 1;
} else {
int xh = value_area_get_height (xval, ep);
int xw = value_area_get_width (xval, ep);
int i, nx;
if (yw == 1) {
/* X's columns are the variables. */
if (xh != yh)
goto ref_error;
data->dim = xw;
data->xss = g_new0 (gnm_float *, data->dim);
for (i = 0; i < data->dim; i++) {
data->xss[i] = gnm_reg_get_var
(xval, i, 0, 0, +1, xh, ep);
if (!data->xss[i])
goto error;
}
} else if (yh == 1) {
/* X's rows are the variables. */
if (xw != yw)
goto ref_error;
data->dim = xh;
data->xss = g_new0 (gnm_float *, data->dim);
for (i = 0; i < data->dim; i++) {
data->xss[i] = gnm_reg_get_var
(xval, 0, i, +1, 0, xw, ep);
if (!data->xss[i])
goto error;
}
} else {
if (xh != yh || xw != yw)
goto ref_error;
data->dim = 1;
data->xss = g_new0 (gnm_float *, data->dim);
data->xss[0] = collect_floats_value (xval, ep, 0,
&nx, &result);
if (result)
goto error;
}
}
return NULL;
error:
value_release (result);
/* Always this kind of error. */
result = value_new_error_VALUE (ep);
gnm_reg_data_free (data);
return result;
ref_error:
/* If the areas have the wrong shape, we get #REF! */
gnm_reg_data_free (data);
return value_new_error_REF (ep);
}
static GnmFuncHelp const help_linest[] = {
{ GNM_FUNC_HELP_NAME, F_("LINEST:multiple linear regression coefficients and statistics") },
{ GNM_FUNC_HELP_ARG, F_("known_ys:vector of values of dependent variable") },
{ GNM_FUNC_HELP_ARG, F_("known_xs:array of values of independent variables, defaults to a single vector {1,\xe2\x80\xa6,n}") },
{ GNM_FUNC_HELP_ARG, F_("affine:if true, the model contains a constant term, defaults to true") },
{ GNM_FUNC_HELP_ARG, F_("stats:if true, some additional statistics are provided, defaults to false") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function returns an array with the first row giving the regression "
"coefficients for the independent variables "
"x_m, x_(m-1),\xe2\x80\xa6,x_2, x_1 followed by the y-intercept if @{affine} is true.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("If @{stats} is true, the second row contains the corresponding standard "
"errors of the regression coefficients."
"In this case, the third row contains the R^2 value and the standard error "
"for the predicted value. "
"The fourth row contains the observed F value and its degrees of freedom. "
"Finally, the fifth row contains the regression sum of squares and the "
"residual sum of squares.") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("If @{affine} is false, R^2 is the uncentered version of the coefficient "
"of determination; "
"that is the proportion of the sum of squares explained by the model.")},
{ GNM_FUNC_HELP_NOTE, F_("If the length of @{known_ys} does not match the corresponding length of @{known_xs}, "
"this function returns a #NUM! error.")},
{ GNM_FUNC_HELP_SEEALSO, "LOGEST,TREND" },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_linest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmRegData data;
gnm_regression_stat_t *extra_stat = NULL;
GORegressionResult regres;
GnmValue *result;
gnm_float *linres = NULL;
gboolean affine, withstat;
int i, dim;
result = gnm_reg_data_collect (argv[0], argv[1], &data, ei->pos);
if (result)
return result;
dim = data.dim;
affine = argv[2] ? value_get_as_checked_bool (argv[2]) : TRUE;
withstat = argv[3] ? value_get_as_checked_bool (argv[3]) : FALSE;
linres = g_new (gnm_float, dim + 1);
extra_stat = gnm_regression_stat_new ();
regres = gnm_linear_regression (data.xss, dim,
data.ys, data.n, affine,
linres, extra_stat);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
result = value_new_error_NUM (ei->pos);
goto out;
}
if (withstat) {
result = value_new_array (dim + 1, 5);
value_array_set (result, 0, 2,
value_new_float (extra_stat->sqr_r));
value_array_set (result, 1, 2,
value_new_float (gnm_sqrt (extra_stat->var)));
value_array_set (result, 0, 3,
value_new_float (extra_stat->F));
value_array_set (result, 1, 3,
value_new_float (extra_stat->df_resid));
value_array_set (result, 0, 4,
value_new_float (extra_stat->ss_reg));
value_array_set (result, 1, 4,
value_new_float (extra_stat->ss_resid));
for (i = 0; i < dim; i++)
value_array_set (result, dim - i - 1, 1,
value_new_float (extra_stat->se[i+affine]));
value_array_set (result, dim, 1,
affine ? value_new_float (extra_stat->se[0])
: value_new_error_NA (ei->pos));
} else
result = value_new_array (dim + 1, 1);
value_array_set (result, dim, 0, value_new_float (linres[0]));
for (i = 0; i < dim; i++)
value_array_set (result, dim - i - 1, 0,
value_new_float (linres[i + 1]));
out:
gnm_reg_data_free (&data);
g_free (linres);
gnm_regression_stat_destroy (extra_stat);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_logreg[] = {
{ GNM_FUNC_HELP_NAME, F_("LOGREG:the logarithmic regression")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values; defaults to the array {1, 2, 3, \xe2\x80\xa6}")},
{ GNM_FUNC_HELP_ARG, F_("affine:if true, the model contains a constant term, defaults to true")},
{ GNM_FUNC_HELP_ARG, F_("stat:if true, extra statistical information will be returned; defaults to FALSE")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("LOGREG function transforms your x's to z=ln(x) and "
"applies the \xe2\x80\x9cleast squares\xe2\x80\x9d method to fit the linear equation "
"y = m * z + b "
"to your y's and z's --- equivalent to fitting the equation "
"y = m * ln(x) + b "
"to y's and x's. "
"LOGREG returns an array having two columns and one row. "
"m is given in the first column and b in the second. ") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("Any extra statistical information is written below m and b in the "
"result array. This extra statistical information consists of four "
"rows of data: In the first row the standard error values for the "
"coefficients m, b are given. The second row "
"contains the square of R and the standard error for the y "
"estimate. The third row contains the F-observed value and the "
"degrees of freedom. The last row contains the regression sum "
"of squares and the residual sum of squares."
"The default of @{stat} is FALSE.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{known_ys} and @{known_xs} have unequal number of data points, "
"this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_SEEALSO, "LOGFIT,LINEST,LOGEST"},
{ GNM_FUNC_HELP_END }
};
/* The following is a copy of "gnumeric_linest"
* with "linear_regression" replaced by "logarithmic_regression".
*
* In Excel, this functionality is not available as a function, but only
* as a "trend curve" within graphs.
*
* The function "logarithmic_regression" transforms x's logarithmically
* before calling "general_linear_regression" written by others.
*
* I do not know if in statistical praxis logarithmically transformed x-data
* is useful for *multidimensional* regression, and also if extra statistical
* data is useful in this case, but since "general_linear_regression" written
* by others provides it I have passed this functionality to the user.
* But see comment to "gnumeric_linest" for problem with reading more than
* one x-range.
*/
static GnmValue *
gnumeric_logreg (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmRegData data;
gnm_regression_stat_t *extra_stat = NULL;
GORegressionResult regres;
GnmValue *result;
gnm_float *logres = NULL;
gboolean affine, withstat;
int i, dim;
result = gnm_reg_data_collect (argv[0], argv[1], &data, ei->pos);
if (result)
return result;
dim = data.dim;
affine = argv[2] ? value_get_as_checked_bool (argv[2]) : TRUE;
withstat = argv[3] ? value_get_as_checked_bool (argv[3]) : FALSE;
logres = g_new (gnm_float, dim + 1);
extra_stat = gnm_regression_stat_new ();
regres = gnm_logarithmic_regression (data.xss, dim,
data.ys, data.n, affine,
logres, extra_stat);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
result = value_new_error_NUM (ei->pos);
goto out;
}
if (withstat) {
result = value_new_array (dim + 1, 5);
value_array_set (result, 0, 2,
value_new_float (extra_stat->sqr_r));
value_array_set (result, 1, 2,
value_new_float (gnm_sqrt (extra_stat->var)));
value_array_set (result, 0, 3,
value_new_float (extra_stat->F));
value_array_set (result, 1, 3,
value_new_float (extra_stat->df_resid));
value_array_set (result, 0, 4,
value_new_float (extra_stat->ss_reg));
value_array_set (result, 1, 4,
value_new_float (extra_stat->ss_resid));
for (i = 0; i < dim; i++)
value_array_set (result, dim - i - 1, 1,
value_new_float (extra_stat->se[i+affine]));
value_array_set (result, dim, 1,
affine ? value_new_float (extra_stat->se[0])
: value_new_error_NA (ei->pos));
} else
result = value_new_array (dim + 1, 1);
value_array_set (result, dim, 0, value_new_float (logres[0]));
for (i = 0; i < dim; i++)
value_array_set (result, dim - i - 1, 0,
value_new_float (logres[i + 1]));
out:
gnm_reg_data_free (&data);
g_free (logres);
gnm_regression_stat_destroy (extra_stat);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_logfit[] = {
{ GNM_FUNC_HELP_NAME, F_("LOGFIT:logarithmic least square fit (using a trial and error method)")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values")},
{ GNM_FUNC_HELP_DESCRIPTION, F_(
"LOGFIT function applies the \xe2\x80\x9cleast squares\xe2\x80\x9d method to fit "
"the logarithmic equation "
"y = a + b * ln(sign * (x - c)) , sign = +1 or -1 "
"to your data. The graph of the equation is a logarithmic curve "
"moved horizontally by c and possibly mirrored across the y-axis "
"(if sign = -1).")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("LOGFIT returns an array having five columns and one row. "
"`Sign' is given in the first column, `a', `b', and `c' are "
"given in columns 2 to 4. Column 5 holds the sum of squared "
"residuals.")},
{ GNM_FUNC_HELP_NOTE, F_("An error is returned when there are less than 3 different x's "
"or y's, or when the shape of the point cloud is too different "
"from a ``logarithmic'' one.")},
{ GNM_FUNC_HELP_NOTE, F_("You can use the above formula "
"= a + b * ln(sign * (x - c)) "
"or rearrange it to "
"= (exp((y - a) / b)) / sign + c "
"to compute unknown y's or x's, respectively. ")},
{ GNM_FUNC_HELP_NOTE, F_("This is non-linear fitting by trial-and-error. "
"The accuracy of `c' is: width of x-range -> rounded to the "
"next smaller (10^integer), times 0.000001. There might be cases "
"in which the returned fit is not the best possible.") },
{ GNM_FUNC_HELP_SEEALSO, "LOGREG,LINEST,LOGEST"},
{ GNM_FUNC_HELP_END }
};
/* This function is not available in Excel.
* It is intended for calculation of unknowns from a calibration curve.
* It adapts well to some types of scientific data.
* It does not do multidimensional regression or extra statistics.
*
* One could do this kind of non-linear fitting with a general solver, too,
* but then the success depends on the choosing of suitable starting values.
* Also, determination of `sign' would be complicated.
*/
static GnmValue *
gnumeric_logfit (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs = NULL, *ys = NULL;
GnmValue *result = NULL;
int nx, ny, i;
gnm_float *logfit_res = NULL;
if (argv[0] == NULL || argv[0]->type != VALUE_CELLRANGE)
goto out;
ys = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_BLANKS | /* zeroing blanks
is prone to produce unwanted results */
COLLECT_IGNORE_STRINGS | /* dangerous, user
should use validation tool to prevent erroneously inputting strings instead of
numbers */
COLLECT_IGNORE_BOOLS,
&ny, &result);
if (result)
goto out;
if (argv[1] == NULL || argv[1]->type != VALUE_CELLRANGE)
goto out;
xs = collect_floats_value (argv[1], ei->pos,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&nx, &result);
if (result)
goto out;
if (nx != ny || nx < 3) {
result = value_new_error_VALUE (ei->pos);
goto out;
}
logfit_res = g_new (gnm_float, 5);
if (gnm_logarithmic_fit (xs, ys, nx, logfit_res) != GO_REG_ok) {
result = value_new_error_NUM (ei->pos);
goto out;
}
result = value_new_array (5, 1);
for (i=0; i<5; i++)
value_array_set (result, i, 0,
value_new_float (logfit_res[i]));
out:
g_free (xs);
g_free (ys);
g_free (logfit_res);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_trend[] = {
{ GNM_FUNC_HELP_NAME, F_("TREND:estimates future values of a given data set using a least squares approximation")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values; defaults to the array {1, 2, 3, \xe2\x80\xa6}")},
{ GNM_FUNC_HELP_ARG, F_("new_xs:x-values for which to estimate the y-values; defaults to @{known_xs}")},
{ GNM_FUNC_HELP_ARG, F_("affine:if true, the model contains a constant term, defaults to true")},
{ GNM_FUNC_HELP_NOTE, F_("If @{known_ys} and @{known_xs} have unequal number of data points, "
"this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, \xe2\x80\xa6, A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then TREND(A1:A5,B1:B5) equals {12.1, 15.7, 21.6, 26.7, 39.7}.") },
{ GNM_FUNC_HELP_SEEALSO, "LINEST"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_trend (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs = NULL, *ys = NULL, *nxs = NULL;
GnmValue *result = NULL;
int nx, ny, nnx, i, dim;
gboolean affine, err;
gnm_float linres[2];
GORegressionResult regres;
ys = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&ny, &result);
if (result)
goto out;
affine = TRUE;
if (argv[2] != NULL) {
xs = collect_floats_value (argv[1], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&nx, &result);
if (result)
goto out;
nxs = collect_floats_value (argv[2], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&nnx, &result);
if (result)
goto out;
if (argv[3] != NULL) {
affine = value_get_as_bool (argv[3], &err);
if (err) {
result = value_new_error_VALUE (ei->pos);
goto out;
}
}
} else {
if (argv[1] != NULL) {
xs = collect_floats_value (argv[1], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&nx, &result);
if (result)
goto out;
} else {
xs = g_new (gnm_float, ny);
for (nx = 0; nx < ny; nx++)
xs[nx] = nx + 1;
}
/* @{new_x}'s is assumed to be the same as @{known_x}'s */
nnx = nx;
nxs = g_memdup (xs, nnx * sizeof (*xs));
}
if (ny < 1 || nnx < 1) {
result = value_new_error_NUM (ei->pos);
goto out;
}
if (nx != ny) {
result = value_new_error_NUM (ei->pos);
goto out;
}
dim = 1;
regres = gnm_linear_regression (&xs, dim, ys, nx, affine, linres, NULL);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
result = value_new_error_NUM (ei->pos);
goto out;
}
result = value_new_array (1, nnx);
for (i = 0; i < nnx; i++)
value_array_set (result, 0, i,
value_new_float (linres[1] * nxs[i] + linres[0]));
out:
g_free (xs);
g_free (ys);
g_free (nxs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_logest[] = {
{ GNM_FUNC_HELP_NAME, F_("LOGEST:exponential least square fit")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values; default to an array {1, 2, 3, \xe2\x80\xa6}")},
{ GNM_FUNC_HELP_ARG, F_("affine:if true, the model contains a constant term, defaults to true")},
{ GNM_FUNC_HELP_ARG, F_("stat:if true, extra statistical information will be returned; defaults to FALSE")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("LOGEST function applies the "
"\xe2\x80\x9cleast squares\xe2\x80\x9d method to fit "
"an exponential curve of the form\t"
"y = b * m{1}^x{1} * m{2}^x{2}... to your data.") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("LOGEST returns an array { m{n},m{n-1}, ...,m{1},b }.") },
{ GNM_FUNC_HELP_NOTE, F_("Extra statistical information is written below the regression "
"line coefficients in the result array. Extra statistical "
"information consists of four rows of data. In the first row "
"the standard error values for the coefficients m1, (m2, ...), b "
"are represented. The second row contains the square of R and "
"the standard error for the y estimate. The third row contains "
"the F-observed value and the degrees of freedom. The last row "
"contains the regression sum of squares and the residual sum "
"of squares.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{known_ys} and @{known_xs} have unequal number of data points, "
"this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_SEEALSO, "GROWTH,TREND"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_logest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmRegData data;
gnm_regression_stat_t *extra_stat = NULL;
GORegressionResult regres;
GnmValue *result;
gnm_float *expres = NULL;
gboolean affine, withstat;
int i, dim;
result = gnm_reg_data_collect (argv[0], argv[1], &data, ei->pos);
if (result)
return result;
dim = data.dim;
affine = argv[2] ? value_get_as_checked_bool (argv[2]) : TRUE;
withstat = argv[3] ? value_get_as_checked_bool (argv[3]) : FALSE;
expres = g_new (gnm_float, dim + 1);
extra_stat = gnm_regression_stat_new ();
regres = gnm_exponential_regression (data.xss, dim,
data.ys, data.n, affine,
expres, extra_stat);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
result = value_new_error_NUM (ei->pos);
goto out;
}
if (withstat) {
result = value_new_array (dim + 1, 5);
value_array_set (result, 0, 2,
value_new_float (extra_stat->sqr_r));
value_array_set (result, 1, 2,
value_new_float (gnm_sqrt (extra_stat->var)));
value_array_set (result, 0, 3,
value_new_float (extra_stat->F));
value_array_set (result, 1, 3,
value_new_float (extra_stat->df_resid));
value_array_set (result, 0, 4,
value_new_float (extra_stat->ss_reg));
value_array_set (result, 1, 4,
value_new_float (extra_stat->ss_resid));
for (i = 0; i < dim; i++)
value_array_set (result, dim - i - 1, 1,
value_new_float (extra_stat->se[i+affine]));
value_array_set (result, dim, 1,
affine ? value_new_float (extra_stat->se[0])
: value_new_error_NA (ei->pos));
} else
result = value_new_array (dim + 1, 1);
value_array_set (result, dim, 0, value_new_float (expres[0]));
for (i = 0; i < dim; i++)
value_array_set (result, dim - i - 1, 0,
value_new_float (expres[i + 1]));
out:
gnm_reg_data_free (&data);
g_free (expres);
gnm_regression_stat_destroy (extra_stat);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_growth[] = {
{ GNM_FUNC_HELP_NAME, F_("GROWTH:exponential growth prediction")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values; defaults to the array {1, 2, 3, \xe2\x80\xa6}")},
{ GNM_FUNC_HELP_ARG, F_("new_xs:x-values for which to estimate the y-values; defaults to @{known_xs}")},
{ GNM_FUNC_HELP_ARG, F_("affine:if true, the model contains a constant term, defaults to true")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("GROWTH function applies the \xe2\x80\x9cleast "
"squares\xe2\x80\x9d method to fit an "
"exponential curve to your data and predicts "
"the exponential "
"growth by using this curve.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("GROWTH returns an array having one column and a row for each "
"data point in @{new_xs}.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{known_ys} and @{known_xs} have unequal number of data points, "
"this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_SEEALSO, "LOGEST,GROWTH,TREND"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_growth (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *ys, *xs, *nxs;
int i, n, nnx;
GnmValue *res;
int dim = 1;
gboolean affine;
GORegressionResult regres;
gnm_float expres[2];
res = collect_float_pairs (argv[0], argv[1], ei->pos,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&ys, &xs, &n);
if (res)
return res;
if (argv[2] != NULL) {
nxs = collect_floats_value (argv[2], ei->pos,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
&nnx, &res);
if (res)
goto out;
} else {
/* @{new_x}'s is assumed to be the same as @{known_x}'s */
nxs = g_memdup (xs, n * sizeof (gnm_float));
nnx = n;
}
affine = argv[3] ? value_get_as_checked_bool (argv[3]) : TRUE;
if (n <= 0) {
res = value_new_error_NUM (ei->pos);
goto out;
}
regres = gnm_exponential_regression (&xs, dim,
ys, n, affine, expres, NULL);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
res = value_new_error_NUM (ei->pos);
goto out;
}
res = value_new_array (1, nnx);
for (i = 0; i < nnx; i++)
value_array_set (res, 0, i,
value_new_float (gnm_pow (expres[1], nxs[i]) *
expres[0]));
out:
g_free (xs);
g_free (ys);
g_free (nxs);
return res;
}
/***************************************************************************/
static GnmFuncHelp const help_forecast[] = {
{ GNM_FUNC_HELP_NAME, F_("FORECAST:estimates a future value according to existing values "
"using simple linear regression")},
{ GNM_FUNC_HELP_ARG, F_("x:x-value whose matching y-value should be forecast")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function estimates a future value according to "
"existing values using simple linear regression.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{known_xs} or @{known_ys} contains no data entries or different "
"number of data entries, this function returns a #N/A error.") },
{ GNM_FUNC_HELP_NOTE, F_("If the variance of the @{known_xs} is zero, this function returns a #DIV/0 "
"error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then FORECAST(7,A1:A5,B1:B5) equals -10.859397661.") },
{ GNM_FUNC_HELP_SEEALSO, "INTERCEPT,TREND"},
{ GNM_FUNC_HELP_END }
};
static int
range_forecast (gnm_float const *xs, gnm_float const *ys, int n, gnm_float *res, gpointer user)
{
gnm_float const *px = user;
gnm_float linres[2];
int dim = 1;
gboolean affine = TRUE;
GORegressionResult regres;
regres = gnm_linear_regression ((gnm_float **)&xs, dim,
ys, n, affine, linres, NULL);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
return 1;
}
*res = linres[0] + (*px) * linres[1];
return 0;
}
static GnmValue *
gnumeric_forecast (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
return float_range_function2d (argv[2], argv[1],
ei,
range_forecast,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE,
&x);
}
/***************************************************************************/
static GnmFuncHelp const help_intercept[] = {
{ GNM_FUNC_HELP_NAME, F_("INTERCEPT:the intercept of a linear regression line")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values")},
{ GNM_FUNC_HELP_NOTE, F_("If @{known_xs} or @{known_ys} contains no data entries or different "
"number of data entries, this function returns a #N/A error.") },
{ GNM_FUNC_HELP_NOTE, F_("If the variance of the @{known_xs} is zero, this function returns "
"#DIV/0 error.")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then INTERCEPT(A1:A5,B1:B5) equals -20.785117212.") },
{ GNM_FUNC_HELP_SEEALSO, "FORECAST,TREND"},
{ GNM_FUNC_HELP_END }
};
static int
range_intercept (gnm_float const *xs, gnm_float const *ys, int n, gnm_float *res)
{
gnm_float linres[2];
int dim = 1;
GORegressionResult regres;
regres = gnm_linear_regression ((gnm_float **)&xs, dim,
ys, n, 1, linres, NULL);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
return 1;
}
*res = linres[0];
return 0;
}
static GnmValue *
gnumeric_intercept (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return float_range_function2 (argv[1], argv[0],
ei,
range_intercept,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_slope[] = {
{ GNM_FUNC_HELP_NAME, F_("SLOPE:the slope of a linear regression line")},
{ GNM_FUNC_HELP_ARG, F_("known_ys:known y-values")},
{ GNM_FUNC_HELP_ARG, F_("known_xs:known x-values")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{known_xs} or @{known_ys} contains no data entries or different "
"number of data entries, this function returns a #N/A error.") },
{ GNM_FUNC_HELP_NOTE, F_("If the variance of the @{known_xs} is zero, this function returns "
"#DIV/0 error.")},
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers "
"11.4, 17.3, 21.3, 25.9, and 40.1, and the cells B1, B2, ... "
"B5 23.2, 25.8, 29.9, 33.5, and 42.7.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then SLOPE(A1:A5,B1:B5) equals 1.417959936.") },
{ GNM_FUNC_HELP_SEEALSO, "STDEV,STDEVPA"},
{ GNM_FUNC_HELP_END }
};
static int
range_slope (gnm_float const *xs, gnm_float const *ys, int n, gnm_float *res)
{
gnm_float linres[2];
int dim = 1;
GORegressionResult regres;
regres = gnm_linear_regression ((gnm_float **)&xs, dim,
ys, n, 1, linres, NULL);
switch (regres) {
case GO_REG_ok:
case GO_REG_near_singular_good:
break;
default:
return 1;
}
*res = linres[1];
return 0;
}
static GnmValue *
gnumeric_slope (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
return float_range_function2 (argv[1], argv[0],
ei,
range_slope,
COLLECT_IGNORE_BLANKS |
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS,
GNM_ERROR_VALUE);
}
/***************************************************************************/
static GnmFuncHelp const help_subtotal[] = {
{ GNM_FUNC_HELP_NAME, F_("SUBTOTAL:the subtotal of the given list of arguments")},
{ GNM_FUNC_HELP_ARG, F_("function_nbr:determines which function to use according to the following table:\n"
"\t1 AVERAGE\n"
"\t2 COUNT\n"
"\t3 COUNTA\n"
"\t4 MAX\n"
"\t5 MIN\n"
"\t6 PRODUCT\n"
"\t7 STDEV\n"
"\t8 STDEVP\n"
"\t9 SUM\n"
"\t10 VAR\n"
"\t11 VARP"
)},
{ GNM_FUNC_HELP_ARG, F_("ref1:first value")},
{ GNM_FUNC_HELP_ARG, F_("ref2:second value")},
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Let us assume that the cells A1, A2, ..., A5 contain numbers 23, 27, 28, 33, and 39.") },
{ GNM_FUNC_HELP_EXAMPLES, F_("Then SUBTOTAL(1,A1:A5) equals 30."
"SUBTOTAL(6,A1:A5) equals 22378356."
"SUBTOTAL(7,A1:A5) equals 6.164414003."
"SUBTOTAL(9,A1:A5) equals 150."
"SUBTOTAL(11,A1:A5) equals 30.4.") },
{ GNM_FUNC_HELP_SEEALSO, "COUNT,SUM"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_subtotal (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
GnmExpr const *expr;
GnmValue *val;
int fun_nbr, res;
float_range_function_t func;
GnmStdError err = GNM_ERROR_DIV0;
if (argc == 0)
return value_new_error_NUM (ei->pos);
expr = argv[0];
if (expr == NULL)
return value_new_error_NUM (ei->pos);
val = gnm_expr_eval (expr, ei->pos, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
if (VALUE_IS_ERROR (val))
return val;
fun_nbr = value_get_as_int (val);
value_release (val);
/* Skip the first node */
argc--;
argv++;
switch (fun_nbr) {
case 2: res = 0;
/* no need to check for error, this is not strict */
function_iterate_argument_values
(ei->pos, callback_function_count, &res,
argc, argv, FALSE,
CELL_ITER_IGNORE_BLANK | CELL_ITER_IGNORE_SUBTOTAL);
return value_new_int (res);
case 3: res = 0;
/* no need to check for error, this is not strict */
function_iterate_argument_values
(ei->pos, callback_function_counta, &res,
argc, argv, FALSE,
CELL_ITER_IGNORE_BLANK | CELL_ITER_IGNORE_SUBTOTAL);
return value_new_int (res);
case 1: func = gnm_range_average; break;
case 4: err = GNM_ERROR_VALUE;
func = range_max0; break;
case 5: err = GNM_ERROR_VALUE;
func = range_min0; break;
case 6: err = GNM_ERROR_VALUE;
func = gnm_range_product; break;
case 7: func = gnm_range_stddev_est; break;
case 8: func = gnm_range_stddev_pop; break;
case 9: err = GNM_ERROR_VALUE;
func = gnm_range_sum; break;
case 10: func = gnm_range_var_est; break;
case 11: func = gnm_range_var_pop; break;
default:
return value_new_error_NUM (ei->pos);
}
return float_range_function (argc, argv, ei, func,
COLLECT_IGNORE_STRINGS | COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS | COLLECT_IGNORE_SUBTOTAL,
err);
}
/***************************************************************************/
static GnmFuncHelp const help_cronbach[] = {
{ GNM_FUNC_HELP_NAME, F_("CRONBACH:Cronbach's alpha")},
{ GNM_FUNC_HELP_ARG, F_("ref1:first data set")},
{ GNM_FUNC_HELP_ARG, F_("ref2:second data set")},
{ GNM_FUNC_HELP_SEEALSO, "VAR" },
{ GNM_FUNC_HELP_END }
};
static void
free_values (GnmValue **values, int top)
{
int i;
for (i = 0; i < top; i++)
if (values [i])
value_release (values [i]);
g_free (values);
}
static GnmValue *
function_marshal_arg (GnmFuncEvalInfo *ei,
GnmExpr const *t,
GnmValue **type_mismatch)
{
GnmValue *v;
*type_mismatch = NULL;
if (GNM_EXPR_GET_OPER (t) == GNM_EXPR_OP_CELLREF)
v = value_new_cellrange (&t->cellref.ref, &t->cellref.ref,
ei->pos->eval.col,
ei->pos->eval.row);
else
v = gnm_expr_eval (t, ei->pos, GNM_EXPR_EVAL_PERMIT_NON_SCALAR);
if (v->type != VALUE_ARRAY &&
v->type != VALUE_CELLRANGE) {
*type_mismatch = value_new_error_VALUE (ei->pos);
}
if (v->type == VALUE_CELLRANGE) {
gnm_cellref_make_abs (&v->v_range.cell.a, &v->v_range.cell.a,
ei->pos);
gnm_cellref_make_abs (&v->v_range.cell.b, &v->v_range.cell.b,
ei->pos);
}
return v;
}
static GnmValue *
gnumeric_cronbach (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
{
int i, j;
GnmValue **values;
gnm_float sum_variance = 0.0;
gnm_float sum_covariance = 0.0;
if (argc < 2)
return value_new_error_VALUE (ei->pos);
for (i = 0; i < argc; i++) {
GnmValue *fl_val =
float_range_function (1, argv + i, ei,
gnm_range_var_pop, 0,
GNM_ERROR_VALUE);
if (!VALUE_IS_NUMBER (fl_val))
return fl_val;
sum_variance += value_get_as_float (fl_val);
value_release (fl_val);
}
values = g_new0 (GnmValue *, argc);
for (i = 0; i < argc; i++) {
GnmValue *type_mismatch;
values[i] = function_marshal_arg (ei, argv[i], &type_mismatch);
if (type_mismatch || values[i] == NULL) {
free_values (values, i + 1);
if (type_mismatch)
return type_mismatch;
else
return value_new_error_VALUE (ei->pos);
}
}
g_return_val_if_fail (i == argc, value_new_error_VALUE (ei->pos));
/* We now have an array of array values and an expression list */
for (i = 0; i < argc; ++i) {
for (j = i + 1; j < argc; ++j) {
GnmValue *fl_val;
fl_val = float_range_function2 (values[i], values[j],
ei,
gnm_range_covar, 0,
GNM_ERROR_VALUE);
if (!VALUE_IS_NUMBER (fl_val)) {
free_values (values, argc);
return fl_val;
}
sum_covariance += value_get_as_float (fl_val);
value_release (fl_val);
}
}
free_values (values, argc);
return value_new_float
(argc * (1 - sum_variance / (sum_variance + 2 * sum_covariance)) / (argc - 1));
}
/***************************************************************************/
static GnmFuncHelp const help_geomdist[] = {
{ GNM_FUNC_HELP_NAME, F_("GEOMDIST:probability mass or cumulative distribution function of the hypergeometric distribution")},
{ GNM_FUNC_HELP_ARG, F_("k:number of trials")},
{ GNM_FUNC_HELP_ARG, F_("p:probability of success in any trial")},
{ GNM_FUNC_HELP_ARG, F_("cumulative:whether to evaluate the mass function or the cumulative distribution function")},
{ GNM_FUNC_HELP_NOTE, F_("If @{k} < 0 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{cumulative} is neither TRUE nor FALSE this function returns a #VALUE! error.") },
{ GNM_FUNC_HELP_EXAMPLES, "=GEOMDIST(2,10.4,TRUE)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDGEOM"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_geomdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float k = gnm_fake_floor (value_get_as_float (argv[0]));
gnm_float p = value_get_as_float (argv[1]);
gboolean cum = value_get_as_checked_bool (argv[2]);
if (p < 0 || p > 1 || k < 0)
return value_new_error_NUM (ei->pos);
if (cum)
return value_new_float (pgeom (k, p, TRUE, FALSE));
else
return value_new_float (dgeom (k, p, FALSE));
}
/***************************************************************************/
static GnmFuncHelp const help_logistic[] = {
{ GNM_FUNC_HELP_NAME, F_("LOGISTIC:probability density function of the logistic distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("a:scale parameter")},
{ GNM_FUNC_HELP_EXAMPLES, "=LOGISTIC(0.4,1)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDLOGISTIC"},
{ GNM_FUNC_HELP_END }
};
static gnm_float
random_logistic_pdf (gnm_float x, gnm_float a)
{
gnm_float u = gnm_exp (-gnm_abs (x) / a);
return u / (gnm_abs (a) * (1 + u) * (1 + u));
}
static GnmValue *
gnumeric_logistic (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
if (a <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (random_logistic_pdf (x, a));
}
/***************************************************************************/
static GnmFuncHelp const help_pareto[] = {
{ GNM_FUNC_HELP_NAME, F_("PARETO:probability density function of the pareto distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("a:exponent")},
{ GNM_FUNC_HELP_ARG, F_("b:scale parameter")},
{ GNM_FUNC_HELP_EXAMPLES, "=PARETO(0.6,1,2)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDPARETO"},
{ GNM_FUNC_HELP_END }
};
static gnm_float
random_pareto_pdf (gnm_float x, gnm_float a, gnm_float b)
{
if (x >= b)
return (a / b) / gnm_pow (x / b, a + 1);
else
return 0;
}
static GnmValue *
gnumeric_pareto (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
gnm_float b = value_get_as_float (argv[2]);
if (a <= 0 || b <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (random_pareto_pdf (x, a, b));
}
/***************************************************************************/
static GnmFuncHelp const help_rayleigh[] = {
{ GNM_FUNC_HELP_NAME, F_("RAYLEIGH:probability density function of the Rayleigh distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("sigma:scale parameter")},
{ GNM_FUNC_HELP_EXAMPLES, "=RAYLEIGH(0.4,1)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDRAYLEIGH"},
{ GNM_FUNC_HELP_END }
};
static gnm_float
random_rayleigh_pdf (gnm_float x, gnm_float sigma)
{
if (x < 0)
return 0;
else {
gnm_float u = x / sigma;
return (u / sigma) * gnm_exp (-u * u / 2.0);
}
}
static GnmValue *
gnumeric_rayleigh (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float sigma = value_get_as_float (argv[1]);
if (sigma <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (random_rayleigh_pdf (x, sigma));
}
/***************************************************************************/
static GnmFuncHelp const help_rayleightail[] = {
{ GNM_FUNC_HELP_NAME, F_("RAYLEIGHTAIL:probability density function of the Rayleigh tail distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("a:lower limit")},
{ GNM_FUNC_HELP_ARG, F_("sigma:scale parameter")},
{ GNM_FUNC_HELP_EXAMPLES, "=RAYLEIGHTAIL(0.6,0.3,1)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDRAYLEIGHTAIL"},
{ GNM_FUNC_HELP_END }
};
static gnm_float
random_rayleigh_tail_pdf (gnm_float x, gnm_float a, gnm_float sigma)
{
if (x < a)
return 0;
else {
gnm_float u = x / sigma ;
gnm_float v = a / sigma ;
return (u / sigma) * gnm_exp ((v + u) * (v - u) / 2.0) ;
}
}
static GnmValue *
gnumeric_rayleightail (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
gnm_float sigma = value_get_as_float (argv[2]);
if (sigma <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (random_rayleigh_tail_pdf (x, a, sigma));
}
/***************************************************************************/
static GnmFuncHelp const help_exppowdist[] = {
{ GNM_FUNC_HELP_NAME, F_("EXPPOWDIST:the probability density function of the "
"Exponential Power distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("a:scale parameter")},
{ GNM_FUNC_HELP_ARG, F_("b:scale parameter")},
{ GNM_FUNC_HELP_DESCRIPTION, F_(
"This distribution has been recommended for lifetime analysis "
"when a U-shaped hazard function is desired. "
"This corresponds to rapid failure once the product starts to "
"wear out after a period of steady or even improving reliability.") },
{ GNM_FUNC_HELP_EXAMPLES, "=EXPPOWDIST(0.4,1,2)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDEXPPOW"},
{ GNM_FUNC_HELP_END }
};
/* Part of help text quoted from the PEXPDF manpage of the DATAPLOT program
* by NIST. */
static GnmValue *
gnumeric_exppowdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
gnm_float b = value_get_as_float (argv[2]);
/* FIXME: Check this condition. */
if (b <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (random_exppow_pdf (x, a, b));
}
/***************************************************************************/
static GnmFuncHelp const help_laplace[] = {
{ GNM_FUNC_HELP_NAME, F_("LAPLACE:probability density function of the Laplace distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:number")},
{ GNM_FUNC_HELP_ARG, F_("a:mean")},
{ GNM_FUNC_HELP_EXAMPLES, "=LAPLACE(0.4,1)" },
{ GNM_FUNC_HELP_SEEALSO, "RANDLAPLACE"},
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_laplace (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
if (a <= 0)
return value_new_error_NUM (ei->pos);
return value_new_float (random_laplace_pdf (x, a));
}
/***************************************************************************/
static GnmFuncHelp const help_permutationa[] = {
{ GNM_FUNC_HELP_NAME, F_("PERMUTATIONA:the number of permutations of @{y} objects chosen from @{x} objects with repetition allowed")},
{ GNM_FUNC_HELP_ARG, F_("x:total number of objects")},
{ GNM_FUNC_HELP_ARG, F_("y:number of selected objects")},
{ GNM_FUNC_HELP_NOTE, F_("If both @{x} and @{y} equal 0, PERMUTATIONA returns 1.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} < 0 or @{y} < 0, PERMUTATIONA returns #NUM!") },
{ GNM_FUNC_HELP_NOTE, F_("If @{x} or @{y} are not integers, they are truncated") },
{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") },
{ GNM_FUNC_HELP_EXAMPLES, "=PERMUTATIONA(2,7)" },
{ GNM_FUNC_HELP_EXAMPLES, "=PERMUTATIONA(2.3,7.6)" },
{ GNM_FUNC_HELP_EXAMPLES, "=PERMUTATIONA(0,0)" },
{ GNM_FUNC_HELP_SEEALSO, "POWER"},
{ GNM_FUNC_HELP_END}
};
static GnmValue *
gnumeric_permutationa (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float y = value_get_as_float (argv[1]);
int ix = (int) x;
int iy = (int) y;
if (ix < 0 || iy < 0)
return value_new_error_NUM (ei->pos);
else if (ix == 0 && iy == 0)
return value_new_float (0);
else
return value_new_float (gnm_pow (ix, iy));
}
/***************************************************************************/
static GnmFuncHelp const help_lkstest[] = {
{ GNM_FUNC_HELP_NAME, F_("LKSTEST:Lilliefors (Kolmogorov-Smirnov) Test of Normality") },
{ GNM_FUNC_HELP_ARG, F_("x:array of sample values") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function returns an array with the first row giving the p-value of the Lilliefors (Kolmogorov-Smirnov) Test,"
" the second row the test statistic of the test, and the third the number of observations in the sample.")},
{ GNM_FUNC_HELP_NOTE, F_("If there are less than 5 sample values, LKSTEST returns #VALUE!") },
{ GNM_FUNC_HELP_SEEALSO, "CHITEST,ADTEST,SFTEST,CVMTEST" },
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Lilliefors_test") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_lkstest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs;
int n;
GnmValue *result = NULL;
gnm_float mu = 0.;
gnm_float sigma = 1.;
xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
if (result)
goto out;
result = value_new_array (1, 3);
value_array_set (result, 0, 2,
value_new_int (n));
if ((n < 5) || gnm_range_average (xs, n, &mu)
|| gnm_range_stddev_est (xs, n, &sigma)) {
value_array_set (result, 0, 0,
value_new_error_VALUE (ei->pos));
value_array_set (result, 0, 1,
value_new_error_VALUE (ei->pos));
} else {
int i;
gnm_float dplus, dminus;
gnm_float p, nd;
gnm_float *ys;
gnm_float val;
gnm_float stat;
ys = range_sort (xs, n);
val = pnorm (ys[0], mu, sigma, TRUE, FALSE);
dplus = 1./(gnm_float)n - val;
dminus = val;
for (i = 1; i < n; i++) {
gnm_float one_dplus, one_dminus;
val = pnorm (ys[i], mu, sigma, TRUE, FALSE);
one_dplus = (i + 1)/(gnm_float)n - val;
one_dminus = val - i/(gnm_float)n;
if (one_dplus > dplus)
dplus = one_dplus;
if (one_dminus > dminus)
dminus = one_dminus;
}
stat = ((dplus < dminus) ? dminus : dplus);
value_array_set (result, 0, 1,
value_new_float (stat));
g_free (ys);
if (n > 100) {
stat = stat * gnm_pow (n/100., 0.49);
nd = 100.;
} else
nd = n;
p = gnm_exp (-7.01256 * stat * stat * (nd + 2.78019) + 2.99587 * stat * gnm_sqrt (nd + 2.78019)
- 0.122119 + 0.974598/gnm_sqrt(nd) + 1.67997/nd);
if (p > 0.1) {
stat = (gnm_sqrt (nd) - 0.01 + 0.85/gnm_sqrt (nd)) * stat;
if (stat <= 0.302)
p = 1.;
else if (stat <= 0.5)
p = 2.76773 - 19.828315 * stat
+ 80.709644 * stat * stat
- 138.55152 * stat * stat * stat
+ 81.218052 * stat * stat * stat * stat;
else if (stat <= 0.9)
p = -4.901232 + 40.662806 * stat
- 97.490286 * stat * stat
+ 94.029866 * stat * stat * stat
- 32.355711 * stat * stat * stat * stat;
else if (stat <= 1.31)
p = 6.198765 - 19.558097 * stat
+ 23.186922 * stat * stat
- 12.234627 * stat * stat * stat
+ 2.423045 * stat * stat * stat * stat;
else
p = 0.;
}
value_array_set (result, 0, 0,
value_new_float (p));
}
out:
g_free (xs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_sftest[] = {
{ GNM_FUNC_HELP_NAME, F_("SFTEST:Shapiro-Francia Test of Normality") },
{ GNM_FUNC_HELP_ARG, F_("x:array of sample values") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function returns an array with the first row giving the p-value of the Shapiro-Francia Test,"
" the second row the test statistic of the test, and the third the number of observations in the sample.")},
{ GNM_FUNC_HELP_NOTE, F_("If there are less than 5 or more than 5000 sample values, SFTEST returns #VALUE!") },
{ GNM_FUNC_HELP_SEEALSO, "CHITEST,ADTEST,LKSTEST,CVMTEST" },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_sftest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs;
int n;
GnmValue *result = NULL;
xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
if (result)
goto out;
result = value_new_array (1, 3);
value_array_set (result, 0, 2,
value_new_int (n));
if ((n < 5) || (n > 5000)) {
value_array_set (result, 0, 0,
value_new_error_VALUE (ei->pos));
value_array_set (result, 0, 1,
value_new_error_VALUE (ei->pos));
} else {
int i;
gnm_float stat_;
gnm_float *ys;
gnm_float *zs;
ys = range_sort (xs, n);
zs = g_new (gnm_float, n);
for (i = 0; i < n; i++)
zs[i] = qnorm ((((gnm_float)(i+1))-3./8.)/(n+0.25), 0., 1., TRUE, FALSE);
if (gnm_range_correl_pop (ys, zs, n, &stat_)) {
value_array_set (result, 0, 0,
value_new_error_VALUE (ei->pos));
value_array_set (result, 0, 1,
value_new_error_VALUE (ei->pos));
} else {
gnm_float p;
gnm_float u, v, mu, sig;
stat_ = stat_ * stat_;
value_array_set (result, 0, 1,
value_new_float (stat_));
u = gnm_log (n);
v = gnm_log (u);
mu = -1.2725 + 1.0521 * (v - u);
sig = 1.0308 - 0.26758 * (v + 2./u);
p = pnorm (gnm_log1p (-stat_), mu, sig, FALSE, FALSE);
value_array_set (result, 0, 0,
value_new_float (p));
}
g_free (ys);
g_free (zs);
}
out:
g_free (xs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_cvmtest[] = {
{ GNM_FUNC_HELP_NAME, F_("CVMTEST:Cram\xc3\xa9r-von Mises Test of Normality") },
{ GNM_FUNC_HELP_ARG, F_("x:array of sample values") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function returns an array with the first row giving the p-value of the Cram\xc3\xa9r-von Mises Test,"
" the second row the test statistic of the test, and the third the number of observations in the sample.")},
{ GNM_FUNC_HELP_NOTE, F_("If there are less than 8 sample values, CVMTEST returns #VALUE!") },
{ GNM_FUNC_HELP_SEEALSO, "CHITEST,ADTEST,LKSTEST,SFTEST" },
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Cramér–von-Mises_criterion") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_cvmtest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs;
int n;
GnmValue *result = NULL;
gnm_float mu = 0.;
gnm_float sigma = 1.;
xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
if (result)
goto out;
result = value_new_array (1, 3);
value_array_set (result, 0, 2,
value_new_int (n));
if ((n < 8) || gnm_range_average (xs, n, &mu)
|| gnm_range_stddev_est (xs, n, &sigma)) {
value_array_set (result, 0, 0,
value_new_error_VALUE (ei->pos));
value_array_set (result, 0, 1,
value_new_error_VALUE (ei->pos));
} else {
int i;
gnm_float total = 0.;
gnm_float p;
gnm_float *ys;
ys = range_sort (xs, n);
for (i = 0; i < n; i++) {
gnm_float val = pnorm (ys[i], mu, sigma, TRUE, FALSE);
gnm_float delta;
delta = val - (2*i+1)/(2. * n);
total += (delta * delta);
}
total += (1 / (12 * (gnm_float)n));
value_array_set (result, 0, 1,
value_new_float (total));
g_free (ys);
total *= (1 + 0.5 / n);
if (total < 0.0275)
p = 1. - gnm_exp (-13.953 + 775.5 * total - 12542.61 * total * total);
else if (total < 0.051)
p = 1. - gnm_exp (-5.903 + 179.546 * total - 1515.29 * total * total);
else if (total < 0.092)
p = gnm_exp (0.886 - 31.62 * total - 10.897 * total * total);
else if (total < 1.)
p = gnm_exp (1.111 - 34.242 * total + 12.832 * total * total);
else
p = 0.;
value_array_set (result, 0, 0,
value_new_float (p));
}
out:
g_free (xs);
return result;
}
/***************************************************************************/
static GnmFuncHelp const help_adtest[] = {
{ GNM_FUNC_HELP_NAME, F_("ADTEST:Anderson-Darling Test of Normality") },
{ GNM_FUNC_HELP_ARG, F_("x:array of sample values") },
{ GNM_FUNC_HELP_DESCRIPTION, F_("This function returns an array with the first row giving the p-value of the Anderson-Darling Test,"
" the second row the test statistic of the test, and the third the number of observations in the sample.")},
{ GNM_FUNC_HELP_NOTE, F_("If there are less than 8 sample values, ADTEST returns #VALUE!") },
{ GNM_FUNC_HELP_SEEALSO, "CHITEST,CVMTEST,LKSTEST,SFTEST" },
{ GNM_FUNC_HELP_EXTREF, F_("wiki:en:Anderson–Darling_test") },
{ GNM_FUNC_HELP_END }
};
static GnmValue *
gnumeric_adtest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float *xs;
int n;
GnmValue *result = NULL;
gnm_float mu = 0.;
gnm_float sigma = 1.;
xs = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_STRINGS |
COLLECT_IGNORE_BOOLS |
COLLECT_IGNORE_BLANKS |
COLLECT_ORDER_IRRELEVANT,
&n, &result);
if (result)
goto out;
result = value_new_array (1, 3);
value_array_set (result, 0, 2,
value_new_int (n));
if ((n < 8) || gnm_range_average (xs, n, &mu)
|| gnm_range_stddev_est (xs, n, &sigma)) {
value_array_set (result, 0, 0,
value_new_error_VALUE (ei->pos));
value_array_set (result, 0, 1,
value_new_error_VALUE (ei->pos));
} else {
int i;
gnm_float total = 0.;
gnm_float p;
gnm_float *ys;
ys = range_sort (xs, n);
for (i = 0; i < n; i++) {
gnm_float val = (pnorm (ys[i], mu, sigma, TRUE, TRUE) + pnorm (ys[n - i - 1], mu, sigma, FALSE, TRUE));
total += ((2*i+1)* val);
}
total = - n - total/n;
value_array_set (result, 0, 1,
value_new_float (total));
g_free (ys);
total *= (1 + 0.75 / n + 2.25 / (n * n));
if (total < 0.2)
p = 1. - gnm_exp (-13.436 + 101.14 * total - 223.73 * total * total);
else if (total < 0.34)
p = 1. - gnm_exp (-8.318 + 42.796 * total - 59.938 * total * total);
else if (total < 0.6)
p = gnm_exp (0.9177 - 4.279 * total - 1.38 * total * total);
else
p = gnm_exp (1.2937 - 5.709 * total + 0.0186 * total * total);
value_array_set (result, 0, 0,
value_new_float (p));
}
out:
g_free (xs);
return result;
}
/***************************************************************************/
GnmFuncDescriptor const stat_functions[] = {
{ "adtest", "A",
help_adtest, gnumeric_adtest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
{ "sftest", "A",
help_sftest, gnumeric_sftest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
{ "cvmtest", "A",
help_cvmtest, gnumeric_cvmtest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
{ "lkstest", "A",
help_lkstest, gnumeric_lkstest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC,
GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
{ "avedev", NULL,
help_avedev, NULL, gnumeric_avedev, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "average", NULL,
help_average, NULL, gnumeric_average, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "averagea", NULL,
help_averagea, NULL, gnumeric_averagea, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "bernoulli", "ff", help_bernoulli,
gnumeric_bernoulli, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "betadist", "fff|ff",
help_betadist, gnumeric_betadist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "betainv", "fff|ff",
help_betainv, gnumeric_betainv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "binomdist", "fffb",
help_binomdist, gnumeric_binomdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "binom.dist.range", "fff|f",
help_binom_dist_range, gnumeric_binom_dist_range, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "cauchy", "ffb", help_cauchy,
gnumeric_cauchy, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "chidist", "ff",
help_chidist, gnumeric_chidist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "chiinv", "ff",
help_chiinv, gnumeric_chiinv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "chitest", "AA",
help_chitest, gnumeric_chitest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "confidence", "fff",
help_confidence, gnumeric_confidence, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "correl", "AA",
help_correl, gnumeric_correl, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "count", NULL,
help_count, NULL, gnumeric_count, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "counta", NULL,
help_counta, NULL, gnumeric_counta, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "covar", "AA",
help_covar, gnumeric_covar, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "critbinom", "fff",
help_critbinom, gnumeric_critbinom, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "devsq", NULL,
help_devsq, NULL, gnumeric_devsq, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "expondist", "ffb",
help_expondist, gnumeric_expondist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "fdist", "fff",
help_fdist, gnumeric_fdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "finv", "fff",
help_finv, gnumeric_finv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "fisher", "f",
help_fisher, gnumeric_fisher, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "fisherinv", "f",
help_fisherinv, gnumeric_fisherinv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "forecast", "frr",
help_forecast, gnumeric_forecast, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "frequency", "AA",
help_frequency, gnumeric_frequency, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ftest", "rr",
help_ftest, gnumeric_ftest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "gammadist", "fffb",
help_gammadist, gnumeric_gammadist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "gammainv", "fff",
help_gammainv, gnumeric_gammainv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "geomean", NULL,
help_geomean, NULL, gnumeric_geomean, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "growth", "A|AAb",
help_growth, gnumeric_growth, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "harmean", NULL,
help_harmean, NULL, gnumeric_harmean, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "hypgeomdist", "ffff|b",
help_hypgeomdist, gnumeric_hypgeomdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "intercept", "AA",
help_intercept, gnumeric_intercept, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "kurt", NULL,
help_kurt, NULL, gnumeric_kurt, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "large", "Af",
help_large, gnumeric_large, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "linest", "A|Abb",
help_linest, gnumeric_linest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "logest", "A|Abb",
help_logest, gnumeric_logest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "logfit", "rr",
help_logfit, gnumeric_logfit, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "loginv", "fff",
help_loginv, gnumeric_loginv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "lognormdist", "fff",
help_lognormdist, gnumeric_lognormdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "logreg", "A|Abb",
help_logreg, gnumeric_logreg, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "max", NULL,
help_max, NULL, gnumeric_max, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "maxa", NULL,
help_maxa, NULL, gnumeric_maxa, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "median", NULL,
help_median, NULL, gnumeric_median, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "min", NULL,
help_min, NULL, gnumeric_min, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "mina", NULL,
help_mina, NULL, gnumeric_mina, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "mode", NULL,
help_mode, NULL, gnumeric_mode, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "negbinomdist", "fff",
help_negbinomdist, gnumeric_negbinomdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "normdist", "fffb",
help_normdist, gnumeric_normdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "norminv", "fff",
help_norminv, gnumeric_norminv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "normsdist", "f",
help_normsdist, gnumeric_normsdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "normsinv", "f",
help_normsinv, gnumeric_normsinv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "pearson", "AA",
help_pearson, gnumeric_pearson, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "percentile", "Af",
help_percentile, gnumeric_percentile, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "percentrank", "Af|f",
help_percentrank, gnumeric_percentrank, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "permut", "ff",
help_permut, gnumeric_permut, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "poisson", "ffb",
help_poisson, gnumeric_poisson, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "prob", "AAf|f",
help_prob, gnumeric_prob, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "quartile", "Af",
help_quartile, gnumeric_quartile, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "rank", "fr|b",
help_rank, gnumeric_rank, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "rank.avg", "fr|b",
help_rank_avg, gnumeric_rank_avg, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE},
{ "slope", "AA",
help_slope, gnumeric_slope, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "small", "Af",
help_small, gnumeric_small, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "standardize", "fff",
help_standardize, gnumeric_standardize, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ssmedian", "A|f",
help_ssmedian, gnumeric_ssmedian, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "stdev", NULL,
help_stdev, NULL, gnumeric_stdev, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "stdeva", NULL,
help_stdeva, NULL, gnumeric_stdeva, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "stdevp", NULL,
help_stdevp, NULL, gnumeric_stdevp, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "stdevpa", NULL,
help_stdevpa, NULL, gnumeric_stdevpa, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "steyx", "AA",
help_steyx, gnumeric_steyx, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "rsq", "AA",
help_rsq, gnumeric_rsq, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "skew", NULL,
help_skew, NULL, gnumeric_skew, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "tdist", "fff",
help_tdist, gnumeric_tdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "tinv", "ff",
help_tinv, gnumeric_tinv, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "trend", "A|AAb",
help_trend, gnumeric_trend, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "trimmean", "rf",
help_trimmean, gnumeric_trimmean, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ttest", "rrff",
help_ttest, gnumeric_ttest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "var", NULL,
help_var, NULL, gnumeric_var, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "vara", NULL,
help_vara, NULL, gnumeric_vara, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "varp", NULL,
help_varp, NULL, gnumeric_varp, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "varpa", NULL,
help_varpa, NULL, gnumeric_varpa, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "weibull", "fffb",
help_weibull, gnumeric_weibull, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "ztest", "Af|f",
help_ztest, gnumeric_ztest, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "exppowdist", "fff", help_exppowdist,
gnumeric_exppowdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "geomdist", "ffb", help_geomdist,
gnumeric_geomdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "kurtp", NULL,
help_kurtp, NULL, gnumeric_kurtp, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "landau", "f", help_landau,
gnumeric_landau, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "laplace", "ff", help_laplace,
gnumeric_laplace, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "logistic", "ff", help_logistic,
gnumeric_logistic, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "pareto", "fff", help_pareto,
gnumeric_pareto, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "rayleigh", "ff", help_rayleigh,
gnumeric_rayleigh, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "rayleightail", "fff", help_rayleightail,
gnumeric_rayleightail, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "skewp", NULL,
help_skewp, NULL, gnumeric_skewp, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "subtotal", NULL,
help_subtotal, NULL, gnumeric_subtotal, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "cronbach", NULL,
help_cronbach, NULL, gnumeric_cronbach, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "permutationa", "ff", help_permutationa,
gnumeric_permutationa, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{NULL}
};
|