R Under development (unstable) (2024-01-28 r85838 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > suppressMessages(library(cobs)) > > options(digits = 6) > > x <- c(1:3, 5,6,9,12) > y <- c(-1:1,0,1,-2,0) + 8*x > > all(abs(residuals(cobs(x,y))) < 1e-10)# no constraints -> perfect fit qbsks2(): Performing general knot selection ... WARNING! Since the number of 6 knots selected by AIC reached the upper bound during general knot selection, you might want to rerun cobs with a larger number of knots. Deleting unnecessary knots ... WARNING! Since the number of 6 knots selected by AIC reached the upper bound during general knot selection, you might want to rerun cobs with a larger number of knots. [1] TRUE > summary(c1 <- cobs(x,y, constraint = "convex"))# 99.88 % qbsks2(): Performing general knot selection ... Deleting unnecessary knots ... COBS regression spline (degree = 2) from call: cobs(x = x, y = y, constraint = "convex") {tau=0.5}-quantile; dimensionality of fit: 3 from {3} x$knots[1:2]: 0.999989, 12.000011 coef[1:3]: 7.99991, 52.00000, 96.00009 R^2 = 99.88% ; empirical tau (over all): 3/7 = 0.428571 (target tau= 0.5) > summary(c2 <- cobs(x,y, constraint = "concave"))# 99.84 % qbsks2(): Performing general knot selection ... Deleting unnecessary knots ... COBS regression spline (degree = 2) from call: cobs(x = x, y = y, constraint = "concave") {tau=0.5}-quantile; dimensionality of fit: 3 from {3} x$knots[1:2]: 0.999989, 12.000011 coef[1:3]: 7.54157, 54.29167, 96.00008 R^2 = 99.84% ; empirical tau (over all): 3/7 = 0.428571 (target tau= 0.5) > > sum(resid(c1)^2)# 7 [1] 7 > sum(resid(c2)^2)# 9.715 [1] 9.71528 > > plot(x,y) > lines(predict(c1), col=2) > lines(predict(c2), col=3) > > ##using browser() inside > predict(c1, interval = "both") z fit cb.lo cb.up ci.lo ci.up [1,] 0.999989 7.99991 4.82789 11.1719 4.84949 11.1503 [2,] 1.111100 8.88880 5.84444 11.9332 5.86518 11.9124 [3,] 1.222212 9.77769 6.85519 12.7002 6.87510 12.6803 [4,] 1.333323 10.66658 7.85994 13.4732 7.87905 13.4541 [5,] 1.444434 11.55548 8.85846 14.2525 8.87683 14.2341 [6,] 1.555546 12.44437 9.85054 15.0382 9.86821 15.0205 [7,] 1.666657 13.33326 10.83596 15.8305 10.85297 15.8135 [8,] 1.777768 14.22215 11.81451 16.6298 11.83091 16.6134 [9,] 1.888880 15.11104 12.78598 17.4361 12.80181 17.4203 [10,] 1.999991 15.99993 13.75019 18.2497 13.76551 18.2343 [11,] 2.111102 16.88882 14.70699 19.0706 14.72185 19.0558 [12,] 2.222214 17.77771 15.65628 19.8991 15.67072 19.8847 [13,] 2.333325 18.66660 16.59799 20.7352 16.61208 20.7211 [14,] 2.444436 19.55549 17.53215 21.5788 17.54593 21.5651 [15,] 2.555548 20.44438 18.45883 22.4299 18.47235 22.4164 [16,] 2.666659 21.33327 19.37817 23.2884 19.39149 23.2751 [17,] 2.777770 22.22216 20.29043 24.1539 20.30359 24.1407 [18,] 2.888882 23.11105 21.19590 25.0262 21.20894 25.0132 [19,] 2.999993 23.99994 22.09496 25.9049 22.10793 25.8920 [20,] 3.111104 24.88884 22.98804 26.7896 23.00099 26.7767 [21,] 3.222216 25.77773 23.87563 27.6798 23.88858 27.6669 [22,] 3.333327 26.66662 24.75824 28.5750 24.77123 28.5620 [23,] 3.444438 27.55551 25.63639 29.4746 25.64946 29.4616 [24,] 3.555550 28.44440 26.51062 30.3782 26.52379 30.3650 [25,] 3.666661 29.33329 27.38147 31.2851 27.39476 31.2718 [26,] 3.777772 30.22218 28.24944 32.1949 28.26287 32.1815 [27,] 3.888884 31.11107 29.11501 33.1071 29.12861 33.0935 [28,] 3.999995 31.99996 29.97866 34.0213 29.99243 34.0075 [29,] 4.111106 32.88885 30.84080 34.9369 30.85475 34.9230 [30,] 4.222218 33.77774 31.70184 35.8536 31.71597 35.8395 [31,] 4.333329 34.66663 32.56212 36.7711 32.57645 36.7568 [32,] 4.444440 35.55552 33.42197 37.6891 33.43650 37.6745 [33,] 4.555552 36.44441 34.28170 38.6071 34.29643 38.5924 [34,] 4.666663 37.33330 35.14155 39.5251 35.15648 39.5101 [35,] 4.777774 38.22219 36.00178 40.4426 36.01690 40.4275 [36,] 4.888886 39.11109 36.86257 41.3596 36.87789 41.3443 [37,] 4.999997 39.99998 37.72413 42.2758 37.73963 42.2603 [38,] 5.111108 40.88887 38.58661 43.1911 38.60229 43.1754 [39,] 5.222220 41.77776 39.45015 44.1054 39.46601 44.0895 [40,] 5.333331 42.66665 40.31488 45.0184 40.33090 45.0024 [41,] 5.444442 43.55554 41.18091 45.9302 41.19708 45.9140 [42,] 5.555554 44.44443 42.04831 46.8405 42.06463 46.8242 [43,] 5.666665 45.33332 42.91718 47.7495 42.93363 47.7330 [44,] 5.777776 46.22221 43.78757 48.6569 43.80415 48.6403 [45,] 5.888888 47.11110 44.65953 49.5627 44.67622 49.5460 [46,] 5.999999 47.99999 45.53310 50.4669 45.54990 50.4501 [47,] 6.111110 48.88888 46.40831 51.3695 46.42520 51.3526 [48,] 6.222222 49.77777 47.28517 52.2704 47.30215 52.2534 [49,] 6.333333 50.66666 48.16370 53.1696 48.18074 53.1526 [50,] 6.444444 51.55555 49.04388 54.0672 49.06099 54.0501 [51,] 6.555556 52.44445 49.92572 54.9632 49.94287 54.9460 [52,] 6.666667 53.33334 50.80918 55.8575 50.82637 55.8403 [53,] 6.777778 54.22223 51.69424 56.7502 51.71145 56.7330 [54,] 6.888890 55.11112 52.58085 57.6414 52.59808 57.6242 [55,] 7.000001 56.00001 53.46896 58.5311 53.48620 58.5138 [56,] 7.111112 56.88890 54.35852 59.4193 54.37575 59.4020 [57,] 7.222224 57.77779 55.24944 60.3061 55.26666 60.2889 [58,] 7.333335 58.66668 56.14166 61.1917 56.15886 61.1745 [59,] 7.444446 59.55557 57.03507 62.0761 57.05224 62.0589 [60,] 7.555558 60.44446 57.92957 62.9593 57.94670 62.9422 [61,] 7.666669 61.33335 58.82505 63.8417 58.84213 63.8246 [62,] 7.777780 62.22224 59.72137 64.7231 59.73840 64.7061 [63,] 7.888892 63.11113 60.61839 65.6039 60.63536 65.5869 [64,] 8.000003 64.00002 61.51595 66.4841 61.53286 66.4672 [65,] 8.111114 64.88891 62.41387 67.3640 62.43073 67.3471 [66,] 8.222226 65.77781 63.31198 68.2436 63.32877 68.2268 [67,] 8.333337 66.66670 64.21005 69.1233 64.22678 69.1066 [68,] 8.444448 67.55559 65.10788 70.0033 65.12455 69.9866 [69,] 8.555560 68.44448 66.00522 70.8837 66.02184 70.8671 [70,] 8.666671 69.33337 66.90183 71.7649 66.91839 71.7484 [71,] 8.777782 70.22226 67.79742 72.6471 67.81393 72.6306 [72,] 8.888894 71.11115 68.69171 73.5306 68.70819 73.5141 [73,] 9.000005 72.00004 69.58441 74.4157 69.60086 74.3992 [74,] 9.111116 72.88893 70.47520 75.3027 70.49164 75.2862 [75,] 9.222228 73.77782 71.36376 76.1919 71.38020 76.1754 [76,] 9.333339 74.66671 72.24976 77.0837 72.26622 77.0672 [77,] 9.444450 75.55560 73.13285 77.9783 73.14935 77.9618 [78,] 9.555562 76.44449 74.01272 78.8763 74.02928 78.8597 [79,] 9.666673 77.33338 74.88902 79.7777 74.90567 79.7611 [80,] 9.777784 78.22227 75.76143 80.6831 75.77819 80.6664 [81,] 9.888896 79.11116 76.62965 81.5927 76.64655 81.5758 [82,] 10.000007 80.00006 77.49337 82.5067 77.51044 82.4897 [83,] 10.111118 80.88895 78.35232 83.4256 78.36960 83.4083 [84,] 10.222230 81.77784 79.20626 84.3494 79.22378 84.3319 [85,] 10.333341 82.66673 80.05498 85.2785 80.07276 85.2607 [86,] 10.444452 83.55562 80.89827 86.2130 80.91637 86.1949 [87,] 10.555564 84.44451 81.73600 87.1530 81.75445 87.1346 [88,] 10.666675 85.33340 82.56803 88.0988 82.58687 88.0799 [89,] 10.777786 86.22229 83.39429 89.0503 83.41355 89.0310 [90,] 10.888898 87.11118 84.21470 90.0077 84.23443 89.9879 [91,] 11.000009 88.00007 85.02924 90.9709 85.04947 90.9507 [92,] 11.111120 88.88896 85.83791 91.9400 85.85868 91.9192 [93,] 11.222232 89.77785 86.64072 92.9150 86.66208 92.8936 [94,] 11.333343 90.66674 87.43771 93.8958 87.45970 93.8738 [95,] 11.444454 91.55563 88.22894 94.8823 88.25160 94.8597 [96,] 11.555566 92.44452 89.01448 95.8746 89.03784 95.8512 [97,] 11.666677 93.33342 89.79440 96.8724 89.81850 96.8483 [98,] 11.777788 94.22231 90.56880 97.8758 90.59368 97.8509 [99,] 11.888900 95.11120 91.33776 98.8846 91.36346 98.8589 [100,] 12.000011 96.00009 92.10139 99.8988 92.12794 99.8722 > predict(c2, interval = "both") z fit cb.lo cb.up ci.lo ci.up [1,] 0.999989 7.54157 3.84088 11.2423 3.86608 11.2171 [2,] 1.111100 8.48551 4.93375 12.0373 4.95794 12.0131 [3,] 1.222212 9.42841 6.01883 12.8380 6.04205 12.8148 [4,] 1.333323 10.37028 7.09586 13.6447 7.11816 13.6224 [5,] 1.444434 11.31113 8.16461 14.4576 8.18604 14.4362 [6,] 1.555546 12.25095 9.22482 15.2771 9.24543 15.2565 [7,] 1.666657 13.18973 10.27623 16.1032 10.29607 16.0834 [8,] 1.777768 14.12749 11.31858 16.9364 11.33771 16.9173 [9,] 1.888880 15.06422 12.35165 17.7768 12.37013 17.7583 [10,] 1.999991 15.99993 13.37523 18.6246 13.39310 18.6067 [11,] 2.111102 16.93460 14.38913 19.4801 14.40646 19.4627 [12,] 2.222214 17.86824 15.39324 20.3432 15.41009 20.3264 [13,] 2.333325 18.80086 16.38748 21.2142 16.40392 21.1978 [14,] 2.444436 19.73244 17.37188 22.0930 17.38795 22.0769 [15,] 2.555548 20.66300 18.34652 22.9795 18.36229 22.9637 [16,] 2.666659 21.59253 19.31158 23.8735 19.32712 23.8579 [17,] 2.777770 22.52103 20.26734 24.7747 20.28269 24.7594 [18,] 2.888882 23.44850 21.21415 25.6828 21.22937 25.6676 [19,] 2.999993 24.37494 22.15246 26.5974 22.16759 26.5823 [20,] 3.111104 25.30036 23.08276 27.5179 23.09787 27.5028 [21,] 3.222216 26.22474 24.00563 28.4439 24.02074 28.4287 [22,] 3.333327 27.14810 24.92165 29.3745 24.93682 29.3594 [23,] 3.444438 28.07042 25.83145 30.3094 25.84670 30.2941 [24,] 3.555550 28.99172 26.73565 31.2478 26.75102 31.2324 [25,] 3.666661 29.91199 27.63487 32.1891 27.65038 32.1736 [26,] 3.777772 30.83123 28.52970 33.1328 28.54537 33.1171 [27,] 3.888884 31.74944 29.42071 34.0782 29.43657 34.0623 [28,] 3.999995 32.66663 30.30844 35.0248 30.32450 35.0087 [29,] 4.111106 33.58278 31.19339 35.9722 31.20966 35.9559 [30,] 4.222218 34.49791 32.07601 36.9198 32.09251 36.9033 [31,] 4.333329 35.41200 32.95673 37.8673 32.97345 37.8505 [32,] 4.444440 36.32507 33.83593 38.8142 33.85288 38.7973 [33,] 4.555552 37.23711 34.71394 39.7603 34.73112 39.7431 [34,] 4.666663 38.14812 35.59108 40.7052 35.60849 40.6877 [35,] 4.777774 39.05810 36.46761 41.6486 36.48525 41.6309 [36,] 4.888886 39.96705 37.34379 42.5903 37.36165 42.5725 [37,] 4.999997 40.87498 38.21982 43.5301 38.23791 43.5120 [38,] 5.111108 41.78187 39.09591 44.4678 39.11420 44.4495 [39,] 5.222220 42.68774 39.97220 45.4033 39.99069 45.3848 [40,] 5.333331 43.59257 40.84885 46.3363 40.86754 46.3176 [41,] 5.444442 44.49638 41.72598 47.2668 41.74485 47.2479 [42,] 5.555554 45.39916 42.60369 48.1946 42.62273 48.1756 [43,] 5.666665 46.30091 43.48208 49.1197 43.50128 49.1005 [44,] 5.777776 47.20163 44.36122 50.0421 44.38056 50.0227 [45,] 5.888888 48.10133 45.24116 50.9615 45.26064 50.9420 [46,] 5.999999 48.99999 46.12195 51.8780 46.14155 51.8584 [47,] 6.111110 49.89763 47.00362 52.7916 47.02333 52.7719 [48,] 6.222222 50.79423 47.88620 53.7023 47.90600 53.6825 [49,] 6.333333 51.68981 48.76968 54.6099 48.78957 54.5901 [50,] 6.444444 52.58436 49.65408 55.5146 49.67404 55.4947 [51,] 6.555556 53.47788 50.53937 56.4164 50.55938 56.3964 [52,] 6.666667 54.37037 51.42553 57.3152 51.44558 57.2952 [53,] 6.777778 55.26184 52.31252 58.2112 52.33260 58.1911 [54,] 6.888890 56.15227 53.20029 59.1043 53.22039 59.0841 [55,] 7.000001 57.04167 54.08879 59.9946 54.10890 59.9745 [56,] 7.111112 57.93005 54.97794 60.8822 54.99804 60.8621 [57,] 7.222224 58.81740 55.86766 61.7671 55.88775 61.7470 [58,] 7.333335 59.70372 56.75786 62.6496 56.77792 62.6295 [59,] 7.444446 60.58901 57.64842 63.5296 57.66845 63.5096 [60,] 7.555558 61.47327 58.53923 64.4073 58.55921 64.3873 [61,] 7.666669 62.35650 59.43015 65.2829 59.45008 65.2629 [62,] 7.777780 63.23870 60.32102 66.1564 60.34089 66.1365 [63,] 7.888892 64.11988 61.21168 67.0281 61.23148 67.0083 [64,] 8.000003 65.00002 62.10193 67.8981 62.12167 67.8784 [65,] 8.111114 65.87914 62.99159 68.7667 63.01126 68.7470 [66,] 8.222226 66.75723 63.88043 69.6340 63.90002 69.6144 [67,] 8.333337 67.63429 64.76820 70.5004 64.78772 70.4809 [68,] 8.444448 68.51032 65.65466 71.3660 65.67411 71.3465 [69,] 8.555560 69.38532 66.53952 72.2311 66.55890 72.2117 [70,] 8.666671 70.25929 67.42249 73.0961 67.44181 73.0768 [71,] 8.777782 71.13224 68.30326 73.9612 68.32252 73.9420 [72,] 8.888894 72.00415 69.18148 74.8268 69.20070 74.8076 [73,] 9.000005 72.87504 70.05681 75.6933 70.07600 75.6741 [74,] 9.111116 73.74490 70.92888 76.5609 70.94806 76.5417 [75,] 9.222228 74.61373 71.79732 77.4301 71.81650 77.4109 [76,] 9.333339 75.48153 72.66174 78.3013 72.68095 78.2821 [77,] 9.444450 76.34830 73.52176 79.1748 73.54101 79.1556 [78,] 9.555562 77.21404 74.37697 80.0511 74.39629 80.0318 [79,] 9.666673 78.07875 75.22700 80.9305 75.24642 80.9111 [80,] 9.777784 78.94244 76.07146 81.8134 76.09101 81.7939 [81,] 9.888896 79.80509 76.90999 82.7002 76.92971 82.6805 [82,] 10.000007 80.66672 77.74225 83.5912 77.76217 83.5713 [83,] 10.111118 81.52732 78.56792 84.4867 78.58808 84.4666 [84,] 10.222230 82.38689 79.38672 85.3871 79.40715 85.3666 [85,] 10.333341 83.24543 80.19839 86.2925 80.21914 86.2717 [86,] 10.444452 84.10294 81.00271 87.2032 81.02382 87.1821 [87,] 10.555564 84.95942 81.79950 88.1194 81.82102 88.0978 [88,] 10.666675 85.81488 82.58862 89.0411 82.61059 89.0192 [89,] 10.777786 86.66930 83.36997 89.9686 83.39244 89.9462 [90,] 10.888898 87.52270 84.14347 90.9019 84.16649 90.8789 [91,] 11.000009 88.37507 84.90910 91.8410 84.93270 91.8174 [92,] 11.111120 89.22641 85.66684 92.7860 85.69108 92.7617 [93,] 11.222232 90.07672 86.41672 93.7367 86.44165 93.7118 [94,] 11.333343 90.92600 87.15879 94.6932 87.18445 94.6676 [95,] 11.444454 91.77425 87.89311 95.6554 87.91954 95.6290 [96,] 11.555566 92.62148 88.61975 96.6232 88.64701 96.5959 [97,] 11.666677 93.46767 89.33882 97.5965 89.36694 97.5684 [98,] 11.777788 94.31284 90.05041 98.5753 90.07944 98.5462 [99,] 11.888900 95.15697 90.75463 99.5593 90.78461 99.5293 [100,] 12.000011 96.00008 91.45160 100.5486 91.48257 100.5176 > > cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons'' Time elapsed: 1.82 0.26 2.07 NA NA > > proc.time() user system elapsed 1.82 0.26 2.07