7.7 Random Dataset

20200421 Using wakefield::r_data_frame() it is straightforward to create simple random data datasets. More sophisticated sampling can be used if required though extra work is required to get correlated distributions across variables when looking to most accurately match some real world data. Nonetheless, creating random data quickly is the forte of wakefield (Rinker 2020b).

library(wakefield)    # Generate random datasets.

nobs <- 100 # Number of observatios.

r_data_frame(n=nobs,
             id=id_factor,
             givennames=name,
             surname=name,
             dob=dob(start=Sys.Date()-365*100, k=365*99),
             sex=sex,
             phone=r_sample(x=400000000:499999999),
             diabetes=answer,
             result=r_sample_factor(x=c("pending", "positive", "negative")),
             previous=answer(prob=c(0.8,0.2)),
             bps=r_sample(90:135),
             temp=normal(36.3, 1.2),
             gcs=r_sample(3:15, prob=c(rep(0.01, 12), 0.88)),
             crp=normal(2.5, 2, min=0, max=200)) ->
random_ds

glimpse(random_ds)
## Rows: 100
## Columns: 13
## $ id         <fct> 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012,…
## $ givennames <chr> "Kayjuan", "Deerica", "Annajean", "Janetta", "Eisha", "Leas…
## $ surname    <chr> "Namyia", "Pharyn", "Elissabeth", "Alitza", "Lauire", "Jany…
## $ dob        <date> 2014-02-20, 1961-03-14, 1925-12-06, 1933-02-18, 1949-11-17…
## $ sex        <fct> Male, Female, Female, Male, Female, Female, Female, Female,…
## $ phone      <int> 494438542, 437279128, 423569925, 467982485, 453331629, 4002…
## $ diabetes   <fct> Yes, No, No, No, No, No, Yes, Yes, Yes, Yes, No, Yes, Yes, …
## $ result     <fct> negative, pending, negative, negative, pending, negative, p…
## $ previous   <fct> No, Yes, Yes, No, Yes, No, No, No, Yes, No, No, No, No, No,…
## $ bps        <int> 90, 128, 135, 117, 124, 115, 114, 103, 126, 109, 115, 114, …
## $ temp       <dbl> 36.88249, 37.32358, 35.64939, 36.11359, 36.57237, 37.49851,…
## $ gcs        <int> 15, 15, 15, 15, 15, 15, 5, 15, 6, 15, 13, 15, 15, 15, 15, 1…
## $ crp        <dbl> 2.3517065, 1.4579896, 3.7510125, 3.2607771, 0.0000000, 0.00…

References

———. 2020b. Wakefield: Generate Random Data Sets. https://github.com/trinker/wakefield.


Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.