Skip to contents

Generates either:

  • Structured (x, y) scatter data (linear, sine, circle, etc.), or

  • A matrix of scaled orthogonal polynomial features.

Usage

data_gen(type = "all", n = 500, degree = NULL, seed = NULL)

Arguments

type

Character string. Options:

  • "polynomial" for orthogonal polynomial features

  • "linear", "sine", "circle", "cluster", "snake", "outliers", "sparse", "clumpy", "skewed", "striated", "concave", "monotonic", "doughnut", or "all" to generate all scatter structures.

n

Integer. Number of samples to generate. Default is 500.

degree

Integer. Degree of polynomial features (only for type = "polynomial").

seed

Optional integer. Sets random seed for reproducibility.

Value

  • If type = "polynomial", returns a matrix (n x degree).

  • Otherwise a tibble with columns:

  • x: Numeric vector of x-values

  • y: Numeric vector of y-values

  • structure: Character name of the structure type

Examples

data_gen("linear", n = 200)
#> # A tibble: 200 × 3
#>         x      y structure
#>     <dbl>  <dbl> <chr>    
#>  1  0.674  0.666 linear   
#>  2 -0.132 -0.126 linear   
#>  3 -1.68  -1.68  linear   
#>  4  0.935  0.921 linear   
#>  5  0.389  0.391 linear   
#>  6  1.22   1.23  linear   
#>  7  1.40   1.39  linear   
#>  8 -0.615 -0.600 linear   
#>  9  1.38   1.38  linear   
#> 10 -1.44  -1.47  linear   
#> # ℹ 190 more rows
data_gen("polynomial", degree = 4, n = 200)
#>                   1           2           3            4
#>   [1,] -1.149832909  0.57144840  0.36623274 -1.188154092
#>   [2,]  0.701762452 -0.68208221 -1.18116691  0.005965585
#>   [3,] -0.851796645 -0.13986081  1.03532347 -1.151214220
#>   [4,]  0.976110885 -0.22596486 -1.23123708 -0.905096071
#>   [5,] -1.478459991  1.58239750 -1.34246977  1.028275020
#>   [6,]  0.661230846 -0.73542302 -1.14088804  0.141208488
#>   [7,] -0.444879631 -0.79535113  0.96789248  0.090149710
#>   [8,] -0.839732053 -0.16453766  1.04776375 -1.125865826
#>   [9,] -1.536521384  1.78571814 -1.76947531  1.792308240
#>  [10,]  1.192536438  0.25074102 -0.92637310 -1.361129780
#>  [11,]  1.864282669  2.38692291  2.82321626  3.108771710
#>  [12,] -0.348951439 -0.89679530  0.83544486  0.393798378
#>  [13,]  1.647940330  1.59052271  1.06976472  0.182859182
#>  [14,]  0.682362924 -0.70806372 -1.16279367  0.071133034
#>  [15,]  0.179493717 -1.09252820 -0.26506204  1.151019265
#>  [16,]  0.385100820 -1.00259314 -0.70594854  0.893746193
#>  [17,]  1.075199657 -0.02050371 -1.13479264 -1.165125001
#>  [18,] -1.504627119  1.67311168 -1.52989098  1.356042599
#>  [19,] -1.255047301  0.86924937 -0.05813045 -0.810093796
#>  [20,] -0.548097671 -0.66357713  1.06856032 -0.256851712
#>  [21,] -0.094131179 -1.06790999  0.35250652  0.995912068
#>  [22,] -0.086495138 -1.07083219  0.33599465  1.007806563
#>  [23,] -0.667096765 -0.48255558  1.12024709 -0.651668602
#>  [24,]  1.483809399  1.05504518  0.10826129 -0.939648274
#>  [25,]  1.507673548  1.12921835  0.22978931 -0.824509496
#>  [26,]  0.190926911 -1.08997026 -0.29089328  1.144965509
#>  [27,]  0.476651104 -0.93260968 -0.87640931  0.686784775
#>  [28,]  0.670532246 -0.72350177 -1.15076863  0.110493043
#>  [29,] -1.456661057  1.50797731 -1.19252257  0.775173243
#>  [30,]  1.531607144  1.20486628  0.35774870 -0.693739236
#>  [31,] -0.926561880  0.02020775  0.93463446 -1.276118004
#>  [32,]  1.201866289  0.27360914 -0.90508227 -1.369925834
#>  [33,] -0.068493045 -1.07721340  0.29676004  1.034223098
#>  [34,]  0.937596630 -0.29999224 -1.25075460 -0.788144878
#>  [35,] -0.311014568 -0.93132492  0.77423599  0.505031016
#>  [36,] -1.369356752  1.22040811 -0.64673381 -0.068871995
#>  [37,] -0.106468640 -1.06291745  0.37900858  0.975838411
#>  [38,]  0.320998268 -1.04061457 -0.57534313  1.006626020
#>  [39,] -1.233026486  0.80490514  0.03968603 -0.911297578
#>  [40,]  1.534311120  1.21349212  0.37259256 -0.677971620
#>  [41,] -1.510596075  1.69401549 -1.57379141  1.434568684
#>  [42,] -1.267194965  0.90520129 -0.11419040 -0.748870921
#>  [43,]  0.001063679 -1.09516698  0.14183220  1.114217244
#>  [44,] -1.037725726  0.28094915  0.70467563 -1.334057665
#>  [45,]  0.177502411 -1.09294429 -0.26055416  1.151970524
#>  [46,]  1.676023095  1.68808304  1.26488107  0.460362998
#>  [47,]  0.751513126 -0.61166593 -1.22029914 -0.163746528
#>  [48,] -0.142206353 -1.04656492  0.45442992  0.911854528
#>  [49,]  1.583391179  1.37285720  0.65592916 -0.355085840
#>  [50,]  0.378714650 -1.00678662 -0.69330745  0.906233341
#>  [51,] -0.430434905 -0.81192171  0.95017122  0.137500424
#>  [52,]  1.272051379  0.45177922 -0.72125947 -1.397039359
#>  [53,]  1.010576663 -0.15695094 -1.20544649 -1.003070745
#>  [54,] -0.792079367 -0.25887462  1.08703671 -1.013864305
#>  [55,] -0.427752647 -0.81494816  0.94678926  0.146241048
#>  [56,] -0.404843178 -0.84015226  0.91676799  0.220155424
#>  [57,] -0.557358218 -0.65060832  1.07519967 -0.288238983
#>  [58,]  0.564134807 -0.84849857 -1.01686645  0.445936624
#>  [59,] -0.749464773 -0.33900458  1.10931746 -0.899830456
#>  [60,] -1.275607220  0.93028831 -0.15389620 -0.704165621
#>  [61,] -0.955338465  0.08509590  0.88461868 -1.307333692
#>  [62,] -1.487490167  1.61353232 -1.40622647  1.138388045
#>  [63,]  0.200673560 -1.08756248 -0.31283952  1.139010387
#>  [64,] -0.985597040  0.15529159  0.82497623 -1.328548759
#>  [65,]  0.388749924 -1.00015666 -0.71313184  0.886491271
#>  [66,]  0.580279705 -0.83113490 -1.03998214  0.397631158
#>  [67,] -0.664455959 -0.48691093  1.11993262 -0.643250805
#>  [68,]  0.405525532 -0.98857863 -0.74576994  0.852034092
#>  [69,] -0.800423420 -0.24271703  1.08127572 -1.034750418
#>  [70,] -1.169885061  0.62632516  0.29360979 -1.135829087
#>  [71,]  1.863099469  2.38228715  2.81200209  3.087375783
#>  [72,]  0.042632582 -1.10081301  0.04746293  1.144752138
#>  [73,] -1.295735963  0.99094847 -0.25187032 -0.589332581
#>  [74,] -0.779631427 -0.28269423  1.09477019 -0.981785885
#>  [75,] -0.707112838 -0.41468059  1.12004725 -0.776067865
#>  [76,] -1.520688582  1.72953872 -1.64899838  1.570586555
#>  [77,] -0.998384760  0.18556309  0.79754815 -1.333680472
#>  [78,]  0.549803007 -0.86343160 -0.99557427  0.487890917
#>  [79,] -0.840279964 -0.16342391  1.04722103 -1.127045093
#>  [80,] -1.382209881  1.26169160 -0.72170137  0.039198663
#>  [81,]  0.637185622 -0.76535848 -1.11365159  0.219556627
#>  [82,] -0.520965249 -0.70048772  1.04674565 -0.164845244
#>  [83,]  0.616172967 -0.79047659 -1.08791446  0.286616065
#>  [84,]  1.783603515  2.07788161  2.10056617  1.794416532
#>  [85,] -1.043661445  0.29563664  0.68953086 -1.331989028
#>  [86,]  0.254608871 -1.07045868 -0.43272015  1.092971947
#>  [87,]  0.428495160 -0.97172102 -0.78938375  0.801976978
#>  [88,] -0.499800744 -0.72815476  1.02735774 -0.093258764
#>  [89,]  0.021032862 -1.09835393  0.09661624  1.130526570
#>  [90,]  0.617540568 -0.78887135 -1.08964301  0.282295064
#>  [91,] -1.340211767  1.12814319 -0.48345091 -0.294500475
#>  [92,]  1.848907017  2.32692154  2.67893576  2.835797843
#>  [93,]  1.408034123  0.82783366 -0.23868006 -1.211890340
#>  [94,]  1.178146980  0.21584704 -0.95780320 -1.345384059
#>  [95,]  1.385342669  0.76225238 -0.33139187 -1.267955217
#>  [96,]  1.174761962  0.20770470 -0.96495095 -1.341306173
#>  [97,] -0.460588240 -0.77680939  0.98620363  0.038172110
#>  [98,] -0.113634096 -1.05986405  0.39429614  0.963699502
#>  [99,] -0.849640687 -0.14429410  1.03762215 -1.146780630
#> [100,] -0.328625738 -0.91568940  0.80322078  0.454137328
#> [101,] -1.489961626  1.62208486 -1.42384475  1.169071501
#> [102,]  1.770806428  2.03017881  1.99363920  1.611779766
#> [103,] -1.155414193  0.58663383  0.34639927 -1.174460344
#> [104,] -0.027999833 -1.08896040  0.20712484  1.085126459
#> [105,]  1.371254228  0.72210517 -0.38643363 -1.297310246
#> [106,] -1.116274537  0.48158899  0.47938851 -1.256870490
#> [107,] -1.367564747  1.21468118 -0.63642645 -0.083516508
#> [108,]  0.372487694 -1.01078912 -0.68089752  0.918150504
#> [109,] -1.399717054  1.31850852 -0.82676720  0.195119063
#> [110,]  0.920554672 -0.33170629 -1.25636410 -0.734308767
#> [111,]  1.113461179  0.06461504 -1.07857599 -1.244779620
#> [112,]  0.266615562 -1.06577986 -0.45897154  1.079745703
#> [113,]  1.377499549  0.73984828 -0.36227032 -1.284801589
#> [114,] -0.338283916 -0.90682486  0.81870036  0.425672302
#> [115,] -0.121551713 -1.05635872  0.41109500  0.949880360
#> [116,]  0.633805369 -0.76946476 -1.10963113  0.230437964
#> [117,]  1.666991581  1.65651796  1.20111598  0.368110872
#> [118,] -1.394512750  1.30154826 -0.79517686  0.147704386
#> [119,] -0.161973452 -1.03631267  0.49519337  0.872846385
#> [120,] -1.592209914  1.98770047 -2.21784100  2.656331934
#> [121,]  1.261156560  0.42341105 -0.75258832 -1.397645755
#> [122,]  0.734113463 -0.63691258 -1.20795640 -0.104072398
#> [123,]  0.687706605 -0.70098966 -1.16802302  0.053255673
#> [124,] -0.478600356 -0.75488030  1.00593142 -0.021947430
#> [125,] -1.260617724  0.88569513 -0.08365062 -0.782503951
#> [126,]  0.048156061 -1.10127698  0.03486135  1.147816127
#> [127,] -0.853944808 -0.13543337  1.03300022 -1.155589384
#> [128,] -0.642263455 -0.52290544  1.11573169 -0.571660444
#> [129,] -1.570343355  1.90757657 -2.03717013  2.301069884
#> [130,]  0.477092931 -0.93222721 -0.87717819  0.685666658
#> [131,] -0.043001838 -1.08502919  0.24053541  1.067660336
#> [132,]  0.312834222 -1.04480768 -0.55816518  1.018961708
#> [133,]  1.617507023  1.48675630  0.86871181 -0.087567483
#> [134,]  0.421537794 -0.97694969 -0.77630916  0.817483759
#> [135,] -1.350370197  1.16008970 -0.53931340 -0.218864711
#> [136,] -1.250376683  0.85551277 -0.03697527 -0.832601124
#> [137,]  1.626656130  1.51773710  0.92802935 -0.009495890
#> [138,] -0.726709402 -0.38015545  1.11646035 -0.834475802
#> [139,] -0.813345350 -0.21739235  1.07142831 -1.066068100
#> [140,] -0.465322736 -0.77111450  0.99152199  0.022418989
#> [141,] -0.284255457 -0.95377553  0.72840021  0.579694774
#> [142,] -0.642720150 -0.52217564  1.11584591 -0.573147871
#> [143,]  0.592902487 -0.81715962 -1.05739322  0.359135921
#> [144,] -0.546517419 -0.66577132  1.06738583 -0.251493161
#> [145,] -0.663120446 -0.48910768  1.11975843 -0.638985035
#> [146,] -0.303893244 -0.93745353  0.76224495  0.525223934
#> [147,] -0.272740787 -0.96295123  0.70804123  0.610771799
#> [148,]  1.269704009  0.44564501 -0.72809799 -1.397328780
#> [149,] -0.054224080 -1.08176459  0.26537772  1.053518840
#> [150,]  0.855131300 -0.44751795 -1.26146926 -0.518871426
#> [151,]  1.151208606  0.15174752 -1.01212499 -1.309154896
#> [152,]  1.221391639  0.32208716 -0.85817239 -1.384579156
#> [153,] -0.242514697 -0.98564909  0.65288783  0.689133532
#> [154,] -0.627305587 -0.54655442  1.11135678 -0.522653179
#> [155,]  1.820954849  2.21917484  2.42460958  2.367130651
#> [156,] -0.714163163 -0.40235670  1.11902618 -0.797292257
#> [157,]  1.395574330  0.79168293 -0.29021170 -1.244040720
#> [158,]  0.902987892 -0.36372794 -1.26025851 -0.677690939
#> [159,]  1.077935868 -0.01452355 -1.13113580 -1.171260857
#> [160,] -1.415581974  1.37057839 -0.92494946  0.345318593
#> [161,] -1.214441799  0.75143166  0.11847102 -0.987226385
#> [162,]  0.923108242 -0.32699496 -1.25563939 -0.742447530
#> [163,]  0.579959364 -0.83148501 -1.03953264  0.398599960
#> [164,]  1.101378052  0.03738613 -1.09752125 -1.221097622
#> [165,] -0.576506946 -0.62319308  1.08758915 -0.352994696
#> [166,]  1.134630977  0.11309513 -1.04267880 -1.282745559
#> [167,]  1.527626488  1.19219705  0.33604005 -0.716580059
#> [168,]  0.003978323 -1.09568684  0.13524860  1.116785605
#> [169,]  0.172466019 -1.09395772 -0.24914195  1.154239679
#> [170,] -0.998261266  0.18526903  0.79781943 -1.333642251
#> [171,] -0.403808099 -0.84126374  0.91536441  0.223461555
#> [172,]  0.546275067 -0.86703820 -0.99022422  0.498079184
#> [173,] -0.761356404 -0.31704631  1.10428363 -0.932814212
#> [174,]  1.679422687  1.70001110  1.28913412  0.495838634
#> [175,] -1.373737154  1.23443686 -0.67207809 -0.032641123
#> [176,]  1.246003199  0.38438877 -0.79443375 -1.395429609
#> [177,]  1.615606769  1.48034475  0.85651206 -0.103441075
#> [178,] -0.505651028 -0.72060564  1.03292003 -0.113016129
#> [179,] -0.340672550 -0.90460084  0.82248221  0.418574143
#> [180,] -1.391898036  1.29304970 -0.77941992  0.124224360
#> [181,]  0.076296190 -1.10259825 -0.02947650  1.159775029
#> [182,] -1.468191512  1.54721126 -1.27114134  0.906832512
#> [183,]  1.504327541  1.11874293  0.21238739 -0.841555643
#> [184,]  0.393496916 -0.99694326 -0.72243219  0.876924284
#> [185,] -1.299637915  1.00281062 -0.27135058 -0.565763344
#> [186,]  1.479895867  1.04300100  0.08890215 -0.957122943
#> [187,] -0.623887294 -0.55188974  1.11018571 -0.511379880
#> [188,] -0.149360796 -1.04295356  0.46926697  0.898027545
#> [189,] -0.773421316 -0.29445001  1.09824681 -0.965387574
#> [190,] -1.402173995  1.32653613 -0.84178657  0.217819832
#> [191,] -1.499928779  1.65671284 -1.49563697  1.295225094
#> [192,]  0.637240357 -0.76529178 -1.11371630  0.219380148
#> [193,] -0.207636052 -1.00934179  0.58638358  0.773382228
#> [194,]  0.749324702 -0.61487793 -1.21882817 -0.156227995
#> [195,] -0.325646627 -0.91838228  0.79838587  0.462839734
#> [196,] -0.933639139  0.03599722  0.92292985 -1.284742016
#> [197,] -0.210880035 -1.00725112  0.59269035  0.765838941
#> [198,]  1.001711497 -0.17495221 -1.21284961 -0.978547972
#> [199,]  0.749302941 -0.61490982 -1.21881342 -0.156153250
#> [200,] -0.646629747 -0.51590931  1.11677628 -0.585858209
#> attr(,"coefs")
#> attr(,"coefs")$alpha
#> [1] 0.4620492 0.5100059 0.4952491 0.5190970
#> 
#> attr(,"coefs")$norm2
#> [1] 1.000000e+00 2.000000e+02 1.638707e+01 1.114267e+00 7.078459e-02
#> [6] 4.094565e-03
#> 
#> attr(,"degree")
#> [1] 1 2 3 4
#> attr(,"class")
#> [1] "poly"   "matrix"
data_gen("all", n = 200)
#> # A tibble: 2,602 × 3
#>          x       y structure
#>      <dbl>   <dbl> <chr>    
#>  1 -0.508  -0.504  linear   
#>  2 -0.0782 -0.0625 linear   
#>  3  0.190   0.200  linear   
#>  4  0.0443  0.0341 linear   
#>  5 -0.835  -0.865  linear   
#>  6  0.588   0.598  linear   
#>  7 -1.58   -1.56   linear   
#>  8  1.67    1.67   linear   
#>  9 -0.212  -0.190  linear   
#> 10 -0.889  -0.886  linear   
#> # ℹ 2,592 more rows