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 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695
|
> # test.full.R: test earth
>
> print(R.version.string)
[1] "R version 3.5.2 (2018-12-20)"
>
> source("test.prolog.R")
> source("check.models.equal.R")
> library(earth)
Loading required package: plotmo
Loading required package: plotrix
Loading required package: TeachingDemos
> library(mda)
Loading required package: class
Loaded mda 0.4-10
> data(ozone1)
> data(trees)
> data(etitanic)
>
> PRINT.TIME <- FALSE # FALSE for no time results (for diff against reference)
> PLOT <- TRUE # TRUE to do plots too, FALSE for speed
> options.old <- options()
> options(warn=1) # print warnings as they occur
> # options(digits=5) # removed because want to check against default
>
> printh <- function(x, expect.warning=FALSE, max.print=0) # like print but with a header
+ {
+ cat("===", deparse(substitute(x)), " ", sep="")
+ if(expect.warning)
+ cat(" expect warning -->")
+ else if (NROW(x) > 1)
+ cat("\n")
+ if (max.print > 0)
+ print(head(x, n=max.print))
+ else
+ print(x)
+ }
>
> print(citation("earth"))
To cite package 'earth' in publications use:
Stephen Milborrow. Derived from mda:mars by Trevor Hastie and Rob
Tibshirani. Uses Alan Miller's Fortran utilities with Thomas Lumley's
leaps wrapper. (2011). earth: Multivariate Adaptive Regression
Splines. R package version 4.7.0.
https://CRAN.R-project.org/package=earth
A BibTeX entry for LaTeX users is
@Manual{,
title = {earth: Multivariate Adaptive Regression Splines},
author = {Stephen Milborrow. Derived from mda:mars by Trevor Hastie and Rob Tibshirani. Uses Alan Miller's Fortran utilities with Thomas Lumley's leaps wrapper.},
year = {2011},
note = {R package version 4.7.0},
url = {https://CRAN.R-project.org/package=earth},
}
ATTENTION: This citation information has been auto-generated from the
package DESCRIPTION file and may need manual editing, see
'help("citation")'.
>
> #--- test examples from man pages ------------------------------------------------------------
>
> cat("--- earth.Rd -----------------------------\n")
--- earth.Rd -----------------------------
> example(earth)
earth> earth.mod <- earth(Volume ~ ., data = trees)
earth> plotmo(earth.mod)
plotmo grid: Girth Height
12.9 76
earth> summary(earth.mod, digits = 2, style = "pmax")
Call: earth(formula=Volume~., data=trees)
Volume =
29
- 3.4 * pmax(0, 14 - Girth)
+ 6.2 * pmax(0, Girth - 14)
+ 0.58 * pmax(0, Height - 75)
Selected 4 of 5 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: Girth, Height
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 11 RSS 209 GRSq 0.96 RSq 0.97
>
> set.seed(2015)
>
> train.subset <- sample(1:nrow(trees), .8 * nrow(trees))
> test.subset <- (1:nrow(trees))[-train.subset]
>
> earth.model <- earth(Volume ~ ., data = trees[train.subset,])
>
> # print R-Squared on the test data
> print(summary(earth.model, newdata=trees[test.subset,]))
RSq 0.882 on newdata (7 cases)
>
> # manually calculate R-Squared on the test data (same as above call to summary)
> yhat <- predict(earth.model, newdata = trees[test.subset,])
> y <- trees$Volume[test.subset]
> printh(1 - sum((y - yhat)^2) / sum((y - mean(y))^2)) # print R-Squared
===1 - sum((y - yhat)^2)/sum((y - mean(y))^2) [1] 0.8821553
>
> newrsq <- 1 - sum((y - yhat)^2) / sum((y - mean(y))^2)
> stopifnot(abs(summary(earth.model, newdata=trees[test.subset,])$newrsq - newrsq) < 1e-10)
>
> cars <- earth(mpg ~ ., data = mtcars, pmethod = "none", trace = 4)
Call: earth(formula=mpg~., data=mtcars, pmethod="none", trace=4)
x[32,10]:
cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 4 108 93 3.85 2.320 18.61 1 1 4 1
... 6 258 110 3.08 3.215 19.44 1 0 3 1
Volvo 142E 4 121 109 4.11 2.780 18.60 1 1 4 2
y[32,1]:
mpg
1 21.0
2 21.0
3 22.8
... 21.4
32 21.4
Forward pass: minspan 5 endspan 10 x[32,10] 2.5 kB bx[32,21] 5.25 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.8157 0.8602 0.8602 2 disp 145 2 3 1
4 0.7815 0.8797 0.01956 3 hp 123 4 5 1
6 0.7601 0.9099 0.03016 6 qsec 18.52 6 7 1
8 0.6839 0.9260 0.01611 4 drat 3.15 8 9 1
10 0.5031 0.9374 0.01144 9 gear 4 10 11 1
12 0.3575 0.9458 0.008417 2 disp 275.8 12 1
14 0.0073 0.9494 0.003535 6 qsec 17.02 13 1
16 -0.5893 0.9587 0.009271 7 vs 0< 14 1
18 -35.8726 0.9616 0.002977 10 carb 2 15 16 1 reject (negative GRSq)
Reached minimum GRSq -10 at 17 terms, 14 terms used (GRSq -36)
After forward pass GRSq -35.873 RSq 0.962
Forward pass complete: 17 terms, 14 terms used
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 0.6706 0.7118 0.6706 1 1 3
3 0.8157 0.8602 0.1450 1 1 2 3
4 0.7988 0.8691 -0.0169 2 1 2 3 4
5 0.7815 0.8797 -0.0173 2 1 2 3 4 5
6 0.7601 0.8899 -0.0214 4 1 3 4 6 13 14
7 0.7934 0.9224 0.0332 4 1 3 4 5 6 13 14
8 0.7852 0.9354 -0.0082 5 1 3 4 5 6 9 13 14
9 0.7579 0.9433 -0.0272 5 1 3 4 5 6 9 12 13 14
10 0.6997 0.9472 -0.0582 6 1 3 4 5 6 9 10 12 13 14
11 0.6132 0.9513 -0.0865 6 1 2 3 4 5 6 9 10 12 13 14
12 0.4534 0.9539 -0.1598 6 1 2 3 4 5 6 9 10 11 12 13 14
13 0.1741 0.9579 -0.2793 6 1 2 3 4 5 6 8 9 10 11 12 13 14
chosen 14 -0.5893 0.9587 -0.7634 6 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Prune method "none" penalty 2 nprune null: selected 14 of 14 terms, and 6 of 10 preds
After pruning pass GRSq -0.589 RSq 0.959
>
> get.used.pred.names <- function(obj) # obj is an earth object
+ {
+ any1 <- function(x) any(x != 0) # like any but no warning if x is double
+ names(which(apply(obj$dirs[obj$selected.terms,,drop=FALSE],2,any1)))
+ }
> printh(get.used.pred.names(cars))
===get.used.pred.names(cars)
[1] "disp" "hp" "drat" "qsec" "vs" "gear"
>
> a1 <- earth(survived ~ ., data=etitanic, # c.f. Harrell "Reg. Mod. Strat." ch. 12
+ degree=2, trace=1,
+ glm=list(family=binomial))
x[1046,6] with colnames pclass2nd pclass3rd sexmale age sibsp parch
y[1046,1] with colname survived
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.406 RSq 0.450
Prune method "backward" penalty 3 nprune null: selected 8 of 17 terms, and 5 of 6 preds
After pruning pass GRSq 0.42 RSq 0.439
GLM survived devratio 0.37 dof 1038/1045 iters 5
> printh(a1)
===a1
Earth selected 8 of 17 terms, and 5 of 6 predictors
Termination condition: Reached nk 21
Importance: sexmale, pclass3rd, pclass2nd, age, sibsp, parch-unused
Number of terms at each degree of interaction: 1 3 4
Earth GCV 0.1404529 RSS 141.7629 GRSq 0.4197106 RSq 0.4389834
GLM (family binomial, link logit):
nulldev df dev df devratio AIC iters converged
1414.62 1045 892.794 1038 0.369 908.8 5 1
>
> a1a <- earth(etitanic[,-2], etitanic[,2], # equivalent but using earth.default
+ degree=2, trace=1,
+ glm=list(family=binomial))
x[1046,6] with colnames pclass2nd pclass3rd sexmale age sibsp parch
y[1046,1] with colname etitanic[,2]
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
Reached nk 21
After forward pass GRSq 0.406 RSq 0.450
Prune method "backward" penalty 3 nprune null: selected 8 of 17 terms, and 5 of 6 preds
After pruning pass GRSq 0.42 RSq 0.439
GLM etitanic[,2] devratio 0.37 dof 1038/1045 iters 5
> printh(a1a)
===a1a
Earth selected 8 of 17 terms, and 5 of 6 predictors
Termination condition: Reached nk 21
Importance: sexmale, pclass3rd, pclass2nd, age, sibsp, parch-unused
Number of terms at each degree of interaction: 1 3 4
Earth GCV 0.1404529 RSS 141.7629 GRSq 0.4197106 RSq 0.4389834
GLM (family binomial, link logit):
nulldev df dev df devratio AIC iters converged
1414.62 1045 892.794 1038 0.369 908.8 5 1
>
> a2 <- earth(pclass ~ ., data=etitanic, trace=1, glm=list(family=binomial))
x[1046,5] with colnames survived sexmale age sibsp parch
y[1046,3] with colnames 1st 2nd 3rd
Forward pass term 1, 2, 4, 6, 8, 10, 12, 14
RSq changed by less than 0.001 at 13 terms, 10 terms used (DeltaRSq 0.00065)
After forward pass GRSq 0.163 RSq 0.195
Prune method "backward" penalty 2 nprune null: selected 8 of 10 terms, and 4 of 5 preds
After pruning pass GRSq 0.167 RSq 0.189
GLM 1st devratio 0.25 dof 1038/1045 iters 5
GLM 2nd devratio 0.02 dof 1038/1045 iters 5
GLM 3rd devratio 0.21 dof 1038/1045 iters 5
> printh(a2)
===a2
Earth selected 8 of 10 terms, and 4 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 10 terms
Importance: age, survived, sibsp, parch, sexmale-unused
Number of terms at each degree of interaction: 1 7 (additive model)
Earth
GCV RSS GRSq RSq
1st 0.1483414 150.7467 0.251448718 0.27137124
2nd 0.1885520 191.6094 -0.004971341 0.02177575
3rd 0.1927692 195.8949 0.229032722 0.24955184
All 0.5296626 538.2511 0.166969402 0.18914032
GLM (family binomial, link logit):
nulldev df dev df devratio AIC iters converged
1st 1223.308 1045 920.8021 1038 0.2470 936.8 5 1
2nd 1175.305 1045 1147.5176 1038 0.0236 1164.0 5 1
3rd 1448.213 1045 1142.7559 1038 0.2110 1159.0 5 1
>
> ldose <- rep(0:5, 2) - 2 # V&R 4th ed. p. 191
> sex <- factor(rep(c("male", "female"), times=c(6,6)))
> numdead <- c(1,4,9,13,18,20,0,2,6,10,12,16)
> pair <- cbind(numdead, numalive=20 - numdead)
>
> a3 <- earth(pair ~ sex + ldose, trace=1, pmethod="none",
+ glm=list(family=binomial(link=probit), maxit=100))
x[12,2] with colnames sexmale ldose
y[12,2] with colnames numdead numalive
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.907 RSq 0.981
Prune method "none" penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.952 RSq 0.981
GLM numdead devratio 0.96 dof 9/11 iters 4
> printh(a3)
===a3
Earth selected 3 of 3 terms, and 2 of 2 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: ldose, sexmale
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 2.376093 RSS 9.702381 GRSq 0.952486 RSq 0.9807588
GLM (family binomial, link probit):
nulldev df dev df devratio AIC iters converged
124.8756 11 5.565963 9 0.955 41.68 4 1
>
> numdead2.verylongname <- c(2,8,11,12,20,23,0,4,6,16,12,14) # bogus data
> doublepair <- cbind(numdead, numalive=20-numdead,
+ numdead2.verylongname=numdead2.verylongname,
+ numalive2.verylongname=30-numdead2.verylongname)
>
> a4 <- earth(doublepair ~ sex + ldose, trace=1, pmethod="none",
+ glm=list(family="binomial"))
x[12,2] with colnames sexmale ldose
y[12,4] with colnames numdead numalive numdead2.verylongname numalive2.verylong...
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.658 RSq 0.929
Prune method "none" penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.826 RSq 0.929
GLM numdead devratio 0.95 dof 9/11 iters 4
GLM numdead2.verylongname devratio 0.82 dof 9/11 iters 4
> printh(a4)
===a4
Earth selected 3 of 3 terms, and 2 of 2 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: ldose, sexmale
Number of terms at each degree of interaction: 1 2 (additive model)
Earth
GCV RSS GRSq RSq
numdead 2.376093 9.702381 0.9524860 0.9807588
numdead2.verylongname 15.773761 64.409524 0.7079827 0.8817451
All 18.149854 74.111905 0.8255238 0.9293443
GLM (family binomial, link logit):
nulldev df dev df devratio AIC iters converged
numdead 124.87559 11 6.757064 9 0.946 42.87 4 1
numdead2.verylongname 91.62481 11 16.067427 9 0.825 61.29 4 1
>
> counts <- c(18,17,15,20,10,20,25,13,12) # Dobson 1990 p. 93
> outcome <- gl(3,1,9)
> treatment <- gl(3,3)
>
> a5 <- earth(counts ~ outcome + treatment, trace=1, pmethod="none",
+ glm=list(family=poisson))
x[9,4] with colnames outcome2 outcome3 treatment2 treatment3
y[9,1] with colname counts
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq -6.576 RSq 0.527
Prune method "none" penalty 2 nprune null: selected 3 of 3 terms, and 2 of 4 preds
After pruning pass GRSq -0.894 RSq 0.527
GLM counts devratio 0.52 dof 6/8 iters 4
> printh(a5)
===a5
Earth selected 3 of 3 terms, and 2 of 4 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: outcome2, outcome3, treatment2-unused, treatment3-unused
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 46.875 RSS 83.33333 GRSq -0.8939394 RSq 0.5265152
GLM (family poisson, link log):
nulldev df dev df devratio AIC iters converged
10.58145 8 5.129141 6 0.515 52.76 4 1
>
> a6 <- earth(numdead ~ sex + ldose, trace=1, pmethod="none",
+ glm=list(family=gaussian(link=identity)))
x[12,2] with colnames sexmale ldose
y[12,1] with colname numdead
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.907 RSq 0.981
Prune method "none" penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.952 RSq 0.981
GLM numdead devratio 0.98 dof 9/11 iters 2
> printh(a6$coefficients == a6$glm.coefficients) # all TRUE
===a6$coefficients == a6$glm.coefficients
numdead
(Intercept) TRUE
ldose TRUE
sexmale TRUE
> printh(a6)
===a6
Earth selected 3 of 3 terms, and 2 of 2 predictors (pmethod="none")
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: ldose, sexmale
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 2.376093 RSS 9.702381 GRSq 0.952486 RSq 0.9807588
GLM (family gaussian, link identity):
nulldev df dev df devratio AIC iters converged
504.25 11 9.702381 9 0.981 39.5 2 1
>
> remove(ldose)
> remove(sex)
> remove(numdead)
> remove(pair)
> remove(numdead2.verylongname)
> remove(doublepair)
> remove(counts)
> remove(outcome)
> remove(treatment)
>
> printh(earth(cbind(Volume,lvol=log(Volume)) ~ ., data=trees))
===earth(cbind(Volume, lvol = log(Volume)) ~ ., data = trees)
Selected 4 of 5 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: Girth, Height
Number of terms at each degree of interaction: 1 3 (additive model)
GCV RSS GRSq RSq
Volume 11.2543915 209.113855 0.9596919 0.9742028
lvol 0.0158825 0.295106 0.9445035 0.9644822
All 11.2702739 209.408961 0.9596764 0.9741929
> attach(trees)
> printh(earth(data.frame(Girth,Height), data.frame(Volume,lvol=log(Volume))))
===earth(data.frame(Girth, Height), data.frame(Volume, lvol = log(Volume)))
Selected 4 of 5 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: Girth, Height
Number of terms at each degree of interaction: 1 3 (additive model)
GCV RSS GRSq RSq
Volume 11.2543915 209.113855 0.9596919 0.9742028
lvol 0.0158825 0.295106 0.9445035 0.9644822
All 11.2702739 209.408961 0.9596764 0.9741929
> detach(trees)
>
> lm.fit <- lm(O3 ~ log(temp) + humidity*temp, data=ozone1)
> printh(lm.fit)
===lm.fit
Call:
lm(formula = O3 ~ log(temp) + humidity * temp, data = ozone1)
Coefficients:
(Intercept) log(temp) humidity temp humidity:temp
94.85623 -31.27411 -0.20050 0.63299 0.00475
> plotmo(lm.fit, level=.95, trace=-1)
> lm.fit2 <- lm(O3 ~ temp+ibh+doy, data=ozone1)
> printh(lm.fit2)
===lm.fit2
Call:
lm(formula = O3 ~ temp + ibh + doy, data = ozone1)
Coefficients:
(Intercept) temp ibh doy
-7.6740829 0.3785184 -0.0009858 -0.0066324
> plotmo(lm.fit2, all2=TRUE, clip=FALSE, trace=-1)
>
> cat("--- print.default of earth object---------\n")
--- print.default of earth object---------
> print.default(cars, digits=3)
$rss
[1] 46.6
$rsq
[1] 0.959
$gcv
[1] 59.6
$grsq
[1] -0.589
$bx
(Intercept) h(disp-145) h(145-disp) h(hp-123) h(123-hp) h(qsec-18.52)
[1,] 1 15.0 0.0 0 13 0.00
[2,] 1 15.0 0.0 0 13 0.00
[3,] 1 0.0 37.0 0 30 0.09
[4,] 1 113.0 0.0 0 13 0.92
[5,] 1 215.0 0.0 52 0 0.00
[6,] 1 80.0 0.0 0 18 1.70
[7,] 1 215.0 0.0 122 0 0.00
[8,] 1 1.7 0.0 0 61 1.48
[9,] 1 0.0 4.2 0 28 4.38
[10,] 1 22.6 0.0 0 0 0.00
[11,] 1 22.6 0.0 0 0 0.38
[12,] 1 130.8 0.0 57 0 0.00
[13,] 1 130.8 0.0 57 0 0.00
[14,] 1 130.8 0.0 57 0 0.00
[15,] 1 327.0 0.0 82 0 0.00
[16,] 1 315.0 0.0 92 0 0.00
[17,] 1 295.0 0.0 107 0 0.00
[18,] 1 0.0 66.3 0 57 0.95
[19,] 1 0.0 69.3 0 71 0.00
[20,] 1 0.0 73.9 0 58 1.38
[21,] 1 0.0 24.9 0 26 1.49
[22,] 1 173.0 0.0 27 0 0.00
[23,] 1 159.0 0.0 27 0 0.00
[24,] 1 205.0 0.0 122 0 0.00
[25,] 1 255.0 0.0 52 0 0.00
[26,] 1 0.0 66.0 0 57 0.38
[27,] 1 0.0 24.7 0 32 0.00
[28,] 1 0.0 49.9 0 10 0.00
[29,] 1 206.0 0.0 141 0 0.00
[30,] 1 0.0 0.0 52 0 0.00
[31,] 1 156.0 0.0 212 0 0.00
[32,] 1 0.0 24.0 0 14 0.08
h(18.52-qsec) h(drat-3.15) h(3.15-drat) h(gear-4) h(4-gear) h(disp-275.8)
[1,] 2.06 0.75 0.00 0 0 0.0
[2,] 1.50 0.75 0.00 0 0 0.0
[3,] 0.00 0.70 0.00 0 0 0.0
[4,] 0.00 0.00 0.07 0 1 0.0
[5,] 1.50 0.00 0.00 0 1 84.2
[6,] 0.00 0.00 0.39 0 1 0.0
[7,] 2.68 0.06 0.00 0 1 84.2
[8,] 0.00 0.54 0.00 0 0 0.0
[9,] 0.00 0.77 0.00 0 0 0.0
[10,] 0.22 0.77 0.00 0 0 0.0
[11,] 0.00 0.77 0.00 0 0 0.0
[12,] 1.12 0.00 0.08 0 1 0.0
[13,] 0.92 0.00 0.08 0 1 0.0
[14,] 0.52 0.00 0.08 0 1 0.0
[15,] 0.54 0.00 0.22 0 1 196.2
[16,] 0.70 0.00 0.15 0 1 184.2
[17,] 1.10 0.08 0.00 0 1 164.2
[18,] 0.00 0.93 0.00 0 0 0.0
[19,] 0.00 1.78 0.00 0 0 0.0
[20,] 0.00 1.07 0.00 0 0 0.0
[21,] 0.00 0.55 0.00 0 1 0.0
[22,] 1.65 0.00 0.39 0 1 42.2
[23,] 1.22 0.00 0.00 0 1 28.2
[24,] 3.11 0.58 0.00 0 1 74.2
[25,] 1.47 0.00 0.07 0 1 124.2
[26,] 0.00 0.93 0.00 0 0 0.0
[27,] 1.82 1.28 0.00 1 0 0.0
[28,] 1.62 0.62 0.00 1 0 0.0
[29,] 4.02 1.07 0.00 1 0 75.2
[30,] 3.02 0.47 0.00 1 0 0.0
[31,] 3.92 0.39 0.00 1 0 25.2
[32,] 0.00 0.96 0.00 0 0 0.0
h(qsec-17.02) vs
[1,] 0.00 0
[2,] 0.00 0
[3,] 1.59 1
[4,] 2.42 1
[5,] 0.00 0
[6,] 3.20 1
[7,] 0.00 0
[8,] 2.98 1
[9,] 5.88 1
[10,] 1.28 1
[11,] 1.88 1
[12,] 0.38 0
[13,] 0.58 0
[14,] 0.98 0
[15,] 0.96 0
[16,] 0.80 0
[17,] 0.40 0
[18,] 2.45 1
[19,] 1.50 1
[20,] 2.88 1
[21,] 2.99 1
[22,] 0.00 0
[23,] 0.28 0
[24,] 0.00 0
[25,] 0.03 0
[26,] 1.88 1
[27,] 0.00 0
[28,] 0.00 1
[29,] 0.00 0
[30,] 0.00 0
[31,] 0.00 0
[32,] 1.58 1
$dirs
cyl disp hp drat wt qsec vs am gear carb
(Intercept) 0 0 0 0 0 0 0 0 0 0
h(disp-145) 0 1 0 0 0 0 0 0 0 0
h(145-disp) 0 -1 0 0 0 0 0 0 0 0
h(hp-123) 0 0 1 0 0 0 0 0 0 0
h(123-hp) 0 0 -1 0 0 0 0 0 0 0
h(qsec-18.52) 0 0 0 0 0 1 0 0 0 0
h(18.52-qsec) 0 0 0 0 0 -1 0 0 0 0
h(drat-3.15) 0 0 0 1 0 0 0 0 0 0
h(3.15-drat) 0 0 0 -1 0 0 0 0 0 0
h(gear-4) 0 0 0 0 0 0 0 0 1 0
h(4-gear) 0 0 0 0 0 0 0 0 -1 0
h(disp-275.8) 0 1 0 0 0 0 0 0 0 0
h(qsec-17.02) 0 0 0 0 0 1 0 0 0 0
vs 0 0 0 0 0 0 2 0 0 0
$cuts
cyl disp hp drat wt qsec vs am gear carb
(Intercept) 0 0 0 0.00 0 0.0 0 0 0 0
h(disp-145) 0 145 0 0.00 0 0.0 0 0 0 0
h(145-disp) 0 145 0 0.00 0 0.0 0 0 0 0
h(hp-123) 0 0 123 0.00 0 0.0 0 0 0 0
h(123-hp) 0 0 123 0.00 0 0.0 0 0 0 0
h(qsec-18.52) 0 0 0 0.00 0 18.5 0 0 0 0
h(18.52-qsec) 0 0 0 0.00 0 18.5 0 0 0 0
h(drat-3.15) 0 0 0 3.15 0 0.0 0 0 0 0
h(3.15-drat) 0 0 0 3.15 0 0.0 0 0 0 0
h(gear-4) 0 0 0 0.00 0 0.0 0 0 4 0
h(4-gear) 0 0 0 0.00 0 0.0 0 0 4 0
h(disp-275.8) 0 276 0 0.00 0 0.0 0 0 0 0
h(qsec-17.02) 0 0 0 0.00 0 17.0 0 0 0 0
vs 0 0 0 0.00 0 0.0 0 0 0 0
$selected.terms
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14
$prune.terms
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,] 1 0 0 0 0 0 0 0 0 0 0 0 0
[2,] 1 3 0 0 0 0 0 0 0 0 0 0 0
[3,] 1 2 3 0 0 0 0 0 0 0 0 0 0
[4,] 1 2 3 4 0 0 0 0 0 0 0 0 0
[5,] 1 2 3 4 5 0 0 0 0 0 0 0 0
[6,] 1 3 4 6 13 14 0 0 0 0 0 0 0
[7,] 1 3 4 5 6 13 14 0 0 0 0 0 0
[8,] 1 3 4 5 6 9 13 14 0 0 0 0 0
[9,] 1 3 4 5 6 9 12 13 14 0 0 0 0
[10,] 1 3 4 5 6 9 10 12 13 14 0 0 0
[11,] 1 2 3 4 5 6 9 10 12 13 14 0 0
[12,] 1 2 3 4 5 6 9 10 11 12 13 14 0
[13,] 1 2 3 4 5 6 8 9 10 11 12 13 14
[14,] 1 2 3 4 5 6 7 8 9 10 11 12 13
[,14]
[1,] 0
[2,] 0
[3,] 0
[4,] 0
[5,] 0
[6,] 0
[7,] 0
[8,] 0
[9,] 0
[10,] 0
[11,] 0
[12,] 0
[13,] 0
[14,] 14
$fitted.values
mpg
[1,] 20.4
[2,] 20.8
[3,] 24.4
[4,] 20.0
[5,] 18.1
[6,] 17.7
[7,] 14.7
[8,] 24.7
[9,] 23.8
[10,] 18.5
[11,] 18.0
[12,] 16.8
[13,] 16.1
[14,] 14.8
[15,] 10.7
[16,] 11.6
[17,] 13.8
[18,] 30.6
[19,] 30.4
[20,] 31.7
[21,] 21.8
[22,] 16.1
[23,] 18.6
[24,] 13.8
[25,] 17.0
[26,] 30.1
[27,] 26.2
[28,] 31.1
[29,] 16.0
[30,] 18.7
[31,] 14.9
[32,] 21.0
$residuals
mpg
[1,] 0.5985
[2,] 0.2222
[3,] -1.5897
[4,] 1.4241
[5,] 0.6074
[6,] 0.3738
[7,] -0.3637
[8,] -0.2722
[9,] -1.0463
[10,] 0.7205
[11,] -0.2200
[12,] -0.4350
[13,] 1.1530
[14,] 0.4290
[15,] -0.2985
[16,] -1.1876
[17,] 0.9460
[18,] 1.8033
[19,] 0.0178
[20,] 2.2245
[21,] -0.3183
[22,] -0.6363
[23,] -3.4341
[24,] -0.4700
[25,] 2.2104
[26,] -2.8176
[27,] -0.1547
[28,] -0.6588
[29,] -0.2107
[30,] 0.9699
[31,] 0.0543
[32,] 0.3589
$coefficients
mpg
(Intercept) 21.2246
h(disp-145) 0.0215
h(145-disp) 0.1101
h(hp-123) -0.0365
h(123-hp) 0.0972
h(qsec-18.52) 4.8944
h(18.52-qsec) -0.6719
h(drat-3.15) -1.3666
h(3.15-drat) -8.2362
h(gear-4) 2.0743
h(4-gear) -2.1513
h(disp-275.8) -0.0321
h(qsec-17.02) -4.1119
vs 3.2318
$rss.per.response
[1] 46.6
$rsq.per.response
[1] 0.959
$gcv.per.response
[1] 59.6
$grsq.per.response
[1] -0.589
$rss.per.subset
[1] 1126.0 324.6 157.5 147.3 135.4 123.9 87.4 72.8 63.8 59.5
[11] 54.8 51.9 47.4 46.6
$gcv.per.subset
[1] 37.50 12.35 6.91 7.54 8.19 8.99 7.75 8.06 9.08 11.26 14.50 20.50
[13] 30.97 59.59
$leverages
[1] 0.385 0.343 0.196 0.494 0.209 0.549 0.297 0.792 0.877 0.340 0.322 0.232
[13] 0.241 0.371 0.456 0.323 0.337 0.261 0.572 0.347 0.615 0.550 0.280 0.469
[25] 0.217 0.259 0.640 0.775 0.672 0.615 0.724 0.238
$pmethod
[1] "none"
$nprune
NULL
$penalty
[1] 2
$nk
[1] 21
$thresh
[1] 0.001
$termcond
[1] 3
$weights
NULL
$call
earth(formula = mpg ~ ., data = mtcars, pmethod = "none", trace = 4)
$namesx.org
[1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
$namesx
[1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
$terms
mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb
attr(,"variables")
list(mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb)
attr(,"factors")
cyl disp hp drat wt qsec vs am gear carb
mpg 0 0 0 0 0 0 0 0 0 0
cyl 1 0 0 0 0 0 0 0 0 0
disp 0 1 0 0 0 0 0 0 0 0
hp 0 0 1 0 0 0 0 0 0 0
drat 0 0 0 1 0 0 0 0 0 0
wt 0 0 0 0 1 0 0 0 0 0
qsec 0 0 0 0 0 1 0 0 0 0
vs 0 0 0 0 0 0 1 0 0 0
am 0 0 0 0 0 0 0 1 0 0
gear 0 0 0 0 0 0 0 0 1 0
carb 0 0 0 0 0 0 0 0 0 1
attr(,"term.labels")
[1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
attr(,"order")
[1] 1 1 1 1 1 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb)
attr(,"dataClasses")
mpg cyl disp hp drat wt qsec vs
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
am gear carb
"numeric" "numeric" "numeric"
attr(,"class")
[1] "earth"
> cat("--- done print.default of earth object----\n")
--- done print.default of earth object----
> if (PLOT)
+ plot(cars)
> library(mda)
> (a <- fda(Species~., data=iris, method=earth, keepxy=TRUE))
Call:
fda(formula = Species ~ ., data = iris, method = earth, keepxy = TRUE)
Dimension: 2
Percent Between-Group Variance Explained:
v1 v2
97.97 100.00
Training Misclassification Error: 0.04 ( N = 150 )
> if (PLOT)
+ plot(a)
> printh(summary(a$fit))
===summary(a$fit)
Call: earth(x=x, y=Theta, weights=weights, keepxy=TRUE)
Theta1 Theta2
(Intercept) 1.2060322 -0.7346235
h(Sepal.Length-5.4) -0.1373750 -0.2294201
h(3.3-Sepal.Width) 0.1830045 0.3597030
h(Petal.Length-1.9) -1.7002724 -0.1836390
h(Petal.Length-3.5) 2.0219035 0.4940619
h(Petal.Length-4.5) 0.5710668 1.2862155
h(Petal.Length-5.3) -0.7975568 -1.4507177
h(Petal.Width-1.5) 2.0119980 3.5355314
h(Petal.Width-1.8) -1.9863032 -3.4901478
Selected 9 of 15 terms, and 4 of 4 predictors
Termination condition: Reached nk 21
Importance: Petal.Length, Petal.Width, Sepal.Width, Sepal.Length
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS GRSq RSq
Theta1 0.0473001 5.577943 0.9533285 0.9628137
Theta2 0.1234732 14.560786 0.8781676 0.9029281
All 0.1707733 20.138729 0.9157480 0.9328709
> expect.err(try(printh(summary(a$fit, none.such1="xxx"))), "unrecognized argument") # summary.earth unrecognized argument "none.such1"
===summary(a$fit, none.such1 = "xxx") Error : summary.earth: unrecognized argument 'none.such1'
Got error as expected from try(printh(summary(a$fit, none.such1 = "xxx")))
> printh(summary(a$fit, style="bf", none.such2="xxx")) # Warning: format.earth ignored unrecognized argument "none.such2"
===summary(a$fit, style = "bf", none.such2 = "xxx") Warning: format.earth ignored argument 'none.such2'
Call: earth(x=x, y=Theta, weights=weights, keepxy=TRUE)
Theta1 =
1.206032
- 0.137375 * bf1
+ 0.1830045 * bf2
- 1.700272 * bf3
+ 2.021903 * bf4
+ 0.5710668 * bf5
- 0.7975568 * bf6
+ 2.011998 * bf7
- 1.986303 * bf8
bf1 h(Sepal.Length-5.4)
bf2 h(3.3-Sepal.Width)
bf3 h(Petal.Length-1.9)
bf4 h(Petal.Length-3.5)
bf5 h(Petal.Length-4.5)
bf6 h(Petal.Length-5.3)
bf7 h(Petal.Width-1.5)
bf8 h(Petal.Width-1.8)
Theta2 =
-0.7346235
- 0.2294201 * bf1
+ 0.359703 * bf2
- 0.183639 * bf3
+ 0.4940619 * bf4
+ 1.286216 * bf5
- 1.450718 * bf6
+ 3.535531 * bf7
- 3.490148 * bf8
bf1 h(Sepal.Length-5.4)
bf2 h(3.3-Sepal.Width)
bf3 h(Petal.Length-1.9)
bf4 h(Petal.Length-3.5)
bf5 h(Petal.Length-4.5)
bf6 h(Petal.Length-5.3)
bf7 h(Petal.Width-1.5)
bf8 h(Petal.Width-1.8)
Selected 9 of 15 terms, and 4 of 4 predictors
Termination condition: Reached nk 21
Importance: Petal.Length, Petal.Width, Sepal.Width, Sepal.Length
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS GRSq RSq
Theta1 0.0473001 5.577943 0.9533285 0.9628137
Theta2 0.1234732 14.560786 0.8781676 0.9029281
All 0.1707733 20.138729 0.9157480 0.9328709
> if (PLOT) {
+ plot(a$fit, col.residuals=iris$Species, nresponse=1)
+ plotmo(a$fit, nresponse=1, ylim=c(-1.5,1.5), clip=FALSE, trace=-1)
+ plotmo(a$fit, nresponse=2, ylim=c(-1.5,1.5), clip=FALSE, trace=-1)
+ }
> a <- update(a, nk=3) # not on man page
> printh(a)
===a
Call:
fda(formula = Species ~ ., data = iris, method = earth, keepxy = TRUE,
nk = 3)
Dimension: 2
Percent Between-Group Variance Explained:
v1 v2
94.38 100.00
Training Misclassification Error: 0.04 ( N = 150 )
> printh(summary(a$fit))
===summary(a$fit)
Call: earth(x=x, y=Theta, weights=weights, keepxy=TRUE, nk=3)
Theta1 Theta2
(Intercept) -1.300791 -0.74367728
h(1.2-Petal.Width) 2.601323 0.03896856
h(Petal.Width-1.2) 1.351182 2.22366217
Selected 3 of 3 terms, and 1 of 4 predictors
Termination condition: Reached nk 3
Importance: Petal.Width, Sepal.Length-unused, Sepal.Width-unused, ...
Number of terms at each degree of interaction: 1 2 (additive model)
GCV RSS GRSq RSq
Theta1 0.1190355 16.68481 0.8825464 0.8887680
Theta2 0.2430154 34.06267 0.7602140 0.7729156
All 0.3620509 50.74747 0.8213802 0.8308418
> head(etitanic) # pclass and sex are unordered factors
pclass survived sex age sibsp parch
1 1st 1 female 29.0000 0 0
2 1st 1 male 0.9167 1 2
3 1st 0 female 2.0000 1 2
4 1st 0 male 30.0000 1 2
5 1st 0 female 25.0000 1 2
6 1st 1 male 48.0000 0 0
> earth(pclass ~ ., data=etitanic, trace=2)
x[1046,5] with colnames survived sexmale age sibsp parch
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 6 endspan 9 x[1046,5] 40.9 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0910 0.0980 0.09797 3 age 26 2 3 1
4 0.1525 0.1622 0.0642 1 survived 0< 4 1
6 0.1598 0.1758 0.01368 4 sibsp 1 5 6 1
8 0.1670 0.1891 0.0133 5 parch 2 7 8 1
10 0.1664 0.1918 0.002617 3 age 21 9 1
12 0.1656 0.1941 0.002331 3 age 57 10 1
14 0.1630 0.1947 0.0006471 3 age 55.5 11 1 reject (small DeltaRSq)
RSq changed by less than 0.001 at 13 terms, 10 terms used (DeltaRSq 0.00065)
After forward pass GRSq 0.163 RSq 0.195
Forward pass complete: 13 terms, 10 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 2 nprune null: selected 8 of 10 terms, and 4 of 5 preds
After pruning pass GRSq 0.167 RSq 0.189
Selected 8 of 10 terms, and 4 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 10 terms
Importance: age, survived, sibsp, parch, sexmale-unused
Number of terms at each degree of interaction: 1 7 (additive model)
GCV RSS GRSq RSq
1st 0.1483414 150.7467 0.251448718 0.27137124
2nd 0.1885520 191.6094 -0.004971341 0.02177575
3rd 0.1927692 195.8949 0.229032722 0.24955184
All 0.5296626 538.2511 0.166969402 0.18914032
>
> cat("--- format.earth.Rd ----------------------\n")
--- format.earth.Rd ----------------------
> as.func <- function( # convert expression string to func
+ object, digits = 8, use.names = TRUE, ...)
+ eval(parse(text=paste(
+ "function(x)\n",
+ "{\n",
+ "if(is.vector(x))\n",
+ " x <- matrix(x, nrow = 1, ncol = length(x))\n",
+ "with(as.data.frame(x),\n",
+ format(object, digits = digits, use.names = use.names, style = "p", ...),
+ ")\n",
+ "}\n", sep = "")))
> a <- earth(Volume ~ ., data = trees)
> my.func <- as.func(a, use.names = FALSE)
> printh(my.func(c(10,80))) # yields 17.76888
===my.func(c(10, 80)) [1] 17.60359
> printh(predict(a, c(10,80))) # yields 17.76888, but is slower
===predict(a, c(10, 80)) Volume
[1,] 17.60359
> example(format.earth)
frmt.r> earth.mod <- earth(Volume ~ ., data = trees)
frmt.r> cat(format(earth.mod))
29.05995
- 3.419806 * h(14.2-Girth)
+ 6.229514 * h(Girth-14.2)
+ 0.5813644 * h(Height-75)
frmt.r> # yields:
frmt.r> # 37.9
frmt.r> # - 3.92 * h(16-Girth)
frmt.r> # + 7.4 * h(Girth-16)
frmt.r> # + 0.484 * h(Height-75)
frmt.r>
frmt.r> cat(format(earth.mod, style="pmax"))
29.05995
- 3.419806 * pmax(0, 14.2 - Girth)
+ 6.229514 * pmax(0, Girth - 14.2)
+ 0.5813644 * pmax(0, Height - 75)
frmt.r> # yields:
frmt.r> # 37.9
frmt.r> # - 3.92 * pmax(0, 16 - Girth)
frmt.r> # + 7.4 * pmax(0, Girth - 16)
frmt.r> # + 0.484 * pmax(0, Height - 75)
frmt.r>
frmt.r> cat(format(earth.mod, style="C"))
29.05995
- 3.419806 * max(0, 14.2 - x[0])
+ 6.229514 * max(0, x[0] - 14.2)
+ 0.5813644 * max(0, x[1] - 75)
frmt.r> # yields (note zero based indexing):
frmt.r> # 37.927
frmt.r> # - 3.9187 * max(0, 16 - x[0])
frmt.r> # + 7.4011 * max(0, x[0] - 16)
frmt.r> # + 0.48411 * max(0, x[1] - 75)
frmt.r>
frmt.r> cat(format(earth.mod, style="bf"))
29.05995
- 3.419806 * bf1
+ 6.229514 * bf2
+ 0.5813644 * bf3
bf1 h(14.2-Girth)
bf2 h(Girth-14.2)
bf3 h(Height-75)
frmt.r> # yields:
frmt.r> # 37.9
frmt.r> # - 3.92 * bf1
frmt.r> # + 7.4 * bf2
frmt.r> # + 0.484 * bf3
frmt.r> #
frmt.r> # bf1 h(16-Girth)
frmt.r> # bf2 h(Girth-16)
frmt.r> # bf3 h(Height-75)
frmt.r>
frmt.r>
frmt.r>
> a <- earth(Volume ~ ., data = trees)
> cat(format(a)) # basic tests of format.earth
29.05995
- 3.419806 * h(14.2-Girth)
+ 6.229514 * h(Girth-14.2)
+ 0.5813644 * h(Height-75)
> cat(format(a, digits=4))
29.06
- 3.42 * h(14.2-Girth)
+ 6.23 * h(Girth-14.2)
+ 0.5814 * h(Height-75)
> # cat(format(a, use.names=FALSE))
> cat(format(a, style="pmax"))
29.05995
- 3.419806 * pmax(0, 14.2 - Girth)
+ 6.229514 * pmax(0, Girth - 14.2)
+ 0.5813644 * pmax(0, Height - 75)
> cat(format(a, style="max"))
29.05995
- 3.419806 * max(0, 14.2 - Girth)
+ 6.229514 * max(0, Girth - 14.2)
+ 0.5813644 * max(0, Height - 75)
> cat(format(a, style="bf"))
29.05995
- 3.419806 * bf1
+ 6.229514 * bf2
+ 0.5813644 * bf3
bf1 h(14.2-Girth)
bf2 h(Girth-14.2)
bf3 h(Height-75)
> cat(format(a, use.names=FALSE, style="p"))
29.05995
- 3.419806 * pmax(0, 14.2 - x[,1])
+ 6.229514 * pmax(0, x[,1] - 14.2)
+ 0.5813644 * pmax(0, x[,2] - 75)
> cat(format(a, use.names=FALSE, style="m"))
29.05995
- 3.419806 * max(0, 14.2 - x[,1])
+ 6.229514 * max(0, x[,1] - 14.2)
+ 0.5813644 * max(0, x[,2] - 75)
> a <- earth(Volume ~ Girth*Height, data = trees, pmethod="none")
> cat(format(a))
25.24205
- 0.8905681 * h(13.3-Girth)
+ 2.590203 * h(Girth-13.3)
- 0.02669905 * h(972.7-Girth:Height)
+ 0.03883467 * h(Girth:Height-972.7)
> cat(format(a, colon.char="*"))
25.24205
- 0.8905681 * h(13.3-Girth)
+ 2.590203 * h(Girth-13.3)
- 0.02669905 * h(972.7-Girth*Height)
+ 0.03883467 * h(Girth*Height-972.7)
> a <- lm(Volume ~ ., data = trees)
> cat(format(a)) # basic tests of format.lm
-57.98766
+ 4.708161 * Girth
+ 0.3392512 * Height
> cat(format(a, digits=4))
-57.99
+ 4.708 * Girth
+ 0.3393 * Height
> cat(format(a, use.names=FALSE))
-57.98766
+ 4.708161 * x[,1]
+ 0.3392512 * x[,2]
> cat(format(a, style="p"))
-57.98766
+ 4.708161 * Girth
+ 0.3392512 * Height
> cat(format(a, use.names=FALSE, style="p"))
-57.98766
+ 4.708161 * x[,1]
+ 0.3392512 * x[,2]
> a <- lm(Volume ~ Girth*Height, data = trees)
> cat(format(a))
69.39632
- 5.855848 * Girth
- 1.297083 * Height
+ 0.1346544 * Girth:Height
> cat(format(a, colon.char="*"))
69.39632
- 5.855848 * Girth
- 1.297083 * Height
+ 0.1346544 * Girth*Height
> cat("--- mars.to.earth.Rd ----------------------\n")
--- mars.to.earth.Rd ----------------------
> example(mars.to.earth)
mrs.t.> if(require(mda)) {
mrs.t.+ mars.mod <- mars(trees[,-3], trees[,3])
mrs.t.+ earth.mod <- mars.to.earth(mars.mod)
mrs.t.+ # the standard earth functions can now be used
mrs.t.+ # note the reconstructed call in the summary
mrs.t.+ summary(earth.mod, digits = 2)
mrs.t.+ }
Converted mars(x=trees[,-3], y=trees[,3])
to earth(x=trees[,-3], y=trees[,3])
Call: earth(x=trees[,-3], y=trees[,3])
coefficients
(Intercept) 26.3
h(13.8-Girth) -3.2
h(Girth-13.8) 6.1
h(11.4-Girth) 0.5
Selected 4 of 8 terms, and 2 of 2 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 10 RSS 190 GRSq 0.96 RSq 0.98
> library(mda)
> a <- mars(trees[,-3], trees[,3])
> a <- mars.to.earth(a)
Converted mars(x=trees[,-3], y=trees[,3])
to earth(x=trees[,-3], y=trees[,3])
> print(summary(a, digits = 2))
Call: earth(x=trees[,-3], y=trees[,3])
coefficients
(Intercept) 26.3
h(13.8-Girth) -3.2
h(Girth-13.8) 6.1
h(11.4-Girth) 0.5
Selected 4 of 8 terms, and 2 of 2 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 10 RSS 190 GRSq 0.96 RSq 0.98
> printh(summary(a, digits=2))
===summary(a, digits = 2)
Call: earth(x=trees[,-3], y=trees[,3])
coefficients
(Intercept) 26.3
h(13.8-Girth) -3.2
h(Girth-13.8) 6.1
h(11.4-Girth) 0.5
Selected 4 of 8 terms, and 2 of 2 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 10 RSS 190 GRSq 0.96 RSq 0.98
> printh(summary(a, digits=2, style="bf"))
===summary(a, digits = 2, style = "bf")
Call: earth(x=trees[,-3], y=trees[,3])
y =
26
- 3.2 * bf1
+ 6.1 * bf2
+ 0.5 * bf3
bf1 h(13.8-Girth)
bf2 h(Girth-13.8)
bf3 h(11.4-Girth)
Selected 4 of 8 terms, and 2 of 2 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 10 RSS 190 GRSq 0.96 RSq 0.98
> cat("--- plot.earth.models.Rd ----------------------\n")
--- plot.earth.models.Rd ----------------------
> if (PLOT)
+ example(plot.earth.models)
plt.r.> data(ozone1)
plt.r.> a1 <- earth(O3 ~ ., data = ozone1, degree = 2)
plt.r.> a2 <- earth(O3 ~ .-wind, data = ozone1, degree = 2)
plt.r.> a3 <- earth(O3 ~ .-humidity, data = ozone1, degree = 2)
plt.r.> plot.earth.models(list(a1,a2,a3), ylim=c(.65,.85))
> cat("--- plot.earth.Rd ----------------------\n")
--- plot.earth.Rd ----------------------
> if (PLOT) {
+ data(etitanic)
+ a <- earth(survived ~ ., data=etitanic, glm=list(family=binomial))
+ par(mfrow=c(2,2))
+ plot(a$glm.list[[1]], caption="a$glm.list[[1]]")
+ example(plot.earth)
+ }
plt.rt> data(ozone1)
plt.rt> earth.mod <- earth(O3 ~ ., data = ozone1, degree = 2)
plt.rt> plot(earth.mod)
> cat("--- predict.earth.Rd ----------------------\n")
--- predict.earth.Rd ----------------------
> example(predict.earth)
prdct.> data(trees)
prdct.> earth.mod <- earth(Volume ~ ., data = trees)
prdct.> predict(earth.mod) # same as earth.mod$fitted.values
Volume
[1,] 8.883097
[2,] 9.909039
[3,] 10.593000
[4,] 16.406671
[5,] 20.578818
[6,] 22.083528
[7,] 18.116574
[8,] 18.116574
[9,] 21.365376
[10,] 18.800535
[11,] 21.467973
[12,] 20.065861
[13,] 20.065861
[14,] 20.510438
[15,] 21.536380
[16,] 24.614206
[17,] 30.427849
[18,] 32.377136
[19,] 27.350050
[20,] 27.692031
[21,] 30.120085
[22,] 31.966775
[23,] 30.928808
[24,] 40.273079
[25,] 43.304662
[26,] 51.859634
[27,] 53.686902
[28,] 55.015978
[29,] 55.638930
[30,] 55.638930
[31,] 75.905218
prdct.> predict(earth.mod, c(10,80)) # yields 16.8
Volume
[1,] 17.60359
> cat("--- residuals.earth.Rd --------------------\n")
--- residuals.earth.Rd --------------------
> example(residuals.earth)
rsdls.> data(etitanic)
rsdls.> earth.mod <- earth(pclass ~ ., data=etitanic, glm=list(family=binomial))
rsdls.> head(resid(earth.mod, warn=FALSE)) # earth residuals, a column for each response
1st 2nd 3rd
1 0.6459266 -0.2575797 -0.3883469
2 0.7904775 -0.3372244 -0.4532531
3 1.0316575 -0.3335720 -0.6980855
4 0.7171249 -0.3904317 -0.3266933
5 0.7873520 -0.3970218 -0.3903302
6 0.3628026 -0.2131729 -0.1496297
rsdls.> head(resid(earth.mod, type="response")) # GLM response resids, a column for each response
1st 2nd 3rd
1 0.6573382 -0.2572600 -0.3595878
2 0.8654089 -0.3490739 -0.4071918
3 0.9669576 -0.3441215 -0.7048640
4 0.7394748 -0.4155799 -0.2598236
5 0.8095001 -0.4246067 -0.3324777
6 0.2959240 -0.2130374 -0.1283785
> cat("--- update.earth.Rd ----------------------\n")
--- update.earth.Rd ----------------------
> example(update.earth)
updt.r> data(ozone1)
updt.r> (earth.mod <- earth(O3 ~ ., data = ozone1, degree = 2))
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
updt.r> update(earth.mod, formula = O3 ~ . - temp) # requires forward pass and pruning
Selected 15 of 21 terms, and 8 of 8 predictors
Termination condition: Reached nk 21
Importance: ibt, humidity, doy, vh, dpg, vis, ibh, wind
Number of terms at each degree of interaction: 1 9 5
GCV 13.01626 RSS 3409.313 GRSq 0.7978077 RSq 0.8385391
updt.r> update(earth.mod, nprune = 8) # requires only pruning
Selected 8 of 21 terms, and 6 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibh-unused, ibt, doy, dpg, vis, vh-unused, ...
Number of terms at each degree of interaction: 1 5 2
GCV 14.70227 RSS 4323.013 GRSq 0.7716175 RSq 0.7952674
updt.r> update(earth.mod, penalty=1, ponly=TRUE) # pruning pass only with a new penalty
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 12.48074 RSS 3693.401 GRSq 0.8061264 RSq 0.825085
>
> cat("--- evimp.Rd -----------------------------\n")
--- evimp.Rd -----------------------------
>
> par(mfrow=c(2,2))
> cat('before calling evimp par("mar", "cex"):\n')
before calling evimp par("mar", "cex"):
> print(par("mar", "cex"))
$mar
[1] 5.1 4.1 4.1 2.1
$cex
[1] 0.83
>
> example(evimp)
evimp> data(ozone1)
evimp> earth.mod <- earth(O3 ~ ., data=ozone1, degree=2)
evimp> ev <- evimp(earth.mod, trim=FALSE)
evimp> plot(ev)
evimp> print(ev)
nsubsets gcv rss
temp 11 100.0 100.0
humidity 9 35.7 38.9
ibt 7 31.6 34.0
doy 7 31.6 34.0
ibh 6 33.4> 36.0>
dpg 6 27.5 29.8
vis 5 21.4 24.1
wind 2 10.3 12.6
vh 1 5.3 7.7
>
> cat("--- plot.evimp.Rd ------------------------\n")
--- plot.evimp.Rd ------------------------
>
> example(plot.evimp)
plt.vm> data(ozone1)
plt.vm> earth.mod <- earth(O3 ~ ., data=ozone1, degree=2)
plt.vm> ev <- evimp(earth.mod)
plt.vm> plot(ev)
plt.vm> print(ev)
nsubsets gcv rss
temp 11 100.0 100.0
humidity 9 35.7 38.9
ibt 7 31.6 34.0
doy 7 31.6 34.0
ibh 6 33.4> 36.0>
dpg 6 27.5 29.8
vis 5 21.4 24.1
wind 2 10.3 12.6
vh 1 5.3 7.7
>
> rownames(ev)[4] <- "a_long_variable_name"
>
> plot(ev, main="plot.evimp with various options",
+ cex.var = .8,
+ type.nsubsets = "p",
+ col.nsubsets = "red",
+ lty.nsubsets = 2, # ignored because type.nsubsets="p"
+ type.gcv = "l",
+ col.gcv = "green",
+ lty.gcv = 3,
+ type.rss = "b",
+ col.rss = "blue",
+ lty.rss = 4,
+ cex.legend = .8,
+ x.legend = "topright",
+ rh.col = "pink")
>
> a <- earth(Volume ~ Girth, data = trees)
> plot(evimp(a), main="plot.evimp with single var in model")
>
> cat('after calling evimp par("mar", "cex"):\n')
after calling evimp par("mar", "cex"):
> print(par("mar", "cex"))
$mar
[1] 5.1 4.1 4.1 2.1
$cex
[1] 0.83
> par(mfrow=c(1,1))
>
> cat("--- test predict.earth -------------------\n")
--- test predict.earth -------------------
>
> a <- earth(Volume ~ ., data = trees)
> cat("1a predict(a, c(10,80))\n")
1a predict(a, c(10,80))
> printh(predict(a, c(10,80), trace=1))
===predict(a, c(10, 80), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
Girth Height
1 10 80
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,2]:
Girth Height
1 10 80
predict.earth: bx[1,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
predict.earth: returning earth predictions
Volume
[1,] 17.60359
> cat("1b predict(a, c(10,10,80,80))\n")
1b predict(a, c(10,10,80,80))
> printh(predict(a, c(10,10,80,80), trace=1))
===predict(a, c(10, 10, 80, 80), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 10 80
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 10 80
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 4.2 5
predict.earth: returning earth predictions
Volume
[1,] 17.60359
[2,] 17.60359
> cat("1c predict(a, c(10,11,80,81))\n")
1c predict(a, c(10,11,80,81))
> printh(predict(a, c(10,11,80,81), trace=1))
===predict(a, c(10, 11, 80, 81), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 11 81
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 11 81
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 3.2 6
predict.earth: returning earth predictions
Volume
[1,] 17.60359
[2,] 21.60476
> cat("2 predict(a)\n")
2 predict(a)
> printh(head(predict(a, trace=1)))
===head(predict(a, trace = 1)) predict.earth: returning earth fitted.values
Volume
[1,] 8.883097
[2,] 9.909039
[3,] 10.593000
[4,] 16.406671
[5,] 20.578818
[6,] 22.083528
> cat("3a predict(a, matrix(c(10,12), nrow=1, ncol=2))\n")
3a predict(a, matrix(c(10,12), nrow=1, ncol=2))
> printh(predict(a, matrix(c(10,12), nrow=1, ncol=2), trace=1))
===predict(a, matrix(c(10, 12), nrow = 1, ncol = 2), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
Girth Height
1 10 12
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,2]:
Girth Height
1 10 12
predict.earth: bx[1,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 0
predict.earth: returning earth predictions
Volume
[1,] 14.69677
> cat("3b predict(a, matrix(c(10,12), nrow=2, ncol=2, byrow=TRUE)\n")
3b predict(a, matrix(c(10,12), nrow=2, ncol=2, byrow=TRUE)
> printh(predict(a, matrix(c(10,12), nrow=2, ncol=2, byrow=TRUE), trace=1))
===predict(a, matrix(c(10, 12), nrow = 2, ncol = 2, byrow = TRUE), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 12
2 10 12
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 12
2 10 12
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 0
2 1 0 4.2 0
predict.earth: returning earth predictions
Volume
[1,] 14.69677
[2,] 14.69677
> cat("3c predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2))\n")
3c predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2))
> printh(predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2), trace=1))
===predict(a, matrix(c(10, 12, 80, 90), nrow = 2, ncol = 2), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume
[1,] 17.60359
[2,] 30.25685
> xpredict <- matrix(c(10,12,80,90), nrow=2, ncol=2)
> colnames(xpredict) <- c("Girth", "Height")
> cat("4 predict(a, xpredict with colnames)\n")
4 predict(a, xpredict with colnames)
> printh(predict(a, xpredict, trace=1))
===predict(a, xpredict, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume
[1,] 17.60359
[2,] 30.25685
> cat("5 predict(a, as.data.frame(xpredict with colnames))\n")
5 predict(a, as.data.frame(xpredict with colnames))
> printh(predict(a, as.data.frame(xpredict), trace=1))
===predict(a, as.data.frame(xpredict), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume
[1,] 17.60359
[2,] 30.25685
> # reverse dataframe columns (and their names), predict should deal with it correctly
> xpredict <- as.data.frame(cbind(xpredict[,2], xpredict[,1]))
> colnames(xpredict) <- c("Height", "Girth")
> cat("6a predict(a, xpredict with reversed columns and colnames)\n")
6a predict(a, xpredict with reversed columns and colnames)
> printh(predict(a, xpredict, trace=1))
===predict(a, xpredict, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
Old columns: Height Girth
New columns: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume
[1,] 17.60359
[2,] 30.25685
> xpredict2 <- cbind(xpredict[,1], xpredict[,2]) # nameless matrix
> cat("6b predict(a, xpredict2)\n")
6b predict(a, xpredict2)
> printh(predict(a, xpredict2, trace=1))
===predict(a, xpredict2, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 80 10
2 90 12
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 80 10
2 90 12
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 65.8 0 0
2 1 75.8 0 0
predict.earth: returning earth predictions
Volume
[1,] 438.9620
[2,] 501.2571
>
> # repeat but with x,y (not formula) call to earth
>
> x1 <- cbind(trees$Girth, trees$Height)
> colnames(x1) <- c("Girth", "Height")
> a <- earth(x1, trees$Volume)
> xpredict <- matrix(c(10,12,80,90), nrow=2, ncol=2)
> cat("7a predict(a)\n")
7a predict(a)
> printh(head(predict(a, trace=1)))
===head(predict(a, trace = 1)) predict.earth: returning earth fitted.values
trees$Volume
[1,] 8.883097
[2,] 9.909039
[3,] 10.593000
[4,] 16.406671
[5,] 20.578818
[6,] 22.083528
> cat("7n predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2)\n")
7n predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2)
> printh(predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2), trace=1))
===predict(a, matrix(c(10, 12, 80, 90), nrow = 2, ncol = 2), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
trees$Volume
[1,] 17.60359
[2,] 30.25685
> colnames(xpredict) <- c("Girth", "Height")
> cat("8 predict(a, xpredict with colnames)\n")
8 predict(a, xpredict with colnames)
> printh(predict(a, xpredict, trace=1))
===predict(a, xpredict, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
trees$Volume
[1,] 17.60359
[2,] 30.25685
> cat("9 predict(a, as.data.frame(xpredict with colnames))\n")
9 predict(a, as.data.frame(xpredict with colnames))
> printh(predict(a, as.data.frame(xpredict), trace=1))
===predict(a, as.data.frame(xpredict), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
trees$Volume
[1,] 17.60359
[2,] 30.25685
> cat("--Expect warning from predict.earth: the variable names in 'data' do not match those in 'object'\n")
--Expect warning from predict.earth: the variable names in 'data' do not match those in 'object'
> xpredict2 <- cbind(xpredict[,1], xpredict[,2])
> colnames(xpredict2) <- c("none.such", "joe")
> cat("10a predict(a, xpredict2)\n")
10a predict(a, xpredict2)
> printh(predict(a, xpredict2, trace=1), expect.warning=TRUE)
===predict(a, xpredict2, trace = 1) expect warning -->get.earth.x from model.matrix.earth from predict.earth: unexpected x column names, renaming columns
Old names: none.such joe
New names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
trees$Volume
[1,] 17.60359
[2,] 30.25685
> cat("--Expect warning from predict.earth: the variable names in 'data' do not match those in 'object'\n")
--Expect warning from predict.earth: the variable names in 'data' do not match those in 'object'
> xpredict2 <- cbind(xpredict[,1], xpredict[,2])
> colnames(xpredict2) <- c("Height", "Girth") # reversed
> cat("10b predict(a, xpredict2)\n")
10b predict(a, xpredict2)
> printh(predict(a, xpredict2, trace=1), expect.warning=TRUE)
===predict(a, xpredict2, trace = 1) expect warning -->get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
Old columns: Height Girth
New columns: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 80 10
2 90 12
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 65.8 0 0
2 1 75.8 0 0
predict.earth: returning earth predictions
trees$Volume
[1,] 438.9620
[2,] 501.2571
>
> cat("--- test predict.earth with multiple response models-------------------\n")
--- test predict.earth with multiple response models-------------------
>
> a <- earth(cbind(Volume, Volume + 100) ~ ., data = trees)
> cat("1a predict(a, c(10,80))\n")
1a predict(a, c(10,80))
> printh(predict(a, c(10,80), trace=1))
===predict(a, c(10, 80), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
Girth Height
1 10 80
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,2]:
Girth Height
1 10 80
predict.earth: bx[1,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
> cat("1b predict(a, c(10,10,80,80))\n")
1b predict(a, c(10,10,80,80))
> printh(predict(a, c(10,10,80,80), trace=1))
===predict(a, c(10, 10, 80, 80), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 10 80
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 10 80
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 4.2 5
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
[2,] 17.60359 117.6036
> cat("1c predict(a, c(10,11,80,81))\n")
1c predict(a, c(10,11,80,81))
> printh(predict(a, c(10,11,80,81), trace=1))
===predict(a, c(10, 11, 80, 81), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 11 81
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 11 81
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 3.2 6
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
[2,] 21.60476 121.6048
> cat("2 predict(a)\n")
2 predict(a)
> printh(head(predict(a, trace=1)))
===head(predict(a, trace = 1)) predict.earth: returning earth fitted.values
Volume cbind(Volume,Volume+100)2
[1,] 8.883097 108.8831
[2,] 9.909039 109.9090
[3,] 10.593000 110.5930
[4,] 16.406671 116.4067
[5,] 20.578818 120.5788
[6,] 22.083528 122.0835
> cat("3a predict(a, matrix(c(10,12), nrow=1, ncol=2))\n")
3a predict(a, matrix(c(10,12), nrow=1, ncol=2))
> printh(predict(a, matrix(c(10,12), nrow=1, ncol=2), trace=1))
===predict(a, matrix(c(10, 12), nrow = 1, ncol = 2), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[1,2]:
Girth Height
1 10 12
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,2]:
Girth Height
1 10 12
predict.earth: bx[1,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 0
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 14.69677 114.6968
> cat("3b predict(a, matrix(c(10,12), nrow=2, ncol=2, byrow=TRUE)\n")
3b predict(a, matrix(c(10,12), nrow=2, ncol=2, byrow=TRUE)
> printh(predict(a, matrix(c(10,12), nrow=2, ncol=2, byrow=TRUE), trace=1))
===predict(a, matrix(c(10, 12), nrow = 2, ncol = 2, byrow = TRUE), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 12
2 10 12
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 12
2 10 12
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 0
2 1 0 4.2 0
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 14.69677 114.6968
[2,] 14.69677 114.6968
> cat("3c predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2))\n")
3c predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2))
> printh(predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2), trace=1))
===predict(a, matrix(c(10, 12, 80, 90), nrow = 2, ncol = 2), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> xpredict <- matrix(c(10,12,80,90), nrow=2, ncol=2)
> colnames(xpredict) <- c("Girth", "Height")
> cat("4 predict(a, xpredict with colnames)\n")
4 predict(a, xpredict with colnames)
> printh(predict(a, xpredict, trace=1))
===predict(a, xpredict, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> cat("5 predict(a, as.data.frame(xpredict with colnames))\n")
5 predict(a, as.data.frame(xpredict with colnames))
> printh(predict(a, as.data.frame(xpredict), trace=1))
===predict(a, as.data.frame(xpredict), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> # reverse dataframe columns (and their names), predict should deal with it correctly
> xpredict <- as.data.frame(cbind(xpredict[,2], xpredict[,1]))
> colnames(xpredict) <- c("Height", "Girth")
> cat("6 predict(a, xpredict with reversed columns and colnames)\n")
6 predict(a, xpredict with reversed columns and colnames)
> printh(predict(a, xpredict, trace=1))
===predict(a, xpredict, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
Old columns: Height Girth
New columns: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
Volume cbind(Volume,Volume+100)2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> expect.err(try(predict(a, interval="pin")), "no prediction intervals because the earth model was not built with varmod.method")
Error : no prediction intervals because the earth model was not built with varmod.method
Got error as expected from try(predict(a, interval = "pin"))
> expect.err(try(earth(cbind(Volume, Volume + 100) ~ ., data = trees, nfold=3, ncross=3, varmod.method="lm")), "variance models are not supported for multiple response models")
Error : variance models are not supported for multiple response models
Got error as expected from try(earth(cbind(Volume, Volume + 100) ~ ., data = trees, nfold = 3, ncross = 3, varmod.method = "lm"))
>
> # repeat but with x,y (not formula) call to earth
>
> x1 <- cbind(trees$Girth, trees$Height)
> colnames(x1) <- c("Girth", "Height")
> a <- earth(x1, cbind(trees$Volume, trees$Volume+100))
> xpredict <- matrix(c(10,12,80,90), nrow=2, ncol=2)
> cat("7a predict(a)\n")
7a predict(a)
> printh(head(predict(a, trace=1)))
===head(predict(a, trace = 1)) predict.earth: returning earth fitted.values
y1 y2
[1,] 8.883097 108.8831
[2,] 9.909039 109.9090
[3,] 10.593000 110.5930
[4,] 16.406671 116.4067
[5,] 20.578818 120.5788
[6,] 22.083528 122.0835
> cat("7b predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2)\n")
7b predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2)
> printh(predict(a, matrix(c(10,12,80,90), nrow=2, ncol=2), trace=1))
===predict(a, matrix(c(10, 12, 80, 90), nrow = 2, ncol = 2), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x has no column names, adding column names: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
y1 y2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> colnames(xpredict) <- c("Girth", "Height")
> cat("8 predict(a, xpredict with colnames)\n")
8 predict(a, xpredict with colnames)
> printh(predict(a, xpredict, trace=1))
===predict(a, xpredict, trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
y1 y2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> cat("9 predict(a, as.data.frame(xpredict with colnames))\n")
9 predict(a, as.data.frame(xpredict with colnames))
> printh(predict(a, as.data.frame(xpredict), trace=1))
===predict(a, as.data.frame(xpredict), trace = 1) get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
y1 y2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
> cat("--Expect warning from predict.earth: the variable names in 'data' do not match those in 'object'\n")
--Expect warning from predict.earth: the variable names in 'data' do not match those in 'object'
> xpredict <- as.data.frame(cbind(xpredict[,2], xpredict[,1]))
> colnames(xpredict) <- c("Height", "Girth")
> cat("10 predict(a, xpredict)\n")
10 predict(a, xpredict)
> printh(predict(a, xpredict, trace=1), expect.warning=TRUE)
===predict(a, xpredict, trace = 1) expect warning -->get.earth.x from model.matrix.earth from predict.earth: x columns are in the wrong order, correcting the column order
Old columns: Height Girth
New columns: Girth Height
get.earth.x from model.matrix.earth from predict.earth: x[2,2]:
Girth Height
1 10 80
2 12 90
predict.earth: bx[2,4]:
(Intercept) h(Girth-14.2) h(14.2-Girth) h(Height-75)
1 1 0 4.2 5
2 1 0 2.2 15
predict.earth: returning earth predictions
y1 y2
[1,] 17.60359 117.6036
[2,] 30.25685 130.2568
>
> cat("--- earth.predict with NAs, with formula interface ---\n")
--- earth.predict with NAs, with formula interface ---
>
> predict.with.message <- function(message, earth.model, newdata) {
+ cat("predict.earth ", message, ":\n", sep="")
+ print(predict(earth.model, newdata=newdata, trace=1))
+ cat("\n")
+ }
>
> iris.earth <- earth(Petal.Width ~ Sepal.Length + Sepal.Width + Petal.Length, data=iris)
> x <- iris[1,]
> predict.with.message("formula interface and vector", iris.earth, newdata=x)
predict.earth formula interface and vector:
get.earth.x from model.matrix.earth from predict.earth: x[1,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,3]:
Sepal.Length Sepal.Width Petal.Length
1 5.1 3.5 1.4
predict.earth: bx[1,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
predict.earth: returning earth predictions
Petal.Width
[1,] 0.2562505
> x$Sepal.Width <- as.numeric(NA)
> predict.with.message("formula interface and vector with NA", iris.earth, newdata=x)
predict.earth formula interface and vector with NA:
get.earth.x from model.matrix.earth from predict.earth: x[1,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 NA 1.4 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,3]:
Sepal.Length Sepal.Width Petal.Length
1 5.1 NA 1.4
predict.earth: bx[1,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 NA 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
predict.earth: returning earth predictions
Petal.Width
[1,] NA
> x <- iris[1,]
> x$Petal.Width <- as.numeric(NA) # Petal.Width is unused in the earth model
> predict.with.message("formula interface and vector with NA in unused variable", iris.earth, newdata=x)
predict.earth formula interface and vector with NA in unused variable:
get.earth.x from model.matrix.earth from predict.earth: x[1,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 NA setosa
Species is a factor with levels: setosa versicolor virginica
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[1,3]:
Sepal.Length Sepal.Width Petal.Length
1 5.1 3.5 1.4
predict.earth: bx[1,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
predict.earth: returning earth predictions
Petal.Width
[1,] 0.2562505
>
> x <- iris[1:3,]
> predict.with.message("formula interface and matrix", iris.earth, newdata=x)
predict.earth formula interface and matrix:
get.earth.x from model.matrix.earth from predict.earth: x[3,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[3,3]:
Sepal.Length Sepal.Width Petal.Length
1 5.1 3.5 1.4
2 4.9 3.0 1.4
3 4.7 3.2 1.3
predict.earth: bx[3,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0.0 0
2 1 4.6 0.5 0
3 1 4.7 0.3 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
2 2.0 0 0
3 2.2 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
2 0 0
3 0 0
predict.earth: returning earth predictions
Petal.Width
[1,] 0.2562505
[2,] 0.1733787
[3,] 0.1880121
> x[2,]$Sepal.Width <- as.numeric(NA)
> predict.with.message("formula interface and matrix with NA", iris.earth, newdata=x)
predict.earth formula interface and matrix with NA:
get.earth.x from model.matrix.earth from predict.earth: x[3,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 NA 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[3,3]:
Sepal.Length Sepal.Width Petal.Length
1 5.1 3.5 1.4
2 4.9 NA 1.4
3 4.7 3.2 1.3
predict.earth: bx[3,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0.0 0
2 1 4.6 NA 0
3 1 4.7 0.3 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
2 2.0 0 0
3 2.2 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
2 0 0
3 0 0
predict.earth: returning earth predictions
Petal.Width
[1,] 0.2562505
[2,] NA
[3,] 0.1880121
> x <- iris[1:3,]
> x[2,]$Petal.Width <- as.numeric(NA) # Petal.Width is unused in the earth model
> predict.with.message("formula interface and matrix with NA in unused variable", iris.earth, newdata=x)
predict.earth formula interface and matrix with NA in unused variable:
get.earth.x from model.matrix.earth from predict.earth: x[3,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 NA setosa
3 4.7 3.2 1.3 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
get.earth.x from model.matrix.earth from predict.earth: after call to model.frame: data[3,3]:
Sepal.Length Sepal.Width Petal.Length
1 5.1 3.5 1.4
2 4.9 3.0 1.4
3 4.7 3.2 1.3
predict.earth: bx[3,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0.0 0
2 1 4.6 0.5 0
3 1 4.7 0.3 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
2 2.0 0 0
3 2.2 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
2 0 0
3 0 0
predict.earth: returning earth predictions
Petal.Width
[1,] 0.2562505
[2,] 0.1733787
[3,] 0.1880121
>
> cat("--- earth.predict with NAs, with matrix interface ---\n")
--- earth.predict with NAs, with matrix interface ---
>
> iris.earth <- earth(iris[,1:3], iris[,4])
> x <- iris[1,]
> predict.with.message("default interface and vector", iris.earth, newdata=x)
predict.earth default interface and vector:
get.earth.x from model.matrix.earth from predict.earth: x[1,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
predict.earth: bx[1,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
predict.earth: returning earth predictions
iris[,4]
[1,] 0.2562505
> x$Sepal.Width <- as.numeric(NA)
> predict.with.message("default interface and vector with NA", iris.earth, newdata=x)
predict.earth default interface and vector with NA:
get.earth.x from model.matrix.earth from predict.earth: x[1,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 NA 1.4 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
predict.earth: bx[1,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 NA 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
predict.earth: returning earth predictions
iris[,4]
[1,] NA
> x <- iris[1,]
> x$Petal.Width <- as.numeric(NA) # Petal.Width is unused in the earth model
> predict.with.message("default interface and vector with NA in unused variable", iris.earth, newdata=x)
predict.earth default interface and vector with NA in unused variable:
get.earth.x from model.matrix.earth from predict.earth: x[1,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 NA setosa
Species is a factor with levels: setosa versicolor virginica
predict.earth: bx[1,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
predict.earth: returning earth predictions
iris[,4]
[1,] 0.2562505
>
> x <- iris[1:3,]
> predict.with.message("default interface and matrix", iris.earth, newdata=x)
predict.earth default interface and matrix:
get.earth.x from model.matrix.earth from predict.earth: x[3,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
predict.earth: bx[3,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0.0 0
2 1 4.6 0.5 0
3 1 4.7 0.3 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
2 2.0 0 0
3 2.2 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
2 0 0
3 0 0
predict.earth: returning earth predictions
iris[,4]
[1,] 0.2562505
[2,] 0.1733787
[3,] 0.1880121
> x[2,]$Sepal.Width <- as.numeric(NA)
> predict.with.message("default interface and matrix with NA", iris.earth, newdata=x)
predict.earth default interface and matrix with NA:
get.earth.x from model.matrix.earth from predict.earth: x[3,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 NA 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
predict.earth: bx[3,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0.0 0
2 1 4.6 NA 0
3 1 4.7 0.3 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
2 2.0 0 0
3 2.2 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
2 0 0
3 0 0
predict.earth: returning earth predictions
iris[,4]
[1,] 0.2562505
[2,] NA
[3,] 0.1880121
> x <- iris[1:3,]
> x[2,]$Petal.Width <- as.numeric(NA) # Petal.Width is unused in the earth model
> predict.with.message("default interface and matrix with NA in unused variable", iris.earth, newdata=x)
predict.earth default interface and matrix with NA in unused variable:
get.earth.x from model.matrix.earth from predict.earth: x[3,5]:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 NA setosa
3 4.7 3.2 1.3 0.2 setosa
Species is a factor with levels: setosa versicolor virginica
predict.earth: bx[3,9]:
(Intercept) h(6-Petal.Length) h(3.5-Sepal.Width) h(Sepal.Length-6.9)
1 1 4.6 0.0 0
2 1 4.6 0.5 0
3 1 4.7 0.3 0
h(6.9-Sepal.Length) h(Sepal.Length-7.2) h(Petal.Length-5.3)
1 1.8 0 0
2 2.0 0 0
3 2.2 0 0
h(Petal.Length-4.7) h(Petal.Length-5.5)
1 0 0
2 0 0
3 0 0
predict.earth: returning earth predictions
iris[,4]
[1,] 0.2562505
[2,] 0.1733787
[3,] 0.1880121
>
> cat("--- test reorder.earth ----------------------\n")
--- test reorder.earth ----------------------
> a <- earth(O3 ~ ., data = ozone1, degree = 2)
> earth:::reorder.earth(a, decomp = "none")
[1] 1 2 3 4 5 6 7 8 9 10 11 12
> earth:::reorder.earth(a) # defaults to decomp = "anova"
[1] 1 2 10 8 5 4 12 9 3 6 7 11
> a$selected.terms[earth:::reorder.earth(a)]
[1] 1 2 17 13 9 8 21 14 7 10 11 19
>
> cat("--- tests with ozone data ----------------------\n")
--- tests with ozone data ----------------------
>
> ozone.test <- function(itest, sModel, x, y, degree=2, nk=51,
+ plotit=PLOT, trace=0, smooth.col="red")
+ {
+ fite <- earth(x, y, degree=degree, nk=nk, trace=trace)
+ fitm <- mars(x, y, degree=degree, nk=nk)
+
+ cat("itest",
+ sprint("%-3d", itest),
+ sprint("%-32s", sModel),
+ "degree", sprint("%-2d", degree), "nk", sprint("%-3g", nk),
+ "nTerms", sprint("%-2d", sum(fite$selected.terms != 0)),
+ "of", sprint("%-3d", nrow(fite$dirs)),
+ "GRSq", sprint("%4.2g", fite$grsq),
+ "GRSq ratio", fite$grsq/mars.to.earth(fitm)$grsq,
+ "\n")
+ caption <- paste("itest ", itest, ": ", sModel, " degree=", degree, " nk=", nk, sep="")
+ printh(summary(fite))
+ printh(summary(fite, style="bf"))
+ if(plotit) {
+ fitme <- mars.to.earth(fitm)
+ plotmo(fite, caption=paste("EARTH", caption), trace=-1)
+ plotmo(fitme, caption=paste("MARS", caption), trace=-1)
+ plot(fite, npoints=500, smooth.col=smooth.col, caption=paste("EARTH", caption), info=TRUE)
+ plot(fitme, caption=paste("MARS", caption), info=TRUE)
+ fitme <- update(fitme) # generate model selection data
+ plot.earth.models(list(fite, fitme), caption=paste(itest, ": Compare earth to mars ", sModel, sep=""))
+ }
+ fite
+ }
> data(ozone1)
> attach(ozone1)
>
> x.global <- cbind(wind, humidity, temp, vis)
> y <- doy
> itest <- 1; ozone.test(itest, "doy ~ wind+humidity+temp+vis", x.global, y, degree=1, nk=21)
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
itest 1 doy ~ wind+humidity+temp+vis degree 1 nk 21 nTerms 7 of 15 GRSq 0.2 GRSq ratio 1.209183
===summary(fite)
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
coefficients
(Intercept) 68.211814
h(3-wind) 58.202580
h(28-humidity) 8.904095
h(humidity-28) 1.514544
h(temp-45) 45.704313
h(temp-48) -118.146795
h(temp-49) 73.558997
Selected 7 of 15 terms, and 3 of 4 predictors
Termination condition: Reached nk 21
Importance: wind, temp, humidity, vis-unused
Number of terms at each degree of interaction: 1 6 (additive model)
GCV 8737.327 RSS 2660622 GRSq 0.2004306 RSq 0.2576942
===summary(fite, style = "bf")
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
y =
68.21181
+ 58.20258 * bf1
+ 8.904095 * bf2
+ 1.514544 * bf3
+ 45.70431 * bf4
- 118.1468 * bf5
+ 73.559 * bf6
bf1 h(3-wind)
bf2 h(28-humidity)
bf3 h(humidity-28)
bf4 h(temp-45)
bf5 h(temp-48)
bf6 h(temp-49)
Selected 7 of 15 terms, and 3 of 4 predictors
Termination condition: Reached nk 21
Importance: wind, temp, humidity, vis-unused
Number of terms at each degree of interaction: 1 6 (additive model)
GCV 8737.327 RSS 2660622 GRSq 0.2004306 RSq 0.2576942
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
Selected 7 of 15 terms, and 3 of 4 predictors
Termination condition: Reached nk 21
Importance: wind, temp, humidity, vis-unused
Number of terms at each degree of interaction: 1 6 (additive model)
GCV 8737.327 RSS 2660622 GRSq 0.2004306 RSq 0.2576942
>
> x.global <- cbind(wind, humidity, temp, vis)
> y <- doy
> itest <- itest+1; a91 <- ozone.test(itest, "doy ~ wind+humidity+temp+vis", x.global, y, degree=2, nk=21)
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
itest 2 doy ~ wind+humidity+temp+vis degree 2 nk 21 nTerms 10 of 20 GRSq 0.17 GRSq ratio 0.9365432
===summary(fite)
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
coefficients
(Intercept) 130.291709
h(3-wind) 56.324090
h(28-humidity) 15.639545
h(humidity-28) 2.108507
h(49-temp) -8.918573
h(wind-3) * h(44-temp) 1.473267
h(23-humidity) * h(temp-49) -4.977131
h(28-humidity) * h(temp-53) 1.856655
h(humidity-28) * h(vis-200) -0.022851
h(temp-49) * h(vis-120) 0.024712
Selected 10 of 20 terms, and 4 of 4 predictors
Termination condition: Reached nk 21
Importance: wind, temp, humidity, vis
Number of terms at each degree of interaction: 1 4 5
GCV 9046.094 RSS 2575183 GRSq 0.1721748 RSq 0.2815314
===summary(fite, style = "bf")
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
y =
130.2917
+ 56.32409 * bf1
+ 15.63955 * bf2
+ 2.108507 * bf3
- 8.918573 * bf4
+ 1.473267 * bf5 * bf6
- 4.977131 * bf7 * bf8
+ 1.856655 * bf2 * bf9
- 0.02285106 * bf3 * bf10
+ 0.02471206 * bf8 * bf11
bf1 h(3-wind)
bf2 h(28-humidity)
bf3 h(humidity-28)
bf4 h(49-temp)
bf5 h(wind-3)
bf6 h(44-temp)
bf7 h(23-humidity)
bf8 h(temp-49)
bf9 h(temp-53)
bf10 h(vis-200)
bf11 h(vis-120)
Selected 10 of 20 terms, and 4 of 4 predictors
Termination condition: Reached nk 21
Importance: wind, temp, humidity, vis
Number of terms at each degree of interaction: 1 4 5
GCV 9046.094 RSS 2575183 GRSq 0.1721748 RSq 0.2815314
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
>
> # this is a basic test of RegressAndFix (because this generates lin dep bx cols)
>
> cat("--Expect warning from mda::mars: NAs introduced by coercion\n") # why do we get a warning?
--Expect warning from mda::mars: NAs introduced by coercion
> x.global <- cbind(wind, exp(humidity))
> y <- doy
> # smooth.col is 0 else get loess errors
> # trace==2 so we print the "Fixed rank deficient bx by removing 2 terms, 7 terms remain" message
> # TODO why are we getting the rank deficient message?
> itest <- itest+1; ozone.test(itest, "doy ~ wind+exp(humidity)", x.global, y, degree=1, nk=21, smooth.col=0, trace=2)
x[330,2] with colnames wind ""
y[330,1] with colname y
Forward pass: minspan 5 endspan 8 x[330,2] 5.16 kB bx[330,21] 54.1 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0887 0.1107 0.1107 1 wind 3 2 3 1
4 0.0906 0.1235 0.01274 1 wind 9 4 1
6 0.0821 0.1262 0.002668 1 wind 4 5 1
8 0.0730 0.1285 0.002307 1 wind 6 6 1
10 0.0633 0.1304 0.001925 2 1.7848e+08< 7 1
12 0.0527 0.1316 0.001264 2 1.7848e+08< 8 1
14 0.0420 0.1329 0.001279 2 1.7848e+08< 9 1
16 0.0297 0.1329 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 15 terms, 9 terms used (DeltaRSq 0)
After forward pass GRSq 0.030 RSq 0.133
Forward pass complete: 15 terms, 9 terms used
Fixed rank deficient bx by removing 2 terms, 7 terms remain
Prune method "backward" penalty 2 nprune null: selected 3 of 7 terms, and 1 of 2 preds
After pruning pass GRSq 0.101 RSq 0.123
Warning in storage.mode(tagx) <- "integer" :
NAs introduced by coercion to integer range
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
itest 3 doy ~ wind+exp(humidity) degree 1 nk 21 nTerms 3 of 7 GRSq 0.1 GRSq ratio 1.318534
===summary(fite)
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
coefficients
(Intercept) 202.17924
h(3-wind) 50.04004
h(wind-9) -61.15513
Selected 3 of 7 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 7 terms
Importance: wind, x2-unused
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 9821.564 RSS 3143644 GRSq 0.1012101 RSq 0.1229323
===summary(fite, style = "bf")
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
y =
202.1792
+ 50.04004 * bf1
- 61.15513 * bf2
bf1 h(3-wind)
bf2 h(wind-9)
Selected 3 of 7 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 7 terms
Importance: wind, x2-unused
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 9821.564 RSS 3143644 GRSq 0.1012101 RSq 0.1229323
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
Selected 3 of 7 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 7 terms
Importance: wind, x2-unused
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 9821.564 RSS 3143644 GRSq 0.1012101 RSq 0.1229323
>
> x.global <- cbind(vh,wind,humidity,temp,ibh,dpg,ibt,vis,doy)
> y <- O3
> itest <- itest+1; ozone.test(itest, "O3~.", x.global, y, degree=2, nk=21)
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
itest 4 O3~. degree 2 nk 21 nTerms 12 of 21 GRSq 0.79 GRSq ratio 1.014924
===summary(fite)
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
===summary(fite, style = "bf")
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
y =
13.21699
+ 0.3726072 * bf1
- 0.04550995 * bf2
+ 0.02224623 * bf3
- 0.1223029 * bf4
- 0.02402354 * bf5
- 0.01044957 * bf6 * bf1
- 0.01808982 * bf7 * bf3
- 0.02227539 * bf8 * bf1
- 0.01682493 * bf1 * bf9
+ 0.004123235 * bf1 * bf10
- 0.000102163 * bf11 * bf12
bf1 h(temp-58)
bf2 h(194-ibt)
bf3 h(200-vis)
bf4 h(96-doy)
bf5 h(doy-96)
bf6 h(5730-vh)
bf7 h(wind-7)
bf8 h(55-humidity)
bf9 h(dpg-52)
bf10 h(52-dpg)
bf11 h(1105-ibh)
bf12 h(21-dpg)
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
>
> x.global <- cbind(vh,wind,humidity,temp,ibh,dpg,ibt,vis,doy)
> y <- O3
> itest <- itest+1; ozone.test(itest, "O3~., nk=51", x.global, y, degree=2, nk=51)
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
itest 5 O3~., nk=51 degree 2 nk 51 nTerms 25 of 46 GRSq 0.81 GRSq ratio 1.006346
===summary(fite)
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
coefficients
(Intercept) 68.254338
h(temp-58) 0.361808
h(10-dpg) -0.037457
h(dpg-10) -0.043446
h(ibt-281) 0.276811
h(vis-17) -0.293855
h(200-vis) -0.247686
h(vis-200) 0.321231
h(96-doy) -0.111486
h(doy-96) -0.023111
h(5730-vh) * h(temp-58) -0.009559
h(vh-5850) * h(doy-96) 0.000494
h(wind-7) * h(200-vis) -0.012406
h(55-humidity) * h(temp-58) -0.018386
h(humidity-55) * h(temp-58) 0.005696
h(temp-71) * h(1105-ibh) 0.000423
h(temp-58) * h(dpg-52) -0.013575
h(temp-72) * h(doy-96) -0.003615
h(1105-ibh) * h(21-dpg) -0.000100
h(ibt-194) * h(vis-80) 0.014133
h(ibt-194) * h(vis-70) -0.008274
h(ibt-194) * h(vis-100) -0.006492
h(230-ibt) * h(vis-17) -0.000179
h(260-ibt) * h(200-vis) -0.000331
h(ibt-260) * h(200-vis) -0.001086
Selected 25 of 46 terms, and 9 of 9 predictors
Termination condition: Reached nk 51
Importance: temp, ibt, vis, doy, ibh, dpg, humidity, wind, vh
Number of terms at each degree of interaction: 1 9 15
GCV 12.35626 RSS 2709.428 GRSq 0.80806 RSq 0.8716848
===summary(fite, style = "bf")
Call: earth(x=x, y=y, trace=trace, degree=degree, nk=nk)
y =
68.25434
+ 0.3618078 * bf1
- 0.03745668 * bf2
- 0.04344561 * bf3
+ 0.2768106 * bf4
- 0.2938554 * bf5
- 0.2476858 * bf6
+ 0.3212311 * bf7
- 0.1114864 * bf8
- 0.02311108 * bf9
- 0.009559369 * bf10 * bf1
+ 0.0004937219 * bf11 * bf9
- 0.01240617 * bf12 * bf6
- 0.01838558 * bf13 * bf1
+ 0.005696166 * bf14 * bf1
+ 0.0004227812 * bf15 * bf16
- 0.01357508 * bf1 * bf17
- 0.003615445 * bf18 * bf9
- 0.0001000355 * bf16 * bf19
+ 0.01413322 * bf20 * bf21
- 0.008274048 * bf20 * bf22
- 0.006492333 * bf20 * bf23
- 0.0001792429 * bf24 * bf5
- 0.0003309519 * bf25 * bf6
- 0.001086437 * bf26 * bf6
bf1 h(temp-58)
bf2 h(10-dpg)
bf3 h(dpg-10)
bf4 h(ibt-281)
bf5 h(vis-17)
bf6 h(200-vis)
bf7 h(vis-200)
bf8 h(96-doy)
bf9 h(doy-96)
bf10 h(5730-vh)
bf11 h(vh-5850)
bf12 h(wind-7)
bf13 h(55-humidity)
bf14 h(humidity-55)
bf15 h(temp-71)
bf16 h(1105-ibh)
bf17 h(dpg-52)
bf18 h(temp-72)
bf19 h(21-dpg)
bf20 h(ibt-194)
bf21 h(vis-80)
bf22 h(vis-70)
bf23 h(vis-100)
bf24 h(230-ibt)
bf25 h(260-ibt)
bf26 h(ibt-260)
Selected 25 of 46 terms, and 9 of 9 predictors
Termination condition: Reached nk 51
Importance: temp, ibt, vis, doy, ibh, dpg, humidity, wind, vh
Number of terms at each degree of interaction: 1 9 15
GCV 12.35626 RSS 2709.428 GRSq 0.80806 RSq 0.8716848
Converted mars(x=x, y=y, degree=degree, nk=nk)
to earth(x=x, y=y, degree=degree, nk=nk)
Selected 25 of 46 terms, and 9 of 9 predictors
Termination condition: Reached nk 51
Importance: temp, ibt, vis, doy, ibh, dpg, humidity, wind, vh
Number of terms at each degree of interaction: 1 9 15
GCV 12.35626 RSS 2709.428 GRSq 0.80806 RSq 0.8716848
>
> detach(ozone1)
>
> cat("--- fast mars -----------------------------------\n")
--- fast mars -----------------------------------
>
> printh(earth(O3 ~ ., data=ozone1, degree=2, nk = 31, fast.k = 0, fast.beta = 1))
===earth(O3 ~ ., data = ozone1, degree = 2, nk = 31, fast.k = 0, fast.beta = 1)
Selected 15 of 31 terms, and 9 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibt, humidity, doy, dpg, vis, wind, ibh, vh
Number of terms at each degree of interaction: 1 5 9
GCV 13.22659 RSS 3464.405 GRSq 0.7945405 RSq 0.83593
> printh(earth(O3 ~ ., data=ozone1, degree=2, nk = 31, fast.k = 0, fast.beta = 0))
===earth(O3 ~ ., data = ozone1, degree = 2, nk = 31, fast.k = 0, fast.beta = 0)
Selected 15 of 31 terms, and 9 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibt, humidity, doy, dpg, vis, wind, ibh, vh
Number of terms at each degree of interaction: 1 5 9
GCV 13.22659 RSS 3464.405 GRSq 0.7945405 RSq 0.83593
> printh(earth(O3 ~ ., data=ozone1, degree=2, nk = 31, fast.k = 5, fast.beta = 1))
===earth(O3 ~ ., data = ozone1, degree = 2, nk = 31, fast.k = 5, fast.beta = 1)
Selected 11 of 17 terms, and 7 of 9 predictors
Termination condition: RSq changed by less than 0.001 at 17 terms
Importance: humidity, ibt, doy, temp, dpg, ibh, wind, vh-unused, ...
Number of terms at each degree of interaction: 1 8 2
GCV 14.15189 RSS 3963.216 GRSq 0.780167 RSq 0.8123069
> printh(earth(O3 ~ ., data=ozone1, degree=2, nk = 31, fast.k = 5, fast.beta = 0))
===earth(O3 ~ ., data = ozone1, degree = 2, nk = 31, fast.k = 5, fast.beta = 0)
Selected 11 of 17 terms, and 6 of 9 predictors
Termination condition: RSq changed by less than 0.001 at 17 terms
Importance: humidity, ibt, doy, ibh, vis, dpg, temp-unused, vh-unused, ...
Number of terms at each degree of interaction: 1 6 4
GCV 13.89191 RSS 3890.408 GRSq 0.7842055 RSq 0.815755
>
> cat("--- plot.earth and plot.earth.models ------------\n")
--- plot.earth and plot.earth.models ------------
>
> a <- earth(O3 ~ ., data=ozone1) # formula interface
>
> if (PLOT)
+ plot(a, caption="plot.earth test 1", col.rsq=3, smooth.col=4, qqline.col="pink",
+ col.vline=1, col.npreds=0, nresiduals=100, cum.grid="grid",
+ grid.col="lightblue", col.sel.grid="lightgreen")
>
> set.seed(1)
> if (PLOT) {
+ plot(a, caption="plot.earth test 2", which=c(3,4,1), ylim=c(.2,.9),
+ id.n=20, legend.pos=c(10,.6), pch=20, lty.vline=1, cex.legend=1,
+ grid.col="lightblue")
+
+ plot(a, caption="plot.earth test 3", which=2, main="test main")
+ }
>
> a1 <- earth(ozone1[,c(2:4,10)], ozone1[,1]) # x,y interface
>
> if (PLOT) {
+ plot(a, caption="plot.earth test 4", id.n=1)
+ set.seed(1)
+ plot.earth.models(a, which=1, ylim=c(.4,.8), jitter=.01)
+
+ plot.earth.models(a1)
+
+ plot.earth.models(list(a, a1), col.cum=c(3,4), col.grsq=c(1,2), col.rsq=c(3,4),
+ col.npreds=1, col.vline=1, lty.vline=3,
+ legend.pos=c(5,.4), legend.text=c("a", "b", "c"), cex.legend=1.3)
+ }
>
> cat("--- plot.earth args -----------------------------\n")
--- plot.earth args -----------------------------
>
> test.plot.earth.args <- function()
+ {
+ caption <- "test earth args"
+ printh(caption)
+
+ argtest <- earth(ozone1[,c(2:4,10)], ozone1[,1])
+
+ old.par <- par(no.readonly=TRUE)
+ on.exit(par(old.par))
+ par(mfrow=c(2,3))
+ par(cex = 0.8)
+ par(mar = c(3, 3, 3, 0.5)) # small margins and text to pack figs in
+ par(mgp = c(1.6, 0.6, 0)) # flatten axis elements
+ oma <- par("oma") # make space for caption
+ oma[3] <- 2.4
+ par(oma=oma)
+ par(cex.main=1)
+
+ plot(argtest, do.par=FALSE, which=1,
+ main="default")
+
+ mtext(caption, outer=TRUE, font=2)
+
+ plot(argtest, do.par=FALSE, which=1,
+ col.rsq=3, col.grsq=2,
+ col.npreds="blue", grid.col="lightblue",
+ main=sprint("%s\n%s",
+ "col.rsq=3, col.grsq=2, ",
+ "col.npreds=\"lightblue\", col.sel.grid=\"gray\""))
+
+ plot(argtest, do.par=FALSE, which=1,
+ col.vline="pink", legend.pos="topleft",
+ lty.grsq=2, lty.npreds=1, lty.vline=1,
+ main=sprint("%s\n%s",
+ "col.vline=\"pink\", legend.pos=\"topleft\", ",
+ "lty.grsq=2, lty.npreds=1, lty.vline=1"))
+
+ plot(argtest, do.par=FALSE, which=1,
+ legend.pos=NA, col.npreds=0,
+ main="legend.pos=NA, col.npreds=0")
+
+ plot(argtest, do.par=FALSE, which=1,
+ legend.pos=0,
+ main="legend.pos=0")
+ }
> test.plot.earth.args()
===caption [1] "test earth args"
>
> cat("--- test minspan --------------------------------\n")
--- test minspan --------------------------------
>
> a.minspan2 <- earth(O3 ~ ., data=ozone1, minspan=2)
> printh(summary(a.minspan2))
===summary(a.minspan2)
Call: earth(formula=O3~., data=ozone1, minspan=2)
coefficients
(Intercept) 37.206815
h(5740-vh) -0.020094
h(54-humidity) -0.130146
h(temp-58) 0.322610
h(1046-ibh) -0.003655
h(dpg-12) -0.092232
h(ibt-120) 0.038616
h(vis-17) -0.372533
h(80-vis) -0.319300
h(vis-80) 0.365130
h(89-doy) -0.144947
h(doy-159) -0.032265
Selected 12 of 19 terms, and 8 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, vh, humidity, dpg, doy, ibh, vis, ibt, wind-unused
Number of terms at each degree of interaction: 1 11 (additive model)
GCV 14.47406 RSS 4133.834 GRSq 0.7751625 RSq 0.8042266
>
> a.minspan0 <- earth(O3 ~ ., data=ozone1, minspan=0)
> printh(summary(a.minspan0))
===summary(a.minspan0)
Call: earth(formula=O3~., data=ozone1, minspan=0)
coefficients
(Intercept) 14.1595171
h(5860-vh) -0.0137728
h(wind-3) -0.3377222
h(54-humidity) -0.1349547
h(temp-58) 0.2791320
h(1105-ibh) -0.0033837
h(dpg-10) -0.0991581
h(ibt-120) 0.0326330
h(150-vis) 0.0231881
h(96-doy) -0.1105145
h(doy-96) 0.0406468
h(doy-158) -0.0836732
Selected 12 of 20 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, dpg, doy, vh, ibh, vis, ibt, wind
Number of terms at each degree of interaction: 1 11 (additive model)
GCV 14.61004 RSS 4172.671 GRSq 0.7730502 RSq 0.8023874
>
> a.minspan.minus1 <- earth(O3 ~ ., data=ozone1, minspan=-1)
> printh(summary(a.minspan.minus1))
===summary(a.minspan.minus1)
Call: earth(formula=O3~., data=ozone1, minspan=-1)
coefficients
(Intercept) 14.8317540
ibh 0.0035879
h(5760-vh) -0.0131360
h(64-humidity) -0.0630395
h(temp-62) 0.3670405
h(ibh-823) -0.0043888
h(dpg-24) -0.1188100
h(120-vis) 0.0359176
h(206-doy) -0.0486385
h(doy-206) -0.0585411
Selected 10 of 19 terms, and 7 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, ibh, humidity, dpg, vis, doy, vh, wind-unused, ...
Number of terms at each degree of interaction: 1 9 (additive model)
GCV 16.16163 RSS 4736.877 GRSq 0.748948 RSq 0.7756673
>
> a.minspan.minus3 <- earth(O3 ~ ., data=ozone1, minspan=-3)
> printh(summary(a.minspan.minus3))
===summary(a.minspan.minus3)
Call: earth(formula=O3~., data=ozone1, minspan=-3)
coefficients
(Intercept) 13.5336798
h(5690-vh) -0.0169026
h(vh-5690) 0.0155040
h(wind-3) -0.2790195
h(64-humidity) -0.0997117
h(temp-62) 0.5474683
h(temp-72) -0.3244650
h(dpg-24) -0.1084691
h(ibt-107) 0.0171885
h(150-vis) 0.0232805
h(119-doy) -0.1064486
h(doy-119) -0.0334354
Selected 12 of 20 terms, and 8 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, dpg, vis, doy, vh, humidity, ibh-unused, wind, ibt
Number of terms at each degree of interaction: 1 11 (additive model)
GCV 14.82868 RSS 4235.117 GRSq 0.7696538 RSq 0.79943
>
> a.endspan80 <- earth(O3 ~ ., data=ozone1, endspan=80)
> printh(summary(a.endspan80))
===summary(a.endspan80)
Call: earth(formula=O3~., data=ozone1, endspan=80)
coefficients
(Intercept) 14.7832332
h(5770-vh) -0.0160418
h(wind-3) -0.3028539
h(55-humidity) -0.1303358
h(temp-58) 0.3179697
h(1046-ibh) -0.0041830
h(dpg-10) -0.0933000
h(ibt-121) 0.0371643
h(150-vis) 0.0223985
h(118-doy) -0.0989561
h(doy-147) -0.0367509
Selected 11 of 20 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, doy, humidity, dpg, ibh, vh, vis, ibt, wind
Number of terms at each degree of interaction: 1 10 (additive model)
GCV 14.31885 RSS 4142.964 GRSq 0.7775735 RSq 0.8037943
>
> cat("--- test multiple responses ---------------------\n")
--- test multiple responses ---------------------
>
> # this uses the global matrix data.global (data.global[,1:2] is the response)
>
> test.two.responses <- function(itest, func1, func2,
+ degree=2, nk=51, plotit=PLOT, test.rsq=TRUE, trace=0, minspan=0,
+ test.mars.to.earth=FALSE, pmethod="backward")
+ {
+ if(typeof(func1) == "character")
+ funcnames <- paste("multiple responses", func1, func2)
+ else
+ funcnames <- paste("multiple responses", deparse(substitute(func1)), deparse(substitute(func2)))
+ cat("itest", sprint("%-3d", itest), funcnames,
+ " degree", sprint("%-2d", degree), "nk", sprint("%-3g", nk), "\n\n")
+ gc()
+ fite <- earth(x=data.global[,c(-1,-2), drop=FALSE], y=data.global[,1:2],
+ degree=degree, trace=trace, nk=nk, pmethod=pmethod, minspan=minspan)
+ printh(fite)
+ caption <- paste("itest ", itest, ": ", funcnames, " degree=", degree, " nk=", nk, sep="")
+ if(plotit) {
+ if(typeof(func1) == "character") {
+ plotmo(fite, caption=caption, nresponse=1, trace=-1)
+ plotmo(fite, nresponse=2, trace=-1)
+ } else {
+ plotmo(fite, func=func1, caption=caption, nresponse=1)
+ plotmo(fite, func=func2, nresponse=2)
+ }
+ plot(fite, caption=caption, nresponse=1)
+ plot(fite, nresponse=2)
+ }
+ cat("\n")
+ if(test.mars.to.earth) {
+ cat("Testing mars.to.earth with a multiple response model\n")
+ fitm <- mars(data.global[,c(-1,-2), drop=FALSE], data.global[,1:2],
+ degree=degree, trace=(trace!=0), nk=nk)
+ fitme <- mars.to.earth(fitm)
+ printh(fitme)
+ printh(summary(fitme))
+ if(plotit) {
+ plotmo(fitm, func=func1, caption=caption, nresponse=1, clip=FALSE)
+ plotmo(fitm, func=func2, nresponse=2, clip=FALSE)
+ }
+ # TODO following code causes error "nk" not found, looking in wrong environment?
+ # cat("Expect warnings because of weights in the mars model\n")
+ # fitm <- mars(data.global[,c(-1,-2), drop=FALSE], data.global[,1:2],
+ # degree=degree, trace=(trace!=0), nk=nk, wp=c(1,2))
+ # fitme <- mars.to.earth(fitm)
+ # printh(fitme)
+ # printh(summary(fitme))
+ }
+ fite
+ }
>
> N <- 100
> set.seed(1)
> x1 <- runif(N, -1, 1)
> x2 <- runif(N, -1, 1)
> x3 <- runif(N, -1, 1)
> x4 <- runif(N, -1, 1)
> x5 <- runif(N, -1, 1)
>
> func1 <- function(x)
+ {
+ sin(3 * x[,1]) + x[,2]
+ }
> func7 <- function(x) # just one predictor
+ {
+ sin(5 * x[,1])
+ }
> x.global <- cbind( x1, x2)
> data.global <- cbind(func1(x.global), func7(x.global), x1, x2)
> colnames(data.global) = c("func1", "func7", "x1", "x2")
> # expect pmethod="ex" cannot be used with multiple response models
> expect.err(try(test.two.responses(itest, func1, func7, nk=51, degree=1, pmethod="ex")), "not allowed with multiple response models")
itest 5 multiple responses func1 func7 degree 1 nk 51
Error : pmethod="exhaustive" is not allowed with multiple response models
(y has 2 columns, use trace=4 to see y)
Got error as expected from try(test.two.responses(itest, func1, func7, nk = 51, degree = 1, pmethod = "ex"))
> # expect pmethod="seq" cannot be used with multiple response models
> expect.err(try(test.two.responses(itest, func1, func7, nk=51, degree=1, pmethod="seq")), "not allowed with multiple response models")
itest 5 multiple responses func1 func7 degree 1 nk 51
Error : pmethod="seqrep" is not allowed with multiple response models
(y has 2 columns, use trace=4 to see y)
Got error as expected from try(test.two.responses(itest, func1, func7, nk = 51, degree = 1, pmethod = "seq"))
> itest <- itest+1; a <- test.two.responses(itest, func1, func7, nk=51, degree=1)
itest 6 multiple responses func1 func7 degree 1 nk 51
===fite
Selected 9 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1, x2
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS GRSq RSq
func1 0.002626520 0.1809409 0.9969000 0.9978211
func7 0.007889046 0.5434764 0.9846251 0.9891931
All 0.010515566 0.7244173 0.9922701 0.9945668
plotmo grid: x1 x2
-0.02437858 0.03719751
plotmo grid: x1 x2
-0.02437858 0.03719751
> printh(summary(a))
===summary(a)
Call: earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
pmethod=pmethod, trace=trace, degree=degree, nk=nk,
minspan=minspan)
func1 func7
(Intercept) -1.4159357 -0.6824246
h(-0.468983-x1) 1.4219106 3.9942993
h(x1- -0.468983) 1.8463556 -1.4788784
h(x1- -0.235224) 0.9882662 5.9409061
h(x1-0.209867) -0.8510911 -4.4376027
h(x1-0.425029) -2.5321006 -4.8071373
h(x1-0.739382) -2.1198279 2.4557576
h(-0.329025-x2) -1.0346040 -0.0308457
h(x2- -0.329025) 0.9870580 -0.0232994
Selected 9 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1, x2
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS GRSq RSq
func1 0.002626520 0.1809409 0.9969000 0.9978211
func7 0.007889046 0.5434764 0.9846251 0.9891931
All 0.010515566 0.7244173 0.9922701 0.9945668
> printh(summary(a, style="bf"))
===summary(a, style = "bf")
Call: earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
pmethod=pmethod, trace=trace, degree=degree, nk=nk,
minspan=minspan)
func1 =
-1.415936
+ 1.421911 * bf1
+ 1.846356 * bf2
+ 0.9882662 * bf3
- 0.8510911 * bf4
- 2.532101 * bf5
- 2.119828 * bf6
- 1.034604 * bf7
+ 0.987058 * bf8
bf1 h(-0.468983-x1)
bf2 h(x1--0.468983)
bf3 h(x1--0.235224)
bf4 h(x1-0.209867)
bf5 h(x1-0.425029)
bf6 h(x1-0.739382)
bf7 h(-0.329025-x2)
bf8 h(x2--0.329025)
func7 =
-0.6824246
+ 3.994299 * bf1
- 1.478878 * bf2
+ 5.940906 * bf3
- 4.437603 * bf4
- 4.807137 * bf5
+ 2.455758 * bf6
- 0.03084575 * bf7
- 0.02329942 * bf8
bf1 h(-0.468983-x1)
bf2 h(x1--0.468983)
bf3 h(x1--0.235224)
bf4 h(x1-0.209867)
bf5 h(x1-0.425029)
bf6 h(x1-0.739382)
bf7 h(-0.329025-x2)
bf8 h(x2--0.329025)
Selected 9 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1, x2
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS GRSq RSq
func1 0.002626520 0.1809409 0.9969000 0.9978211
func7 0.007889046 0.5434764 0.9846251 0.9891931
All 0.010515566 0.7244173 0.9922701 0.9945668
> if (PLOT) {
+ plotmo(a, nresponse=1, trace=-1) # test generation of caption based on response name
+ plotmo(a, nresponse=2, trace=-1)
+ plot(a, nresponse=1)
+ plot(a, nresponse=2)
+ }
> x.global <- cbind( x1, x2)
> data.global <- cbind(func1(x.global), func7(x.global), x1, x2)
> colnames(data.global) = c("func1",
+ "a.very.long.in.fact.extremely.long.response.name",
+ "x1.a.very.long.in.fact.extremely.long.predictor.name",
+ "x2")
> itest <- itest+1; a <- test.two.responses(itest, func1, func7, nk=51, degree=3)
itest 7 multiple responses func1 func7 degree 3 nk 51
===fite
Selected 9 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1.a.very.long.in.fact.extremely.long.predictor.name, x2
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS
func1 0.002899230 0.1809409
a.very.long.in.fact.extremely.long.response.name 0.008708162 0.5434764
All 0.011607392 0.7244173
GRSq RSq
func1 0.9965782 0.9978211
a.very.long.in.fact.extremely.long.response.name 0.9830287 0.9891931
All 0.9914675 0.9945668
plotmo grid: x1.a.very.long.in.fact.extremely.long.predictor.name
-0.02437858
x2
0.03719751
plotmo grid: x1.a.very.long.in.fact.extremely.long.predictor.name
-0.02437858
x2
0.03719751
> printh(summary(a))
===summary(a)
Call: earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
pmethod=pmethod, trace=trace, degree=degree, nk=nk,
minspan=minspan)
func1
(Intercept) -1.4159357
h(-0.468983-x1.a.very.long.in.fact.extremely.long.predictor.name) 1.4219106
h(x1.a.very.long.in.fact.extremely.long.predictor.name- -0.468983) 1.8463556
h(x1.a.very.long.in.fact.extremely.long.predictor.name- -0.235224) 0.9882662
h(x1.a.very.long.in.fact.extremely.long.predictor.name-0.209867) -0.8510911
h(x1.a.very.long.in.fact.extremely.long.predictor.name-0.425029) -2.5321006
h(x1.a.very.long.in.fact.extremely.long.predictor.name-0.739382) -2.1198279
h(-0.329025-x2) -1.0346040
h(x2- -0.329025) 0.9870580
a.very.long.in.fact.extremely.long.response.name
(Intercept) -0.6824246
h(-0.468983-x1.a.very.long.in.fact.extremely.long.predictor.name) 3.9942993
h(x1.a.very.long.in.fact.extremely.long.predictor.name- -0.468983) -1.4788784
h(x1.a.very.long.in.fact.extremely.long.predictor.name- -0.235224) 5.9409061
h(x1.a.very.long.in.fact.extremely.long.predictor.name-0.209867) -4.4376027
h(x1.a.very.long.in.fact.extremely.long.predictor.name-0.425029) -4.8071373
h(x1.a.very.long.in.fact.extremely.long.predictor.name-0.739382) 2.4557576
h(-0.329025-x2) -0.0308457
h(x2- -0.329025) -0.0232994
Selected 9 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1.a.very.long.in.fact.extremely.long.predictor.name, x2
Number of terms at each degree of interaction: 1 8 (additive model)
GCV RSS
func1 0.002899230 0.1809409
a.very.long.in.fact.extremely.long.response.name 0.008708162 0.5434764
All 0.011607392 0.7244173
GRSq RSq
func1 0.9965782 0.9978211
a.very.long.in.fact.extremely.long.response.name 0.9830287 0.9891931
All 0.9914675 0.9945668
> print(evimp(a))
nsubsets gcv rss
x1.a.very.long.in.fact.extremely.long.predictor.name 8 100.0 100.0
x2 6 65.6 62.4
> print.default(evimp(a))
col used nsubsets
x1.a.very.long.in.fact.extremely.long.predictor.name 1 1 8
x2 2 1 6
gcv gcv.match
x1.a.very.long.in.fact.extremely.long.predictor.name 100.00000 1
x2 65.60412 1
rss rss.match
x1.a.very.long.in.fact.extremely.long.predictor.name 100.00000 1
x2 62.37599 1
attr(,"class")
[1] "evimp"
attr(,"sqrt")
[1] TRUE
>
> eqn56 <- function(x) # Friedman MARS paper equation 56
+ {
+ 0.1 * exp(4*x[,1]) +
+ 4 / (1 + exp(-20*(x[,2]-0.5))) +
+ 3 * x[,3] +
+ 2 * x[,4] +
+ x[,5]
+ }
> neg.eqn56 <- function(x)
+ {
+ -eqn56(x)
+ }
>
> eqn56noise <- function(x)
+ {
+ set.seed(ncol(x))
+ eqn56(x) + rnorm(nrow(x),0,1)
+ }
>
> neg.eqn56noise <- function(x)
+ {
+ -eqn56noise(x)
+ }
>
> robot.arm <- function(x) # Friedman Fast MARS paper
+ {
+ l1 <- x[,1]
+ l2 <- x[,2]
+ theta1 <- x[,3]
+ theta2 <- x[,4]
+ phi <- x[,5]
+
+ x1 <- l1 * cos(theta1) - l2 * cos(theta1 + theta2) * cos(phi)
+ y <- l1 * sin(theta1) - l2 * sin(theta1 + theta2) * cos(phi)
+ z <- l2 * sin(theta2) * sin(phi)
+
+ sqrt(x1^2 + y^2 + z^2)
+ }
> x.global <- cbind( x1, x2, x3, x4, x5)
> data.global <- cbind(eqn56=eqn56(x.global), neg.eqn56noise(x.global), x1, x2, x3, x4, x5)
> colnames(data.global) = c("", "neg.eqn56noise", "x1", "x2", "x3", "x4", "x5")
> itest <- itest+1; a <- test.two.responses(itest, eqn56, neg.eqn56noise, nk=51, degree=1)
itest 8 multiple responses eqn56 neg.eqn56noise degree 1 nk 51
===fite
Selected 12 of 22 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 22 terms
Importance: x3, x2, x4, x1, x5
Number of terms at each degree of interaction: 1 11 (additive model)
GCV RSS GRSq RSq
data.global[,1:2][1] 0.1186568 7.035159 0.9859153 0.9914796
neg.eqn56noise 1.0576805 62.709877 0.8846994 0.9302502
All 1.1763373 69.745036 0.9331542 0.9595624
plotmo grid: x1 x2 x3 x4 x5
-0.02437858 0.03719751 -0.2437968 -0.07448578 -0.04164241
plotmo grid: x1 x2 x3 x4 x5
-0.02437858 0.03719751 -0.2437968 -0.07448578 -0.04164241
> print(evimp(a))
nsubsets gcv rss
x3 11 100.0 100.0
x2 10 82.5 81.2
x4 9 59.0 57.8
x1 8 48.0 46.6
x5 6 33.7 32.2
> print.default(evimp(a))
col used nsubsets gcv gcv.match rss rss.match
x3 3 1 11 100.00000 1 100.00000 1
x2 2 1 10 82.46294 1 81.21481 1
x4 4 1 9 58.98392 1 57.75405 1
x1 1 1 8 47.99407 1 46.58408 1
x5 5 1 6 33.69458 1 32.15406 1
attr(,"class")
[1] "evimp"
attr(,"sqrt")
[1] TRUE
>
> x.global <- cbind( x1, x2, x3, x4, x5)
> data.global <- cbind(eqn56=eqn56(x.global), neg.eqn56noise(x.global), x1, x2, x3, x4, x5)
> colnames(data.global) = NULL
> itest <- itest+1; a70 <- test.two.responses(itest, eqn56, neg.eqn56noise, nk=51, degree=2)
itest 9 multiple responses eqn56 neg.eqn56noise degree 2 nk 51
===fite
Selected 11 of 36 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 36 terms
Importance: x3, x2, x4, x1, x5
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
data.global[,1:2][1] 0.1491246 8.166063 0.9822988 0.9901100
data.global[,1:2][2] 1.2644713 69.242451 0.8621565 0.9229843
All 1.4135959 77.408514 0.9196719 0.9551192
plotmo grid: x1 x2 x3 x4 x5
-0.02437858 0.03719751 -0.2437968 -0.07448578 -0.04164241
plotmo grid: x1 x2 x3 x4 x5
-0.02437858 0.03719751 -0.2437968 -0.07448578 -0.04164241
> printh(summary(a70))
===summary(a70)
Call: earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
pmethod=pmethod, trace=trace, degree=degree, nk=nk,
minspan=minspan)
data.global[,1:2][1] data.global[,1:2][2]
(Intercept) 0.2818910 -0.199523
h(0.565866-x1) -0.5573832 0.701461
h(x1-0.565866) 8.6735609 -6.756016
h(x2-0.266987) 5.6617262 -3.485078
h(x2-0.458619) 24.7167189 -41.977152
h(x2-0.516206) -26.6087010 42.046569
h(x3-0.109801) 2.5861859 -2.829496
h(0.26284-x3) -2.9626317 2.501109
h(-0.303396-x4) -3.1086768 3.484234
h(x4-0.124354) 2.6383691 -2.972662
h(x5- -0.859935) 0.9423879 -0.854188
Selected 11 of 36 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 36 terms
Importance: x3, x2, x4, x1, x5
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
data.global[,1:2][1] 0.1491246 8.166063 0.9822988 0.9901100
data.global[,1:2][2] 1.2644713 69.242451 0.8621565 0.9229843
All 1.4135959 77.408514 0.9196719 0.9551192
> printh(summary(a70, style="bf"))
===summary(a70, style = "bf")
Call: earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
pmethod=pmethod, trace=trace, degree=degree, nk=nk,
minspan=minspan)
data.global[,1:2][1] =
0.281891
- 0.5573832 * bf1
+ 8.673561 * bf2
+ 5.661726 * bf3
+ 24.71672 * bf4
- 26.6087 * bf5
+ 2.586186 * bf6
- 2.962632 * bf7
- 3.108677 * bf8
+ 2.638369 * bf9
+ 0.9423879 * bf10
bf1 h(0.565866-x1)
bf2 h(x1-0.565866)
bf3 h(x2-0.266987)
bf4 h(x2-0.458619)
bf5 h(x2-0.516206)
bf6 h(x3-0.109801)
bf7 h(0.26284-x3)
bf8 h(-0.303396-x4)
bf9 h(x4-0.124354)
bf10 h(x5--0.859935)
data.global[,1:2][2] =
-0.1995226
+ 0.7014611 * bf1
- 6.756016 * bf2
- 3.485078 * bf3
- 41.97715 * bf4
+ 42.04657 * bf5
- 2.829496 * bf6
+ 2.501109 * bf7
+ 3.484234 * bf8
- 2.972662 * bf9
- 0.8541879 * bf10
bf1 h(0.565866-x1)
bf2 h(x1-0.565866)
bf3 h(x2-0.266987)
bf4 h(x2-0.458619)
bf5 h(x2-0.516206)
bf6 h(x3-0.109801)
bf7 h(0.26284-x3)
bf8 h(-0.303396-x4)
bf9 h(x4-0.124354)
bf10 h(x5--0.859935)
Selected 11 of 36 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 36 terms
Importance: x3, x2, x4, x1, x5
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
data.global[,1:2][1] 0.1491246 8.166063 0.9822988 0.9901100
data.global[,1:2][2] 1.2644713 69.242451 0.8621565 0.9229843
All 1.4135959 77.408514 0.9196719 0.9551192
>
> N1 <- 100
> set.seed(1)
> x1. <- runif(N1, -1, 1)
> x2. <- runif(N1, -1, 1)
> x3. <- runif(N1, -1, 1)
> x4. <- runif(N1, -1, 1)
> x5. <- runif(N1, -1, 1)
>
> x.global <- cbind( (x1.+1)/2, (x2.+2)/2, pi*(x3.+1), pi*(x4.+1), pi*x5./2 )
> data.global <- cbind(robot.arm(x.global), eqn56(x.global), (x1.+1)/2, (x2.+2)/2, pi*(x3.+1), pi*(x4.+1), pi*x5./2 )
> colnames(x.global) <- c( "l1", "l2", "theta1", "theta2", "phi")
> colnames(data.global) <- c("arm", "eqn56", "l1", "l2", "theta1", "theta2", "phi")
> itest <- itest+1; test.two.responses(itest, robot.arm, eqn56, nk=51, degree=1)
itest 10 multiple responses robot.arm eqn56 degree 1 nk 51
===fite
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.06212730 3.877365 0.6674660 0.7882518
eqn56 0.04559835 2.845793 0.9990475 0.9993935
All 0.10772566 6.723158 0.9977586 0.9985727
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.06212730 3.877365 0.6674660 0.7882518
eqn56 0.04559835 2.845793 0.9990475 0.9993935
All 0.10772566 6.723158 0.9977586 0.9985727
> itest <- itest+1; test.two.responses(itest, robot.arm, eqn56, nk=51, degree=2, test.mars.to.earth=TRUE)
itest 11 multiple responses robot.arm eqn56 degree 2 nk 51
===fite
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.07080652 3.877365 0.6210109 0.7882518
eqn56 0.05196847 2.845793 0.9989145 0.9993935
All 0.12277499 6.723158 0.9974454 0.9985727
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
Testing mars.to.earth with a multiple response model
Converted mars(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
degree=degree, nk=nk, trace.mars=(trace!=0))
to earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
degree=degree, nk=nk)
===fitme
Selected 14 of 14 terms, and 5 of 5 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 11 2
GCV RSS GRSq RSq
arm 0.06354264 2.810014 0.6598905 0.8465412
eqn56 0.02822229 1.248060 0.9994105 0.9997340
All 0.09176492 4.058074 0.9997770 0.9998994
===summary(fitme)
Call: earth(x=data.global[,c(-1,-2),drop=FALSE], y=data.global[,1:2],
degree=degree, nk=nk)
arm eqn56
(Intercept) 1.21455366 17.9497354
h(l1-0.48208) 0.74838045 3.1350878
h(0.712515-l1) -0.29309259 -1.2345462
h(l1-0.712515) 0.45693753 8.6324286
h(0.689194-l2) -0.56638468 -6.5226645
h(l2-0.689194) 0.80658229 0.0048442
h(2.05469-theta1) 0.04949653 -2.9820177
h(theta1-2.05469) 0.01153761 3.0259557
h(3.53226-theta2) -0.14968401 -1.9869680
h(theta2-3.53226) -0.26441106 2.0236977
h(-0.0748075-phi) -0.14373035 -0.9622197
h(phi- -0.0748075) -0.22638721 0.9964946
h(0.48208-l1) -0.18021728 -0.0612455
h(l1-0.48208) * h(theta2-1.51306) -2.04353916 -0.4060211
Selected 14 of 14 terms, and 5 of 5 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 11 2
GCV RSS GRSq RSq
arm 0.06354264 2.810014 0.6598905 0.8465412
eqn56 0.02822229 1.248060 0.9994105 0.9997340
All 0.09176492 4.058074 0.9997770 0.9998994
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.07080652 3.877365 0.6210109 0.7882518
eqn56 0.05196847 2.845793 0.9989145 0.9993935
All 0.12277499 6.723158 0.9974454 0.9985727
> itest <- itest+1; test.two.responses(itest, robot.arm, eqn56, nk=201, degree=1)
itest 12 multiple responses robot.arm eqn56 degree 1 nk 201
===fite
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.06212730 3.877365 0.6674660 0.7882518
eqn56 0.04559835 2.845793 0.9990475 0.9993935
All 0.10772566 6.723158 0.9977586 0.9985727
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.06212730 3.877365 0.6674660 0.7882518
eqn56 0.04559835 2.845793 0.9990475 0.9993935
All 0.10772566 6.723158 0.9977586 0.9985727
> itest <- itest+1; test.two.responses(itest, robot.arm, eqn56, nk=201, degree=2)
itest 13 multiple responses robot.arm eqn56 degree 2 nk 201
===fite
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.07080652 3.877365 0.6210109 0.7882518
eqn56 0.05196847 2.845793 0.9989145 0.9993935
All 0.12277499 6.723158 0.9974454 0.9985727
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.07080652 3.877365 0.6210109 0.7882518
eqn56 0.05196847 2.845793 0.9989145 0.9993935
All 0.12277499 6.723158 0.9974454 0.9985727
> itest <- itest+1; test.two.responses(itest, robot.arm, eqn56, nk=201, degree=10)
itest 14 multiple responses robot.arm eqn56 degree 10 nk 201
===fite
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.07080652 3.877365 0.6210109 0.7882518
eqn56 0.05196847 2.845793 0.9989145 0.9993935
All 0.12277499 6.723158 0.9974454 0.9985727
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
plotmo grid: l1 l2 theta1 theta2 phi
0.4878107 1.018599 2.375682 2.907589 -0.06541174
Selected 11 of 11 terms, and 5 of 5 predictors
Termination condition: RSq changed by less than 0.001 at 11 terms
Importance: theta1, theta2, l1, phi, l2
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
arm 0.07080652 3.877365 0.6210109 0.7882518
eqn56 0.05196847 2.845793 0.9989145 0.9993935
All 0.12277499 6.723158 0.9974454 0.9985727
>
> attach(ozone1)
> x.global <- cbind( wind, humidity, temp, ibh, dpg, ibt, vis)
> data.global <- cbind(O3, doy, vh, wind, humidity, temp, ibh, dpg, ibt, vis)
> itest <- itest+1; test.two.responses(itest, "O3", "doy", nk=51, degree=2)
itest 15 multiple responses O3 doy degree 2 nk 51
===fite
Selected 13 of 47 terms, and 8 of 8 predictors
Termination condition: Reached nk 51
Importance: wind, vh, ibh, temp, dpg, vis, humidity, ibt
Number of terms at each degree of interaction: 1 5 7
GCV RSS GRSq RSq
O3 22.9046 6205.13 0.6442040 0.7061325
doy 6853.8813 1856799.52 0.3727883 0.4819583
All 6876.7859 1863004.66 0.3743779 0.4832712
Selected 13 of 47 terms, and 8 of 8 predictors
Termination condition: Reached nk 51
Importance: wind, vh, ibh, temp, dpg, vis, humidity, ibt
Number of terms at each degree of interaction: 1 5 7
GCV RSS GRSq RSq
O3 22.9046 6205.13 0.6442040 0.7061325
doy 6853.8813 1856799.52 0.3727883 0.4819583
All 6876.7859 1863004.66 0.3743779 0.4832712
> detach(ozone1)
>
> cat("--- formula based multiple response -------------\n")
--- formula based multiple response -------------
>
> a2 <- earth(cbind(O3,doy) ~ ., data=ozone1, degree=2)
> if (PLOT) {
+ plotmo(a2, nresponse=1, trace=-1) # TODO1 delete
+ plotmo(a2, nresponse=1, trace=-1) # test generation of caption based on response name
+ plotmo(a2, nresponse=2, trace=-1)
+ plot(a2, nresponse=1) # TODO delete
+ plot(a2, nresponse=1)
+ plot(a2, nresponse=2)
+ }
>
> cat("--- test plot.earth.models with multiple responses ---\n")
--- test plot.earth.models with multiple responses ---
>
> set.seed(1)
> a <- earth(O3 ~ ., data=ozone1, degree=2)
> a2 <- earth(cbind(O3,doy) ~ ., data=ozone1, degree=2)
> b2 <- earth(cbind(O3,doy) ~ ., data=ozone1, degree=1)
> if (PLOT) {
+ plot.earth.models(list(a, a2), caption="plot.earth.models with multiple responses, list(a,a2)")
+ plot.earth.models(list(a2, a), caption="plot.earth.models with multiple responses, list(a2,a)",
+ col.rsq=c(2,3), col.npreds=c(2,3))
+ plot.earth.models(list(a2, b2), caption="plot.earth.models with multiple responses, list(a2,b2)",
+ col.rsq=c(2,3), col.npreds=c(4,5), jitter=.01, legend.pos="topleft")
+ }
>
> cat("--- subset --------------------------------------\n")
--- subset --------------------------------------
>
> set.seed(9)
> train.subset <- sample(1:nrow(ozone1), .8 * nrow(ozone1))
> test.subset <- (1:nrow(ozone1))[-train.subset]
>
> # all the following models should be identical
> a <- earth(ozone1[,-1], ozone1[,1], subset=train.subset, nprune=7, degree=2)
> printh(a)
===a
Selected 7 of 21 terms, and 4 of 9 predictors
Termination condition: Reached nk 21
Importance: humidity, ibt, doy, temp, vh-unused, wind-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 5 1
GCV 15.60427 RSS 3635.322 GRSq 0.7561022 RSq 0.7831299
> if (PLOT)
+ plotmo(a, caption="test subset: earth(ozone1[,-1], ozone1[,1], subset=train.subset)", trace=-1)
>
> a <- earth(ozone1[train.subset,-1], ozone1[train.subset,1], nprune=7, degree=2)
> printh(a)
===a
Selected 7 of 21 terms, and 4 of 9 predictors
Termination condition: Reached nk 21
Importance: humidity, ibt, doy, temp, vh-unused, wind-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 5 1
GCV 15.60427 RSS 3635.322 GRSq 0.7561022 RSq 0.7831299
> if (PLOT)
+ plotmo(a, caption="test subset: earth(ozone1[train.subset,-1], ozone1[train.subset,1]", trace=-1)
>
> a <- earth(O3 ~ ., data=ozone1, subset=train.subset, nprune=7, degree=2)
> printh(a)
===a
Selected 7 of 21 terms, and 4 of 9 predictors
Termination condition: Reached nk 21
Importance: humidity, ibt, doy, temp, vh-unused, wind-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 5 1
GCV 15.60427 RSS 3635.322 GRSq 0.7561022 RSq 0.7831299
> if (PLOT)
+ plotmo(a, caption="test subset: earth(O3 ~ ., data=ozone1, subset=train.subset", trace=-1)
>
> y <- ozone1[test.subset, 1]
> yhat <- predict(a, newdata = ozone1[test.subset, -1])
> printh(1 - sum((y - yhat)^2)/sum((y - mean(y))^2)) # print RSquared
===1 - sum((y - yhat)^2)/sum((y - mean(y))^2) [1] 0.7931236
>
> cat("--- update -------------------------\n")
--- update -------------------------
>
> a <- earth(O3 ~ ., data=ozone1, degree=2)
> printh(update(a, penalty = -1, ponly=TRUE))
===update(a, penalty = -1, ponly = TRUE)
Selected 21 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 10 10
GCV 10.85657 RSS 3582.667 GRSq 0.8303292 RSq 0.8303292
> printh(update(a, penalty = 10, ponly=TRUE))
===update(a, penalty = 10, ponly = TRUE)
Selected 11 of 21 terms, and 8 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh-unused
Number of terms at each degree of interaction: 1 5 5
GCV 17.30867 RSS 3795.372 GRSq 0.7311301 RSq 0.8202558
> a <- earth(O3 ~ ., data=ozone1, nk=31, pmethod="n", degree=2)
> a.none <- printh(update(a, nprune=10, pmethod="n"))
===update(a, nprune = 10, pmethod = "n")
Selected 10 of 31 terms, and 5 of 9 predictors (pmethod="none")
Termination condition: Reached nk 31
Importance: temp, ibt-unused, humidity, doy, dpg, vis-unused, wind-unused, ...
Number of terms at each degree of interaction: 1 6 3
GCV 14.03861 RSS 3996.421 GRSq 0.7819266 RSq 0.8107343
> printh(update(a.none, pmethod="b"))
===update(a.none, pmethod = "b")
Selected 10 of 31 terms, and 8 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibt, humidity, doy, dpg, vis, wind, ibh, vh-unused
Number of terms at each degree of interaction: 1 5 4
GCV 14.03861 RSS 3996.421 GRSq 0.7819266 RSq 0.8107343
> printh(update(a.none, nprune=4, pmethod="e"))
===update(a.none, nprune = 4, pmethod = "e")
Selected 4 of 31 terms, and 3 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibh, humidity, vh-unused, wind-unused, dpg-unused, ...
Number of terms at each degree of interaction: 1 2 1
GCV 18.56782 RSS 5815.792 GRSq 0.7115708 RSq 0.7245711
> a.updated <- update(a.none, nprune=10, pmethod="b")
> printh(a.updated)
===a.updated
Selected 10 of 31 terms, and 8 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibt, humidity, doy, dpg, vis, wind, ibh, vh-unused
Number of terms at each degree of interaction: 1 5 4
GCV 14.03861 RSS 3996.421 GRSq 0.7819266 RSq 0.8107343
> a.backwards <- update(a, nprune=10, pmethod="b")
> printh(a.backwards)
===a.backwards
Selected 10 of 31 terms, and 8 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibt, humidity, doy, dpg, vis, wind, ibh, vh-unused
Number of terms at each degree of interaction: 1 5 4
GCV 14.03861 RSS 3996.421 GRSq 0.7819266 RSq 0.8107343
> printh(all.equal(a.updated$bx, a.backwards$bx))
===all.equal(a.updated$bx, a.backwards$bx) [1] TRUE
> a <- earth(O3 ~ ., data=ozone1, nk=31, nprune=10, pmethod="b", degree=2)
> printh(a)
===a
Selected 10 of 31 terms, and 8 of 9 predictors
Termination condition: Reached nk 31
Importance: temp, ibt, humidity, doy, dpg, vis, wind, ibh, vh-unused
Number of terms at each degree of interaction: 1 5 4
GCV 14.03861 RSS 3996.421 GRSq 0.7819266 RSq 0.8107343
> printh(all.equal(a$bx, a.backwards$bx))
===all.equal(a$bx, a.backwards$bx) [1] TRUE
>
> cat("--- Auto.linpreds -----------------------------\n")
--- Auto.linpreds -----------------------------
>
> set.seed(2017)
> x1 <- runif(10)
> x2 <- runif(10)
> y <- x1 + x2
> data=data.frame(x1=x1, x2=x2, y=y)
> OLD.PAR <- par(no.readonly=TRUE)
> par(mfrow = c(6, 4), mar = c(3, 3, 3, 1), mgp = c(1.5, 0.5, 0))
>
> expect.err(try(earth(y~., data=data, Auto.linpr=99)), "Auto.linpreds=99 but it should be FALSE, TRUE, 0, or 1")
Error : Auto.linpreds=99 but it should be FALSE, TRUE, 0, or 1
Got error as expected from try(earth(y ~ ., data = data, Auto.linpr = 99))
>
> a <- earth(y~., data=data, trace=2) # default Auto.linpreds=TRUE
x[10,2] with colnames x1 x2
y[10,1] with colname y
Forward pass: minspan 3 endspan 4 x[10,2] 160 B bx[10,21] 1.64 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 -0.3656 0.5785 0.5785 2 x2 0.43208 2 3 1
4 1.0000 1.0000 0.4215 1 x1 0.039322< 4 1 final (max RSq)
Reached maximum RSq 0.9990 at 5 terms, 4 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 5 terms, 4 terms used
Prune method "backward" penalty 2 nprune null: selected 4 of 4 terms, and 2 of 2 preds
After pruning pass GRSq 1 RSq 1
> print(summary(a, style="pmax"))
Call: earth(formula=y~., data=data, trace=2)
y =
0.4320778
+ 1 * x1
- 1 * pmax(0, 0.4320778 - x2)
+ 1 * pmax(0, x2 - 0.4320778)
Selected 4 of 4 terms, and 2 of 2 predictors
Termination condition: Reached maximum RSq 0.9990 at 4 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> plotmo(a, extend=.3, ylim=c(.2, 1.7),
+ do.par=FALSE, pt.col=2, jitter=0,
+ main=c("default Auto.linpreds=T", ""))
plotmo grid: x1 x2
0.470681 0.4657348
> empty.plot()
> empty.plot()
>
> a1 <- earth(y~., data=data, trace=2, Auto.linpreds=FALSE)
x[10,2] with colnames x1 x2
y[10,1] with colname y
Forward pass: minspan 3 endspan 4 x[10,2] 160 B bx[10,21] 1.64 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 -0.3656 0.5785 0.5785 2 x2 0.43208 2 3 1
4 1.0000 1.0000 0.4215 1 x1 0.039322< 4 1 final (max RSq)
Reached maximum RSq 0.9990 at 5 terms, 4 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 5 terms, 4 terms used
Prune method "backward" penalty 2 nprune null: selected 4 of 4 terms, and 2 of 2 preds
After pruning pass GRSq 1 RSq 1
> print(summary(a1, style="pmax"))
Call: earth(formula=y~., data=data, trace=2, Auto.linpreds=FALSE)
y =
0.4714001
+ 1 * pmax(0, x1 - 0.03932234)
- 1 * pmax(0, 0.4320778 - x2)
+ 1 * pmax(0, x2 - 0.4320778)
Selected 4 of 4 terms, and 2 of 2 predictors
Termination condition: Reached maximum RSq 0.9990 at 4 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> plotmo(a1, extend=.3, ylim=c(.2, 1.7),
+ do.par=FALSE, pt.col=2, jitter=0,
+ main=c("Auto.linpreds=F", ""))
plotmo grid: x1 x2
0.470681 0.4657348
> empty.plot()
> empty.plot()
> stopifnot(isTRUE(all.equal(predict(a), predict(a1))))
>
> a2 <- earth(y~., data=data, trace=2, linpreds=TRUE, Auto.linpreds=FALSE)
x[10,2] with colnames x1 x2
y[10,1] with colname y
Linear predictors 1=x1 2=x2
Forward pass: minspan 3 endspan 4 x[10,2] 160 B bx[10,21] 1.64 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.3033 0.5785 0.5785 2 x2 0.0020208< 2 1
4 1.0000 1.0000 0.4215 1 x1 0.039322< 3 1 final (max RSq)
Reached maximum RSq 0.9990 at 5 terms, 3 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 5 terms, 3 terms used
Prune method "backward" penalty 2 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 1 RSq 1
> print(summary(a2, style="pmax"))
Call: earth(formula=y~., data=data, trace=2, linpreds=TRUE,
Auto.linpreds=FALSE)
y =
-0
+ 1 * x1
+ 1 * x2
Selected 3 of 3 terms, and 2 of 2 predictors
Termination condition: Reached maximum RSq 0.9990 at 3 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> plotmo(a2, extend=.3, ylim=c(.2, 1.7),
+ do.par=FALSE, pt.col=2, jitter=0,
+ main=c("linpreds=T, Auto.linpreds=F", ""))
plotmo grid: x1 x2
0.470681 0.4657348
> empty.plot()
> empty.plot()
> stopifnot(isTRUE(all.equal(predict(a), predict(a2))))
>
> a3 <- earth(y~., data=data, linpreds="x1", Auto.linpreds=FALSE)
> print(summary(a3, style="pmax"))
Call: earth(formula=y~., data=data, linpreds="x1", Auto.linpreds=FALSE)
y =
0.4320778
+ 1 * x1
- 1 * pmax(0, 0.4320778 - x2)
+ 1 * pmax(0, x2 - 0.4320778)
Selected 4 of 4 terms, and 2 of 2 predictors
Termination condition: Reached maximum RSq 0.9990 at 4 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> plotmo(a3, extend=.3, ylim=c(.2, 1.7),
+ do.par=FALSE, pt.col=2, jitter=0,
+ main=c("linpreds=x1, Auto.linpreds=F", ""))
plotmo grid: x1 x2
0.470681 0.4657348
> empty.plot()
> empty.plot()
> stopifnot(isTRUE(all.equal(predict(a), predict(a3))))
>
> a4 <- earth(y~., data=data, linpreds="x2", Auto.linpreds=FALSE)
> print(summary(a4, style="pmax"))
Call: earth(formula=y~., data=data, linpreds="x2", Auto.linpreds=FALSE)
y =
0.03932234
+ 1 * x2
+ 1 * pmax(0, x1 - 0.03932234)
Selected 3 of 3 terms, and 2 of 2 predictors
Termination condition: Reached maximum RSq 0.9990 at 3 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> plotmo(a4, extend=.3, ylim=c(.2, 1.7),
+ do.par=FALSE, pt.col=2, jitter=0,
+ main=c("linpreds=x2, Auto.linpreds=F", ""))
plotmo grid: x1 x2
0.470681 0.4657348
> empty.plot()
> empty.plot()
> stopifnot(isTRUE(all.equal(predict(a), predict(a4))))
>
> # x,y interface
> a5 <- earth(data[,1:2], data[,3], Auto.linpreds=FALSE)
> print(summary(a5, style="pmax"))
Call: earth(x=data[,1:2], y=data[,3], Auto.linpreds=FALSE)
data[,3] =
0.4714001
+ 1 * pmax(0, x1 - 0.03932234)
- 1 * pmax(0, 0.4320778 - x2)
+ 1 * pmax(0, x2 - 0.4320778)
Selected 4 of 4 terms, and 2 of 2 predictors
Termination condition: Reached maximum RSq 0.9990 at 4 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> plotmo(a5, extend=.3, ylim=c(.2, 1.7),
+ do.par=FALSE, pt.col=2, jitter=0,
+ main=c("x,y interface", ""))
plotmo grid: x1 x2
0.470681 0.4657348
> empty.plot()
> empty.plot()
> stopifnot(isTRUE(all.equal(as.vector(predict(a1)), as.vector(predict(a5)))))
> par(OLD.PAR)
>
> # more complicated example (with Auto.linpreds=TRUE, vh enters linearly in a degree2 term)
> data(ozone1)
> oz <- ozone1[1:50,]
> mod.none1 <- earth(O3~., data=oz, degree=2, nk=15, pmethod="none") # default Auto.linpreds=TRUE
> print(summary(mod.none1))
Call: earth(formula=O3~., data=oz, pmethod="none", degree=2, nk=15)
coefficients
(Intercept) 4.2036778
h(5720-vh) 0.0331735
h(vh-5720) 0.0145381
h(4-wind) 1.1184678
h(wind-4) 0.1767766
h(28-humidity) -0.1729997
h(humidity-28) -7.3870298
h(174-ibt) -0.0109694
h(ibt-174) -0.0151749
h(45-doy) -0.0433483
h(doy-45) 0.1827167
h(doy-61) -0.2544981
vh * h(humidity-28) 0.0012973
Selected 13 of 13 terms, and 5 of 9 predictors (pmethod="none")
Termination condition: Reached nk 15
Importance: humidity, vh, doy, wind, ibt, temp-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 11 1
GCV 7.21889 RSS 52.12038 GRSq -0.05294658 RSq 0.8416852
> mod.none2 <- earth(O3~., data=oz, degree=2, nk=15, pmethod="none", Auto.linpreds=FALSE)
> print(summary(mod.none2))
Call: earth(formula=O3~., data=oz, pmethod="none", degree=2, nk=15,
Auto.linpreds=FALSE)
coefficients
(Intercept) 4.2036778
h(5720-vh) 0.0331735
h(vh-5720) 0.0145381
h(4-wind) 1.1184678
h(wind-4) 0.1767766
h(28-humidity) -0.1729997
h(humidity-28) -0.4464325
h(174-ibt) -0.0109694
h(ibt-174) -0.0151749
h(45-doy) -0.0433483
h(doy-45) 0.1827167
h(doy-61) -0.2544981
h(vh-5350) * h(humidity-28) 0.0012973
Selected 13 of 13 terms, and 5 of 9 predictors (pmethod="none")
Termination condition: Reached nk 15
Importance: humidity, vh, doy, wind, ibt, temp-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 11 1
GCV 7.21889 RSS 52.12038 GRSq -0.05294658 RSq 0.8416852
> stopifnot(all.equal(predict(mod.none1), predict(mod.none2)))
>
> # example figure in inst/doc
> OLD.PAR <- par(no.readonly=TRUE)
> par(mfrow=c(2,2), mar=c(4, 3.2, 3, 3), mgp=c(1.6, 0.6, 0), par(cex = 0.7))
> set.seed(2017)
> offset <- 98
> data.autolin <- data.frame(x=offset+(1:10), y=offset+(1:10))
> autolinFALSE <- earth(y~x, data=data.autolin, Auto.linpreds=FALSE)
> print(summary(autolinFALSE, style="max"))
Call: earth(formula=y~x, data=data.autolin, Auto.linpreds=FALSE)
y =
99
+ 1 * max(0, x - 99)
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> set.seed(2017) # for same jitter on this and previous graph
> plotmo(autolinFALSE, extend=.3, do.par=FALSE, pt.col="red", lwd=2,
+ main="Auto.linpreds = FALSE",
+ xaxt="n", yaxt="n", jitter=1, cex.main=1,
+ xlim=offset+c(-2,13), ylim=offset+c(-3,13))
> legend(x="topleft", legend=c("data", "earth model"),
+ lty=c(0, 1), lwd=c(0, 2), pch=c(20, NA), col=c("red", 1))
> text(x=offset+3.8, y=offset-1.2, cex=.9, "The knot happens to be at the")
> text(x=offset+4, y=offset-2.4, cex=.9, "minimum value of the predictor")
>
> autolinTRUE <- earth(y~x, data=data.autolin) # default Auto.linpreds=TRUE
> print(summary(autolinTRUE, style="max"))
Call: earth(formula=y~x, data=data.autolin)
y =
-0
+ 1 * x
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> set.seed(2017) # for same jitter on this and next graph
> plotmo(autolinTRUE, extend=.3, do.par=FALSE, pt.col="red", lwd=2,
+ main="Auto.linpreds = TRUE (default)",
+ xaxt="n", yaxt="n", jitter=1, cex.main=1,
+ xlim=offset+c(-2,13), ylim=offset+c(-3,13))
> legend(x="topleft", legend=c("data", "earth model"),
+ lty=c(0, 1), lwd=c(0, 2), pch=c(20, NA), col=c("red", 1))
> text(x=offset+4, y=offset-2.4, cex=.9, "Same data as previous graph")
> stopifnot(isTRUE(all.equal(predict(autolinTRUE), predict(autolinFALSE))))
> par(OLD.PAR)
>
> # test Auto.linpreds with data sent in by a user
> ndata <- matrix(data=c(
+ -0.0781, -0.6109, -0.216, -1.5172, 0.8184, -1.1242,
+ -0.0781, -0.5885, -0.216, -1.3501, 0.8184, -0.8703,
+ -0.0781, -0.5885, -0.216, -1.3501, 0.8184, -0.9549,
+ -0.0781, -0.5885, -0.216, -1.3501, 1.4136, -0.8703,
+ -2.5759, -0.5885, 1.1665, -1.3501, 2.0089, -0.9549,
+ -2.5759, -0.5885, 1.1665, -1.3501, 2.0089, -0.8703,
+ -0.0781, -0.4937, -0.216, -0.9949, -0.372, -1.0396,
+ -0.0781, -0.4463, -0.216, -0.8278, -0.372, -0.447,
+ -0.0781, -0.4463, -0.216, -0.8278, -0.372, -0.701,
+ -0.0781, -0.4463, -0.216, -0.8278, -0.372, -0.6163,
+ -0.0781, -0.4463, -0.216, -0.8278, 0.8184, -0.447,
+ -0.0781, -0.4463, -0.216, -0.8278, 0.8184, -0.6163,
+ -0.0781, -0.4463, 1.1665, -0.8278, 0.8184, -0.447,
+ -0.0781, -0.4379, 1.1665, 0.2585, -0.372, -0.1085,
+ -0.0781, -0.2147, 1.1665, 0.0496, -0.372, -0.1085,
+ -0.0781, -0.2147, -0.216, 0.2585, -0.372, -0.0238,
+ -0.0781, -0.1589, -0.216, 0.2585, -0.372, -0.1931,
+ -0.0781, -0.1589, -0.216, 0.2585, -0.372, -0.1085,
+ -0.0781, -0.1589, 1.1665, 0.2585, -0.372, -0.1931,
+ -0.0781, -0.1589, -0.216, 0.2585, 0.8184, -0.1085,
+ -0.0781, -0.1589, -0.216, 0.2585, 0.8184, 0.0608,
+ -0.0781, -0.1589, -0.216, 1.0942, 0.8184, -0.0238,
+ -0.0781, 0.0643, 1.1665, 1.0942, -0.372, 0.2301,
+ -0.0781, 0.0643, -0.216, 1.0942, -1.5624, 0.3148,
+ -0.0781, 0.0643, -0.216, 1.0942, -0.9672, 0.1455,
+ -0.0781, 0.0643, 1.1665, 1.4284, 0.2232, 0.4841,
+ -0.0781, 0.1563, -0.216, 1.0942, -0.372, 0.5687,
+ 2.4197, 0.3432, -0.216, 1.0942, -1.5624, 1.0766,
+ -0.0781, 0.3432, -0.216, 1.0942, -1.5624, 1.1613,
+ -0.0781, 0.3432, 1.1665, 1.0942, 0.2232, 0.738,
+ 2.4197, 2.7145, -2.9811, 1.0942, -1.5624, 2.5156,
+ 2.4197, 4.3884, -2.9811, 1.0942, -1.5624, 3.5314),
+ ncol=6)
> colnames(ndata) <- c("x1", "x2", "x3", "x4", "x5", "y")
> ndata <- as.data.frame(ndata)
>
> cat("Auto.linpreds=TRUE pmethod=\"none\":\n")
Auto.linpreds=TRUE pmethod="none":
> auto.linpreds.true.pmethod.none <- earth(y~., data=ndata, degree=2, nk=21, trace=2, pmethod="none")
x[32,5] with colnames x1 x2 x3 x4 x5
y[32,1] with colname y
Forward pass: minspan 4 endspan 9 x[32,5] 1.25 kB bx[32,21] 5.25 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0583 0.3376 0.3376 1 x1 -0.9549 2 3 1
4 -0.2012 0.4488 0.1112 3 x3 -0.0781 4 5 1
6 -0.1801 0.5797 0.131 4 x4 -0.372< 6 2 2
8 -0.2458 0.6681 0.08841 3 x3 -0.8278< 7 2 2
10 -0.4175 0.7312 0.06304 3 x3 -0.8278< 8 3 2
12 -0.8452 0.7677 0.03649 1 x1 -0.216 9 1
14 -1.7625 0.7923 0.02464 1 x1 -2.5759< 10 4 2
16 -13.8221 0.8111 0.01875 2 x2 -0.216 11 12 1 reject (negative GRSq)
Reached minimum GRSq -10 at 15 terms, 10 terms used (GRSq -14)
After forward pass GRSq -13.822 RSq 0.811
Forward pass complete: 15 terms, 10 terms used
Prune method "none" penalty 3 nprune null: selected 10 of 10 terms, and 3 of 5 preds
After pruning pass GRSq -1.76 RSq 0.792
> print(summary(auto.linpreds.true.pmethod.none, decomp="none"))
Call: earth(formula=y~., data=ndata, pmethod="none", trace=2, degree=2, nk=21)
coefficients
(Intercept) 2.4332961
h(x1- -0.9549) -0.9865989
h(-0.9549-x1) 6.9070794
h(x3- -0.0781) -8.9336500
h(-0.0781-x3) 0.0165408
h(x1- -0.9549) * x4 -1.2581107
h(x1- -0.9549) * x3 6.4769097
h(-0.9549-x1) * x3 25.0101165
h(x1- -0.216) 1.8627919
x1 * h(x3- -0.0781) -5.5959046
Selected 10 of 10 terms, and 3 of 5 predictors (pmethod="none")
Termination condition: GRSq -10 at 10 terms
Importance: x1, x4, x3, x2-unused, x5-unused
Number of terms at each degree of interaction: 1 5 4
GCV 8.371258 RSS 18.90073 GRSq -1.762519 RSq 0.792308
> cat("\nAuto.linpreds=FALSE pmethod=\"none\":\n")
Auto.linpreds=FALSE pmethod="none":
> auto.linpreds.false.pmethod.none <- earth(y~., data=ndata, degree=2, nk=21, trace=2, Auto.linpreds=FALSE, pmethod="none")
x[32,5] with colnames x1 x2 x3 x4 x5
y[32,1] with colname y
Forward pass: minspan 4 endspan 9 x[32,5] 1.25 kB bx[32,21] 5.25 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0583 0.3376 0.3376 1 x1 -0.9549 2 3 1
4 -0.2012 0.4488 0.1112 3 x3 -0.0781 4 5 1
6 -0.1801 0.5797 0.131 4 x4 -0.372< 6 2 2
8 -0.2458 0.6681 0.08841 3 x3 -0.8278< 7 2 2
10 -0.4175 0.7312 0.06304 3 x3 -0.8278< 8 3 2
12 -0.8452 0.7677 0.03649 1 x1 -0.216 9 1
14 -1.7625 0.7923 0.02464 1 x1 -2.5759< 10 5 2
16 -13.8221 0.8111 0.01875 2 x2 -0.216 11 12 1 reject (negative GRSq)
Reached minimum GRSq -10 at 15 terms, 12 terms used (GRSq -14)
After forward pass GRSq -13.822 RSq 0.811
Forward pass complete: 15 terms, 12 terms used
Fixed rank deficient bx by removing 2 terms, 10 terms remain
Prune method "none" penalty 3 nprune null: selected 10 of 10 terms, and 3 of 5 preds
After pruning pass GRSq -1.76 RSq 0.792
> print(summary(auto.linpreds.false.pmethod.none, decomp="none"))
Call: earth(formula=y~., data=ndata, pmethod="none", trace=2, degree=2, nk=21,
Auto.linpreds=FALSE)
coefficients
(Intercept) 2.433296
h(x1- -0.9549) -1.684918
h(-0.9549-x1) -17.991545
h(x3- -0.0781) -3.590121
h(-0.0781-x3) 9.087502
h(x1- -0.9549) * h(x4- -0.372) -1.258111
h(x1- -0.9549) * h(x3- -0.8278) 0.881005
h(-0.9549-x1) * h(x3- -0.8278) 30.606021
h(x1- -0.216) 1.862792
h(x1- -2.5759) * h(-0.0781-x3) -5.595905
Selected 10 of 10 terms, and 3 of 5 predictors (pmethod="none")
Termination condition: GRSq -10 at 10 terms
Importance: x1, x4, x3, x2-unused, x5-unused
Number of terms at each degree of interaction: 1 5 4
GCV 8.371258 RSS 18.90073 GRSq -1.762519 RSq 0.792308
> stopifnot(isTRUE(all.equal(predict(auto.linpreds.true.pmethod.none), predict(auto.linpreds.false.pmethod.none))))
>
> cat("\nAuto.linpreds=TRUE:\n")
Auto.linpreds=TRUE:
> auto.linpreds.true <- earth(y~., data=ndata, degree=2, nk=21, trace=2)
x[32,5] with colnames x1 x2 x3 x4 x5
y[32,1] with colname y
Forward pass: minspan 4 endspan 9 x[32,5] 1.25 kB bx[32,21] 5.25 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0583 0.3376 0.3376 1 x1 -0.9549 2 3 1
4 -0.2012 0.4488 0.1112 3 x3 -0.0781 4 5 1
6 -0.1801 0.5797 0.131 4 x4 -0.372< 6 2 2
8 -0.2458 0.6681 0.08841 3 x3 -0.8278< 7 2 2
10 -0.4175 0.7312 0.06304 3 x3 -0.8278< 8 3 2
12 -0.8452 0.7677 0.03649 1 x1 -0.216 9 1
14 -1.7625 0.7923 0.02464 1 x1 -2.5759< 10 4 2
16 -13.8221 0.8111 0.01875 2 x2 -0.216 11 12 1 reject (negative GRSq)
Reached minimum GRSq -10 at 15 terms, 10 terms used (GRSq -14)
After forward pass GRSq -13.822 RSq 0.811
Forward pass complete: 15 terms, 10 terms used
Prune method "backward" penalty 3 nprune null: selected 4 of 10 terms, and 3 of 5 preds
After pruning pass GRSq 0.209 RSq 0.546
> print(summary(auto.linpreds.true, decomp="none"))
Call: earth(formula=y~., data=ndata, trace=2, degree=2, nk=21)
coefficients
(Intercept) 1.371239
h(x3- -0.0781) -1.882810
h(x1- -0.9549) * x4 -1.413220
h(-0.9549-x1) * x3 4.319452
Selected 4 of 10 terms, and 3 of 5 predictors
Termination condition: GRSq -10 at 10 terms
Importance: x1, x4, x3, x2-unused, x5-unused
Number of terms at each degree of interaction: 1 1 2
GCV 2.396481 RSS 41.35802 GRSq 0.20916 RSq 0.5455344
> cat("\nAuto.linpreds=FALSE:\n")
Auto.linpreds=FALSE:
> auto.linpreds.false <- earth(y~., data=ndata, degree=2, nk=21, trace=2, Auto.linpreds=FALSE)
x[32,5] with colnames x1 x2 x3 x4 x5
y[32,1] with colname y
Forward pass: minspan 4 endspan 9 x[32,5] 1.25 kB bx[32,21] 5.25 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0583 0.3376 0.3376 1 x1 -0.9549 2 3 1
4 -0.2012 0.4488 0.1112 3 x3 -0.0781 4 5 1
6 -0.1801 0.5797 0.131 4 x4 -0.372< 6 2 2
8 -0.2458 0.6681 0.08841 3 x3 -0.8278< 7 2 2
10 -0.4175 0.7312 0.06304 3 x3 -0.8278< 8 3 2
12 -0.8452 0.7677 0.03649 1 x1 -0.216 9 1
14 -1.7625 0.7923 0.02464 1 x1 -2.5759< 10 5 2
16 -13.8221 0.8111 0.01875 2 x2 -0.216 11 12 1 reject (negative GRSq)
Reached minimum GRSq -10 at 15 terms, 12 terms used (GRSq -14)
After forward pass GRSq -13.822 RSq 0.811
Forward pass complete: 15 terms, 12 terms used
Fixed rank deficient bx by removing 2 terms, 10 terms remain
Prune method "backward" penalty 3 nprune null: selected 5 of 10 terms, and 3 of 5 preds
After pruning pass GRSq 0.223 RSq 0.643
> print(summary(auto.linpreds.false, decomp="none"))
Call: earth(formula=y~., data=ndata, trace=2, degree=2, nk=21,
Auto.linpreds=FALSE)
coefficients
(Intercept) 1.635321
h(-0.9549-x1) -12.155291
h(x3- -0.0781) -1.555091
h(x1- -0.9549) * h(x4- -0.372) -1.220702
h(-0.9549-x1) * h(x3- -0.8278) 22.975120
Selected 5 of 10 terms, and 3 of 5 predictors
Termination condition: GRSq -10 at 10 terms
Importance: x1, x4, x3, x2-unused, x5-unused
Number of terms at each degree of interaction: 1 2 2
GCV 2.354961 RSS 32.4543 GRSq 0.2228618 RSq 0.6433736
> # following fails because of different pruning because of different term count
> # stopifnot(isTRUE(all.equal(predict(auto.linpreds.true), predict(auto.linpreds.false))))
>
> cat("--- Force.xtx.prune -----------------------------\n")
--- Force.xtx.prune -----------------------------
>
> expect.err(try(earth(Volume ~ ., data = trees, Force.xtx.prune=TRUE, pmethod="ex")), "not allowed with") # pmethod="ex" cannot be used with Force.xtx.prune
Error : pmethod="exhaustive" is not allowed with 'eval.subsets.xtx'
Got error as expected from try(earth(Volume ~ ., data = trees, Force.xtx.prune = TRUE, pmethod = "ex"))
>
> m1 <- earth(Volume ~ ., data = trees)
> m2 <- earth(Volume ~ ., data = trees, Force.xtx.prune=TRUE)
> check.models.equal(m1, m2, "Force.xtx.prune test 1", check.subsets=FALSE)
check.models.equal not identical: Force.xtx.prune test 1 (m1$rsq 0.9742029 != m1$rsq 0.9742029) [but within numerical tolerances]
>
> m1 <- earth(O3 ~ wind+temp, data = ozone1, nk=51)
> m2 <- earth(O3 ~ wind+temp, data = ozone1, nk=51, Force.xtx.prune=TRUE)
> check.models.equal(m1, m2, "Force.xtx.prune test 2", check.subsets=FALSE)
check.models.equal not identical: Force.xtx.prune test 2 (m1$rsq 0.6647086 != m1$rsq 0.6647086) [but within numerical tolerances]
>
> # TODO The following exposes a bug in leaps(?). It is described in
> # check.one.term.per.step in the earth R code. The test is commented out
> # because this bug causes a discrepancy with Force.xtx.prune (although
> # usually the bug does not cause any problems).
> #
> # m1 <- earth(O3 ~ ., data = ozone1, nk=51, degree=2, trace=5)
> # m2 <- earth(O3 ~ ., data = ozone1, nk=51, degree=2, Force.xtx.prune=TRUE)
> # check.models.equal(m1, m2, "Force.xtx.prune test 3", check.subsets=FALSE)
>
> cat("--- extractAIC.earth ----------------------------\n")
--- extractAIC.earth ----------------------------
>
> a <-earth(O3 ~ ., data=ozone1, degree=2)
> cat("Ignore 10 warnings: extractAIC.earth: using GCV instead of AIC\n")
Ignore 10 warnings: extractAIC.earth: using GCV instead of AIC
> printh(drop1(a), expect.warning=TRUE)
===drop1(a) expect warning -->Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Warning: extractAIC.earth: returning GCV instead of AIC
Single term deletions
Model:
O3 ~ vh + wind + humidity + temp + ibh + dpg + ibt + vis + doy
Df AIC
<none> 13.408
vh 0.0 13.486
wind 2.5 13.887
humidity -10.0 15.191
temp -7.5 13.016
ibh 0.0 12.836
dpg 0.0 14.800
ibt -7.5 13.736
vis -7.5 14.785
doy -2.5 15.353
> printh(drop1(a, warn=FALSE)) # repeat but with warnings suppressed
===drop1(a, warn = FALSE)
Single term deletions
Model:
O3 ~ vh + wind + humidity + temp + ibh + dpg + ibt + vis + doy
Df AIC
<none> 13.408
vh 0.0 13.486
wind 2.5 13.887
humidity -10.0 15.191
temp -7.5 13.016
ibh 0.0 12.836
dpg 0.0 14.800
ibt -7.5 13.736
vis -7.5 14.785
doy -2.5 15.353
>
> cat("--- fda and mda with earth -----------------------------------\n")
--- fda and mda with earth -----------------------------------
>
> am <- fda(Species ~ ., data=iris, method=mars, degree=1, keepxy=TRUE)
> printh(am)
===am
Call:
fda(formula = Species ~ ., data = iris, method = mars, degree = 1,
keepxy = TRUE)
Dimension: 2
Percent Between-Group Variance Explained:
v1 v2
92.73 100.00
Training Misclassification Error: 0.02667 ( N = 150 )
> a <- fda(Species ~ ., data=iris, method=earth, degree=1, keepxy=TRUE)
> printh(a)
===a
Call:
fda(formula = Species ~ ., data = iris, method = earth, degree = 1,
keepxy = TRUE)
Dimension: 2
Percent Between-Group Variance Explained:
v1 v2
97.97 100.00
Training Misclassification Error: 0.04 ( N = 150 )
> printh(confusion(a))
===confusion(a)
true
predicted setosa versicolor virginica
setosa 50 0 0
versicolor 0 47 3
virginica 0 3 47
> if (PLOT) {
+ par(mar=c(3, 3, 2, .5)) # small margins and text to pack figs in
+ par(mgp=c(1.6, 0.6, 0)) # flatten axis elements
+ par(oma=c(0,0,4,0)) # make space for caption
+ layout(rbind(c(1,1,0,0), c(2,3,4,5), c(6,7,8,9)), heights=c(2,1,1))
+ plot(a)
+ plotmo(a$fit, nresponse=1, ylim=c(-1.5,1.5), clip=FALSE, do.par=FALSE, trace=-1)
+ plotmo(a$fit, nresponse=2, ylim=c(-1.5,1.5), clip=FALSE, do.par=FALSE, trace=-1)
+ mtext("fda test", outer=TRUE, font=2, line=1.5, cex=1)
+ }
>
> data(glass)
> set.seed(123)
> samp <- sample(c(1:214), size=100, replace=FALSE)
> glass.train <- glass[samp,]
> glass.test <- glass[-samp,]
> am <- mda(Type ~ ., data=glass.train, method=mars, keepxy=TRUE, degree=2)
> a <- mda(Type ~ ., data=glass.train, method=earth, keepxy=TRUE, degree=2, keep.fitted=TRUE)
> printh(am)
===am
Call:
mda(formula = Type ~ ., data = glass.train, method = mars, keepxy = TRUE,
degree = 2)
Dimension: 13
Percent Between-Group Variance Explained:
v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13
100 100 100 100 100 100 100 100 100 100 100 100 100
Training Misclassification Error: 0.25 ( N = 100 )
Deviance: 213.874
> printh(a)
===a
Call:
mda(formula = Type ~ ., data = glass.train, method = earth, keep.fitted = TRUE,
keepxy = TRUE, degree = 2)
Dimension: 12
Percent Between-Group Variance Explained:
v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11
65.54 84.85 91.55 95.01 96.73 98.04 99.00 99.88 100.00 100.00 100.00
v12
100.00
Training Misclassification Error: 0.29 ( N = 100 )
Deviance: 213.021
> cat("mda with mars ", attr(confusion(am), "error"), "\n")
mda with mars 0.25
> cat("mda with earth ", attr(confusion(a), "error"), "\n")
mda with earth 0.29
> if (PLOT) {
+ plot(a$fit, caption="mda on glass data", nresponse=1)
+ plotmo(a$fit, nresponse=9, clip=FALSE, ylim=NA, caption="mda on glass data", trace=-1)
+ }
>
> cat("\n---- update and keepxy, formula interface --------------------------\n")
---- update and keepxy, formula interface --------------------------
>
> new.trees <- trees + c(1,2,3,4)
> new.trees <- new.trees[, -c(20:23)]
> a.formula <- earth(Volume ~ ., subset=rep(TRUE, nrow(trees)), data = trees)
> cat("\nupdate(a, trace=1)\n")
update(a, trace=1)
> a.formula.1update <- update(a.formula, trace=1)
update.earth: using 31 by 3 data argument from original call to earth
update.earth: using 31 by 1 subset argument from original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
31 cases after taking subset
Skipped forward pass
Prune method "backward" penalty 2 nprune null: selected 4 of 5 terms, and 2 of 2 preds
After pruning pass GRSq 0.96 RSq 0.974
> a.formula.1 <- earth(Volume ~ ., subset=rep(TRUE, nrow(trees)), data = trees)
> check.models.equal(a.formula.1update, a.formula.1, msg="a1update a1")
check.models.equal identical: a1update a1
>
> cat("\nupdate(a.formula, data=new.trees, trace=1)\n")
update(a.formula, data=new.trees, trace=1)
> a.formula.2update <- update(a.formula, data=new.trees, trace=1)
update.earth: using 31 by 1 subset argument from original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
31 cases after taking subset
Forward pass term 1, 2, 4, 6, 8, 10, 12
RSq changed by less than 0.001 at 11 terms, 8 terms used (DeltaRSq 0.00016)
After forward pass GRSq 0.735 RSq 0.942
Prune method "backward" penalty 2 nprune null: selected 5 of 8 terms, and 2 of 2 preds
After pruning pass GRSq 0.886 RSq 0.938
> a.formula.2 <- earth(Volume ~ ., subset=rep(TRUE, nrow(trees)), data = new.trees)
> check.models.equal(a.formula.2update, a.formula.2, msg="a2update a2")
check.models.equal identical: a2update a2
>
> cat("\nupdate(a.formula, wp=2, trace=1)\n")
update(a.formula, wp=2, trace=1)
> a.formula.3update <- update(a.formula, wp=2, trace=1)
update.earth: using 31 by 3 data argument from original call to earth
update.earth: using 31 by 1 subset argument from original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
31 cases after taking subset
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms (DeltaRSq 0.00087)
After forward pass GRSq 0.947 RSq 0.976
Prune method "backward" penalty 2 nprune null: selected 4 of 5 terms, and 2 of 2 preds
After pruning pass GRSq 0.96 RSq 0.974
> a.formula.3 <- earth(Volume ~ ., subset=rep(TRUE, nrow(trees)), data = trees, wp=2)
> check.models.equal(a.formula.3update, a.formula.3, msg="a3update a3")
check.models.equal identical: a3update a3
>
> cat("\nupdate(a.formula, subset=subset.new, trace=1)\n")
update(a.formula, subset=subset.new, trace=1)
> subset.new <- rep(TRUE, nrow(trees))
> subset.new[1:4] = FALSE
> a.formula.4update <- update(a.formula, subset=subset.new, trace=1)
update.earth: using 31 by 3 data argument from original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
27 cases after taking subset
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms (DeltaRSq 0.00037)
After forward pass GRSq 0.925 RSq 0.972
Prune method "backward" penalty 2 nprune null: selected 4 of 5 terms, and 2 of 2 preds
After pruning pass GRSq 0.947 RSq 0.969
> a.formula.4 <- earth(Volume ~ ., data = trees, subset=subset.new)
> check.models.equal(a.formula.4update, a.formula.4, msg="a4update a4")
check.models.equal identical: a4update a4
>
> # now use keepxy=TRUE
>
> a.formula <- earth(Volume ~ ., wp=1, data = trees, keepxy=TRUE)
>
> cat("\nupdate(a.formula, trace=1)\n")
update(a.formula, trace=1)
> a.formula.5update <- update(a.formula, trace=1)
update.earth: using 31 by 3 data saved by keepxy in original call to earth
update.earth: using 1 by 1 wp saved by keepxy in original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
Skipped forward pass
Prune method "backward" penalty 2 nprune null: selected 4 of 5 terms, and 2 of 2 preds
After pruning pass GRSq 0.96 RSq 0.974
> a.formula.5 <- earth(Volume ~ ., wp=1, data = trees, keepxy=TRUE)
> check.models.equal(a.formula.5update, a.formula.5, msg="a5update a5")
check.models.equal identical: a5update a5
>
> cat("\nupdate(a.formula, data=new.trees, trace=1)\n")
update(a.formula, data=new.trees, trace=1)
> a.formula.6update <- update(a.formula, data=new.trees, trace=1)
update.earth: using 1 by 1 wp saved by keepxy in original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
Forward pass term 1, 2, 4, 6, 8, 10, 12
RSq changed by less than 0.001 at 11 terms, 8 terms used (DeltaRSq 0.00016)
After forward pass GRSq 0.735 RSq 0.942
Prune method "backward" penalty 2 nprune null: selected 5 of 8 terms, and 2 of 2 preds
After pruning pass GRSq 0.886 RSq 0.938
> a.formula.6 <- earth(Volume ~ ., wp=1, data = new.trees, keepxy=TRUE)
> check.models.equal(a.formula.6update, a.formula.6, msg="a6update a6")
check.models.equal identical: a6update a6
>
> cat("\nupdate(a.formula, wp=2, trace=1)\n")
update(a.formula, wp=2, trace=1)
> a.formula.7update <- update(a.formula, wp=2, trace=1)
update.earth: using 31 by 3 data saved by keepxy in original call to earth
x[31,2] with colnames Girth Height
y[31,1] with colname Volume
Forward pass term 1, 2, 4, 6
RSq changed by less than 0.001 at 5 terms (DeltaRSq 0.00087)
After forward pass GRSq 0.947 RSq 0.976
Prune method "backward" penalty 2 nprune null: selected 4 of 5 terms, and 2 of 2 preds
After pruning pass GRSq 0.96 RSq 0.974
> a.formula.7 <- earth(Volume ~ ., wp=2, data = trees, keepxy=TRUE)
> check.models.equal(a.formula.7update, a.formula.7, msg="a7update a7")
check.models.equal identical: a7update a7
>
> cat("\n----- update and keepxy, matrix interface--------------------------\n")
----- update and keepxy, matrix interface--------------------------
>
> Volume <- trees$Volume
> x <- cbind(trees$Height, trees$Volume)
> colnames(x) <- c("Height", "Volume")
>
> new.x <- cbind(new.trees$Height, new.trees$Volume)
> colnames(new.x) <- c("Height", "Volume")
>
> a <- earth(x, Volume, subset=rep(TRUE, nrow(trees)))
> cat("\nupdate(a, trace=1)\n")
update(a, trace=1)
> a1update <- update(a, trace=1)
update.earth: using 31 by 2 x argument from original call to earth
update.earth: using 31 by 1 y argument from original call to earth
update.earth: using 31 by 1 subset argument from original call to earth
x[31,2] with colnames Height Volume
y[31,1] with colname Volume
31 cases after taking subset
Skipped forward pass
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 2 preds
After pruning pass GRSq 1 RSq 1
> a1 <- earth(x, Volume, subset=rep(TRUE, nrow(trees)))
> check.models.equal(a1update, a1, msg="a1update a1")
check.models.equal identical: a1update a1
>
> cat("\nupdate(a, x=new.x, trace=1)\n")
update(a, x=new.x, trace=1)
> a2update <- update(a, x=new.x, trace=1)
update.earth: using 31 by 1 y argument from original call to earth
update.earth: using 31 by 1 subset argument from original call to earth
x[31,2] with colnames Height Volume
y[31,1] with colname Volume
31 cases after taking subset
Forward pass term 1, 2, 4
RSq changed by less than 0.001 at 3 terms (DeltaRSq 0.00028)
After forward pass GRSq 0.992 RSq 0.996
Prune method "backward" penalty 2 nprune null: selected 3 of 3 terms, and 1 of 2 preds
After pruning pass GRSq 0.994 RSq 0.995
> a2 <- earth(new.x, Volume, subset=rep(TRUE, nrow(trees)))
> check.models.equal(a2update, a2, msg="a2update a2")
check.models.equal identical: a2update a2
>
> cat("\nupdate(a, wp=2, trace=0)\n")
update(a, wp=2, trace=0)
> a3update <- update(a, wp=2, trace=0)
> a3 <- earth(x, Volume, subset=rep(TRUE, nrow(trees)), wp=2)
> check.models.equal(a3update, a3, msg="a3update a3")
check.models.equal identical: a3update a3
>
> cat("\nupdate(a, subset=subset.new, trace=4)\n")
update(a, subset=subset.new, trace=4)
> subset.new <- rep(TRUE, nrow(trees))
> subset.new[1:4] = FALSE
> a4update <- update(a, subset=subset.new, trace=4)
update.earth: using 31 by 2 x argument from original call to earth
update.earth: using 31 by 1 y argument from original call to earth
Call: earth(x=x, y=Volume, subset=subset.new, trace=4)
x[31,2]:
Height Volume
1 70 10.3
2 65 10.3
3 63 10.2
... 72 16.4
31 87 77.0
y[31,1]:
Volume
1 10.3
2 10.3
3 10.2
... 16.4
31 77.0
27 cases after taking subset
Forward pass: minspan 4 endspan 8 x[27,2] 432 B bx[27,21] 4.43 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 1.0000 1.0000 1 2 Volume 15.6< 2 1 final (max RSq)
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 3 terms, 2 terms used
EvalSubsetsUsingXtx:
nTerms iTerm DeltaRss RSq
2 2 6527.9 -0.0000 min
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
chosen 2 1.0000 1.0000 1.0000 1 1 2
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 2 preds
After pruning pass GRSq 1 RSq 1
> a4 <- earth(x, Volume, subset=subset.new)
> check.models.equal(a4update, a4, msg="a4update a4")
check.models.equal identical: a4update a4
>
> # now use keepxy=TRUE
>
> a <- earth(x, Volume, wp=1, keepxy=TRUE)
>
> cat("\nupdate(a, trace=4)\n")
update(a, trace=4)
> a5update <- update(a, trace=4)
update.earth: using 31 by 2 x saved by keepxy in original call to earth
update.earth: using 31 by 1 y saved by keepxy in original call to earth
update.earth: using 1 by 1 wp saved by keepxy in original call to earth
Call: earth(x=matrix[31,2], y=c(10.3,10.3,10...), wp=1, keepxy=TRUE, trace=4,
Object=a)
x[31,2]:
Height Volume
1 70 10.3
2 65 10.3
3 63 10.2
... 72 16.4
31 87 77.0
y[31,1]:
Volume
1 10.3
2 10.3
3 10.2
... 16.4
31 77.0
Skipped forward pass
EvalSubsetsUsingXtx:
nTerms iTerm DeltaRss RSq
2 2 8106.1 -0.0000 min
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
chosen 2 1.0000 1.0000 1.0000 1 1 2
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 2 preds
After pruning pass GRSq 1 RSq 1
> a5 <- earth(x, Volume, wp=1, keepxy=TRUE)
> check.models.equal(a5update, a5, msg="a5update a5")
check.models.equal identical: a5update a5
>
> cat("\nupdate(a, x=new.x, trace=4)\n")
update(a, x=new.x, trace=4)
> a6update <- update(a, x=new.x, trace=4)
update.earth: using 31 by 1 y saved by keepxy in original call to earth
update.earth: using 1 by 1 wp saved by keepxy in original call to earth
Call: earth(x=new.x, y=c(10.3,10.3,10...), wp=1, keepxy=TRUE, trace=4)
x[31,2]:
Height Volume
1 74 13.3
2 66 14.3
3 65 11.2
... 75 18.4
31 89 78.0
y[31,1]:
Volume
1 10.3
2 10.3
3 10.2
... 16.4
31 77.0
Forward pass: minspan 4 endspan 8 x[31,2] 496 B bx[31,21] 5.09 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.9938 0.9954 0.9954 2 Volume 37.3 2 3 1
4 0.9919 0.9956 0.0002782 1 Height 75 4 5 1 reject (small DeltaRSq)
RSq changed by less than 0.001 at 3 terms (DeltaRSq 0.00028)
After forward pass GRSq 0.992 RSq 0.996
Forward pass complete: 3 terms
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 0.7964 0.8226 0.7964 1 1 2
chosen 3 0.9938 0.9954 0.1974 1 1 2 3
Prune method "backward" penalty 2 nprune null: selected 3 of 3 terms, and 1 of 2 preds
After pruning pass GRSq 0.994 RSq 0.995
> a6 <- earth(new.x, Volume, wp=1, keepxy=TRUE)
> check.models.equal(a6update, a6, msg="\"allowed\" function a6update a6")
check.models.equal identical: "allowed" function a6update a6
>
> cat("\nupdate(a, wp=2)\n")
update(a, wp=2)
> a7update <- update(a, wp=2)
> a7 <- earth(x, Volume, wp=2, keepxy=TRUE)
> check.models.equal(a7update, a7, msg="\"allowed\" function a7update a7")
check.models.equal identical: "allowed" function a7update a7
>
> cat("--- \"allowed\" argument -----------------\n")
--- "allowed" argument -----------------
>
> example1 <- function(degree, pred, parents)
+ {
+ pred != 2 # disallow predictor 2, which is "Height"
+ }
> a1 <- earth(Volume ~ ., data = trees, allowed = example1)
> printh(summary(a1))
===summary(a1)
Call: earth(formula=Volume~., data=trees, allowed=example1)
coefficients
(Intercept) 30.656747
h(14.2-Girth) -3.569047
h(Girth-14.2) 6.757306
Selected 3 of 3 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: Girth, Height-unused
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.3391 RSS 312.6848 GRSq 0.948644 RSq 0.9614259
>
> example1a <- function(degree, pred, parents, namesx)
+ {
+ namesx[pred] != "Height" # disallow "Height"
+ }
> a1a <- earth(Volume ~ ., data = trees, allowed = example1a)
> check.models.equal(a1, a1a, msg="\"allowed\" function a1 a1a")
check.models.equal identical: "allowed" function a1 a1a
>
> iheight <- 0
> example1b <- function(degree, pred, parents, namesx, first)
+ {
+ if (first) {
+ iheight <<- which(namesx == "Height") # note use of <<- not <-
+ if (length(iheight) != 1)
+ stop("could not find Height in ", paste(namesx, collapse=" "))
+ }
+ pred != iheight
+ }
> a1b <- earth(Volume ~ ., data = trees, allowed = example1b)
> check.models.equal(a1, a1a, msg="\"allowed\" function a1 a1b")
check.models.equal identical: "allowed" function a1 a1b
>
> example2 <- function(degree, pred, parents)
+ {
+ # disallow humidity in terms of degree > 1
+ # 3 is the "humidity" column in the input matrix
+ if (degree > 1 && (pred == 3 || parents[3]))
+ return(FALSE)
+ TRUE
+ }
> a2 <- earth(O3 ~ ., data = ozone1, degree = 2, allowed = example2)
> printh(summary(a2))
===summary(a2)
Call: earth(formula=O3~., data=ozone1, degree=2, allowed=example2)
coefficients
(Intercept) 14.8457466
h(5860-vh) -0.0157499
h(vh-5860) 0.2637241
h(temp-58) 0.5296758
h(ibh-1105) -0.0004860
h(10-dpg) -0.0560986
h(dpg-10) -0.0761112
h(150-vis) 0.0504424
h(96-doy) -0.1184470
h(doy-158) -0.0302548
h(vh-5860) * h(dpg- -15) -0.0038034
h(vh-5860) * h(-15-dpg) -0.0093059
h(temp-58) * h(dpg-52) -0.0160364
h(temp-58) * h(52-dpg) -0.0047659
h(72-temp) * h(150-vis) -0.0012431
h(temp-72) * h(150-vis) -0.0042689
Selected 16 of 20 terms, and 6 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, doy, dpg, vis, vh, ibh, wind-unused, humidity-unused, ...
Number of terms at each degree of interaction: 1 9 6
GCV 15.17392 RSS 3907.158 GRSq 0.764291 RSq 0.8149617
> example3 <- function(degree, pred, parents)
+ {
+ # allow only humidity and temp in terms of degree > 1
+ # 3 and 4 are the "humidity" and "temp" columns
+ allowed.set = c(3,4)
+ if (degree > 1 && (all(allowed.set != pred) || any(parents[-allowed.set])))
+ return(FALSE)
+ TRUE
+ }
> a3 <- earth(O3 ~ ., data = ozone1, degree = 2, allowed = example3)
> printh(summary(a3))
===summary(a3)
Call: earth(formula=O3~., data=ozone1, degree=2, allowed=example3)
coefficients
(Intercept) 13.4717045
h(5850-vh) -0.0142141
h(wind-6) -0.5690100
h(temp-58) 0.2832302
h(1105-ibh) -0.0029012
h(10-dpg) -0.0691576
h(dpg-10) -0.0903813
h(ibt-115) 0.0446509
h(200-vis) 0.0181357
h(96-doy) -0.1237491
h(doy-150) -0.0313603
h(55-humidity) * h(temp-58) -0.0173091
Selected 12 of 20 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, dpg, vis, doy, humidity, ibh, vh, ibt, wind
Number of terms at each degree of interaction: 1 10 1
GCV 13.8999 RSS 3828.887 GRSq 0.7840813 RSq 0.8186686
>
> ihumidity <- 0
> itemp <- 0
> example3a <- function(degree, pred, parents, namesx, first)
+ {
+ if (first) {
+ ihumidity <<- which(namesx == "humidity") # note use of <<- not <-
+ if (length(ihumidity) != 1)
+ stop("could not find humidity in ", paste(namesx, collapse=" "))
+ itemp <<- which(namesx == "temp") # note use of <<- not <-
+ if (length(itemp) != 1)
+ stop("could not find temp in ", paste(namesx, collapse=" "))
+ }
+ # allow only humidity and temp in terms of degree > 1
+ allowed.set = c(ihumidity, itemp)
+ if (degree > 1 &&
+ (all(allowed.set != pred) || any(parents[-allowed.set])))
+ return(FALSE)
+ TRUE
+ }
> a3a <- earth(O3 ~ ., data = ozone1, degree = 2, allowed = example3)
> check.models.equal(a3, a3a, msg="\"allowed\" function a3 a3a")
check.models.equal identical: "allowed" function a3 a3a
>
> #--- no predictor in PREDICTORS is allowed to interact with any predictor in PARENTS
> #--- but all other interactions are allowed
>
> PREDICTORS <- c("age")
> PARENTS <- c("survived", "parch")
>
> example4 <- function(degree, pred, parents, namesx)
+ {
+ if (degree > 1) {
+ predictor <- namesx[pred]
+ parents <- namesx[parents != 0]
+ if((any(predictor %in% PREDICTORS) && any(parents %in% PARENTS)) ||
+ (any(predictor %in% PARENTS) && any(parents %in% PREDICTORS))) {
+ return(FALSE)
+ }
+ }
+ TRUE
+ }
> a4.allowed <- earth(sex~., data=etitanic, degree=2, allowed=example4)
> printh(summary(a4.allowed))
===summary(a4.allowed)
Call: earth(formula=sex~., data=etitanic, degree=2, allowed=example4)
coefficients
(Intercept) 0.74841883
pclass3rd -0.44966704
survived -0.62673470
h(15-age) 0.03878154
pclass2nd * survived -0.16200218
pclass3rd * survived 0.31810348
pclass3rd * h(20-age) -0.02792432
pclass3rd * h(4-parch) 0.08607338
h(3-sibsp) * h(4-parch) 0.01835222
h(sibsp-3) * h(4-parch) 0.08911862
Selected 10 of 16 terms, and 6 of 6 predictors
Termination condition: Reached nk 21
Importance: survived, parch, sibsp, pclass3rd, age, pclass2nd
Number of terms at each degree of interaction: 1 3 6
GCV 0.1525303 RSS 152.4583 GRSq 0.3475741 RSq 0.3753665
> plotmo(a4.allowed, caption="a4.allowed")
plotmo grid: pclass survived age sibsp parch
3rd 0 28 0 0
>
> #--- predictors in PREDICTORS are allowed to interact with predictors in PARENTS
> #--- but no other interactions are allowed
>
> PREDICTORS <- c("age")
> PARENTS <- c("survived", "parch")
>
> example5 <- function(degree, pred, parents, namesx)
+ {
+ if (degree <= 1)
+ return(TRUE)
+ predictor <- namesx[pred]
+ parents <- namesx[parents != 0]
+ if((any(predictor %in% PREDICTORS) && any(parents %in% PARENTS)) ||
+ (any(predictor %in% PARENTS) && any(parents %in% PREDICTORS))) {
+ return(TRUE)
+ }
+ FALSE
+ }
> a5.allowed <- earth(sex~., data=etitanic, degree=2, allowed=example5)
> printh(summary(a5.allowed))
===summary(a5.allowed)
Call: earth(formula=sex~., data=etitanic, degree=2, allowed=example5)
coefficients
(Intercept) 0.34721404
h(2-sibsp) 0.06347988
h(sibsp-2) 0.10099095
h(4-parch) 0.11453239
survived * h(age-15) 0.15093805
survived * h(age-11.5) -0.15199742
h(25-age) * h(4-parch) -0.00419678
Selected 7 of 17 terms, and 4 of 6 predictors
Termination condition: Reached nk 21
Importance: survived, parch, age, sibsp, pclass2nd-unused, ...
Number of terms at each degree of interaction: 1 3 3
GCV 0.1561245 RSS 158.3485 GRSq 0.3322006 RSq 0.3512343
> plotmo(a5.allowed, caption="a5.allowed")
plotmo grid: pclass survived age sibsp parch
3rd 0 28 0 0
>
> # "allowed" function checks, these check error handling by forcing an error
>
> expect.err(try(earth(Volume ~ ., data = trees, allowed = 99)), "argument is not a function")
Error : your 'allowed' argument is not a function
Got error as expected from try(earth(Volume ~ ., data = trees, allowed = 99))
>
> example7 <- function(degree, pred) pred!=2
> expect.err(try(earth(Volume ~ ., data = trees, allowed = example7)), "function does not have the correct number of arguments")
Error : your 'allowed' function does not have the correct number of arguments
The 'allowed' function needs the following arguments (but namesx and first are optional):
degree pred parents namesx first
Got error as expected from try(earth(Volume ~ ., data = trees, allowed = example7))
>
> example8 <- function(degree, pred, parents99) pred!=2
> expect.err(try(earth(Volume ~ ., data = trees, allowed = example8)), "function needs the following arguments")
Error : The 'allowed' function needs the following arguments (but namesx and first are optional):
degree pred parents namesx first
You have:
degree pred parents99
Got error as expected from try(earth(Volume ~ ., data = trees, allowed = example8))
>
> example9 <- function(degree, pred, parents, namesx99) pred!=2
> expect.err(try(earth(Volume ~ ., data = trees, allowed = example9)), "function needs the following arguments")
Error : The 'allowed' function needs the following arguments (but namesx and first are optional):
degree pred parents namesx first
You have:
degree pred parents namesx99
Got error as expected from try(earth(Volume ~ ., data = trees, allowed = example9))
>
> cat("--- beta cache -------------------------\n")
--- beta cache -------------------------
>
> a1 <- earth(O3 ~ ., data = ozone1, degree = 3)
> a2 <- earth(O3 ~ ., data = ozone1, degree = 3, Use.beta.cache=FALSE)
> a1$call <- NULL
> a2$call <- NULL
> stopifnot(identical(a1, a2))
>
> cat("--- test \"call\" printing in earth.default and summary.earth ---\n")
--- test "call" printing in earth.default and summary.earth ---
> # we want to make sure that long x or y aren't printed but short ones are
>
> x = c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0)
>
> y = c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0)
>
> a <- earth(x = x, y=y, trace=5)
Call: earth(x=x, y=y, trace=5)
x[101,1]:
x
1 0
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 0
12 1
13 2
14 3
15 4
16 5
17 6
18 7
19 8
20 9
21 0
22 1
23 2
24 3
25 4
26 5
27 6
28 7
29 8
30 9
31 0
32 1
33 2
34 3
35 4
36 5
37 6
38 7
39 8
40 9
41 0
42 1
43 2
44 3
45 4
46 5
47 6
48 7
49 8
50 9
51 0
52 1
53 2
54 3
55 4
56 5
57 6
58 7
59 8
60 9
61 0
62 1
63 2
64 3
65 4
66 5
67 6
68 7
69 8
70 9
71 0
72 1
73 2
74 3
75 4
76 5
77 6
78 7
79 8
80 9
81 0
82 1
83 2
84 3
85 4
86 5
87 6
88 7
89 8
90 9
91 0
92 1
93 2
94 3
95 4
96 5
97 6
98 7
99 8
100 9
101 0
x
Min. :0.000
1st Qu.:2.000
Median :4.000
Mean :4.455
3rd Qu.:7.000
Max. :9.000
y[101,1]:
y
1 0
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 0
12 1
13 2
14 3
15 4
16 5
17 6
18 7
19 8
20 9
21 0
22 1
23 2
24 3
25 4
26 5
27 6
28 7
29 8
30 9
31 0
32 1
33 2
34 3
35 4
36 5
37 6
38 7
39 8
40 9
41 0
42 1
43 2
44 3
45 4
46 5
47 6
48 7
49 8
50 9
51 0
52 1
53 2
54 3
55 4
56 5
57 6
58 7
59 8
60 9
61 0
62 1
63 2
64 3
65 4
66 5
67 6
68 7
69 8
70 9
71 0
72 1
73 2
74 3
75 4
76 5
77 6
78 7
79 8
80 9
81 0
82 1
83 2
84 3
85 4
86 5
87 6
88 7
89 8
90 9
91 0
92 1
93 2
94 3
95 4
96 5
97 6
98 7
99 8
100 9
101 0
y
Min. :0.000
1st Qu.:2.000
Median :4.000
Mean :4.455
3rd Qu.:7.000
Max. :9.000
maxmem 0.0 GB
earth.c version 4.6.3
BetaCache 3.45 kB
Forward pass: minspan 4 endspan 7 x[101,1] 808 B bx[101,21] 16.6 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 1.0000 1.0000 1 1 x 0< 2 1 final (max RSq)
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 3 terms, 2 terms used
EvalSubsetsUsingXtx:
nTerms iTerm DeltaRss RSq
2 2 845.05 -0.0000 min
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
chosen 2 1.0000 1.0000 1.0000 1 1 2
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 1 RSq 1
>
> a.longx <- earth(x = c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0),
+ y=y,
+ trace=4)
Call: earth(x=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...), y=y,
trace=4)
x[101,1]:
x
1 0
2 1
3 2
... 3
101 0
y[101,1]:
y
1 0
2 1
3 2
... 3
101 0
Forward pass: minspan 4 endspan 7 x[101,1] 808 B bx[101,21] 16.6 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 1.0000 1.0000 1 1 x 0< 2 1 final (max RSq)
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 3 terms, 2 terms used
EvalSubsetsUsingXtx:
nTerms iTerm DeltaRss RSq
2 2 845.05 -0.0000 min
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
chosen 2 1.0000 1.0000 1.0000 1 1 2
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 1 RSq 1
>
> a.longy <- earth(x = x,
+ y = c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0),
+ trace=4)
Call: earth(x=x, y=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...),
trace=4)
x[101,1]:
x
1 0
2 1
3 2
... 3
101 0
y[101,1]:
y
1 0
2 1
3 2
... 3
101 0
Forward pass: minspan 4 endspan 7 x[101,1] 808 B bx[101,21] 16.6 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 1.0000 1.0000 1 1 x 0< 2 1 final (max RSq)
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 3 terms, 2 terms used
EvalSubsetsUsingXtx:
nTerms iTerm DeltaRss RSq
2 2 845.05 -0.0000 min
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
chosen 2 1.0000 1.0000 1.0000 1 1 2
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 1 RSq 1
>
> a.longxy <- earth(x = c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0),
+ y = c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
+ 0,1,2,3,4,5,6,7,8,9,0),
+ trace=4)
Call: earth(x=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...),
y=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...), trace=4)
x[101,1]:
x
1 0
2 1
3 2
... 3
101 0
y[101,1]:
y
1 0
2 1
3 2
... 3
101 0
Forward pass: minspan 4 endspan 7 x[101,1] 808 B bx[101,21] 16.6 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 1.0000 1.0000 1 1 x 0< 2 1 final (max RSq)
Reached maximum RSq 0.9990 at 3 terms, 2 terms used (RSq 1.0000)
After forward pass GRSq 1.000 RSq 1.000
Forward pass complete: 3 terms, 2 terms used
EvalSubsetsUsingXtx:
nTerms iTerm DeltaRss RSq
2 2 845.05 -0.0000 min
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
chosen 2 1.0000 1.0000 1.0000 1 1 2
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 1 RSq 1
> printh(summary(a))
===summary(a)
Call: earth(x=x, y=y, trace=5)
coefficients
(Intercept) -7.070164e-16
x 1.000000e+00
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> printh(summary(a.longx))
===summary(a.longx)
Call: earth(x=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...), y=y,
trace=4)
coefficients
(Intercept) -7.070164e-16
x 1.000000e+00
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> printh(summary(a.longy))
===summary(a.longy)
Call: earth(x=x, y=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...),
trace=4)
coefficients
(Intercept) -7.070164e-16
x 1.000000e+00
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> printh(summary(a.longxy))
===summary(a.longxy)
Call: earth(x=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...),
y=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...), trace=4)
coefficients
(Intercept) -7.070164e-16
x 1.000000e+00
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
> printh(summary(a.longxy, style="bf"))
===summary(a.longxy, style = "bf")
Call: earth(x=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...),
y=c(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,...), trace=4)
y =
-7.070164e-16
+ 1 * bf1
bf1 x
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: Reached maximum RSq 0.9990 at 2 terms
Importance: x
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0 RSS 0 GRSq 1 RSq 1
>
> cat("--- factors with x,y interface -------------------------\n")
--- factors with x,y interface -------------------------
> # this also tests for integer variables in the input matrix
> data(etitanic)
> attach(etitanic)
> a1 <- earth(pclass, sex, degree=2, trace=2) # x=unordered y=unordered
x[1046,2] with colnames x2nd x3rd
y[1046,1] with colname male
Forward pass: minspan 6 endspan 8 x[1046,2] 16.3 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0133 0.0180 0.01797 2 x3rd 0< 2 1
4 0.0116 0.0210 0.003025 1 x2nd 0< 3 1
6 0.0068 0.0210 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.007 RSq 0.021
Forward pass complete: 5 terms, 3 terms used
Prune method "backward" penalty 3 nprune null: selected 2 of 3 terms, and 1 of 2 preds
After pruning pass GRSq 0.0133 RSq 0.018
> printh(summary(a1))
===summary(a1)
Call: earth(x=pclass, y=sex, trace=2, degree=2)
coefficients
(Intercept) 0.5669725
x3rd 0.1296343
Selected 2 of 3 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: x3rd, x2nd-unused
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0.2306901 RSS 239.6897 GRSq 0.01325722 RSq 0.01797283
> printh(summary(a1, style="bf"))
===summary(a1, style = "bf")
Call: earth(x=pclass, y=sex, trace=2, degree=2)
male =
0.5669725
+ 0.1296343 * bf1
bf1 x3rd
Selected 2 of 3 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: x3rd, x2nd-unused
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0.2306901 RSS 239.6897 GRSq 0.01325722 RSq 0.01797283
> if (PLOT)
+ plot(a1)
> a2 <- earth(sex, pclass, degree=2, trace=2) # x=unordered y=unordered
x[1046,1] with colname xmale
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 5 endspan 7 x[1046,1] 8.17 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0073 0.0120 0.01202 1 xmale 0< 2 1
4 0.0025 0.0120 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 3 terms, 2 terms used (DeltaRSq 0)
After forward pass GRSq 0.003 RSq 0.012
Forward pass complete: 3 terms, 2 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 0.00728 RSq 0.012
> printh(summary(a2))
===summary(a2)
Call: earth(x=sex, y=pclass, trace=2, degree=2)
1st 2nd 3rd
(Intercept) 0.3427835 0.26546392 0.3917526
xmale -0.1133002 -0.02534234 0.1386426
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 2 terms
Importance: xmale
Number of terms at each degree of interaction: 1 1 (additive model)
GCV RSS GRSq RSq
1st 0.1961073 203.7578 0.010414990 0.0151441824
2nd 0.1883694 195.7180 -0.003997793 0.0008002778
3rd 0.2467207 256.3457 0.013257223 0.0179728324
All 0.6311974 655.8215 0.007279765 0.0120239411
> if (PLOT)
+ plot(a2, nresponse=1)
> a3 <- earth(pclass, age, degree=2, trace=2) # x=unordered y=numeric
x[1046,2] with colnames x2nd x3rd
y[1046,1] with colname age
Forward pass: minspan 6 endspan 8 x[1046,2] 16.3 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.1094 0.1136 0.1136 2 x3rd 0< 2 1
4 0.1640 0.1720 0.05838 1 x2nd 0< 3 1
6 0.1600 0.1720 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.160 RSq 0.172
Forward pass complete: 5 terms, 3 terms used
Prune method "backward" penalty 3 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.164 RSq 0.172
> printh(summary(a3))
===summary(a3)
Call: earth(x=pclass, y=age, trace=2, degree=2)
coefficients
(Intercept) 39.159918
x2nd -9.653213
x3rd -14.343551
Selected 3 of 3 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: x3rd, x2nd
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 173.8417 RSS 179758.3 GRSq 0.1640128 RSq 0.1719935
> if (PLOT)
+ plot(a3, nresponse=1)
> a4 <- earth(age, pclass, degree=2, trace=2) # x=numeric y=unordered
x[1046,1] with colname age
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 5 endspan 7 x[1046,1] 8.17 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0893 0.0980 0.09797 1 age 26 2 3 1
4 0.0891 0.1021 0.004178 1 age 55 4 1
6 0.0881 0.1055 0.003357 1 age 16 5 1
8 0.0849 0.1067 0.00116 1 age 44 6 1
10 0.0813 0.1075 0.0008104 1 age 48 7 1 reject (small DeltaRSq)
RSq changed by less than 0.001 at 9 terms, 6 terms used (DeltaRSq 0.00081)
After forward pass GRSq 0.081 RSq 0.107
Forward pass complete: 9 terms, 6 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 2 of 6 terms, and 1 of 1 preds
After pruning pass GRSq 0.093 RSq 0.0974
> printh(summary(a4))
===summary(a4)
Call: earth(x=age, y=pclass, trace=2, degree=2)
1st 2nd 3rd
(Intercept) 0.06439450 0.2563335580 0.67927195
h(age-16) 0.01388561 -0.0004566659 -0.01342895
Selected 2 of 6 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 6 terms
Importance: age
Number of terms at each degree of interaction: 1 1 (additive model)
GCV RSS GRSq RSq
1st 0.1670033 173.5184 0.157277818 0.16130516
2nd 0.1884855 195.8387 -0.004616749 0.00018428
3rd 0.2211945 229.8237 0.115347486 0.11957521
All 0.5766834 599.1808 0.093017132 0.09735157
> if (PLOT)
+ plot(a4, nresponse=1)
> a5 <- earth(etitanic[,c(2:4)], pclass, degree=2, trace=2) # x=mixed y=unordered
x[1046,3] with colnames survived sexmale age
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 6 endspan 8 x[1046,3] 24.5 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0893 0.0980 0.09797 3 age 26 2 3 1
4 0.1500 0.1622 0.0642 1 survived 0< 4 1
6 0.1557 0.1758 0.01364 3 age 16 5 6 4 2
8 0.1603 0.1842 0.008445 2 sexmale 0< 7 4 2
10 0.1631 0.1909 0.006652 2 sexmale 0< 8 1
12 0.1616 0.1934 0.00253 3 age 57 9 1
14 0.1599 0.1956 0.002212 2 sexmale 0< 10 2 2
16 0.1541 0.1980 0.002352 3 age 5 11 12 10 2
18 0.1529 0.2008 0.002846 3 age 2 13 1
20 0.1495 0.2016 0.0007302 3 age 12 14 4 2 reject (small DeltaRSq)
RSq changed by less than 0.001 at 19 terms, 13 terms used (DeltaRSq 0.00073)
After forward pass GRSq 0.149 RSq 0.202
Forward pass complete: 19 terms, 13 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 7 of 13 terms, and 3 of 3 preds
After pruning pass GRSq 0.165 RSq 0.189
> printh(summary(a5))
===summary(a5)
Call: earth(x=etitanic[,c(2:4)], y=pclass, trace=2, degree=2)
1st 2nd 3rd
(Intercept) -0.02151789 0.210092649 0.81142524
survived 0.36119246 0.144874864 -0.50606732
sexmale 0.07967096 0.115755401 -0.19542636
h(26-age) -0.00070712 -0.013836973 0.01454409
h(age-26) 0.01592910 -0.003659393 -0.01226971
survived * sexmale -0.07745396 -0.293062401 0.37051636
survived * h(16-age) -0.02037404 0.038860933 -0.01848689
Selected 7 of 13 terms, and 3 of 3 predictors
Termination condition: RSq changed by less than 0.001 at 13 terms
Importance: age, survived, sexmale
Number of terms at each degree of interaction: 1 4 2
GCV RSS GRSq RSq
1st 0.1502539 152.3942 0.24179781 0.26340816
2nd 0.1834402 186.0532 0.02227456 0.05014178
3rd 0.1970609 199.8680 0.21186826 0.23433166
All 0.5307550 538.3155 0.16525132 0.18904341
> if (PLOT)
+ plot(a5, nresponse=1)
> a6 <- earth(etitanic[,c(1,3,4,5,6)], survived, degree=2, trace=2) # x=mixed y=unordered
x[1046,6] with colnames pclass2nd pclass3rd sexmale age sibsp parch
y[1046,1] with colname survived
Forward pass: minspan 6 endspan 9 x[1046,6] 49 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.2860 0.2894 0.2894 3 sexmale 0< 2 1
4 0.3297 0.3361 0.04669 2 pclass3rd 0< 3 1
6 0.3588 0.3710 0.03488 4 age 16 4 5 2 2
8 0.3962 0.4106 0.03954 1 pclass2nd 0< 6 2 2
10 0.4143 0.4338 0.0232 5 sibsp 4 7 8 4 2
12 0.4133 0.4383 0.004574 6 parch 1 9 10 1
14 0.4150 0.4427 0.00437 2 pclass3rd 0< 11 2 2
16 0.4116 0.4449 0.002169 5 sibsp 1 12 13 2 2
18 0.4087 0.4477 0.002807 4 age 17 14 15 13 2
20 0.4056 0.4502 0.002549 4 age 32 16 17 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq 0.406 RSq 0.450
Forward pass complete: 21 terms, 17 terms used
Prune method "backward" penalty 3 nprune null: selected 8 of 17 terms, and 5 of 6 preds
After pruning pass GRSq 0.42 RSq 0.439
> printh(summary(a6))
===summary(a6)
Call: earth(x=etitanic[,c(1,3,4,5,6)], y=survived, trace=2, degree=2)
coefficients
(Intercept) 0.96170950
pclass3rd -0.81545352
sexmale -0.57003496
h(age-32) -0.00471938
pclass2nd * sexmale -0.26568920
pclass3rd * sexmale 0.19310203
pclass3rd * h(4-sibsp) 0.10222181
sexmale * h(16-age) 0.04505232
Selected 8 of 17 terms, and 5 of 6 predictors
Termination condition: Reached nk 21
Importance: sexmale, pclass3rd, pclass2nd, age, sibsp, parch-unused
Number of terms at each degree of interaction: 1 3 4
GCV 0.1404529 RSS 141.7629 GRSq 0.4197106 RSq 0.4389834
> if (PLOT)
+ plot(a6)
> a7 <- earth(etitanic[,c(2,3,5,6)], etitanic[,c(1,4)], degree=2, trace=2) # x=mixed y=mixed
x[1046,4] with colnames survived sexmale sibsp parch
y[1046,4] with colnames pclass1st pclass2nd pclass3rd age
Forward pass: minspan 6 endspan 9 x[1046,4] 32.7 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0813 0.0901 0.09011 4 parch 2 2 3 1
4 0.1049 0.1219 0.03183 3 sibsp 1 4 5 1
6 0.1068 0.1323 0.01034 4 parch 1 6 7 4 2
8 0.1089 0.1385 0.006171 4 parch 4 8 1
10 0.1093 0.1431 0.00463 3 sibsp 2 9 1
12 0.1043 0.1466 0.003515 4 parch 1 10 11 5 2
14 0.1024 0.1491 0.002463 2 sexmale 0< 12 3 2
16 0.0998 0.1507 0.001651 1 survived 0< 13 4 2
18 0.0974 0.1526 0.001929 1 survived 0< 14 10 2
20 0.0944 0.1540 0.001385 4 parch 1 15 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq 0.094 RSq 0.154
Forward pass complete: 21 terms, 15 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 7 of 15 terms, and 2 of 4 preds
After pruning pass GRSq 0.113 RSq 0.138
> printh(summary(a7))
===summary(a7)
Call: earth(x=etitanic[,c(2,3,5,6)], y=etitanic[,c(1,4)], trace=2, degree=2)
pclass1st pclass2nd pclass3rd age
(Intercept) 0.36758408 0.35266924 0.27974668 22.291896
h(sibsp-1) -0.12882542 -0.08036041 0.20918583 -7.715668
h(2-parch) -0.04851620 -0.05326897 0.10178517 4.853565
h(parch-2) -0.03888370 -0.12184854 0.16073223 13.049389
h(parch-4) -0.16812822 0.04401127 0.12411695 -18.899871
h(sibsp-1) * h(parch-1) 0.05211343 -0.02136815 -0.03074529 4.418743
h(sibsp-1) * h(1-parch) 0.06525217 0.09912874 -0.16438091 7.403960
Selected 7 of 15 terms, and 2 of 4 predictors
Termination condition: Reached nk 21
Importance: sibsp, parch, survived-unused, sexmale-unused
Number of terms at each degree of interaction: 1 4 2
GCV RSS GRSq RSq
pclass1st 0.200320 203.173 -0.01084030 0.01797077
pclass2nd 0.189624 192.326 -0.01068680 0.01811990
pclass3rd 0.243908 247.383 0.02450493 0.05230858
age 184.482965 187110.877 0.11283993 0.13812585
All 185.116817 187753.758 0.11250542 0.13780087
> if (PLOT)
+ plot(a7, nresponse=1)
>
> cat("--- factors with formula interface -------------------------\n")
--- factors with formula interface -------------------------
> # these correspond to the models above (except a7 which is a multiple response model)
> a1f <- earth(sex ~ pclass, degree=2, trace=2) # x=unordered y=unordered
x[1046,2] with colnames pclass2nd pclass3rd
y[1046,1] with colname male
Forward pass: minspan 6 endspan 8 x[1046,2] 16.3 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0133 0.0180 0.01797 2 pclass3rd 0< 2 1
4 0.0116 0.0210 0.003025 1 pclass2nd 0< 3 1
6 0.0068 0.0210 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.007 RSq 0.021
Forward pass complete: 5 terms, 3 terms used
Prune method "backward" penalty 3 nprune null: selected 2 of 3 terms, and 1 of 2 preds
After pruning pass GRSq 0.0133 RSq 0.018
> printh(summary(a1f))
===summary(a1f)
Call: earth(formula=sex~pclass, trace=2, degree=2)
coefficients
(Intercept) 0.5669725
pclass3rd 0.1296343
Selected 2 of 3 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: pclass3rd, pclass2nd-unused
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0.2306901 RSS 239.6897 GRSq 0.01325722 RSq 0.01797283
> printh(summary(a1f, style="bf"))
===summary(a1f, style = "bf")
Call: earth(formula=sex~pclass, trace=2, degree=2)
male =
0.5669725
+ 0.1296343 * bf1
bf1 pclass3rd
Selected 2 of 3 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: pclass3rd, pclass2nd-unused
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 0.2306901 RSS 239.6897 GRSq 0.01325722 RSq 0.01797283
> if (PLOT)
+ plot(a1f)
> a2f <- earth(pclass ~ sex, degree=2, trace=2) # x=unordered y=unordered
x[1046,1] with colname sexmale
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 5 endspan 7 x[1046,1] 8.17 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0073 0.0120 0.01202 1 sexmale 0< 2 1
4 0.0025 0.0120 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 3 terms, 2 terms used (DeltaRSq 0)
After forward pass GRSq 0.003 RSq 0.012
Forward pass complete: 3 terms, 2 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 0.00728 RSq 0.012
> printh(summary(a2f))
===summary(a2f)
Call: earth(formula=pclass~sex, trace=2, degree=2)
1st 2nd 3rd
(Intercept) 0.3427835 0.26546392 0.3917526
sexmale -0.1133002 -0.02534234 0.1386426
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 2 terms
Importance: sexmale
Number of terms at each degree of interaction: 1 1 (additive model)
GCV RSS GRSq RSq
1st 0.1961073 203.7578 0.010414990 0.0151441824
2nd 0.1883694 195.7180 -0.003997793 0.0008002778
3rd 0.2467207 256.3457 0.013257223 0.0179728324
All 0.6311974 655.8215 0.007279765 0.0120239411
> if (PLOT)
+ plot(a2f, nresponse=1)
> a3f <- earth(age ~ pclass, degree=2, trace=2) # x=unordered y=numeric
x[1046,2] with colnames pclass2nd pclass3rd
y[1046,1] with colname age
Forward pass: minspan 6 endspan 8 x[1046,2] 16.3 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.1094 0.1136 0.1136 2 pclass3rd 0< 2 1
4 0.1640 0.1720 0.05838 1 pclass2nd 0< 3 1
6 0.1600 0.1720 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 5 terms, 3 terms used (DeltaRSq 0)
After forward pass GRSq 0.160 RSq 0.172
Forward pass complete: 5 terms, 3 terms used
Prune method "backward" penalty 3 nprune null: selected 3 of 3 terms, and 2 of 2 preds
After pruning pass GRSq 0.164 RSq 0.172
> printh(summary(a3f))
===summary(a3f)
Call: earth(formula=age~pclass, trace=2, degree=2)
coefficients
(Intercept) 39.159918
pclass2nd -9.653213
pclass3rd -14.343551
Selected 3 of 3 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: pclass3rd, pclass2nd
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 173.8417 RSS 179758.3 GRSq 0.1640128 RSq 0.1719935
> if (PLOT)
+ plot(a3f)
> a4f <- earth(pclass ~ age, degree=2, trace=2) # x=numeric y=unordered
x[1046,1] with colname age
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 5 endspan 7 x[1046,1] 8.17 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0893 0.0980 0.09797 1 age 26 2 3 1
4 0.0891 0.1021 0.004178 1 age 55 4 1
6 0.0881 0.1055 0.003357 1 age 16 5 1
8 0.0849 0.1067 0.00116 1 age 44 6 1
10 0.0813 0.1075 0.0008104 1 age 48 7 1 reject (small DeltaRSq)
RSq changed by less than 0.001 at 9 terms, 6 terms used (DeltaRSq 0.00081)
After forward pass GRSq 0.081 RSq 0.107
Forward pass complete: 9 terms, 6 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 2 of 6 terms, and 1 of 1 preds
After pruning pass GRSq 0.093 RSq 0.0974
> printh(summary(a4f))
===summary(a4f)
Call: earth(formula=pclass~age, trace=2, degree=2)
1st 2nd 3rd
(Intercept) 0.06439450 0.2563335580 0.67927195
h(age-16) 0.01388561 -0.0004566659 -0.01342895
Selected 2 of 6 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 6 terms
Importance: age
Number of terms at each degree of interaction: 1 1 (additive model)
GCV RSS GRSq RSq
1st 0.1670033 173.5184 0.157277818 0.16130516
2nd 0.1884855 195.8387 -0.004616749 0.00018428
3rd 0.2211945 229.8237 0.115347486 0.11957521
All 0.5766834 599.1808 0.093017132 0.09735157
> if (PLOT)
+ plot(a4f, nresponse=1)
> a5f <- earth(pclass ~ survived + sex + age, data=etitanic, degree=2, trace=2) # x=mixed y=unordered
x[1046,3] with colnames survived sexmale age
y[1046,3] with colnames 1st 2nd 3rd
Forward pass: minspan 6 endspan 8 x[1046,3] 24.5 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0893 0.0980 0.09797 3 age 26 2 3 1
4 0.1500 0.1622 0.0642 1 survived 0< 4 1
6 0.1557 0.1758 0.01364 3 age 16 5 6 4 2
8 0.1603 0.1842 0.008445 2 sexmale 0< 7 4 2
10 0.1631 0.1909 0.006652 2 sexmale 0< 8 1
12 0.1616 0.1934 0.00253 3 age 57 9 1
14 0.1599 0.1956 0.002212 2 sexmale 0< 10 2 2
16 0.1541 0.1980 0.002352 3 age 5 11 12 10 2
18 0.1529 0.2008 0.002846 3 age 2 13 1
20 0.1495 0.2016 0.0007302 3 age 12 14 4 2 reject (small DeltaRSq)
RSq changed by less than 0.001 at 19 terms, 13 terms used (DeltaRSq 0.00073)
After forward pass GRSq 0.149 RSq 0.202
Forward pass complete: 19 terms, 13 terms used
Using EvalSubsetsUsingXtx because this is a multiple response model
Prune method "backward" penalty 3 nprune null: selected 7 of 13 terms, and 3 of 3 preds
After pruning pass GRSq 0.165 RSq 0.189
> printh(summary(a5f))
===summary(a5f)
Call: earth(formula=pclass~survived+sex+age, data=etitanic, trace=2, degree=2)
1st 2nd 3rd
(Intercept) -0.02151789 0.210092649 0.81142524
survived 0.36119246 0.144874864 -0.50606732
sexmale 0.07967096 0.115755401 -0.19542636
h(26-age) -0.00070712 -0.013836973 0.01454409
h(age-26) 0.01592910 -0.003659393 -0.01226971
survived * sexmale -0.07745396 -0.293062401 0.37051636
survived * h(16-age) -0.02037404 0.038860933 -0.01848689
Selected 7 of 13 terms, and 3 of 3 predictors
Termination condition: RSq changed by less than 0.001 at 13 terms
Importance: age, survived, sexmale
Number of terms at each degree of interaction: 1 4 2
GCV RSS GRSq RSq
1st 0.1502539 152.3942 0.24179781 0.26340816
2nd 0.1834402 186.0532 0.02227456 0.05014178
3rd 0.1970609 199.8680 0.21186826 0.23433166
All 0.5307550 538.3155 0.16525132 0.18904341
> if (PLOT)
+ plot(a5f, nresponse=1)
> a6f <- earth(survived ~ ., data=etitanic, degree=2, trace=2) # x=mixed y=unordered
x[1046,6] with colnames pclass2nd pclass3rd sexmale age sibsp parch
y[1046,1] with colname survived
Forward pass: minspan 6 endspan 9 x[1046,6] 49 kB bx[1046,21] 172 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.2860 0.2894 0.2894 3 sexmale 0< 2 1
4 0.3297 0.3361 0.04669 2 pclass3rd 0< 3 1
6 0.3588 0.3710 0.03488 4 age 16 4 5 2 2
8 0.3962 0.4106 0.03954 1 pclass2nd 0< 6 2 2
10 0.4143 0.4338 0.0232 5 sibsp 4 7 8 4 2
12 0.4133 0.4383 0.004574 6 parch 1 9 10 1
14 0.4150 0.4427 0.00437 2 pclass3rd 0< 11 2 2
16 0.4116 0.4449 0.002169 5 sibsp 1 12 13 2 2
18 0.4087 0.4477 0.002807 4 age 17 14 15 13 2
20 0.4056 0.4502 0.002549 4 age 32 16 17 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq 0.406 RSq 0.450
Forward pass complete: 21 terms, 17 terms used
Prune method "backward" penalty 3 nprune null: selected 8 of 17 terms, and 5 of 6 preds
After pruning pass GRSq 0.42 RSq 0.439
> printh(summary(a6f))
===summary(a6f)
Call: earth(formula=survived~., data=etitanic, trace=2, degree=2)
coefficients
(Intercept) 0.96170950
pclass3rd -0.81545352
sexmale -0.57003496
h(age-32) -0.00471938
pclass2nd * sexmale -0.26568920
pclass3rd * sexmale 0.19310203
pclass3rd * h(4-sibsp) 0.10222181
sexmale * h(16-age) 0.04505232
Selected 8 of 17 terms, and 5 of 6 predictors
Termination condition: Reached nk 21
Importance: sexmale, pclass3rd, pclass2nd, age, sibsp, parch-unused
Number of terms at each degree of interaction: 1 3 4
GCV 0.1404529 RSS 141.7629 GRSq 0.4197106 RSq 0.4389834
> if (PLOT)
+ plot(a6f)
> detach(etitanic)
>
> # basic test with ordered factors
> ff <- factor(substring("statistics", 1:10, 1:10), levels=letters, ordered=TRUE)
> ff <- c(ff, ff, ff)
> vowels = (ff == 1 | ff == 9) * 3
> printh(head(ff))
===head(ff)
[1] 19 20 1 20 9 19
> printh(head(vowels))
===head(vowels)
[1] 0 0 3 0 3 0
> a8 <- earth(ff, vowels, degree=1, trace=2) # x=ordered y=numeric
x[30,1] with colname x
y[30,1] with colname vowels
Forward pass: minspan 3 endspan 7 x[30,1] 240 B bx[30,21] 4.92 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.5906 0.6958 0.6958 1 x 9 2 3 1
4 0.5250 0.7012 0.005454 1 x 19 4 1
6 0.4302 0.7012 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 5 terms, 4 terms used (DeltaRSq 0)
After forward pass GRSq 0.430 RSq 0.701
Forward pass complete: 5 terms, 4 terms used
Prune method "backward" penalty 2 nprune null: selected 3 of 4 terms, and 1 of 1 preds
After pruning pass GRSq 0.591 RSq 0.696
> printh(summary(a8))
===summary(a8)
Call: earth(x=ff, y=vowels, trace=2, degree=1)
coefficients
(Intercept) 2.7464305
h(9-x) -0.1445003
h(x-9) -0.2609730
Selected 3 of 4 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 4 terms
Importance: x
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 0.828019 RSS 17.2504 GRSq 0.5906149 RSq 0.6957602
> if (PLOT)
+ plot(a8, nresponse=1)
> plotmo(a8, caption="a8", pt.col=3)
> a9 <- earth(vowels, ff, degree=1, trace=2) # x=numeric y=ordered
x[30,1] with colname vowels
y[30,1] with colname ff
Forward pass: minspan 3 endspan 7 x[30,1] 240 B bx[30,21] 4.92 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.3877 0.4693 0.4693 1 vowels 0< 2 1
4 0.2858 0.4693 0 - reject (no DeltaRsq)
RSq changed by less than 0.001 at 3 terms, 2 terms used (DeltaRSq 0)
After forward pass GRSq 0.286 RSq 0.469
Forward pass complete: 3 terms, 2 terms used
Prune method "backward" penalty 2 nprune null: selected 2 of 2 terms, and 1 of 1 preds
After pruning pass GRSq 0.388 RSq 0.469
> if (PLOT)
+ plot(a9, nresponse=1)
> printh(summary(a9))
===summary(a9)
Call: earth(x=vowels, y=ff, trace=2, degree=1)
coefficients
(Intercept) 17.142857
vowels -3.603175
Selected 2 of 2 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 2 terms
Importance: vowels
Number of terms at each degree of interaction: 1 1 (additive model)
GCV 34.2622 RSS 832.5714 GRSq 0.38772 RSq 0.4692603
>
> cat("--- wp argument---------------------------------\n")
--- wp argument---------------------------------
> set.seed(79)
> NWP <- 100
> x1 <- runif(NWP)
> x2 <- runif(NWP)
> y1 <- (x1 > .5) + .3 * runif(1)
> y2 <- sin(3 * x2) + .3 * runif(1)
> myw <- 10
> m <- mars(cbind(x1,x2), cbind(y1, y2))
> me1 <- mars.to.earth(m)
Converted mars(x=cbind(x1,x2), y=cbind(y1,y2))
to earth(x=cbind(x1,x2), y=cbind(y1,y2))
> printh(me1)
===me1
Selected 7 of 13 terms, and 2 of 2 predictors
Termination condition: Unknown
Importance: object has no prune.terms, call update() on the model to fix that
Number of terms at each degree of interaction: 1 6 (additive model)
GCV RSS GRSq RSq
y1 0.0212617234 1.60929985 0.9166455 0.9356280
y2 0.0006116807 0.04629811 0.9940111 0.9953750
All 0.0218734041 1.65559796 0.9390624 0.9529398
> e1 <- earth(cbind(x1,x2), cbind(y1, y2))
> printh(e1)
===e1
Selected 7 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1, x2
Number of terms at each degree of interaction: 1 6 (additive model)
GCV RSS GRSq RSq
y1 0.0252890017 1.91412454 0.9008570 0.9234350
y2 0.0007586223 0.05742013 0.9925725 0.9942639
All 0.0260476241 1.97154466 0.9270808 0.9436868
> e2 <- earth(cbind(x1,x2), cbind(y1, y2), wp=c(1,1))
> printh(e2)
===e2
Selected 7 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1, x2
Number of terms at each degree of interaction: 1 6 (additive model)
GCV RSS GRSq RSq
y1 0.0252890017 1.91412454 0.9008570 0.9234350
y2 0.0007586223 0.05742013 0.9925725 0.9942639
All 0.0260476241 1.97154466 0.9270808 0.9436868
> e1$call <- NULL
> e2$call <- NULL
> e1$wp <- NULL
> e2$wp <- NULL
> stopifnot(identical(e1, e2))
> e3 <- earth(cbind(x1,x2), cbind(y1, y2), wp=c(.001,1))
> printh(e3)
===e3
Selected 6 of 7 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 7 terms
Importance: x2, x1
Number of terms at each degree of interaction: 1 5 (additive model)
GCV RSS GRSq RSq
y1 0.058039265 4.5972902 0.7724629 0.8161084
y2 0.000297713 0.0235818 0.9970851 0.9976443
All 0.000710793 0.0563019 0.9965256 0.9971920
> wp <- c(1, 2)
> e3 <- earth(cbind(x1,x2), cbind(y1, y2), wp=wp)
> printh(e3)
===e3
Selected 7 of 9 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 9 terms
Importance: x1, x2
Number of terms at each degree of interaction: 1 6 (additive model)
GCV RSS GRSq RSq
y1 0.0252890017 1.91412454 0.9008570 0.9234350
y2 0.0007586223 0.05742013 0.9925725 0.9942639
All 0.0178708309 1.35264319 0.9416429 0.9549327
> m3 <- mars(cbind(x1,x2), cbind(y1, y2), wp=wp)
> cat("response weights: wp", wp, "earth gcv", e3$gcv,
+ "mars gcv", m3$gcv, "mars gcv*length(wp)",
+ m3$gcv * length(wp), "\n")
response weights: wp 1 2 earth gcv 0.01787083 mars gcv 0.007495028 mars gcv*length(wp) 0.01499006
>
> e4 <- earth(cbind(O3, O3) ~ ., data=ozone1, wp=c(1, .01))
> printh(e4) # both sub models should be the same
===e4
Selected 12 of 20 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, dpg, doy, vh, vis, ibt, ibh, wind
Number of terms at each degree of interaction: 1 11 (additive model)
GCV RSS GRSq RSq
O3 14.61004 4172.671 0.7730502 0.8023874
O3.1 14.61004 4172.671 0.7730502 0.8023874
All 29.22008 8345.342 0.7730502 0.8023874
> printh(summary(e4))
===summary(e4)
Call: earth(formula=cbind(O3,O3)~., data=ozone1, wp=c(1,0.01))
O3 O3.1
(Intercept) 14.1595171 14.1595171
h(5860-vh) -0.0137728 -0.0137728
h(wind-3) -0.3377222 -0.3377222
h(54-humidity) -0.1349547 -0.1349547
h(temp-58) 0.2791320 0.2791320
h(1105-ibh) -0.0033837 -0.0033837
h(dpg-10) -0.0991581 -0.0991581
h(ibt-120) 0.0326330 0.0326330
h(150-vis) 0.0231881 0.0231881
h(96-doy) -0.1105145 -0.1105145
h(doy-96) 0.0406468 0.0406468
h(doy-158) -0.0836732 -0.0836732
Selected 12 of 20 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, dpg, doy, vh, vis, ibt, ibh, wind
Number of terms at each degree of interaction: 1 11 (additive model)
GCV RSS GRSq RSq
O3 14.61004 4172.671 0.7730502 0.8023874
O3.1 14.61004 4172.671 0.7730502 0.8023874
All 29.22008 8345.342 0.7730502 0.8023874
>
> # wp with formula interface
> e5 <- earth(cbind(O3, wind) ~ ., data=ozone1, wp=c(1, 1))
> printh(e5)
===e5
Selected 12 of 19 terms, and 8 of 8 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, dpg, doy, vh, vis, ibh, ibt
Number of terms at each degree of interaction: 1 11 (additive model)
GCV RSS GRSq RSq
O3 14.902776 4256.2781 0.7685029 0.7984278
wind 3.488862 996.4297 0.2238615 0.3241907
All 18.391639 5252.7078 0.7329545 0.7674747
> printh(summary(e5))
===summary(e5)
Call: earth(formula=cbind(O3,wind)~., data=ozone1, wp=c(1,1))
O3 wind
(Intercept) 10.5988809 5.6114349
h(5610-vh) -0.0201264 0.0125912
h(vh-5610) 0.0181809 -0.0060755
h(54-humidity) -0.1506629 0.0119373
h(temp-56) 0.2646075 0.0550381
h(1105-ibh) -0.0034196 -0.0008298
h(dpg-13) -0.0954378 0.0046173
h(ibt-120) 0.0336582 -0.0045594
h(150-vis) 0.0217267 -0.0006158
h(96-doy) -0.1307894 -0.0090201
h(doy-158) -0.0418477 0.0043672
h(doy-312) 0.0359320 -0.0570514
Selected 12 of 19 terms, and 8 of 8 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, dpg, doy, vh, vis, ibh, ibt
Number of terms at each degree of interaction: 1 11 (additive model)
GCV RSS GRSq RSq
O3 14.902776 4256.2781 0.7685029 0.7984278
wind 3.488862 996.4297 0.2238615 0.3241907
All 18.391639 5252.7078 0.7329545 0.7674747
> e5 <- earth(cbind(O3, wind) ~ ., data=ozone1, wp=c(.3, 1))
> printh(e5)
===e5
Selected 11 of 19 terms, and 7 of 8 predictors
Termination condition: Reached nk 21
Importance: temp, ibh, doy, humidity, dpg, vh, vis, ibt-unused
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
O3 15.271877 4418.7094 0.7627693 0.7907353
wind 3.410203 986.6958 0.2413602 0.3307925
All 12.295025 3557.3978 0.6643222 0.7038936
> printh(summary(e5))
===summary(e5)
Call: earth(formula=cbind(O3,wind)~., data=ozone1, wp=c(0.3,1))
O3 wind
(Intercept) 7.4506335 4.6371421
h(5610-vh) -0.0141304 0.0118244
h(vh-5610) 0.0175637 -0.0038642
h(humidity-23) 0.0838361 0.0071938
h(temp-55) 0.3675094 0.0292957
h(ibh-1105) -0.0004039 0.0002864
h(dpg-13) -0.0862256 0.0011425
h(150-vis) 0.0197846 -0.0005190
h(96-doy) -0.1367936 -0.0089124
h(doy-150) -0.0391186 0.0036656
h(doy-294) 0.0273699 -0.0421686
Selected 11 of 19 terms, and 7 of 8 predictors
Termination condition: Reached nk 21
Importance: temp, ibh, doy, humidity, dpg, vh, vis, ibt-unused
Number of terms at each degree of interaction: 1 10 (additive model)
GCV RSS GRSq RSq
O3 15.271877 4418.7094 0.7627693 0.7907353
wind 3.410203 986.6958 0.2413602 0.3307925
All 12.295025 3557.3978 0.6643222 0.7038936
> # wp with factors
> e6 <- earth(pclass ~ ., data=etitanic, degree=2, wp=c(.001,.001,1))
> printh(e6)
===e6
Selected 9 of 18 terms, and 5 of 5 predictors
Termination condition: Reached nk 21
Importance: age, survived, sexmale, sibsp, parch
Number of terms at each degree of interaction: 1 5 3
GCV RSS GRSq RSq
1st 0.1498185 150.4809 0.2439951 0.27265613
2nd 0.1876176 188.4472 0.0000000 0.03791987
3rd 0.1888766 189.7117 0.2446010 0.27323905
All 0.5665090 569.0139 0.2444172 0.27306228
> printh(summary(e6))
===summary(e6)
Call: earth(formula=pclass~., data=etitanic, wp=c(0.001,0.001,1), degree=2)
1st 2nd 3rd
(Intercept) -0.013576232 0.282485118 0.73109111
survived 0.312918412 0.174952174 -0.48787059
sexmale 0.073351259 0.149478916 -0.22283017
h(age-9) 0.011822473 -0.003165402 -0.00865707
h(1-sibsp) -0.090396669 -0.045506746 0.13590342
h(parch-2) -0.120345986 -0.075313793 0.19565978
survived * sexmale -0.077447025 -0.291809662 0.36925669
h(21-age) * h(sibsp-1) -0.001063853 -0.008028212 0.00909206
h(57-age) * h(2-parch) -0.001527820 -0.001150068 0.00267789
Selected 9 of 18 terms, and 5 of 5 predictors
Termination condition: Reached nk 21
Importance: age, survived, sexmale, sibsp, parch
Number of terms at each degree of interaction: 1 5 3
GCV RSS GRSq RSq
1st 0.1498185 150.4809 0.2439951 0.27265613
2nd 0.1876176 188.4472 0.0000000 0.03791987
3rd 0.1888766 189.7117 0.2446010 0.27323905
All 0.5665090 569.0139 0.2444172 0.27306228
> e7 <- earth(pclass ~ ., data=etitanic, degree=2, wp=c(1,.001,.001))
> printh(e7)
===e7
Selected 8 of 17 terms, and 4 of 5 predictors
Termination condition: Reached nk 21
Importance: age, parch, survived, sibsp, sexmale-unused
Number of terms at each degree of interaction: 1 3 4
GCV RSS GRSq RSq
1st 0.1446768 146.0263 0.26994041 0.29418743
2nd 0.1903255 192.1007 -0.01442347 0.01926795
3rd 0.1977757 199.6204 0.20900943 0.23528011
All 0.4343262 438.3772 0.26959508 0.29385356
> printh(summary(e7))
===summary(e7)
Call: earth(formula=pclass~., data=etitanic, wp=c(1,0.001,0.001), degree=2)
1st 2nd 3rd
(Intercept) 0.11122944 0.208223042 0.68054751
survived 0.36895988 -0.129640255 -0.23931962
h(age-44) 0.03812399 -0.007721391 -0.03040260
h(2-parch) 0.17926095 0.072120537 -0.25138149
survived * h(52-age) -0.00527271 0.006970050 -0.00169734
h(48-age) * h(2-parch) -0.00631659 -0.002155682 0.00847228
h(age-48) * h(2-parch) -0.02034190 0.002942071 0.01739983
h(1-sibsp) * h(1-parch) -0.13130286 -0.036388271 0.16769113
Selected 8 of 17 terms, and 4 of 5 predictors
Termination condition: Reached nk 21
Importance: age, parch, survived, sibsp, sexmale-unused
Number of terms at each degree of interaction: 1 3 4
GCV RSS GRSq RSq
1st 0.1446768 146.0263 0.26994041 0.29418743
2nd 0.1903255 192.1007 -0.01442347 0.01926795
3rd 0.1977757 199.6204 0.20900943 0.23528011
All 0.4343262 438.3772 0.26959508 0.29385356
> if (PLOT)
+ plot(e7, pt.col=as.numeric(etitanic$pclass)+1, nresponse=1)
>
> cat("--- earth.regress ---------------------------------\n")
--- earth.regress ---------------------------------
>
> msg = "earth.regress with trees data, single response, no weights"
> cat("Test:", msg, "\n")
Test: earth.regress with trees data, single response, no weights
>
> data(trees)
> y <- trees$Volume
> x <- cbind(trees$Girth, trees$Height)
> colnames(x) <- c("girth", "height")
>
> a.lm <- lm(y ~ x)
> a.lm.rss <- sum((a.lm$fitted.values - y)^2)
> if (is.null(dim(a.lm$coefficients)))
+ dim(a.lm$coefficients) <- c(length(a.lm$coefficients), 1)
> a <- earth:::earth.regress(x, y)
> rownames(a.lm$coefficients) <- rownames(a$coefficients)
> check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]", sep=""))
> check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]"))
> check.almost.equal(a.lm$residuals, a$residuals, msg=paste("residuals [", msg, "]"))
>
> msg = "earth.regress with ozone1 data, multiple responses, no weights"
> cat("Test:", msg, "\n")
Test: earth.regress with ozone1 data, multiple responses, no weights
>
> data(ozone1)
> y <- cbind(ozone1$O3, ozone1$O3 ^ 2)
> colnames(y) <- c("O3", "O32")
> x <- cbind(ozone1$wind, ozone1$humidity, ozone1$temp)
> colnames(x) <- c("wind", "humidity", "temp")
>
> a.lm <- lm(y ~ x)
> a.lm.rss <- sum((a.lm$fitted.values - y)^2)
> a <- earth:::earth.regress(x, y)
> rownames(a.lm$coefficients) <- rownames(a$coefficients)
> check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]"))
> check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]", sep=""))
> check.almost.equal(a.lm$residuals, a$residuals, msg=paste("residuals [", msg, "]", sep=""))
>
> # msg = "earth.regress with ozone1 data, multiple responses with case weights"
> # cat("Test:", msg, "\n")
> #
> # # options(digits=10)
> # weights. <- rep(.5, nrow(x))
> # weights.[1] <- 1
> # weights.[2] <- 2
> # weights.[3] <- 3
> # weights.[4] <- 4
> # weights.[5] <- 5
> # a.lm <- lm(y ~ x, weights=weights.)
> # # a.lm.rss <- sum((a.lm$fitted.values - y)^2) # line below is equivalent
> # a.lm.rss <- sum(a.lm$residuals^2)
> # a <- earth:::earth.regress(x, y, weights=weights.)
> # rownames(a.lm$coefficients) <- rownames(a$coefficients)
> # check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]", sep=""))
> # check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]", sep=""))
> # check.almost.equal(a.lm$residuals, a$residuals, msg=paste("residuals [", msg, "]", sep=""))
>
> # msg = "earth.regress case weights with zero weights 1"
> # cat("Test:", msg, "\n")
> #
> # weights. <- rep(1, nrow(x))
> # weights.[2] <- 0
> # weights.[4] <- 0
> # a.lm <- lm(y ~ x, weights=weights.)
> # # a.lm.rss <- sum((a.lm$fitted.values - y)^2) # line below is equivalent
> # a.lm.rss <- sum(a.lm$residuals^2)
> # a <- earth:::earth.regress(x, y, weights=weights.)
> # rownames(a.lm$coefficients) <- rownames(a$coefficients)
> # # options(digits=10)
> # check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]", sep=""))
> # check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]", sep=""))
> # check.almost.equal(a.lm$residuals, a$residuals, max=1e-6, msg=paste("residuals [", msg, "]", sep=""))
> #
> # msg = "earth.regress case weights with zero weights 2"
> # cat("Test:", msg, "\n")
> # weights. <- rep(1, nrow(x))
> # weights.[5] <- 0
> # weights.[6] <- 0
> # weights.[7] <- 0
> # weights.[21] <- 0
> # weights.[22] <- 0
> # weights.[23] <- 0
> # weights.[24] <- 0
> # weights.[25] <- 0
> # weights.[26] <- 0
> # weights.[27] <- 0
> # a.lm <- lm(y ~ x, weights=weights.)
> # # a.lm.rss <- sum((a.lm$fitted.values - y)^2) # line below is equivalent
> # a.lm.rss <- sum(a.lm$residuals^2)
> # a <- earth:::earth.regress(x, y, weights=weights.)
> # rownames(a.lm$coefficients) <- rownames(a$coefficients)
> # check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]", sep=""))
> # check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]", sep=""))
> # check.almost.equal(a.lm$residuals, a$residuals, max=1e-6, msg=paste("residuals [", msg, "]", sep=""))
> #
> # msg = "earth.regress case weights with zero weights and missing columns 1"
> # cat("Test:", msg, "\n")
> # x <- cbind(ozone1$wind, ozone1$humidity, ozone1$temp, ozone1$wind^2, ozone1$humidity^2, ozone1$temp^2)
> # weights. <- rep(1, nrow(x))
> # weights.[5] <- 0
> # weights.[6] <- 0
> # weights.[7] <- 0
> # weights.[21] <- 0
> # weights.[22] <- 0
> # weights.[23] <- 0
> # weights.[24] <- 0
> # weights.[25] <- 0
> # weights.[26] <- 0
> # weights.[27] <- 0
> # colnames(x) <- c("wind", "humidity", "temp", "wind2", "humidity2", "temp2")
> # used.cols = as.logical(c(1,0,1,0,1,1))
> # x.missing <- x[,used.cols]
> # a.lm <- lm(y ~ x.missing, weights=weights.)
> # a.lm.rss <- sum((a.lm$fitted.values - y)^2) # line below is equivalent
> # a.lm.rss <- sum(a.lm$residuals^2)
> # a <- earth:::earth.regress(x, y, weights=weights., used.cols=used.cols)
> # rownames(a.lm$coefficients) <- rownames(a$coefficients)
> # check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]", sep=""))
> # check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]", sep=""))
> # check.almost.equal(a.lm$residuals, a$residuals, max=1e-6, msg=paste("residuals [", msg, "]", sep=""))
> #
> # msg = "earth.regress case weights with zero weights and missing columns 2"
> # cat("Test:", msg, "\n")
> # x <- cbind(ozone1$wind, ozone1$humidity, ozone1$temp, ozone1$wind^2, ozone1$humidity^2, ozone1$temp^2)
> # weights. <- rep(1, nrow(x))
> # weights.[5] <- .1
> # weights.[6] <- .2
> # weights.[7] <- 1.9
> # weights.[21] <- .59
> # colnames(x) <- c("wind", "humidity", "temp", "wind2", "humidity2", "temp2")
> # used.cols = as.logical(c(0,1,0,0,1,0))
> # x.missing <- x[,used.cols]
> # a.lm <- lm(y ~ x.missing, weights=weights.)
> # a.lm.rss <- sum((a.lm$fitted.values - y)^2) # line below is equivalent
> # a.lm.rss <- sum(a.lm$residuals^2)
> # a <- earth:::earth.regress(x, y, weights=weights., used.cols=used.cols)
> # rownames(a.lm$coefficients) <- rownames(a$coefficients)
> # check.almost.equal(a.lm$coefficients, a$coefficients, msg=paste("coefficients [", msg, "]", sep=""))
> # check.almost.equal(a.lm.rss, a$rss, msg=paste("rss [", msg, "]", sep=""))
> # check.almost.equal(a.lm$residuals, a$residuals, max=1e-6, msg=paste("residuals [", msg, "]", sep=""))
>
> cat("---standard method functions ------------------------\n")
---standard method functions ------------------------
>
> short.etitanic <- etitanic[seq(from=1, to=1000, by=20),]
> a1 <- earth(pclass ~ ., data=short.etitanic, glm=list(family=binomial), trace=0)
> printh(variable.names(a1))
===variable.names(a1)
[1] "survived" "sexmale" "age" "sibsp" "parch"
> printh(case.names(a1))
===case.names(a1)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
[46] "46" "47" "48" "49" "50"
> printh(case.names(a1, use.names=FALSE))
===case.names(a1, use.names = FALSE)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
[46] "46" "47" "48" "49" "50"
>
> named.short.etitanic <- short.etitanic
> rownames(named.short.etitanic) <- paste("xx", 1:nrow(named.short.etitanic))
> a2 <- earth(pclass ~ ., data=named.short.etitanic, glm=list(family=binomial), trace=0)
> printh(variable.names(a2))
===variable.names(a2)
[1] "survived" "sexmale" "age" "sibsp" "parch"
> printh(case.names(a2))
===case.names(a2)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
[46] "46" "47" "48" "49" "50"
> printh(case.names(a2, use.names=FALSE))
===case.names(a2, use.names = FALSE)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
[46] "46" "47" "48" "49" "50"
>
> printh(deviance(a1), expect.warning=TRUE)
===deviance(a1) expect warning -->Warning: deviance.earth: returning earth (not GLM) deviance
[1] 25.48701
> printh(deviance(a1, warn=FALSE))
===deviance(a1, warn = FALSE) [1] 25.48701
> printh(effects(a1), expect.warning=TRUE)
===effects(a1) expect warning -->Warning: effects.earth: returning NULL
NULL
> printh(effects(a1, warn=FALSE))
===effects(a1, warn = FALSE) NULL
> printh(family(a1))
===family(a1)
Family: binomial
Link function: logit
> printh(anova(a1), expect.warning=TRUE)
===anova(a1) expect warning -->Warning: anova.earth: returning NULL
NULL
> printh(anova(a1, warn=FALSE))
===anova(a1, warn = FALSE) NULL
> printh(family(a1))
===family(a1)
Family: binomial
Link function: logit
>
> # TODO removed because causes different results on different machines
> # cat("--- thresh=0 -----------------------------------------\n")
> #
> # a.no.thresh <- earth(O3 ~ ., data = ozone1, thresh=0, nk=1000, degree=2, trace=4)
> # printh(a.no.thresh)
> # printh(summary(a.no.thresh))
> # plotmo(a.no.thresh, degree1=1, degree2=c(4,9,16), clip=0, , caption="test with thresh=0", trace=-1)
>
> # test the way plotmo gets the data with earth with a formula interface
> # use strange data name se to make sure eval gets correct environment (don't pick up se in plotmo)
> se <- ozone1
> a <- earth(O3 ~ ., data=se, degree=2, keepxy=0)
> printh(summary(a))
===summary(a)
Call: earth(formula=O3~., data=se, keepxy=0, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=2, caption="getdata earth test1")
plotmo trace 2: plotmo(object=a, caption="getdata earth test1", trace=2)
object call is earth(formula=O3~., data=se, keepxy=0, degree=2)
--get.model.env for earth object
using the environment saved with the earth model: R_GlobalEnv
--plotmo_prolog for earth object 'a'
--plotmo_x for earth object
get.object.x:
object$x is NULL (and it has no colnames)
object call is earth(formula=O3~., data=se, keepxy=0, degree=2)
get.x.from.model.frame:
formula(object) is O3~vh+wind+humidity+temp+ibh+dpg+ibt+vis+doy
naked formula is the same
formula is valid, now looking for data for the model.frame
object$model is NULL (and it has no colnames)
object$data is NULL (and it has no colnames)
argument 2 of the call is 'data'
eval(call$data, R_GlobalEnv)
call$data is usable and has column names O3 vh wind humidity temp ibh dpg ibt vis doy
na.action(object) is "na.fail"
stats::model.frame(O3~vh+wind+humidity+temp+ibh+dpg+ibt+..., data=call$data, na.action="na.fail")
model.frame[,-1] is usable and has column names vh wind humidity temp ibh dpg ibt vis doy
plotmo_x returned[330,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
330 5550 4 85 39 5000 8 44 100 390
----Metadata: plotmo_predict with nresponse=NULL and newdata=NULL
calling predict.earth with NULL newdata
stats::predict(earth.object, NULL, type="response")
predict returned[330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
predict after processing with nresponse=NULL is [330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
----Metadata: plotmo_fitted with nresponse=NULL
stats::fitted(object=earth.object)
fitted(object) returned[330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
fitted(object) after processing with nresponse=NULL is [330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
----Metadata: plotmo_y with nresponse=NULL
--plotmo_y with nresponse=NULL for earth object
get.object.y:
object$y is NULL (and it has no colnames)
object call is earth(formula=O3~., data=se, keepxy=0, degree=2)
get.y.from.model.frame:
formula(object) is O3~vh+wind+humidity+temp+ibh+dpg+ibt+vis+doy
naked formula is the same
formula is valid, now looking for data for the model.frame
object$model is NULL (and it has no colnames)
object$data is NULL (and it has no colnames)
argument 2 of the call is 'data'
eval(call$data, R_GlobalEnv)
call$data is usable and has column names O3 vh wind humidity temp ibh dpg ibt vis doy
na.action(object) is "na.fail"
stats::model.frame(O3~vh+wind+humidity+temp+ibh+dpg+ibt+..., data=call$data, na.action="na.fail")
model.frame[,1] is usable and has column name O3
plotmo_y returned[330,1]:
O3
1 3
2 5
3 5
... 6
330 1
plotmo_y after processing with nresponse=NULL is [330,1]:
O3
1 3
2 5
3 5
... 6
330 1
converted nresponse=NA to nresponse=1
nresponse=1 (was NA) ncol(fitted) 1 ncol(predict) 1 ncol(y) 1
----Metadata: plotmo_y with nresponse=1
--plotmo_y with nresponse=1 for earth object
get.object.y:
object$y is NULL (and it has no colnames)
object call is earth(formula=O3~., data=se, keepxy=0, degree=2)
get.y.from.model.frame:
formula(object) is O3~vh+wind+humidity+temp+ibh+dpg+ibt+vis+doy
formula is valid, now looking for data for the model.frame
object$model is NULL (and it has no colnames)
object$data is NULL (and it has no colnames)
argument 2 of the call is 'data'
eval(call$data, R_GlobalEnv)
call$data is usable and has column names O3 vh wind humidity temp ibh dpg ibt vis doy
na.action(object) is "na.fail"
stats::model.frame(O3~vh+wind+humidity+temp+ibh+dpg+ibt+..., data=call$data, na.action="na.fail")
model.frame[,1] is usable and has column name O3
got model response from model.frame(O3~vh+wind+humidity+temp+ibh+dpg+ibt+...,
data=call$data, na.action="na.fail")
plotmo_y returned[330,1]:
O3
1 3
2 5
3 5
... 6
330 1
plotmo_y after processing with nresponse=1 is [330,1]:
O3
1 3
2 5
3 5
... 6
330 1
got response name "O3" from yhat
resp.levs is NULL
----Metadata: done
number of x values: vh 53 wind 11 humidity 65 temp 63 ibh 196 dpg 128 ibt 193...
----plotmo_singles for earth object
singles: 4 temp, 7 ibt, 8 vis, 9 doy
----plotmo_pairs for earth object
pairs:
[,1] [,2]
[1,] "1 vh" "4 temp"
[2,] "2 wind" "8 vis"
[3,] "3 humidity" "4 temp"
[4,] "4 temp" "6 dpg"
[5,] "5 ibh" "6 dpg"
graphics::par(mfrow=c(3,3), mgp=c(1.5,0.4,0), tcl=-0.3, font.main=2,
mar=c(3,2,1.2,0.8), oma=c(0,0,4,0), cex.main=1.2, cex.lab=1,
cex.axis=1, cex=0.66)
----Figuring out ylim
--get.ylim.by.dummy.plots
--plot.degree1(draw.plot=FALSE)
degree1 plot1 (pmethod "plotmo") variable temp
newdata[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5760 5 64 25.00000 2112.5 24 167.5 120 205.5
2 5760 5 64 26.38776 2112.5 24 167.5 120 205.5
3 5760 5 64 27.77551 2112.5 24 167.5 120 205.5
... 5760 5 64 29.16327 2112.5 24 167.5 120 205.5
50 5760 5 64 93.00000 2112.5 24 167.5 120 205.5
stats::predict(earth.object, data.frame[50,9], type="response")
predict returned[50,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
50 28.24212
predict after processing with nresponse=1 is [50,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
50 28.24212
Reducing trace level for subsequent degree1 plots
degree1 plot2 (pmethod "plotmo") variable ibt
degree1 plot3 (pmethod "plotmo") variable vis
degree1 plot4 (pmethod "plotmo") variable doy
--plot.degree2(draw.plot=FALSE)
degree2 plot1 (pmethod "plotmo") variables vh:temp
newdata[400,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5320.000 5 64 25 2112.5 24 167.5 120 205.5
2 5353.158 5 64 25 2112.5 24 167.5 120 205.5
3 5386.316 5 64 25 2112.5 24 167.5 120 205.5
... 5419.474 5 64 25 2112.5 24 167.5 120 205.5
400 5950.000 5 64 93 2112.5 24 167.5 120 205.5
stats::predict(earth.object, data.frame[400,9], type="response")
predict returned[400,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
400 28.24212
predict after processing with nresponse=1 is [400,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
400 28.24212
Reducing trace level for subsequent degree2 plots
degree2 plot2 (pmethod "plotmo") variables wind:vis
degree2 plot3 (pmethod "plotmo") variables humidity:temp
degree2 plot4 (pmethod "plotmo") variables temp:dpg
degree2 plot5 (pmethod "plotmo") variables ibh:dpg
--done get.ylim.by.dummy.plots
ylim c(-15.89, 38.55) clip TRUE
--plot.degree1(draw.plot=TRUE)
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
graphics::plot.default(x=c(25,26.39,27.7...), y=c(11.16,11.16,1...), type="n",
main="1 temp", xlab="", ylab="", xaxt="s", yaxt="s",
xlim=c(25,93), ylim=c(-15.89,38.55))
--plot.degree2(draw.plot=TRUE)
persp(vh:temp) theta -35
persp(wind:vis) theta 145
persp(humidity:temp) theta -35
persp(temp:dpg) theta 235
persp(ibh:dpg) theta 235
> a <- earth(O3 ~ ., data=se, degree=2, keepxy=1)
> printh(summary(a))
===summary(a)
Call: earth(formula=O3~., data=se, keepxy=1, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=1, caption="getdata earth test2")
stats::predict(earth.object, NULL, type="response")
stats::fitted(object=earth.object)
got model response from object$y
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- earth(O3 ~ ., data=se, degree=2, keepxy=1)
> se <- NULL
> printh(summary(a))
===summary(a)
Call: earth(formula=O3~., data=se, keepxy=1, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=2, caption="getdata earth test3")
plotmo trace 2: plotmo(object=a, caption="getdata earth test3", trace=2)
object call is earth(formula=O3~., data=se, keepxy=1, degree=2)
--get.model.env for earth object
using the environment saved with the earth model: R_GlobalEnv
--plotmo_prolog for earth object 'a'
--plotmo_x for earth object
get.object.x:
object$x is NULL (and it has no colnames)
object call is earth(formula=O3~., data=se, keepxy=1, degree=2)
get.x.from.model.frame:
formula(object) is O3~vh+wind+humidity+temp+ibh+dpg+ibt+vis+doy
naked formula is the same
formula is valid, now looking for data for the model.frame
object$model is NULL (and it has no colnames)
object$data is usable and has column names O3 vh wind humidity temp ibh dpg ibt vis doy
na.action(object) is "na.fail"
stats::model.frame(O3~vh+wind+humidity+temp+ibh+dpg+ibt+..., data=object$data, na.action="na.fail")
model.frame[,-1] is usable and has column names vh wind humidity temp ibh dpg ibt vis doy
plotmo_x returned[330,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
330 5550 4 85 39 5000 8 44 100 390
----Metadata: plotmo_predict with nresponse=NULL and newdata=NULL
calling predict.earth with NULL newdata
stats::predict(earth.object, NULL, type="response")
predict returned[330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
predict after processing with nresponse=NULL is [330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
----Metadata: plotmo_fitted with nresponse=NULL
stats::fitted(object=earth.object)
fitted(object) returned[330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
fitted(object) after processing with nresponse=NULL is [330,1]:
O3
1 0.6423433
2 2.4875500
3 6.3679385
... 5.6710623
330 1.5521976
----Metadata: plotmo_y with nresponse=NULL
--plotmo_y with nresponse=NULL for earth object
get.object.y:
object$y is usable and has column name O3
plotmo_y returned[330,1]:
O3
1 3
2 5
3 5
... 6
330 1
plotmo_y after processing with nresponse=NULL is [330,1]:
O3
1 3
2 5
3 5
... 6
330 1
converted nresponse=NA to nresponse=1
nresponse=1 (was NA) ncol(fitted) 1 ncol(predict) 1 ncol(y) 1
----Metadata: plotmo_y with nresponse=1
--plotmo_y with nresponse=1 for earth object
get.object.y:
object$y is usable and has column name O3
got model response from object$y
plotmo_y returned[330,1]:
O3
1 3
2 5
3 5
... 6
330 1
plotmo_y after processing with nresponse=1 is [330,1]:
O3
1 3
2 5
3 5
... 6
330 1
got response name "O3" from yhat
resp.levs is NULL
----Metadata: done
number of x values: vh 53 wind 11 humidity 65 temp 63 ibh 196 dpg 128 ibt 193...
----plotmo_singles for earth object
singles: 4 temp, 7 ibt, 8 vis, 9 doy
----plotmo_pairs for earth object
pairs:
[,1] [,2]
[1,] "1 vh" "4 temp"
[2,] "2 wind" "8 vis"
[3,] "3 humidity" "4 temp"
[4,] "4 temp" "6 dpg"
[5,] "5 ibh" "6 dpg"
graphics::par(mfrow=c(3,3), mgp=c(1.5,0.4,0), tcl=-0.3, font.main=2,
mar=c(3,2,1.2,0.8), oma=c(0,0,4,0), cex.main=1.2, cex.lab=1,
cex.axis=1, cex=0.66)
----Figuring out ylim
--get.ylim.by.dummy.plots
--plot.degree1(draw.plot=FALSE)
degree1 plot1 (pmethod "plotmo") variable temp
newdata[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5760 5 64 25.00000 2112.5 24 167.5 120 205.5
2 5760 5 64 26.38776 2112.5 24 167.5 120 205.5
3 5760 5 64 27.77551 2112.5 24 167.5 120 205.5
... 5760 5 64 29.16327 2112.5 24 167.5 120 205.5
50 5760 5 64 93.00000 2112.5 24 167.5 120 205.5
stats::predict(earth.object, data.frame[50,9], type="response")
predict returned[50,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
50 28.24212
predict after processing with nresponse=1 is [50,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
50 28.24212
Reducing trace level for subsequent degree1 plots
degree1 plot2 (pmethod "plotmo") variable ibt
degree1 plot3 (pmethod "plotmo") variable vis
degree1 plot4 (pmethod "plotmo") variable doy
--plot.degree2(draw.plot=FALSE)
degree2 plot1 (pmethod "plotmo") variables vh:temp
newdata[400,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5320.000 5 64 25 2112.5 24 167.5 120 205.5
2 5353.158 5 64 25 2112.5 24 167.5 120 205.5
3 5386.316 5 64 25 2112.5 24 167.5 120 205.5
... 5419.474 5 64 25 2112.5 24 167.5 120 205.5
400 5950.000 5 64 93 2112.5 24 167.5 120 205.5
stats::predict(earth.object, data.frame[400,9], type="response")
predict returned[400,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
400 28.24212
predict after processing with nresponse=1 is [400,1]:
O3
1 11.16010
2 11.16010
3 11.16010
... 11.16010
400 28.24212
Reducing trace level for subsequent degree2 plots
degree2 plot2 (pmethod "plotmo") variables wind:vis
degree2 plot3 (pmethod "plotmo") variables humidity:temp
degree2 plot4 (pmethod "plotmo") variables temp:dpg
degree2 plot5 (pmethod "plotmo") variables ibh:dpg
--done get.ylim.by.dummy.plots
ylim c(-15.89, 38.55) clip TRUE
--plot.degree1(draw.plot=TRUE)
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
graphics::plot.default(x=c(25,26.39,27.7...), y=c(11.16,11.16,1...), type="n",
main="1 temp", xlab="", ylab="", xaxt="s", yaxt="s",
xlim=c(25,93), ylim=c(-15.89,38.55))
--plot.degree2(draw.plot=TRUE)
persp(vh:temp) theta -35
persp(wind:vis) theta 145
persp(humidity:temp) theta -35
persp(temp:dpg) theta 235
persp(ibh:dpg) theta 235
> se <- ozone1
> a <- earth(O3 ~ ., data=se, degree=2, keepxy=0)
> se <- NULL
> printh(summary(a))
===summary(a)
Call: earth(formula=O3~., data=se, keepxy=0, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> expect.err(try(plotmo(a, trace=0, caption="getdata earth test4")), "cannot get the original model predictors")
Looked unsuccessfully for the original predictors in the following places:
(1) object$x: NULL
(2) model.frame: object 'O3' not found
(3) getCall(object)$x: NULL
Error : cannot get the original model predictors
Got error as expected from try(plotmo(a, trace = 0, caption = "getdata earth test4"))
>
> # test the way plotmo gets the data with earth with the default interface
> se <- ozone1
> a <- earth(se[,2:10], se[,1], degree=2, keepxy=0)
> printh(summary(a))
===summary(a)
Call: earth(x=se[,2:10], y=se[,1], keepxy=0, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=0, caption="getdata earth test5")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- earth(se[,2:10], se[,1], degree=2, keepxy=1)
> printh(summary(a))
===summary(a)
Call: earth(x=se[,2:10], y=se[,1], keepxy=1, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=0, caption="getdata earth test6")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- earth(se[,2:10], se[,1], degree=2, keepxy=1)
> se <- NULL
> printh(summary(a))
===summary(a)
Call: earth(x=se[,2:10], y=se[,1], keepxy=1, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=0, caption="getdata earth test7")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> se <- ozone1
> a <- earth(se[,2:10], se[,1], degree=2, keepxy=0)
> se <- NULL
> expect.err(try(plotmo(a, trace=0, caption="getdata earth test8")), "cannot get the original model predictors")
Looked unsuccessfully for the original predictors in the following places:
(1) object$x: NULL
(2) model.frame: no formula in getCall(object)
(3) getCall(object)$x: NULL
Error : cannot get the original model predictors
Got error as expected from try(plotmo(a, trace = 0, caption = "getdata earth test8"))
> se <- ozone1
> a <- earth(se[,2:10], se[,1], degree=2, keepxy=0)
> # TODO error message could be improved here
> se$vh <- NULL # vh is unused (but plotmo still needs it --- why?)
> expect.err(try(plotmo(a, trace=0, caption="getdata earth test9")), "cannot get the original model predictors") # plotmo.x.default cannot get the x matrix
Looked unsuccessfully for the original predictors in the following places:
(1) object$x: NULL
(2) model.frame: no formula in getCall(object)
(3) getCall(object)$x: undefined columns selected
Error : cannot get the original model predictors
Got error as expected from try(plotmo(a, trace = 0, caption = "getdata earth test9"))
> se <- ozone1
> a <- earth(se[,2:10], se[,1], degree=2, keepxy=TRUE)
> se$vh <- NULL # vh is unused (but plotmo still needs it --- why?)
> printh(summary(a))
===summary(a)
Call: earth(x=se[,2:10], y=se[,1], keepxy=TRUE, degree=2)
coefficients
(Intercept) 13.2169900
h(temp-58) 0.3726072
h(194-ibt) -0.0455100
h(200-vis) 0.0222462
h(96-doy) -0.1223029
h(doy-96) -0.0240235
h(5730-vh) * h(temp-58) -0.0104496
h(wind-7) * h(200-vis) -0.0180898
h(55-humidity) * h(temp-58) -0.0222754
h(temp-58) * h(dpg-52) -0.0168249
h(temp-58) * h(52-dpg) 0.0041232
h(1105-ibh) * h(21-dpg) -0.0001022
Selected 12 of 21 terms, and 9 of 9 predictors
Termination condition: Reached nk 21
Importance: temp, humidity, ibt, doy, ibh, dpg, vis, wind, vh
Number of terms at each degree of interaction: 1 5 6
GCV 13.40805 RSS 3693.401 GRSq 0.7917216 RSq 0.825085
> plotmo(a, trace=0, caption="getdata earth test9")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
>
> # test the way plotmo gets the data with lm
> se <- ozone1
> a <- lm(O3 ~ ., data=se)
> printh(summary(a))
===summary(a)
Call:
lm(formula = O3 ~ ., data = se)
Residuals:
Min 1Q Median 3Q Max
-12.1011 -2.9289 -0.2715 2.7080 13.3687
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 20.3135755 29.5193067 0.688 0.49186
vh -0.0054271 0.0053985 -1.005 0.31551
wind -0.0545832 0.1348425 -0.405 0.68590
humidity 0.0809741 0.0188394 4.298 2.29e-05 ***
temp 0.2755492 0.0497912 5.534 6.52e-08 ***
ibh -0.0002338 0.0002956 -0.791 0.42944
dpg -0.0033629 0.0112805 -0.298 0.76581
ibt 0.0296411 0.0136088 2.178 0.03013 *
vis -0.0079910 0.0037503 -2.131 0.03387 *
doy -0.0091194 0.0027745 -3.287 0.00113 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.441 on 320 degrees of freedom
Multiple R-squared: 0.7012, Adjusted R-squared: 0.6927
F-statistic: 83.42 on 9 and 320 DF, p-value: < 2.2e-16
> plotmo(a, trace=0, caption="getdata lm test1")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- lm(O3 ~ ., data=se, x=1)
> printh(summary(a))
===summary(a)
Call:
lm(formula = O3 ~ ., data = se, x = 1)
Residuals:
Min 1Q Median 3Q Max
-12.1011 -2.9289 -0.2715 2.7080 13.3687
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 20.3135755 29.5193067 0.688 0.49186
vh -0.0054271 0.0053985 -1.005 0.31551
wind -0.0545832 0.1348425 -0.405 0.68590
humidity 0.0809741 0.0188394 4.298 2.29e-05 ***
temp 0.2755492 0.0497912 5.534 6.52e-08 ***
ibh -0.0002338 0.0002956 -0.791 0.42944
dpg -0.0033629 0.0112805 -0.298 0.76581
ibt 0.0296411 0.0136088 2.178 0.03013 *
vis -0.0079910 0.0037503 -2.131 0.03387 *
doy -0.0091194 0.0027745 -3.287 0.00113 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.441 on 320 degrees of freedom
Multiple R-squared: 0.7012, Adjusted R-squared: 0.6927
F-statistic: 83.42 on 9 and 320 DF, p-value: < 2.2e-16
> plotmo(a, trace=0, caption="getdata lm test2")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- lm(O3 ~ ., data=se, y=1)
> printh(summary(a))
===summary(a)
Call:
lm(formula = O3 ~ ., data = se, y = 1)
Residuals:
Min 1Q Median 3Q Max
-12.1011 -2.9289 -0.2715 2.7080 13.3687
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 20.3135755 29.5193067 0.688 0.49186
vh -0.0054271 0.0053985 -1.005 0.31551
wind -0.0545832 0.1348425 -0.405 0.68590
humidity 0.0809741 0.0188394 4.298 2.29e-05 ***
temp 0.2755492 0.0497912 5.534 6.52e-08 ***
ibh -0.0002338 0.0002956 -0.791 0.42944
dpg -0.0033629 0.0112805 -0.298 0.76581
ibt 0.0296411 0.0136088 2.178 0.03013 *
vis -0.0079910 0.0037503 -2.131 0.03387 *
doy -0.0091194 0.0027745 -3.287 0.00113 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.441 on 320 degrees of freedom
Multiple R-squared: 0.7012, Adjusted R-squared: 0.6927
F-statistic: 83.42 on 9 and 320 DF, p-value: < 2.2e-16
> plotmo(a, trace=0, caption="getdata lm test3")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- lm(O3 ~ ., data=se, x=1, y=1)
> printh(summary(a))
===summary(a)
Call:
lm(formula = O3 ~ ., data = se, x = 1, y = 1)
Residuals:
Min 1Q Median 3Q Max
-12.1011 -2.9289 -0.2715 2.7080 13.3687
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 20.3135755 29.5193067 0.688 0.49186
vh -0.0054271 0.0053985 -1.005 0.31551
wind -0.0545832 0.1348425 -0.405 0.68590
humidity 0.0809741 0.0188394 4.298 2.29e-05 ***
temp 0.2755492 0.0497912 5.534 6.52e-08 ***
ibh -0.0002338 0.0002956 -0.791 0.42944
dpg -0.0033629 0.0112805 -0.298 0.76581
ibt 0.0296411 0.0136088 2.178 0.03013 *
vis -0.0079910 0.0037503 -2.131 0.03387 *
doy -0.0091194 0.0027745 -3.287 0.00113 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.441 on 320 degrees of freedom
Multiple R-squared: 0.7012, Adjusted R-squared: 0.6927
F-statistic: 83.42 on 9 and 320 DF, p-value: < 2.2e-16
> plotmo(a, trace=0, caption="getdata lm test3")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> a <- lm(O3 ~ ., data=se, x=0, y=1, model=F)
> se <- 99
> expect.err(try(plotmo(a, trace=0, caption="getdata lm test4")), "cannot get the original model predictors")
Looked unsuccessfully for the original predictors in the following places:
(1) object$x: NULL
(2) model.frame: object 'O3' not found
(3) getCall(object)$x: less than three rows
Error : cannot get the original model predictors
Got error as expected from try(plotmo(a, trace = 0, caption = "getdata lm test4"))
> se <- ozone1
> a <- lm(O3 ~ ., data=se, x=1, y=1)
> se <- 77
> printh(summary(a))
===summary(a)
Call:
lm(formula = O3 ~ ., data = se, x = 1, y = 1)
Residuals:
Min 1Q Median 3Q Max
-12.1011 -2.9289 -0.2715 2.7080 13.3687
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 20.3135755 29.5193067 0.688 0.49186
vh -0.0054271 0.0053985 -1.005 0.31551
wind -0.0545832 0.1348425 -0.405 0.68590
humidity 0.0809741 0.0188394 4.298 2.29e-05 ***
temp 0.2755492 0.0497912 5.534 6.52e-08 ***
ibh -0.0002338 0.0002956 -0.791 0.42944
dpg -0.0033629 0.0112805 -0.298 0.76581
ibt 0.0296411 0.0136088 2.178 0.03013 *
vis -0.0079910 0.0037503 -2.131 0.03387 *
doy -0.0091194 0.0027745 -3.287 0.00113 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.441 on 320 degrees of freedom
Multiple R-squared: 0.7012, Adjusted R-squared: 0.6927
F-statistic: 83.42 on 9 and 320 DF, p-value: < 2.2e-16
> plotmo(a, trace=0, caption="getdata lm test5")
plotmo grid: vh wind humidity temp ibh dpg ibt vis doy
5760 5 64 62 2112.5 24 167.5 120 205.5
> se <- ozone1
> a <- lm(O3 ~ ., data=se, model=F)
> se$wind <- NULL
> expect.err(try(plotmo(a, trace=0, caption="getdata lm test6")), "cannot get the original model predictors")
Looked unsuccessfully for the original predictors in the following places:
(1) object$x: NULL
(2) model.frame: object 'wind' not found
(3) getCall(object)$x: NULL
Error : cannot get the original model predictors
Got error as expected from try(plotmo(a, trace = 0, caption = "getdata lm test6"))
>
> cat("test fixed.point warning in print.summary.earth\n")
test fixed.point warning in print.summary.earth
> options(digits=3)
> et <- etitanic
> et$age <- 1000 * et$age
> a <- earth(survived~., data=et)
> print(summary(a))
Call: earth(formula=survived~., data=et)
coefficients
(Intercept) 1.0258
pclass2nd -0.2165
pclass3rd -0.3552
sexmale -0.4903
h(11000-age) 0.0000
h(age-11000) 0.0000
h(sibsp-1) -0.0926
Selected 7 of 10 terms, and 5 of 6 predictors
Termination condition: RSq changed by less than 0.001 at 10 terms
Importance: sexmale, pclass3rd, age, pclass2nd, sibsp, parch-unused
Number of terms at each degree of interaction: 1 6 (additive model)
GCV 0.152 RSS 155 GRSq 0.372 RSq 0.386
> print(summary(a, fixed.point=FALSE))
Call: earth(formula=survived~., data=et)
coefficients
(Intercept) 1.03e+00
pclass2nd -2.17e-01
pclass3rd -3.55e-01
sexmale -4.90e-01
h(11000-age) 2.92e-05
h(age-11000) -4.45e-06
h(sibsp-1) -9.26e-02
Selected 7 of 10 terms, and 5 of 6 predictors
Termination condition: RSq changed by less than 0.001 at 10 terms
Importance: sexmale, pclass3rd, age, pclass2nd, sibsp, parch-unused
Number of terms at each degree of interaction: 1 6 (additive model)
GCV 0.152 RSS 155 GRSq 0.372 RSq 0.386
> options(digits=7) # back to default
>
> cat("--- summary earth with new data ----------------------\n")
--- summary earth with new data ----------------------
> a.trees <- earth(Volume~., data=trees)
> cat("summary(a.trees, newdata=trees)\n")
summary(a.trees, newdata=trees)
> print(summary(a.trees, newdata=trees))
RSq 0.974 on newdata (31 cases)
> cat("summary(a.trees, newdata=trees[1:5,])\n")
summary(a.trees, newdata=trees[1:5,])
> a.trees.summary <- print(summary(a.trees, newdata=trees[1:5,]))
RSq 0.919 on newdata (5 cases)
>
> a.xy.trees <- earth(trees[,1:2], trees[,3])
> cat("summary(a.xy.trees, newdata=trees[1:5,])\n")
summary(a.xy.trees, newdata=trees[1:5,])
> a.xy.trees.summary <- print(summary(a.xy.trees, newdata=trees[1:5,]))
Assuming response trees[,3] implies that the response column is 3
RSq 0.919 on newdata (5 cases)
> stopifnot(a.xy.trees.summary$newrsq == a.trees.summary$newrsq)
>
> a.xy1.trees <- earth(trees[,1:2], trees$Volume)
> cat("summary(a.xy1.trees, newdata=trees[1:5,])\n")
summary(a.xy1.trees, newdata=trees[1:5,])
> a.xy1.trees.summary <- print(summary(a.xy1.trees, newdata=trees[1:5,]))
RSq 0.919 on newdata (5 cases)
> stopifnot(a.xy1.trees.summary$newrsq == a.trees.summary$newrsq)
>
> cat("--- ../../tests/test.earth.R -------------------------\n")
--- ../../tests/test.earth.R -------------------------
>
> options(options.old)
> source("../../tests/test.earth.R")
Call: earth(formula=Volume~., data=trees)
coefficients
(Intercept) 29.060
h(14.2-Girth) -3.420
h(Girth-14.2) 6.230
h(Height-75) 0.581
Selected 4 of 5 terms, and 2 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: Girth, Height
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 11.3 RSS 209 GRSq 0.96 RSq 0.974
Call: earth(formula=Volume~., data=trees, allowed=allowed.func)
coefficients
(Intercept) 30.66
h(14.2-Girth) -3.57
h(Girth-14.2) 6.76
Selected 3 of 3 terms, and 1 of 2 predictors
Termination condition: RSq changed by less than 0.001 at 3 terms
Importance: Girth, Height-unused
Number of terms at each degree of interaction: 1 2 (additive model)
GCV 14.3 RSS 313 GRSq 0.949 RSq 0.961
>
> cat("--- check that spurious warn gone: non-integer #successes in a binomial glm ---\n")
--- check that spurious warn gone: non-integer #successes in a binomial glm ---
>
> library(segmented) # for down data
> data(down)
> fit.e <- earth(cases/births~age, data=down, weights=down$births, glm=list(family="binomial"))
> print(summary(fit.e))
Call: earth(formula=cases/births~age, data=down, weights=down$births,
glm=list(family="binomial"))
GLM coefficients
cases/births
(Intercept) -6.943
h(age-36.5) 0.709
h(age-39.5) -0.484
Earth selected 3 of 5 terms, and 1 of 1 predictors
Termination condition: RSq changed by less than 0.001 at 5 terms
Importance: age
Weights: 13555, 13675, 18752, 22005, 23896, 24667, 24807, 23986, 22860, ...
Number of terms at each degree of interaction: 1 2 (additive model)
Earth GCV 0.0124 RSS 0.259 GRSq 0.867 RSq 0.901
GLM (family binomial, link logit):
nulldev df dev df devratio AIC iters converged
625 29 69.6 27 0.89 214 4 1
>
> # test nk=1, 2, and 3
> cat("nk=1\n")
nk=1
> par(mfrow = c(2, 2), mar = c(3, 3, 3, 1), mgp = c(1.5, 0.5, 0))
> a.nk1 <- earth(Volume~., data=trees, nk=1)
> plot(a.nk1, which=1, main="nk=1")
> print(a.nk1)
Selected 1 of 1 terms, and 0 of 2 predictors
Termination condition: Reached nk 1
Importance: Girth-unused, Height-unused
Number of terms at each degree of interaction: 1 (intercept only model)
GCV 279 RSS 8106 GRSq 0 RSq 0
> cat("nk=2\n")
nk=2
> a.nk2 <- earth(Volume~., data=trees, nk=2)
> print(summary(a.nk2))
Call: earth(formula=Volume~., data=trees, nk=2)
coefficients
(Intercept) 30.2
Selected 1 of 1 terms, and 0 of 2 predictors
Termination condition: Reached nk 2
Importance: Girth-unused, Height-unused
Number of terms at each degree of interaction: 1 (intercept only model)
GCV 279 RSS 8106 GRSq 0 RSq 0
> plot(a.nk2, which=1, main="nk=2")
> cat("nk=3\n")
nk=3
> a.nk3 <- earth(Volume~., data=trees, nk=3)
> plot(a.nk3, which=1, main="nk=3")
>
> cat("\ntest model.matrix.earth\n")
test model.matrix.earth
>
> check.model.matrix <- function(msg, xnew, bx1, bx2)
+ {
+ cat("check.model.matrix", msg, ":\n")
+ print(xnew)
+ if(!identical(bx1, bx2)) {
+ cat("\nnot identical\n")
+ cat(deparse(substitute(bx1)), ":\n", sep="")
+ print(bx1)
+ cat(deparse(substitute(bx2)), ":\n", sep="")
+ print(bx2)
+ stop("check.model.matrix ", msg, " failed")
+ }
+ }
>
> data(trees)
> earth.trees.formula <- earth(Volume ~ ., data=trees, subset=1:20)
> bx <- model.matrix(earth.trees.formula)
> check.model.matrix("earth.trees.formula formula 1", NULL, bx, earth.trees.formula$bx)
check.model.matrix earth.trees.formula formula 1 :
NULL
>
> # nprune so only Girth is used, not Height
> earth.girth.formula <- earth(Volume ~ ., data=trees, nprune=3)
>
> # model.matrix where xnew is a data.frame
>
> xnew <- trees[,1:2]
> bx <- model.matrix(earth.girth.formula, xnew)
> lm.mod <- lm(trees$Volume ~ bx[,-1]) # -1 to drop intercept
> stopifnot(coef(earth.girth.formula) == coef(lm.mod))
>
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.formula, xnew)
> lm.mod2 <- lm(trees$Volume ~ bx[,-1])
> stopifnot(coef(earth.girth.formula) == coef(lm.mod2))
>
> xnew <- data.frame(Girth=c(8.3, 8.6), Height=c(70, 65))
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 2", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 2 :
Girth Height
1 8.3 70
2 8.6 65
>
> # test what happens when variables are missing
> predict.girth.height <- predict(earth.girth.formula, xnew)
> predict.girth <- predict(earth.girth.formula, newdata=data.frame(Girth=c(8.3, 8.6)))
> stopifnot(all.equal(predict.girth.height, predict.girth))
> predict.height <- predict(earth.girth.formula, newdata=data.frame(Height=c(70, 65)))
> stopifnot(all(is.na(predict.height)))
>
> xnew <- trees[1:2,]
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 3", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 3 :
Girth Height Volume
1 8.3 70 10.3
2 8.6 65 10.3
>
> xnew <- trees[1:2,1:2] # exclude Volume column
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 4", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 4 :
1 8.3 70
2 8.6 65
>
> xnew <- trees[1:2,3:1] # change order of columns
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 5", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 5 :
Volume Height Girth
1 10.3 70 8.3
2 10.3 65 8.6
>
> xnew <- trees[1:2,1,drop=FALSE] # include only Girth
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 6", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 6 :
Girth
1 8.3
2 8.6
>
> xnew <- trees[1,2:1]
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 7", xnew, bx, earth.girth.formula$bx[1,,drop=FALSE])
check.model.matrix earth.girth.formula formula 7 :
Height Girth
1 70 8.3
>
> xnew <- trees[1,1:2]
> names(xnew) <- NULL
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 8", xnew, bx, earth.girth.formula$bx[1,,drop=FALSE])
check.model.matrix earth.girth.formula formula 8 :
1 8.3 70
>
> # model.matrix where xnew is a matrix (same as above code but with as.matrix)
>
> xnew <- as.matrix(trees[,1:2])
> bx <- model.matrix(earth.girth.formula, xnew)
> lm.mod <- lm(trees$Volume ~ bx[,-1]) # -1 to drop intercept
> stopifnot(coef(earth.girth.formula) == coef(lm.mod))
>
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.formula, xnew)
> lm.mod2 <- lm(trees$Volume ~ bx[,-1])
> stopifnot(coef(earth.girth.formula) == coef(lm.mod2))
>
> xnew <- as.matrix(data.frame(Girth=c(8.3, 8.6), Height=c(70, 65)))
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 9", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 9 :
Girth Height
[1,] 8.3 70
[2,] 8.6 65
>
> xnew <- as.matrix(trees[1:2,])
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 10", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 10 :
Girth Height Volume
1 8.3 70 10.3
2 8.6 65 10.3
>
> xnew <- as.matrix(trees[1:2,1:2]) # exclude Volume column
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 11", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 11 :
[,1] [,2]
1 8.3 70
2 8.6 65
>
> xnew <- as.matrix(trees[1:2,3:1]) # change order of columns
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 12", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 12 :
Volume Height Girth
1 10.3 70 8.3
2 10.3 65 8.6
>
> xnew <- as.matrix(trees[1:2,1,drop=FALSE]) # include only Girth
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 13", xnew, bx, earth.girth.formula$bx[1:2,])
check.model.matrix earth.girth.formula formula 13 :
Girth
1 8.3
2 8.6
>
> xnew <- as.matrix(trees[1,2:1])
> bx <- model.matrix(earth.girth.formula, xnew, trace=2)
get.earth.x from model.matrix.earth: x columns are in the wrong order, correcting the column order
Old columns: Height Girth
New columns: Girth Height
get.earth.x from model.matrix.earth: x[1,2]:
Girth Height
1 8.3 70
get.earth.x from model.matrix.earth: after call to model.frame: data[1,2]:
Girth Height
1 8.3 70
> check.model.matrix("earth.girth.formula formula 14", xnew, bx, earth.girth.formula$bx[1,,drop=FALSE])
check.model.matrix earth.girth.formula formula 14 :
Height Girth
1 70 8.3
>
> xnew <- as.matrix(trees[3,1:2])
> names(xnew) <- NULL
> bx <- model.matrix(earth.girth.formula, xnew)
> check.model.matrix("earth.girth.formula formula 15", xnew, bx, earth.girth.formula$bx[3,,drop=FALSE])
check.model.matrix earth.girth.formula formula 15 :
Girth Height
3 8.8 63
>
> #--- model.matrix with an x,y model
>
> data(trees)
> earth.trees.xy.subset <- earth(trees[,1:2], trees[,3], subset=1:20)
> bx <- model.matrix(earth.trees.xy.subset)
> check.model.matrix("earth.trees.xy.subset x,y 1", NULL, bx, earth.trees.xy.subset$bx)
check.model.matrix earth.trees.xy.subset x,y 1 :
NULL
>
> # nprune so only Girth is used, not Height
> earth.girth.xy <- earth(trees[,1:2], trees[,3], nprune=3)
>
> # model.matrix where xnew is a data.frame
>
> xnew <- trees[,1:2]
> bx <- model.matrix(earth.girth.xy, xnew)
> lm.mod <- lm(trees$Volume ~ bx[,-1]) # -1 to drop intercept
> stopifnot(coef(earth.girth.xy) == coef(lm.mod))
>
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.xy, xnew)
> lm.mod2 <- lm(trees$Volume ~ bx[,-1])
> stopifnot(coef(earth.girth.xy) == coef(lm.mod2))
>
> xnew <- data.frame(Girth=c(8.3, 8.6), Height=c(70, 65))
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 2", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 2 :
Girth Height
1 8.3 70
2 8.6 65
>
> # test what happens when variables are missing
> predict.girth.height <- predict(earth.girth.xy, xnew)
> predict.girth <- predict(earth.girth.xy, newdata=data.frame(Girth=c(8.3, 8.6)))
> stopifnot(all.equal(predict.girth.height, predict.girth))
> predict.height <- predict(earth.girth.xy, newdata=data.frame(Height=c(70, 65)))
> stopifnot(all(is.na(predict.height)))
>
> xnew <- trees[1:2,]
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 3", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 3 :
Girth Height Volume
1 8.3 70 10.3
2 8.6 65 10.3
>
> xnew <- trees[1:2,1:2] # exclude Volume column
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 4", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 4 :
1 8.3 70
2 8.6 65
>
> # # TODO fails
> # xnew <- trees[1:2,3:1] # change order of columns
> # bx <- model.matrix(earth.girth.xy, xnew)
> # check.model.matrix("earth.girth.xy x,y 5", xnew, bx, earth.girth.xy$bx[1:2,])
>
> xnew <- trees[1:2,1,drop=FALSE] # include only Girth
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 6", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 6 :
Girth
1 8.3
2 8.6
>
> xnew <- trees[1,2:1]
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 7", xnew, bx, earth.girth.xy$bx[1,,drop=FALSE])
check.model.matrix earth.girth.xy x,y 7 :
Height Girth
1 70 8.3
>
> xnew <- trees[1,1:2]
> names(xnew) <- NULL
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 8", xnew, bx, earth.girth.xy$bx[1,,drop=FALSE])
check.model.matrix earth.girth.xy x,y 8 :
1 8.3 70
>
> # model.matrix where xnew is a matrix (same as above code but with as.matrix)
>
> xnew <- as.matrix(trees[,1:2])
> bx <- model.matrix(earth.girth.xy, xnew)
> lm.mod <- lm(trees$Volume ~ bx[,-1]) # -1 to drop intercept
> stopifnot(coef(earth.girth.xy) == coef(lm.mod))
>
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.xy, xnew)
> lm.mod2 <- lm(trees$Volume ~ bx[,-1])
> stopifnot(coef(earth.girth.xy) == coef(lm.mod2))
>
> xnew <- as.matrix(data.frame(Girth=c(8.3, 8.6), Height=c(70, 65)))
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 9", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 9 :
Girth Height
[1,] 8.3 70
[2,] 8.6 65
>
> xnew <- as.matrix(trees[1:2,])
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 10", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 10 :
Girth Height Volume
1 8.3 70 10.3
2 8.6 65 10.3
>
> xnew <- as.matrix(trees[1:2,1:2]) # exclude Volume column
> colnames(xnew) <- NULL
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 11", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 11 :
[,1] [,2]
1 8.3 70
2 8.6 65
>
> # # TODO fails
> # xnew <- as.matrix(trees[1:2,3:1]) # change order of columns
> # bx <- model.matrix(earth.girth.xy, xnew)
> # check.model.matrix("earth.girth.xy x,y 12", xnew, bx, earth.girth.xy$bx[1:2,])
>
> xnew <- as.matrix(trees[1:2,1,drop=FALSE]) # include only Girth
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 13", xnew, bx, earth.girth.xy$bx[1:2,])
check.model.matrix earth.girth.xy x,y 13 :
Girth
1 8.3
2 8.6
>
> xnew <- as.matrix(trees[1,2:1])
> bx <- model.matrix(earth.girth.xy, xnew, trace=2)
get.earth.x from model.matrix.earth: x columns are in the wrong order, correcting the column order
Old columns: Height Girth
New columns: Girth Height
get.earth.x from model.matrix.earth: x[1,2]:
Girth Height
1 8.3 70
> check.model.matrix("earth.girth.xy x,y 14", xnew, bx, earth.girth.xy$bx[1,,drop=FALSE])
check.model.matrix earth.girth.xy x,y 14 :
Height Girth
1 70 8.3
>
> xnew <- as.matrix(trees[3,1:2])
> names(xnew) <- NULL
> bx <- model.matrix(earth.girth.xy, xnew)
> check.model.matrix("earth.girth.xy x,y 15", xnew, bx, earth.girth.xy$bx[3,,drop=FALSE])
check.model.matrix earth.girth.xy x,y 15 :
Girth Height
3 8.8 63
>
> cat("--- compare backward, none, exhaustive, forward, seqrep ---------------------\n")
--- compare backward, none, exhaustive, forward, seqrep ---------------------
> data(ozone1)
> oz <- ozone1[1:50,]
> cat("--mod.none\n")
--mod.none
> mod.none <- earth(O3~., data=oz, degree=2, trace=4, pmethod="none")
Call: earth(formula=O3~., data=oz, pmethod="none", trace=4, degree=2)
x[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
50 5640 5 68 50 5000 24 56 300 84
y[50,1]:
O3
1 3
2 5
3 5
... 6
50 6
Forward pass: minspan 5 endspan 10 x[50,9] 3.52 kB bx[50,21] 8.2 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0507 0.2345 0.2345 7 ibt 174 2 3 1
4 0.1107 0.4367 0.2021 9 doy 45 4 5 1
6 0.1332 0.5826 0.146 3 humidity 28 6 7 1
8 0.0724 0.6751 0.09244 1 vh 5720 8 9 1
10 0.1641 0.7555 0.08043 1 vh 5350< 10 6 2
12 0.1705 0.8010 0.04548 9 doy 61 11 1
14 -0.0529 0.8417 0.04069 2 wind 4 12 13 1
16 -0.1680 0.8676 0.02587 4 temp 30< 14 5 2
18 -1.0243 0.8885 0.02094 6 dpg -2 15 16 1
20 -4.1102 0.9101 0.02157 4 temp 51 17 18 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq -4.110 RSq 0.910
Forward pass complete: 21 terms, 18 terms used
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 -0.0643 0.0415 -0.0643 1 1 2
3 0.3274 0.4577 0.3917 2 1 6 10
4 0.2845 0.4867 -0.0429 3 1 4 6 10
5 0.4261 0.6365 0.1417 3 1 4 6 10 11
6 0.4967 0.7207 0.0706 3 1 4 6 9 10 11
7 0.5304 0.7739 0.0337 4 1 4 6 9 10 11 13
8 0.5260 0.8041 -0.0044 5 1 4 6 9 10 11 13 15
9 0.4962 0.8235 -0.0298 5 1 4 6 9 10 11 13 15 16
10 0.4844 0.8492 -0.0119 5 1 4 6 8 9 10 11 13 15 16
11 0.4031 0.8568 -0.0813 6 1 4 6 8 9 10 11 13 14 15 16
12 0.2946 0.8642 -0.1085 6 1 4 5 6 8 9 10 11 13 14 15 16
13 0.1833 0.8772 -0.1113 6 1 4 5 6 8 9 10 11 13 14 15 16 18
14 0.0300 0.8900 -0.1533 6 1 4 5 6 8 9 10 11 13 14 15 16 17 18
15 -0.2295 0.8996 -0.2595 6 1 4 5 6 7 8 9 10 11 13 14 15 16 17 18
16 -0.7245 0.9050 -0.4950 6 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
17 -1.7229 0.9081 -0.9984 7 1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
chosen 18 -4.1102 0.9101 -2.3873 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prune method "none" penalty 3 nprune null: selected 18 of 18 terms, and 7 of 9 preds
After pruning pass GRSq -4.11 RSq 0.91
> print(summary(mod.none))
Call: earth(formula=O3~., data=oz, pmethod="none", trace=4, degree=2)
coefficients
(Intercept) 5.325
h(5720-vh) 0.041
h(vh-5720) 0.024
h(4-wind) 1.482
h(wind-4) 0.155
h(28-humidity) -0.139
h(humidity-28) -7.705
h(51-temp) -0.132
h(temp-51) -0.104
h(-2-dpg) -0.033
h(dpg- -2) -0.023
h(174-ibt) -0.006
h(ibt-174) -0.013
h(45-doy) 1.279
h(doy-45) 0.173
h(doy-61) -0.268
vh * h(humidity-28) 0.001
temp * h(45-doy) -0.030
Selected 18 of 18 terms, and 7 of 9 predictors (pmethod="none")
Termination condition: Reached nk 21
Importance: vh, humidity, doy, wind, dpg, temp, ibt, ibh-unused, ...
Number of terms at each degree of interaction: 1 15 2
GCV 35 RSS 29.6 GRSq -4.11 RSq 0.91
> cat("--mod.backward\n")
--mod.backward
> mod.backward <- earth(O3~., data=oz, degree=2, trace=4, pmethod="backward")
Call: earth(formula=O3~., data=oz, pmethod="backward", trace=4, degree=2)
x[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
50 5640 5 68 50 5000 24 56 300 84
y[50,1]:
O3
1 3
2 5
3 5
... 6
50 6
Forward pass: minspan 5 endspan 10 x[50,9] 3.52 kB bx[50,21] 8.2 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0507 0.2345 0.2345 7 ibt 174 2 3 1
4 0.1107 0.4367 0.2021 9 doy 45 4 5 1
6 0.1332 0.5826 0.146 3 humidity 28 6 7 1
8 0.0724 0.6751 0.09244 1 vh 5720 8 9 1
10 0.1641 0.7555 0.08043 1 vh 5350< 10 6 2
12 0.1705 0.8010 0.04548 9 doy 61 11 1
14 -0.0529 0.8417 0.04069 2 wind 4 12 13 1
16 -0.1680 0.8676 0.02587 4 temp 30< 14 5 2
18 -1.0243 0.8885 0.02094 6 dpg -2 15 16 1
20 -4.1102 0.9101 0.02157 4 temp 51 17 18 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq -4.110 RSq 0.910
Forward pass complete: 21 terms, 18 terms used
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 -0.0643 0.0415 -0.0643 1 1 2
3 0.3274 0.4577 0.3917 2 1 6 10
4 0.2845 0.4867 -0.0429 3 1 4 6 10
5 0.4261 0.6365 0.1417 3 1 4 6 10 11
6 0.4967 0.7207 0.0706 3 1 4 6 9 10 11
chosen 7 0.5304 0.7739 0.0337 4 1 4 6 9 10 11 13
8 0.5260 0.8041 -0.0044 5 1 4 6 9 10 11 13 15
9 0.4962 0.8235 -0.0298 5 1 4 6 9 10 11 13 15 16
10 0.4844 0.8492 -0.0119 5 1 4 6 8 9 10 11 13 15 16
11 0.4031 0.8568 -0.0813 6 1 4 6 8 9 10 11 13 14 15 16
12 0.2946 0.8642 -0.1085 6 1 4 5 6 8 9 10 11 13 14 15 16
13 0.1833 0.8772 -0.1113 6 1 4 5 6 8 9 10 11 13 14 15 16 18
14 0.0300 0.8900 -0.1533 6 1 4 5 6 8 9 10 11 13 14 15 16 17 18
15 -0.2295 0.8996 -0.2595 6 1 4 5 6 7 8 9 10 11 13 14 15 16 17 18
16 -0.7245 0.9050 -0.4950 6 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
17 -1.7229 0.9081 -0.9984 7 1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
18 -4.1102 0.9101 -2.3873 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prune method "backward" penalty 3 nprune null: selected 7 of 18 terms, and 4 of 9 preds
After pruning pass GRSq 0.53 RSq 0.774
> print(summary(mod.backward))
Call: earth(formula=O3~., data=oz, pmethod="backward", trace=4, degree=2)
coefficients
(Intercept) 3.446
h(5720-vh) 0.041
h(4-wind) 1.108
h(humidity-28) -8.941
h(doy-45) 0.204
h(doy-61) -0.334
vh * h(humidity-28) 0.002
Selected 7 of 18 terms, and 4 of 9 predictors
Termination condition: Reached nk 21
Importance: vh, humidity, doy, wind, ibt-unused, temp-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 5 1
GCV 3.22 RSS 74.4 GRSq 0.53 RSq 0.774
> cat("--mod.forward\n")
--mod.forward
> mod.forward <- earth(O3~., data=oz, degree=2, trace=4, pmethod="forward")
Call: earth(formula=O3~., data=oz, pmethod="forward", trace=4, degree=2)
x[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
50 5640 5 68 50 5000 24 56 300 84
y[50,1]:
O3
1 3
2 5
3 5
... 6
50 6
Forward pass: minspan 5 endspan 10 x[50,9] 3.52 kB bx[50,21] 8.2 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0507 0.2345 0.2345 7 ibt 174 2 3 1
4 0.1107 0.4367 0.2021 9 doy 45 4 5 1
6 0.1332 0.5826 0.146 3 humidity 28 6 7 1
8 0.0724 0.6751 0.09244 1 vh 5720 8 9 1
10 0.1641 0.7555 0.08043 1 vh 5350< 10 6 2
12 0.1705 0.8010 0.04548 9 doy 61 11 1
14 -0.0529 0.8417 0.04069 2 wind 4 12 13 1
16 -0.1680 0.8676 0.02587 4 temp 30< 14 5 2
18 -1.0243 0.8885 0.02094 6 dpg -2 15 16 1
20 -4.1102 0.9101 0.02157 4 temp 51 17 18 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq -4.110 RSq 0.910
Forward pass complete: 21 terms, 18 terms used
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 0.1478 0.2325 0.1478 1 1 3
3 0.2867 0.4248 0.1389 2 1 3 4
chosen 4 0.4118 0.5781 0.1251 3 1 3 4 7
5 0.3946 0.6165 -0.0172 4 1 3 4 7 13
6 0.3715 0.6513 -0.0231 5 1 3 4 7 13 16
7 0.3424 0.6834 -0.0292 6 1 3 4 7 13 16 9
8 0.2960 0.7091 -0.0463 7 1 3 4 7 13 16 9 14
9 0.2253 0.7287 -0.0707 7 1 3 4 7 13 16 9 14 5
10 0.1641 0.7555 -0.0612 4 1 2 3 4 5 6 7 8 9 10
11 0.1705 0.8010 0.0064 4 1 2 3 4 5 6 7 8 9 10 11
12 -0.0334 0.8010 -0.2039 5 1 2 3 4 5 6 7 8 9 10 11 12
13 0.0121 0.8515 0.0455 7 1 3 4 7 13 16 9 14 5 8 15 10 6
14 -0.0753 0.8781 -0.0874 7 1 3 4 7 13 16 9 14 5 8 15 10 6 11
15 -0.3788 0.8874 -0.3035 7 1 3 4 7 13 16 9 14 5 8 15 10 6 11 17
16 -0.8136 0.9001 -0.4348 7 1 3 4 7 13 16 9 14 5 8 15 10 6 11 17 18
17 -1.7890 0.9059 -0.9754 7 1 3 4 7 13 16 9 14 5 8 15 10 6 11 17 18 12
18 -4.1102 0.9101 -2.3212 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prune method "forward" penalty 3 nprune null: selected 4 of 18 terms, and 3 of 9 preds
After pruning pass GRSq 0.412 RSq 0.578
> print(summary(mod.forward))
Call: earth(formula=O3~., data=oz, pmethod="forward", trace=4, degree=2)
coefficients
(Intercept) 7.496
h(28-humidity) -0.266
h(174-ibt) -0.046
h(doy-45) 0.110
Selected 4 of 18 terms, and 3 of 9 predictors
Termination condition: Reached nk 21
Importance: ibt, doy, humidity, vh-unused, wind-unused, temp-unused, ...
Number of terms at each degree of interaction: 1 3 (additive model)
GCV 4.03 RSS 139 GRSq 0.412 RSq 0.578
> cat("--mod.exhaustive\n")
--mod.exhaustive
> mod.exhaustive <- earth(O3~., data=oz, degree=2, trace=4, pmethod="exhaustive")
Call: earth(formula=O3~., data=oz, pmethod="exhaustive", trace=4, degree=2)
x[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
50 5640 5 68 50 5000 24 56 300 84
y[50,1]:
O3
1 3
2 5
3 5
... 6
50 6
Forward pass: minspan 5 endspan 10 x[50,9] 3.52 kB bx[50,21] 8.2 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0507 0.2345 0.2345 7 ibt 174 2 3 1
4 0.1107 0.4367 0.2021 9 doy 45 4 5 1
6 0.1332 0.5826 0.146 3 humidity 28 6 7 1
8 0.0724 0.6751 0.09244 1 vh 5720 8 9 1
10 0.1641 0.7555 0.08043 1 vh 5350< 10 6 2
12 0.1705 0.8010 0.04548 9 doy 61 11 1
14 -0.0529 0.8417 0.04069 2 wind 4 12 13 1
16 -0.1680 0.8676 0.02587 4 temp 30< 14 5 2
18 -1.0243 0.8885 0.02094 6 dpg -2 15 16 1
20 -4.1102 0.9101 0.02157 4 temp 51 17 18 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq -4.110 RSq 0.910
Forward pass complete: 21 terms, 18 terms used
Exhaustive pruning: number of subsets 262143 bx sing val ratio 6.6e-07
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 0.1478 0.2325 0.1478 1 1 3
3 0.3274 0.4577 0.1796 2 1 6 10
4 0.4118 0.5781 0.0844 3 1 4 7 3
5 0.4261 0.6365 0.0143 3 1 6 11 4 10
6 0.4967 0.7207 0.0706 3 1 6 9 4 11 10
chosen 7 0.5304 0.7739 0.0337 4 1 6 9 4 11 10 13
8 0.5260 0.8041 -0.0044 5 1 6 15 11 10 13 9 4
9 0.4962 0.8235 -0.0298 5 1 6 15 11 10 13 9 16 4
10 0.4844 0.8492 -0.0119 5 1 6 8 13 15 10 11 4 16 9
11 0.4031 0.8568 -0.0813 6 1 14 16 15 6 13 4 10 9 8 11
12 0.3006 0.8654 -0.1025 6 1 14 16 15 6 13 4 10 9 8 11 17
13 0.1833 0.8772 -0.1174 6 1 14 16 15 6 13 4 10 9 18 11 5 8
14 0.0300 0.8900 -0.1533 6 1 14 16 15 6 13 4 10 9 18 17 8 11 5
15 -0.2295 0.8996 -0.2595 6 1 14 16 15 6 13 4 10 9 18 17 8 7 5 11
16 -0.7245 0.9050 -0.4950 6 1 14 16 15 6 13 4 10 9 18 17 8 7 5 12 11
17 -1.7229 0.9081 -0.9984 7 1 2 11 6 8 12 18 9 14 7 13 10 15 17 5 16 4
18 -4.1102 0.9101 -2.3873 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prune method "exhaustive" penalty 3 nprune null: selected 7 of 18 terms, and 4 of 9 preds
After pruning pass GRSq 0.53 RSq 0.774
> print(summary(mod.exhaustive))
Call: earth(formula=O3~., data=oz, pmethod="exhaustive", trace=4, degree=2)
coefficients
(Intercept) 3.446
h(5720-vh) 0.041
h(4-wind) 1.108
h(humidity-28) -8.941
h(doy-45) 0.204
h(doy-61) -0.334
vh * h(humidity-28) 0.002
Selected 7 of 18 terms, and 4 of 9 predictors
Termination condition: Reached nk 21
Importance: humidity, vh, doy, ibt-unused, wind, temp-unused, ibh-unused, ...
Number of terms at each degree of interaction: 1 5 1
GCV 3.22 RSS 74.4 GRSq 0.53 RSq 0.774
> cat("--mod.seqrep\n")
--mod.seqrep
> mod.seqrep <- earth(O3~., data=oz, degree=2, trace=4, pmethod="seqrep")
Call: earth(formula=O3~., data=oz, pmethod="seqrep", trace=4, degree=2)
x[50,9]:
vh wind humidity temp ibh dpg ibt vis doy
1 5710 4 28 40 2693 -25 87 250 33
2 5700 3 37 45 590 -24 128 100 34
3 5760 3 51 54 1450 25 139 60 35
... 5720 4 69 35 1568 15 121 60 36
50 5640 5 68 50 5000 24 56 300 84
y[50,1]:
O3
1 3
2 5
3 5
... 6
50 6
Forward pass: minspan 5 endspan 10 x[50,9] 3.52 kB bx[50,21] 8.2 kB
GRSq RSq DeltaRSq Pred PredName Cut Terms Par Deg
1 0.0000 0.0000 (Intercept)
2 0.0507 0.2345 0.2345 7 ibt 174 2 3 1
4 0.1107 0.4367 0.2021 9 doy 45 4 5 1
6 0.1332 0.5826 0.146 3 humidity 28 6 7 1
8 0.0724 0.6751 0.09244 1 vh 5720 8 9 1
10 0.1641 0.7555 0.08043 1 vh 5350< 10 6 2
12 0.1705 0.8010 0.04548 9 doy 61 11 1
14 -0.0529 0.8417 0.04069 2 wind 4 12 13 1
16 -0.1680 0.8676 0.02587 4 temp 30< 14 5 2
18 -1.0243 0.8885 0.02094 6 dpg -2 15 16 1
20 -4.1102 0.9101 0.02157 4 temp 51 17 18 1 final (reached nk 21)
Reached nk 21
After forward pass GRSq -4.110 RSq 0.910
Forward pass complete: 21 terms, 18 terms used
Subset size GRSq RSq DeltaGRSq nPreds Terms (col nbr in bx)
1 0.0000 0.0000 0.0000 0 1
2 0.1478 0.2325 0.1478 1 1 3
3 0.2867 0.4248 0.1389 2 1 3 4
4 0.4118 0.5781 0.1251 3 1 4 3 7
chosen 5 0.4131 0.6282 0.0013 4 1 13 3 4 16
6 0.3744 0.6528 -0.0388 5 1 16 13 4 3 9
7 0.1332 0.5826 -0.2412 3 1 2 3 4 5 6 7
8 0.2960 0.7091 0.1629 7 1 9 13 4 3 16 7 14
9 0.2253 0.7287 -0.0707 7 1 14 7 4 3 9 13 16 5
10 0.1641 0.7555 -0.0612 4 1 2 3 4 5 6 7 8 9 10
11 0.1705 0.8010 0.0064 4 1 2 3 4 5 6 7 8 9 10 11
12 0.1955 0.8451 0.0251 6 1 6 9 13 16 14 5 8 15 7 10 18
13 0.1833 0.8772 -0.0123 6 1 4 10 18 6 15 9 13 16 14 5 8 11
14 0.0300 0.8900 -0.1533 6 1 16 5 9 13 8 10 18 6 4 11 14 15 17
15 -0.5442 0.8739 -0.5742 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 -1.0243 0.8885 -0.4801 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 -1.7229 0.9081 -0.6986 7 1 17 5 9 13 8 10 18 6 4 11 14 15 16 7 12 2
18 -4.1102 0.9101 -2.3873 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prune method "seqrep" penalty 3 nprune null: selected 5 of 18 terms, and 4 of 9 preds
After pruning pass GRSq 0.413 RSq 0.628
> print(summary(mod.seqrep))
Call: earth(formula=O3~., data=oz, pmethod="seqrep", trace=4, degree=2)
coefficients
(Intercept) 7.296
h(4-wind) 1.263
h(-2-dpg) -0.052
h(174-ibt) -0.043
h(doy-45) 0.097
Selected 5 of 18 terms, and 4 of 9 predictors
Termination condition: Reached nk 21
Importance: ibt, doy, humidity-unused, wind, dpg, vh-unused, temp-unused, ...
Number of terms at each degree of interaction: 1 4 (additive model)
GCV 4.02 RSS 122 GRSq 0.413 RSq 0.628
> tab <- data.frame(pmethod=c("none", "backward", "forward", "exhaustive", "seqrep"),
+ grsq=c(mod.none$grsq,
+ mod.backward$grsq,
+ mod.forward$grsq,
+ mod.exhaustive$grsq,
+ mod.seqrep$grsq),
+ nterms=c(length(mod.none$selected.terms),
+ length(mod.backward$selected.terms),
+ length(mod.forward$selected.terms),
+ length(mod.exhaustive$selected.terms),
+ length(mod.seqrep$selected.terms)))
> cat("\n")
> print(tab)
pmethod grsq nterms
1 none -4.110 18
2 backward 0.530 7
3 forward 0.412 4
4 exhaustive 0.530 7
5 seqrep 0.413 5
>
> source("test.epilog.R")
|