R Views
https://rviews.rstudio.com/
Recent content on R ViewsHugo -- gohugo.ioen-usWed, 18 Jan 2023 00:00:00 +0000Some R Conferences for 2023
https://rviews.rstudio.com/2023/01/18/some-r-conferences-for-2023/
Wed, 18 Jan 2023 00:00:00 +0000https://rviews.rstudio.com/2023/01/18/some-r-conferences-for-2023/
<div class="figure">
<img src="img.png" alt="" />
<p class="caption">A collage of various conference logos, including posit conf, NICAR, Shiny Conf, Shiny in Production, and more.</p>
</div>
<p>Happy January! Below, we share a list of upcoming conferences that either focus on the R programming language or showcase its use in the field. If we have missed your conference, please leave a comment with the details. We will update our list as we receive more information.</p>
<p><strong>March</strong></p>
<p>(2 - 5) Nashville, TN - <a href="https://www.ire.org/training/conferences/">NICAR</a> is well attended by data journalists. Matthew Ericson, Assistant Managing Editor at The New York Times, noted the prevalence of the R programming language at the conference:</p>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">At <a href="https://twitter.com/hashtag/nicar22?src=hash&ref_src=twsrc%5Etfw">#nicar22</a> and struck by how prevalent R has become in data journalism, so I thought it would be fun to see how the hands-on classes have changed since my early NICAR days. Found a PDF of the 2004 NICAR schedule and totaled up the types of classes then and now. <a href="https://t.co/XRM7y1D6Sb">pic.twitter.com/XRM7y1D6Sb</a></p>— Matthew Ericson (@mericson) <a href="https://twitter.com/mericson/status/1500148424083222531?ref_src=twsrc%5Etfw">March 5, 2022</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>(15 - 17) online and <em>free</em> - <a href="https://shinyconf.appsilon.com/">ShinyConf 2023 by Appsilon</a> will bring together members from the global community of Shiny developers to learn, network, and share.</p>
<p><strong>May</strong></p>
<p>(19 - 20) Chicago, IL - <a href="https://www.rinfinance.com/">R / Finance</a> has talks and sessions on various quantitative finance topics, including portfolio construction, statistics, quant ideas, and more.</p>
<p><strong>June</strong></p>
<p>(6 - 9) online - <a href="https://r-medicine.org/">R / Medicine</a> promotes the development and use of R-based tools to improve clinical research and practice.</p>
<p>(8 - 9) Universität Zürich, Switzerland - <a href="https://www.psychoco.org">Psychoco 2023</a> aims to bring together researchers from statistics, psychology, and related disciplines working on modern techniques for the analysis of data from psychology and the social sciences.</p>
<p>(21 - 23) Avignon, France - <a href="https://rr2023.sciencesconf.org/">Rencontres R 2023</a>, supported by la Société Française de Statistique (SFdS), offers the French-speaking community a place to exchange and share ideas on using R software in all disciplines.</p>
<p><strong>August</strong></p>
<p>(2 - 4) Boston, MA - <a href="https://bioconductor.org/">BioConductor</a> provides an opportunity to learn about developments within and beyond the Bioconductor project.</p>
<p>(5 - 10) Toronto, Canada - <a href="https://ww2.amstat.org/meetings/jsm/2023/">JSM</a> is one of the largest statistical events in the world and will likely feature many R-related talks.</p>
<p>( 19 ) Seattle, WA - <a href="https://cascadiarconf.com/">Cascadia R Conf</a> is an R conference serving the Pacific Northwest.</p>
<p><strong>September</strong></p>
<p>(17 - 20) Chicago, IL / hybrid - <a href="https://posit.co/conference/">posit::conf(2023)</a>, Posit’s annual conference, will be at the Hyatt Regency Chicago. We can’t wait to see you there!</p>
<p><strong>October</strong></p>
<p>(12 - 13) Newcastle Upon Tyne, UK - <a href="https://shiny-in-production.jumpingrivers.com/">Shiny in Production</a> will delve into the world of Shiny and other web-based R packages.</p>
<p>What an exciting season ahead! Hope to see you at one (or many) of these events.</p>
<script>window.location.href='https://rviews.rstudio.com/2023/01/18/some-r-conferences-for-2023/';</script>
November 2022: "Top 40" New CRAN Packages
https://rviews.rstudio.com/2023/01/03/november-2022-top-40-new-cran-packages/
Tue, 03 Jan 2023 00:00:00 +0000https://rviews.rstudio.com/2023/01/03/november-2022-top-40-new-cran-packages/
<p>One hundred sixty-seven new packages made it to CRAN in November: Here are my “Top 40” selections in fourteen categories: Climate Modeling: Computational Methods, Data, Ecology, Epidemiology, Genomics, Machine Learning, Mathematics, Networks, Pharma, Statistics, Time Series, Utilities, and Visualization.</p>
<h2 id="climate-modeling">Climate Modeling</h2>
<p><a href="https://CRAN.R-project.org/package=gtfs2emis">gtfs2emis</a> v0.1.0: Implements a bottom up model to estimate the emission levels of public transport systems based on <a href="https://gtfs.org/">General Transit Feed Specification</a> data. Functions estimate several pollutants at high spatial and temporal resolutions. See <a href="https://osf.io/8m2cy/">Viera et al</a> for background. There is a <a href="https://cran.r-project.org/web/packages/gtfs2emis/vignettes/gtfs2emis_intro_vignette.html">Getting Started Guide</a>, and vignettes on <a href="https://cran.r-project.org/web/packages/gtfs2emis/vignettes/gtfs2emis_emission_factor.html">Emission Factors</a> and <a href="https://cran.r-project.org/web/packages/gtfs2emis/vignettes/gtfs2emis_fleet_data.html">Preparing Data</a>.</p>
<p><img src="gfts.png" height = "400" width="400" alt="Spatial distribution of traffic speeds for Dublin, Ireland"></p>
<h3 id="computational-methods">Computational Methods</h3>
<p><a href="https://cran.r-project.org/package=jmatrix">jmatrix</a> v1.1: A mainly instrumental package that allows other packages with cores written in <code>C++</code> to read, write and manipulate matrices in a binary format to mitigate memory issues. See the <a href="https://cran.r-project.org/web/packages/jmatrix/vignettes/jmatrix.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=lazyNumbers">lazyNumbers</a> v1.2.1: Implements <em>lazy numbers</em>, a new number type whose arithmetic is exact, contrary to ordinary floating-point arithmetic. The lazy numbers are implemented in <code>C++</code> with the <a href="https://www.cgal.org/"><code>CGAL</code> library</a>. See <a href="https://cran.r-project.org/web/packages/lazyNumbers/readme/README.html">README</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=miesmuschel">miesmuschel</a> v0.0.2: Provides optimization algorithms and functions that can be used to manually construct specialized optimization loops including the mixed integer evolution strategy as described in <a href="https://direct.mit.edu/evco/article-abstract/21/1/29/933/Mixed-Integer-Evolution-Strategies-for-Parameter?redirectedFrom=fulltext">Li et al. (2013)</a> and the multi-objective optimization algorithms NSGA-II described in <a href="https://ieeexplore.ieee.org/document/996017">Deb et al. (2002)</a>. See <a href="https://cran.r-project.org/web/packages/miesmuschel/readme/README.html">README</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=mlr3mbo">mlr3mbo</a> v0.1.1: Implements a flexible approach to Bayesian optimization that includes both ready-to-use optimization algorithms as well as fundamental building blocks to construct custom algorithms. See <a href="https://link.springer.com/article/10.1023/A:1008306431147">Jones et al. (1998)</a>, <a href="https://link.springer.com/article/10.1023/A:1008306431147">Knowles (2006)</a>, and <a href="https://link.springer.com/chapter/10.1007/978-3-540-87700-4_78">Ponweiser et al. (2008)</a> for examples of ready to use optimization algorithms and the <a href="https://cran.r-project.org/web/packages/mlr3mbo/vignettes/mlr3mbo.html">vignette</a> for examples.</p>
<h3 id="data">Data</h3>
<p><a href="https://cran.r-project.org/package=googletraffic">googletraffic</a> v0.1.1: Allows users to create geographically referenced traffic data from the <a href="https://developers.google.com/maps/documentation/javascript/examples/layer-traffic">Google Maps JavaScript API</a>. Look <a href="https://dime-worldbank.github.io/googletraffic/">here</a> for information to get started.</p>
<p><img src="googletraffic.jpeg" height = "600" width="400" alt="Traffic map of Manhattan"></p>
<p><a href="https://cran.r-project.org/package=IPEDS">IPEDS</a> v0.1.1: Implements an interface to the US <a href="https://nces.ed.gov/ipeds/use-the-data">Post-Secondary Institution Statistics for 2020</a> which contains information on post-secondary institutions, students, faculty, demographics, financial aid, educational and recreational offerings, and completions. See the <a href="https://cran.r-project.org/web/packages/IPEDS/vignettes/IPEDS-vignette.html">vignette</a>.</p>
<p><img src="IPEDS.png" height = "400" width="500" alt="Scatter plot of student diversity vs. staff diversity in New England institutions"></p>
<p><a href="https://cran.r-project.org/package=npi">npi</a> v0.2.0: Provides access the US <a href="https://npiregistry.cms.hhs.gov/api/">National Provider Identifier Registry API</a> which contains administrative data linked to a specific individual or organizational healthcare providers. There is an <a href="https://cran.r-project.org/web/packages/npi/vignettes/npi.html">Introduction</a> and a vignette on <a href="https://cran.r-project.org/web/packages/npi/vignettes/advanced-use.html">Advanced Use</a>.</p>
<p><a href="https://cran.r-project.org/package=rfars">rfars</a> v0.2.0: Implements an interface to the US <a href="https://cdan.dot.gov/query">Fatality Analysis Reporting System</a>. See the vignettes <a href="https://cran.r-project.org/web/packages/rfars/vignettes/Crash_Sequences.html">Crash Sequences</a> and <a href="img src="googletraffic.png" height = "600" width="400" alt="Traffic map of Manhattan"">Rural Roads</a>.</p>
<p><img src="rfars.png" height = "600" width="400" alt="Bar charts of crash types"></p>
<p><a href="https://cran.r-project.org/package=tidyDisasters">tidyDisasters</a> v0.1.1: Provides a queryable data set that unites information from three complementary resources: Belgium’s Centre for Research on the Epidemiology of Disasters <a href="https://www.cred.be/">EMDAT</a>, the US National Consortium for the Study of Terrorism <a href="https://www.start.umd.edu/">GTD</a>, and the US Federal Emergency Management Agency <a href="https://www.fema.gov/openfema-data-page/disaster-declarations-summaries-v2">FEMA</a>. There is a brief <a href="https://cran.r-project.org/web/packages/tidyDisasters/vignettes/basic_database_example_20221107.html">User Guide</a>.</p>
<h3 id="ecology">Ecology</h3>
<p><a href="https://cran.r-project.org/package=et.nwfva">et.nwfva</a> v0.1.1: Implements a forest management tool developed by the Northwest German Forest Research Institute (<a href="https://goettingen-campus.de/nw-fva">NW-FVA</a>) for the five main commercial tree species oak, beech, spruce, Douglas-fir and pine for northwestern Germany. See <a href="https://zenodo.org/record/6827728#.Y681suzML0o">Albert et al (2022)</a> for background and the vignettes: <a href="https://cran.r-project.org/web/packages/et.nwfva/vignettes/beispiele.html">Beispiele</a>, <a href="https://cran.r-project.org/web/packages/et.nwfva/vignettes/nutzerhinweise.html">Nutzerhinweise zum Geleit</a>, and <a href="https://cran.r-project.org/web/packages/et.nwfva/vignettes/vergleich_methoden.html">Vergleich der Interpolationsmethoden</a>.</p>
<p><img src="nwfva.png" height = "400" width="600" alt="Plots of height vs age"></p>
<p><a href="https://cran.r-project.org/package=mmodely">mmodely</a> v0.2.2: Provides functions to perform multivariate modeling of evolved traits, with special attention to understanding the interplay of the multi-factorial determinants of their origins in complex ecological settings. See <a href="https://www.cell.com/trends/ecology-evolution/fulltext/S0169-5347(06)00400-9?_returnURL=https%3A%2F%2Flinkinghub.elsevier.com%2Fretrieve%2Fpii%2FS0169534706004009%3Fshowall%3Dtrue">Stephens (2007)</a>, <a href="https://onlinelibrary.wiley.com/doi/10.1111/j.1420-9101.2010.02210.x">Gruebner (2011)</a>, and <a href="https://link.springer.com/article/10.1007/s00265-010-1028-7">Garamszegi (2011)</a> for background, and the examples on <a href="https://cran.r-project.org/web/packages/mmodely/vignettes/Schruth-mmodely-vignette-Vision.pdf">primate vision</a> and <a href="https://cran.r-project.org/web/packages/mmodely/vignettes/Schruth-mmodely-vignette-Vocal.pdf">vocal communications</a>.</p>
<p><a href="https://cran.r-project.org/package=webSDM">webSDM</a> v1.1-1: Implements the method of <a href="https://www.authorea.com/users/522841/articles/595095-integrating-food-webs-in-species-distribution-models-improves-ecological-niche-estimation-and-predictions?commit=5fe6a87efdbbb3461a2b7301435ec1bfb2397cf3">Poggiato et al. (2022)</a> for working with tropic Species Distribution Models. There is an <a href="https://cran.r-project.org/web/packages/webSDM/vignettes/Introduction.html">Introduction</a> and there are vignettes on <a href="Composite variables and biotic-abiotic interactions">Composit variables</a>, <a href="https://cran.r-project.org/web/packages/webSDM/vignettes/Differences_with_SDMs.html">Differences between SDM and Trophic SDM</a>.</p>
<p><img src="webSDM.png" height = "450" width="450" alt="Plots of species distributions"></p>
<h3 id="epidemiology">Epidemiology</h3>
<p><a href="https://cran.r-project.org/package=exDE">exDE</a> v1.0.0: Provides tools to set up modular ordinary and delay differential equation models for mosquito-borne pathogens, focusing on malaria. See <a href="https://www.medrxiv.org/content/10.1101/2022.11.07.22282044v1">Wu et al. (2022)</a> for a description on the methods implemented. There are ten vignettes including <a href="https://cran.r-project.org/web/packages/exDE/index.html">Basic Copmetition Aquatic Mosquito Model</a> and <a href="https://cran.r-project.org/web/packages/exDE/vignettes/human_sip.html">SIP Human Model</a>.</p>
<p><img src="exDE.png" height = "400" width="400" alt="Plots of results for 3 population human model"></p>
<h3 id="genomics">Genomics</h3>
<p><a href="https://cran.r-project.org/package=idopNetwork">idopNetwork</a> v0.1.1: Implements a cartographic tool to chart spatial microbial interaction networks. See <a href="https://academic.oup.com/genetics/article/180/2/821/6073848?login=false">Kim et al. (2008)</a> and <a href="https://academic.oup.com/bib/article/13/2/162/253162?login=false">Wang et al. (2011)</a> for information on functional clustering, <a href="https://www.nature.com/articles/s41540-019-0116-1">Chen et al. (2019)</a> and <a href="https://www.tandfonline.com/doi/full/10.1080/19490976.2022.2106103">Cao et al. (2022)</a> for background on the model, and the <a href="https://cran.r-project.org/web/packages/idopNetwork/vignettes/idopNetwork_vignette.html">vignette</a> for examples.</p>
<p><img src="idop.png" height = "400" width="600" alt="Plots of Niche index vs. habitat index for various bacteria"></p>
<p><a href="https://cran.r-project.org/package=tip">tip</a> v0.1.0: Provides functions to cluster data without specifying the number of clusters using the Table Invitation Prior (TIP) introduced by <a href="https://www.mdpi.com/2073-4425/13/11/2036">Harrison et al. (2022)</a>. There are vignettes on matrix clustering with <a href="https://cran.r-project.org/web/packages/tip/vignettes/matrix-CONSTANT-simulated-vignette.html">CONSTANT</a> and <a href="https://cran.r-project.org/web/packages/tip/vignettes/matrix-MNIW-simulated-vignette.html">MNIW</a>, <a href="https://cran.r-project.org/web/packages/tip/vignettes/tensor-CONSTANT-simulated-vignette.html">Tensor clustering CONSTANT</a>, <a href="https://cran.r-project.org/web/packages/tip/vignettes/vector-NIW-iris-vignette.html">iris NIW</a>, and <a href="https://cran.r-project.org/web/packages/tip/vignettes/vector-NIW-usarrests-vignette.html">usarrests NIW</a>.</p>
<p><img src="tip.png" height = "500" width="400" alt="Posterior similarity matrix for clusters"></p>
<p><a href="https://CRAN.R-project.org/package=scistreer">scistreer</a> v1.0.1: Enables fast maximum-likelihood phylogeny inference from noisy single-cell data using the <em>ScisTree</em> algorithm described in <a href="https://academic.oup.com/bioinformatics/article/36/3/742/5555811?login=false">Wu (2019)</a> making the method applicable to massive single-cell datasets (>10,000 cells). Look <a href="https://kharchenkolab.github.io/scistreer/">here</a> for an example.</p>
<p><img src="scistreer.png" height = "500" width="500" alt="Visualization of maximum likelihood tree"></p>
<h3 id="machine-learning">Machine Learning</h3>
<p><a href="https://cran.r-project.org/package=tidyclust">tidyclust</a> v0.1.1: Implements a common interface to specifying clustering models, in the same style as <code>parsnip</code>. Creates unified interface across different functions and computational engines. See <a href="https://cran.r-project.org/web/packages/tidyclust/readme/README.html">README</a> for examples.</p>
<p><img src="tidyclust.svg" height = "400" width="600" alt="Examples of k means vs. hierarchical clusters"></p>
<p><a href="https://cran.r-project.org/package=VSOLassoBag">VSOLassoBag</a> v0.99.0: Implements an integrated <em>Wrapped LASSO</em> ensemble learning strategy to help select efficient, stable, and high confidential variables from omics-based data. Functions integrate and vote on variables generated from multiple LASSO models to determine the optimal candidates. See <a href="https://www.science.org/doi/10.1126/scitranslmed.aax7533">Luo et al. (2020)</a> for details and the <a href="https://cran.r-project.org/web/packages/VSOLassoBag/vignettes/VSOLassoBag.html">vignette</a> for examples.</p>
<p><img src="VSO.png" height = "400" width="400" alt="Histogram of observed frequency distribution"></p>
<h3 id="mathematics">Mathematics</h3>
<p><a href="https://cran.r-project.org/package=tensorFun">tensorFun</a> v0.1.1: Provides basic functions to handle higher-order tensor data. See <a href="https://epubs.siam.org/doi/10.1137/07070111X">Kolda and Bader (2009)</a> for background on tensor decompositions, <a href="https://arxiv.org/abs/1910.06677">Bau and Ng (2021)</a> for information on missing values, and the <a href="https://cran.r-project.org/web/packages/tensorFun/vignettes/A-short-introduction-to-tensorFun.html">vignette</a> for a short introduction.</p>
<p><a href="https://cran.r-project.org/package=TransTGGM">TransTGGM</a> V1.0.0: Implements a transfer learning framework for tensor Gaussian graphical models, which takes full advantage of informative auxiliary domains even when non-informative auxiliary domains are present. See <a href="https://arxiv.org/abs/2211.09391">Ren, Zhen, and Wang</a> for background and the <a href="https://cran.r-project.org/web/packages/TransTGGM/vignettes/TransTGGM.html">vignette</a>.</p>
<h3 id="networks">Networks</h3>
<p><a href="https://cran.r-project.org/package=nett">nett</a> 1.0.0: Provides multiple methods for fitting, model selection and goodness-of-fit testing in degree-corrected stochastic blocks models. Implements the methods in <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-41/issue-4/Pseudo-likelihood-methods-for-community-detection-in-large-sparse-networks/10.1214/13-AOS1138.full">Amini et al.(2013)</a>, <a href="https://rss.onlinelibrary.wiley.com/doi/10.1111/rssb.12117">Bickel and Sarkar (2015)</a>, <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-44/issue-1/A-goodness-of-fit-test-for-stochastic-block-models/10.1214/15-AOS1370.full">Lei (2016)</a>, <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-45/issue-2/Likelihood-based-model-selection-for-stochastic-block-models/10.1214/16-AOS1457.full">Wang and Bickel (2017)</a> and more. There are vignettes <a href="https://cran.r-project.org/web/packages/nett/vignettes/Community_Detection.html">Community Detection</a>, <a href="https://cran.r-project.org/web/packages/nett/vignettes/Visualization.html">Visualization</a>, <a href="https://cran.r-project.org/web/packages/nett/vignettes/explore-comm.html">Explore Comm</a>, and <a href="https://cran.r-project.org/web/packages/nett/vignettes/hard_dcsbm_testing.html">dcsbm testing</a>.</p>
<p><img src="nett.png" height = "400" width="600" alt="Network visualization"></p>
<h3 id="pharma">Pharma</h3>
<p><a href="https://cran.r-project.org/package=DrugSim2DR">DrugSim2DR</a> v0.1.0: Implements a tool to predict drug functional similarity for drug repurposing. See the <a href="https://cran.r-project.org/web/packages/DrugSim2DR/vignettes/DrugSim2DR.html">vignette</a>.</p>
<p><img src="Drug.png" height = "400" width="600" alt="Heatmaps of targets for Phenelzine"></p>
<p><a href="https://cran.r-project.org/package=parttime">parttime</a> v0.1.0: Provides classes for embedding partial missingness as a central part of datetime classes allowing for more ergonomic use of datetimes for challenging datetime computation, including calculations of overlapping date ranges, imputations, and more. See <a href="https://cran.r-project.org/web/packages/parttime/readme/README.html">README</a> for examples.</p>
<h3 id="statistics">Statistics</h3>
<p><a href="https://cran.r-project.org/package=GAGAs">GAGAs</a> v0.5.1: Implements the Global Adaptive Generative Adjustment Algorithm for generalized liner models used for improving the computational efficiency in the high-dimensional data analysis. See <a href="https://arxiv.org/abs/1911.00658">Wang et al. (2022)</a> for the theory.</p>
<p><a href="https://cran.r-project.org/package=kfino">kfino</a> v1.0.0: Implements method for detecting outliers with a Kalman filter on impulsed noised outliers and prediction on cleaned data. See <a href="https://arxiv.org/abs/2208.00961">Cloez et al. (2022)</a> for the details and the vignettes on <a href="https://cran.r-project.org/web/packages/kfino/vignettes/HowTo.html">outlier detection</a> and <a href="https://cran.r-project.org/web/packages/kfino/vignettes/multipleFit.html">outlier detection with parallelization</a>.</p>
<p><img src="kfino.png" height = "400" width="600" alt="Scatter plot with predicted outliers"></p>
<p><a href="https://cran.r-project.org/package=pwrss">pwrss</a> v0.2.0: Implements power and sample size calculations for a number of one, two and three sample tests. See the <a href="https://cran.r-project.org/web/packages/pwrss/vignettes/examples.html">vignette</a> for examples.</p>
<p><img src="pwrss.png" height = "400" width="600" alt="Densities illustrating power calculations for various tests"></p>
<p><a href="https://CRAN.R-project.org/package=spatstat.model">spatstat.models</a> v3.0-2: A member of the <a href="https://spatstat.r-universe.dev/ui#builds"><code>spatstat</code></a> family of packages, it provides multiple functions for exploratory data analysis and nonparametric analysis of spatial data, mainly spatial point patterns. See <a href="https://spatstat.org/">spatstat.org</a> for documentation.</p>
<p><a href="https://cran.r-project.org/package=vMF">vMF</a> v0.0.1: Provides functions for fast sampling from von Mises-Fisher distribution using the method proposed in <a href="https://www.tandfonline.com/doi/abs/10.1080/03610919408813161">Wood (1994)</a>. See the <a href="https://cran.r-project.org/web/packages/vMF/vignettes/vMF.pdf">vignette</a>.</p>
<h3 id="time-series">Time Series</h3>
<p><a href="https://cran.r-project.org/package=ardl.nardl">ardl.nardl</a> v1.2.2: Implements linear and nonlinear autoregressive distributed lag (ARDL & NARDL) models and the corresponding error correction models and includes a test for long-run and short-run asymmetry and the <a href="https://onlinelibrary.wiley.com/doi/10.1002/jae.616">Pesaran, Shin & Smith (2001)</a> bounds test for level relationships.</p>
<h3 id="utilities">Utilities</h3>
<p><a href="https://cran.r-project.org/package=cookies">cookies</a> v0.2.0: Provides tools for working with cookies in <code>shiny</code> apps, in part by wrapping the <a href="https://github.com/js-cookie/js-cookie"><code>js-cookie</code></a> JavaScript library. See <a href="https://cran.r-project.org/web/packages/cookies/readme/README.html">README</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=formatdown">formatdown</a> v0.1.1: Provides a small set of tools for formatting tasks when creating documents in <code>rmarkdown</code> or <code>quarto</code>. See the <a href="https://cran.r-project.org/web/packages/formatdown/vignettes/format_powers_of_ten.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=hellorust">hellorust</a> v1.0.0: Implements tools to use Rust code in R without hacks or frameworks. Includes basic examples of importing cargo dependencies, spawning threads and passing numbers or strings from Rust to R. Look <a href="https://jeroen.github.io/erum2018/#1">here</a> and <a href="https://github.com/r-rust/hellorust">here</a> for for documentation.</p>
<p><a href="https://cran.r-project.org/package=prismjs">prismjs</a> v1.1.0: Implements a server-side rendering in R using <a href="https://prismjs.com/">Prism</a>, a lightweight, extensible syntax highlighter, built with modern web standards in mind such that no JavaScript library is required in the resulting HTML documents. Look <a href="https://docs.ropensci.org/prismjs/">here</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=rjtools">rjtools</a> v1.0.9: Provides tools to create an <a href="https://journal.r-project.org/">R Journal</a> <code>rmarkdown</code> template article, that will generate HTML and PDF versions of your paper. There are vignettes <a href="https://cran.r-project.org/web/packages/rjtools/vignettes/article_template.html">rjtools-template</a>, <a href="https://cran.r-project.org/web/packages/rjtools/vignettes/check_functions.html">Check</a>, <a href="https://cran.r-project.org/web/packages/rjtools/vignettes/create_article.html">Create article</a>, and <a href="https://cran.r-project.org/web/packages/rjtools/vignettes/format-details.html">Format details</a>.</p>
<h3 id="visualization">Visualization</h3>
<p><a href="https://cran.r-project.org/package=funkyheatmap">funkyheatmap</a> v0.1.0: Provides functions for generating heatmap-like visualizations for benchmark data frames, which can be fine-tuned with annotations for columns and rows. See <a href="https://www.nature.com/articles/s41587-019-0071-9">Saelens et al. (2019)</a> for background and the vignettes <a href="https://cran.r-project.org/web/packages/funkyheatmap/vignettes/dynbenchmark.html">Recreating the dynbenchmark figures</a> and <a href="https://cran.r-project.org/web/packages/funkyheatmap/vignettes/mtcars.html">Demo with mtcars</a> for examples.</p>
<p><img src="funky.png" height = "700" width="600" alt="Heat map with annotations"></p>
<p><a href="https://cran.r-project.org/package=ggbrain">ggbrain</a> v0.8.0: Implements a <code>ggplot2</code>-consistent approach to generating 2D displays of volumetric brain imaging data from multiple NIfTI images. There is an <a href="https://cran.r-project.org/web/packages/ggbrain/vignettes/ggbrain_introduction.html">Introduction</a> and there are vignettes on <a href="https://cran.r-project.org/web/packages/ggbrain/vignettes/ggbrain_aesthetics.html">Aesthetic refinement</a> and <a href="https://cran.r-project.org/web/packages/ggbrain/vignettes/ggbrain_labels.html">Annotations and labels</a>.</p>
<p><img src="ggbrain.png" height = "700" width="600" alt="Three views of a brain"></p>
<p><a href="https://cran.r-project.org/package=ggpcp">ggpcp</a> v0.2.0: Provides a Grammar of Graphics implementation of parallel coordinate plots that incorporates categorical variables into the plots in a principled manner. Look <a href="https://github.com/heike/ggpcp">here</a> for examples.</p>
<p><img src="ggpcp.png" height = "400" width="600" alt="Parallel plot with labels"></p>
<p><a href="https://cran.r-project.org/package=ggredist">ggredist</a> v0.0.2: Provides <code>ggplot2</code> extensions for political map making based on simple features and includes palettes and scales for red to blue color mapping and for discrete maps. See <a href="https://cran.r-project.org/web/packages/ggredist/readme/README.html">README</a> for an example.</p>
<p><img src="ggredist.png" height = "400" width="600" alt="Vote share map of Oregon"></p>
<p><a href="https://cran.r-project.org/package=ggsector">ggsector</a> v1.6.6: Implements functions that use <code>grid</code> and <code>ggplot2</code> to plot sectors, draw complex heat maps and interact with <code>Seurat</code> to plot gene expression percentages. See the <a href="https://cran.r-project.org/web/packages/ggsector/vignettes/ggsector.html">vignette</a>.</p>
<p><img src="ggsector.png" height = "400" width="600" alt="Heat map with sectors"></p>
<p><a href="https://cran.r-project.org/package=sherlock">sherlock</a> v0.5.1: Provides graphical displays and statistical tools for structured problem solving and diagnosis with functions that are especially useful for applying the process of elimination as a problem diagnosis technique. See <a href="https://dokumen.pub/the-new-science-of-fixing-things-powerful-insights-about-root-cause-analysis-that-will-transform-product-and-process-performance-9798626423686.html">Hartsborne (2020)</a> for background and <a href="https://cran.r-project.org/web/packages/sherlock/readme/README.html">README</a> for examples.</p>
<p><img src="sherlock.png" height = "400" width="600" alt="Example of a Polar Small Multiples Plot"></p>
<script>window.location.href='https://rviews.rstudio.com/2023/01/03/november-2022-top-40-new-cran-packages/';</script>
October 2022: "Top 40" New CRAN Packages
https://rviews.rstudio.com/2022/11/28/october-2022-top-40-new-cran-packages/
Mon, 28 Nov 2022 00:00:00 +0000https://rviews.rstudio.com/2022/11/28/october-2022-top-40-new-cran-packages/
<p>One hundred seventy-four new packages made it to CRAN in October. Here are my “Top 40” selections in sixteen categories: Astronomy, Biology, Business, Computational Methods, Data, Ecology, Finance, Genomics, Mathematics, Machine Learning, Medicine, Pharma, Statistics, Time Series, Utilities, Visualization.</p>
<h3 id="astronomy">Astronomy</h3>
<p><a href="https://cran.r-project.org/package=skylight">skylight</a> v1.1: Provides a function to calculate sky illuminance values (in lux) for both the sun and moon. The model is a verbatim translation of the code by <a href="https://archive.org/details/DTIC_ADA182110/page/n15/mode/2up">Janiczek and DeYoung (1987)</a>. There are vignettes for <a href="https://cran.r-project.org/web/packages/skylight/vignettes/skylight.html">Use</a> and <a href="https://cran.r-project.org/web/packages/skylight/vignettes/skylight_advanced.html">Advanced Use</a>.</p>
<h3 id="biology">Biology</h3>
<p><a href="https://cran.r-project.org/package=palaeoverse">palaeoverse</a> v1.0.0:
Provides tools to support data preparation and exploration for palaeobiological analyses including functions for data cleaning, binning (time and space), summarisation and visualisation with the goals of improving code reproducibility and accessibility and establishing standards for the palaeobiological community. See <a href="https://eartharxiv.org/repository/view/4619/">Jones et al.</a> for details, and the <a href="https://cran.r-project.org/web/packages/palaeoverse/vignettes/structure-and-standards.html">contribution guide</a> to get involved.</p>
<p><a href="https://cran.r-project.org/package=pirouette">pirouette</a> v1.6.5: Implements a method to create a Bayesian posterior from a phylogeny that depicts the true evolutionary relationships. See <a href="https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.13514">Richèl et al. (2020)</a> for background. There are several vignettes including a <a href="https://cran.r-project.org/web/packages/pirouette/vignettes/tutorial.html">Tutorial</a>, a <a href="https://cran.r-project.org/web/packages/pirouette/vignettes/demo.html">demo</a>, and a guide showing how to use the package in a scientific <a href="https://cran.r-project.org/web/packages/pirouette/vignettes/experiment.html">experiment</a>.</p>
<p><img src="pirouette.png" height = "400" width="400" alt="Heat map depicting DAN alignment"></p>
<h3 id="business">Business</h3>
<p><a href="https://cran.r-project.org/package=bupaverse">bupaverse</a> v0.1.0: Facilitates loading the packages comprising the <a href="https://bupar.net/">bupaverse</a>, an integrated suite of R packages for handling and analysing business process data, developed by the Business Informatics research group at Hasselt University, Belgium. See the <a href="https://cran.r-project.org/web/packages/bupaverse/vignettes/getting_started.html">Getting Started Guide</a>.</p>
<p><img src="bupaverse.png" height = "300" width="500" alt="bupaR logo"></p>
<h3 id="computational-methods">Computational Methods</h3>
<p><a href="https://cran.r-project.org/package=fastWavelets">fastWavelets</a> v1.0.1: Provides an <code>Rcpp</code> implementation of the Maximal Overlap Discrete Wavelet Transform (MODWT) and the À Trous Discrete Wavelet Transform. See <a href="https://www.sciencedirect.com/science/article/abs/pii/S0022169418303317?via%3Dihub">Quilty & Adamowski (2018)</a> for background and <a href="https://cran.r-project.org/web/packages/fastWavelets/readme/README.html">README</a> for examples.</p>
<p><img src="fastWavelets.png" height = "300" width="500" alt="Plots of wavelet coefficients"></p>
<p><a href="https://cran.r-project.org/package=gips">gips</a> v1.0.0: Employs the methods described in <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-50/issue-3/Model-selection-in-the-space-of-Gaussian-models-invariant-by/10.1214/22-AOS2174.short">Graczyk et al. (2022)</a> to find the permutation symmetry group under which the covariance matrix of the data is invariant. See the vignettes <a href="https://cran.r-project.org/web/packages/gips/vignettes/Optimizers.html">Optimizers</a>, <a href="https://cran.r-project.org/web/packages/gips/vignettes/Theory.html">Theory</a>, and <a href="https://cran.r-project.org/web/packages/gips/vignettes/gips.html">gips</a>.</p>
<p><a href="https://cran.r-project.org/package=HomomorphicEncryption">HomomorphicEncryption</a> v0.1.0: Implements the <a href="https://eprint.iacr.org/2012/144">Brakerski-Fan-Vercauteren (2012)</a>, <a href="https://dl.acm.org/doi/10.1145/2633600">Brakerski-Gentry-Vaikuntanathan (2014)</a>, and <a href="https://eprint.iacr.org/2016/421.pdf">Cheon-Kim-Kim-Song (2016)</a> schema for fully homomorphic encryption. There are seven short vignettes including <a href="https://cran.r-project.org/web/packages/HomomorphicEncryption/vignettes/BFV.html">BFV</a>, <a href="https://cran.r-project.org/web/packages/HomomorphicEncryption/vignettes/BGV.html">BGV</a>, and <a href="https://cran.r-project.org/web/packages/HomomorphicEncryption/vignettes/CKKS.html">CKKS</a>.</p>
<p><a href="https://cran.r-project.org/package=rxode2random">rxode2random</a> v2.0.9: Implements parallel random number generation. <a href="https://ascpt.onlinelibrary.wiley.com/doi/10.1002/psp4.12052">See Wang et al. (2016)</a> and <a href="https://ascpt.onlinelibrary.wiley.com/doi/10.1002/psp4.12445">Fidler et al (2019)</a> for background and <a href="https://ascpt.onlinelibrary.wiley.com/doi/10.1002/psp4.12445">README</a> for an example..</p>
<h3 id="data">Data</h3>
<p><a href="https://cran.r-project.org/package=airnow">airnow</a> v0.1.0: Provides functions to retrieve U.S. Government <a href="https://www.airnow.gov/">AirNow</a> air quality data. See <a href="https://cran.r-project.org/web/packages/airnow/readme/README.html">README</a> to get started.</p>
<p><a href="https://cran.r-project.org/package=amazonadsR">amazonadsR</a> v0.1.0: Provides functions to collect data on digital marketing campaigns using the <a href="https://windsor.ai/api-fields/">Windsor.ai API</a>. See the <a href="https://cran.r-project.org/web/packages/amazonadsR/vignettes/tutorial.html">tutorial</a> for an example and also look at the related new packages:
<a href="https://cran.r-project.org/package=bingadsR"><code>bingadsR</code></a>,
<a href="https://cran.r-project.org/package=facebookadsR"><code>facebookadsR</code></a>,
<a href="https://cran.r-project.org/package=googleadsR"><code>googleadsR</code></a>,
<a href="https://cran.r-project.org/package=instagramadsR"><code>instagramadsR</code></a>,
<a href="https://cran.r-project.org/package=linkedInadsR"><code>linkedinadsR</code></a>,
<a href="https://cran.r-project.org/package=pinterestadsR"><code>pinterestadsR</code></a>,
<a href="https://cran.r-project.org/package=redditadsR"><code>redditadsR</code></a>,
<a href="https://cran.r-project.org/package=snapchatadsR"><code>snapchatadsR</code></a>,
<a href="https://cran.r-project.org/package=tiktokadsR"><code>ticktokadsR</code></a>,
<a href="https://cran.r-project.org/package=twitteradsR"><code>twitteradsR</code></a>. Pablo Sanchez was on a roll in October.</p>
<p><img src="amazon.png" height = "400" width="300" alt="Distribution of clicks for two ads campaigns"></p>
<p><a href="https://cran.r-project.org/package=congress">congress</a> v0.0.1: Provides functions to download and read data on United States congressional proceedings through the <a href="https://github.com/LibraryOfCongress/api.congress.gov/">Congress.gov</a> API of the Library of Congress. See <a href="https://cran.r-project.org/web/packages/congress/readme/README.html">README</a> for an example.</p>
<h3 id="ecology">Ecology</h3>
<p><a href="https://cran.r-project.org/package=canaper">canaper</a> v1.0.0: Provides functions to analyze the spatial distribution of biodiversity especially useful in the categorical analysis of neo- and paleo-endemism (CANAPE) as described in <a href="https://www.nature.com/articles/ncomms5473">Mishler et al. (2014)</a> and for statistical tests to determine the types of endemism that occur in a study area while accounting for the evolutionary relationships of species. There are vignettes on <a href="https://cran.r-project.org/web/packages/canaper/vignettes/canape.html">CANAPE</a>, <a href="https://cran.r-project.org/web/packages/canaper/vignettes/how-many-rand.html">randomization</a>, and <a href="https://cran.r-project.org/web/packages/canaper/vignettes/parallel.html">parallel computing</a>.</p>
<p><img src="canaper.png" height = "300" width="500" alt="Plots showing phylogenetic diversity and endemism"></p>
<p><a href="https://cran.r-project.org/package=EcoEnsemble">EcoEnsemble</a> v1.0.1: Provides functions to fit and sample from the ensemble model described in <a href="https://onlinelibrary.wiley.com/doi/abs/10.1111/faf.12310">Spence et al (2018)</a>. There is an <a href="https://cran.r-project.org/web/packages/EcoEnsemble/vignettes/EcoEnsemble.html">Introduction</a> and there are two additional vignettes: <a href="https://cran.r-project.org/web/packages/EcoEnsemble/vignettes/ExploringPriors.html">ExploringPriors</a> and <a href="https://cran.r-project.org/web/packages/EcoEnsemble/vignettes/SyntheticData.html">SyntheticData</a>.</p>
<p><img src="EcoEnsemble.png" height = "500" width="500" alt="Multiple plots of ensemble object"></p>
<p><a href="https://cran.r-project.org/package=rTRIPLEXCWFlux">rTRIPLEXCWFlux</a> v0.2.0: Encodes the carbon uptake submodule and evapotranspiration submodule of the TRIPLEX-CW-Flux model to run the simulation of carbon-water coupling. See <a href="https://www.sciencedirect.com/science/article/abs/pii/S030438000800361X?via%3Dihub">Zhou et al. (2008)</a> <a href="https://www.semanticscholar.org/paper/Evaporation-and-environment.-Monteith/428f880c29b7af69e305a2bf73e425dfb9d14ec8">Monteith (1965)</a> for background and the <a href="https://cran.r-project.org/web/packages/rTRIPLEXCWFlux/vignettes/model-vignette.html">vignette</a> for examples.</p>
<p><img src="rTRIP.png" height = "500" width="500" alt="Plots showing simulated evapotranspiration (ET) by season"></p>
<p><a href="https://cran.r-project.org/package=stopdetection">stopdetection</a> v0.1.1: Enables <em>stop</em> detection in time stamped trajectory by implementing the Stay Point detection algorithm originally described in <a href="https://ieeexplore.ieee.org/document/5088915">Ye (2009)</a> that uses time and distance thresholds to characterize spatial regions as <em>stops</em>. See the <a href="https://cran.r-project.org/web/packages/stopdetection/vignettes/stopdetection-vignette.html">vignette</a> for examples.</p>
<p><img src="stop.png" height = "500" width="500" alt="Latitude vs. longitude plot showing distance in meters subject may range from a stop point"></p>
<h3 id="finance">Finance</h3>
<p><a href="https://cran.r-project.org/package=highOrderPortfolios">highOrderPortfolios</a> v0.1.0: Implements methods to select portfolios using high order moments to characterize return distributions. See <a href="https://arxiv.org/abs/2008.00863">Zhou & Palomar (2021)</a> and <a href="https://arxiv.org/abs/2206.02412">Wang et al. (2022)</a> for the theory and the <a href="https://cran.r-project.org/web/packages/highOrderPortfolios/vignettes/DesignOfHighOrderPortfolios.html">vignette</a> to get started.</p>
<p><img src="highorder.png" height = "500" width="500" alt="Plot of portfolio weights vs. asset indexes for two methods"></p>
<p><a href="https://cran.r-project.org/package=MSTest">MSTest</a> v0.1.0: Implements hypothesis testing procedures described in <a href="https://onlinelibrary.wiley.com/doi/10.1002/jae.3950070506">Hansen (1992)</a>, <a href="https://onlinelibrary.wiley.com/doi/abs/10.3982/ECTA8609">Carrasco, Hu, & Ploberger (2014)</a> and <a href="https://www.tandfonline.com/doi/full/10.1080/07474938.2017.1307548">Dufour & Luger (2017)</a> that can be used to identify the number of regimes in Markov switching models.
See <a href="https://cran.r-project.org/web/packages/MSTest/readme/README.html">README</a> for an example.</p>
<h3 id="genomics">Genomics</h3>
<p><a href="https://cran.r-project.org/package=metevalue">metevalue</a> v0.1.13: Implements the <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-49/issue-3/E-values-Calibration-combination-and-applications/10.1214/20-AOS2020.full">e-value</a> method to correct p-values in omics data association studies. See <a href="https://bioconductor.org/packages/release/bioc/html/BiSeq.html">Hebestreit & Klein (2022)</a> and <a href="https://bioconductor.org/packages/release/bioc/html/methylKit.html">Akalin et.al (2012)</a> for background and the <a href="https://cran.r-project.org/web/packages/metevalue/vignettes/metevalue.html">vignette</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=SCpubr">SCpubr</a> v1.0.4: Implements a system that provides a streamlined way of generating publication ready plots for known Single-Cell transcriptomics data. Look <a href="https://enblacar.github.io/SCpubr-book/">here</a> for an online reference manual.</p>
<p><img src="SCpubr.png" height = "500" width="500" alt="Groupwise DE analysis plot"></p>
<h3 id="mathematics">Mathematics</h3>
<p><a href="https://cran.r-project.org/package=Boov">Boov</a> v1.0.0: Provides functions to perform the Boolean operations union, difference and intersection on volumes. Computations are done by the <code>C++</code> library <a href="https://www.cgal.org/"><code>CGAL</code></a>. See <a href="https://cran.r-project.org/web/packages/Boov/readme/README.html">README</a> for some examples. Also, have a look at the package <a href="https://cran.r-project.org/package=MinkowskiSum">MinkowskiSum</a>.</p>
<p><img src="Boov.gif" height = "400" width="400" alt="Difference of two three dimensional objects"></p>
<p><a href="https://cran.r-project.org/package=fitode">fitode</a> v0.1.1: Provides methods and functions for fitting ordinary differential equations that use sensitivity equations to compute gradients of ODE trajectories with respect to underlying parameters. See the <a href="https://cran.r-project.org/web/packages/fitode/vignettes/fitode.pdf">vignette</a> for details.</p>
<p><a href="https://cran.r-project.org/package=manifold">manifold</a> v0.1.1: Implements operations for Riemannian manifolds including geodesic distance, Riemannian metric, and exponential and logarithm maps, and also incorporates a random object generator on the manifolds. See <a href="https://onlinelibrary.wiley.com/doi/10.1111/biom.13385">Dai, Lin, and Müller (2021)</a> for details.</p>
<h3 id="machine-learning">Machine Learning</h3>
<p><a href="https://cran.r-project.org/package=SoftBart">SoftBart</a> v1.0.1: Implements the SoftBart model of described by <a href="https://rss.onlinelibrary.wiley.com/doi/10.1111/rssb.12293">Linero and Yang (2018)</a> with the optional use of a sparsity-inducing prior to allow for variable selection. The <a href="https://cran.r-project.org/web/packages/SoftBart/vignettes/SoftBart-Vig.pdf">vignette</a> contains theory and examples.</p>
<p><img src="regtree.png" height = "500" width="600" alt="Plots showing the difference between hard and soft regression trees"></p>
<p><a href="https://cran.r-project.org/package=tidyfit">tidyfit</a> v0.5.1: Extends the tidy data environment with functions to fit and cross validate linear regression and classification algorithms on grouped data. There are several vignettes including <a href="https://cran.r-project.org/web/packages/tidyfit/vignettes/Predicting_Boston_House_Prices.html">Predicting Boston House Prices</a>, <a href="https://cran.r-project.org/web/packages/tidyfit/vignettes/Multinomial_Classification.html">Multinomial Classification</a>, and <a href="https://cran.r-project.org/web/packages/tidyfit/vignettes/Rolling_Window_Time_Series_Regression.html">Rolling Window Time Series Regression</a>.</p>
<p><img src="tidyfit.jpeg" height = "700" width="500" alt="Flowchart of the model fitting methodology"></p>
<h3 id="medicine">Medicine</h3>
<p><a href="https://cran.r-project.org/package=cities">cities</a> v0.1.0: Provides functions to simulate clinical trials and summarize causal effects and treatment policy estimands in the presence of intercurrent events. Have a look at the <a href="https://cran.r-project.org/web/packages/cities/vignettes/CITIES_demo.html">demo</a>.</p>
<p><img src="cities.png" height = "400" width="400" alt="Plots showing proportion of treatment discontinuities by trial arm at various times"></p>
<p><a href="https://cran.r-project.org/package=RCT2">RCT2</a> v0.0.1: Implements various statistical methods for designing and analyzing two-stage randomized controlled trials using the methods developed by <a href="https://www.tandfonline.com/doi/abs/10.1080/01621459.2020.1775612?journalCode=uasa20">Imai, Jiang, and Malani (2021)</a> and <a href="https://arxiv.org/abs/2011.07677">Imai, Jiang, and Malani (2022)</a>. There are vignettes on <a href="https://cran.r-project.org/web/packages/RCT2/vignettes/interference_vignette.html">Interference</a> and <a href="https://cran.r-project.org/web/packages/RCT2/vignettes/spillover_vignette.html">Causal Inference</a>.</p>
<h3 id="pharma">Pharma</h3>
<p><a href="https://cran.r-project.org/package=DTSEA">DTSEA</a> v0.0.3: Implements a novel tool to identify candidate drugs against a particular disease based on the drug target set enrichment analysis. It assumes the most effective drugs are those with a closer affinity in the protein-protein interaction network to the specified disease. See <a href="https://www.sciencedirect.com/science/article/pii/S0013935122002171?via%3Dihub">Gómez-Carballa et al. (2022)</a> and <a href="https://www.medsci.org/v19p0402.htm">Feng et al. (2022)</a> for disease expression profiles, <a href="https://academic.oup.com/nar/article/46/D1/D1074/4602867">Wishart et al. (2018)</a> and <a href="https://academic.oup.com/nar/article/45/D1/D945/2605707?login=false">Gaulton et al. (2017)</a> for drug target information, and <a href="https://academic.oup.com/nar/article/49/D1/D545/5943834?login=false">Kanehisa et al. (2021)</a> for the details of KEGG database. There is a <a href="https://cran.r-project.org/web/packages/DTSEA/vignettes/DTSEA.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=nlmixr2lib">nlmixr2lib</a> v0.1.0: Provides tools to create model libraries for <code>nlmixr2</code>. Models include pharmacokinetic, pharmacodynamic, and disease models used in pharmacometrics. See the vignette <a href="https://cran.r-project.org/web/packages/nlmixr2lib/vignettes/create-model-library.html">Creating a model library</a>.</p>
<h3 id="statistics">Statistics</h3>
<p><a href="https://cran.r-project.org/package=aIc">aIc</a> v1.0: Implements set of tests for compositional pathologies including for coherence of correlations as suggested by <a href="https://www.sciencedirect.com/science/article/pii/S2590197420300082?via%3Dihub">Erb et al. (2020)</a>, compositional dominance of distance, compositional perturbation invariance as suggested by <a href="https://link.springer.com/article/10.1007/BF00891269">(Aitchison (1992)</a> and singularity of the covariation matrix. See the <a href="https://cran.r-project.org/web/packages/aIc/vignettes/aIc_vignette.html">vignette</a> for details and examples.</p>
<p><img src="aIc.png" height = "300" width="500" alt="Proportion of dominant distance densities"></p>
<p><a href="https://cran.r-project.org/package=ktweedie">ktweedie</a> v1.0.1: Uses Reproducing Kernel Hilbert Space methods to implement Tweedie compound Poisson gamma models with high-dimensional predictors for the analyses of zero-inflated response variables. See the <a href="https://cran.r-project.org/web/packages/ktweedie/vignettes/ktweedie-vignette.html">vignette</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=missoNet">missoNet</a> v1.0.0: Implements efficient procedures for fitting conditional graphical lasso models linking predictor variables to response variables or tasks, when the response data may contain missing values. See the <a href="https://cran.r-project.org/web/packages/missoNet/vignettes/missoNet.html">vignette</a> for examples.</p>
<p><img src="missoNet.png" height = "500" width="500" alt="Multiple correlation plots for various network fits"></p>
<p><a href="https://cran.r-project.org/package=ShapleyOutlier">ShalpeyOutlier</a> v0.1.0: Provides methods to use <a href="https://www.investopedia.com/terms/s/shapley-value.asp#:~:text=Essentially%2C%20the%20Shapley%20value%20is,or%20less%20than%20the%20others.">Shapley values</a> to detect, explain, and cell wise impute multivariate outliers. See <a href="https://arxiv.org/abs/2210.10063">Mayrhofer and Filzmoser (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/ShapleyOutlier/vignettes/ShapleyOutlier_examples.html">vignette</a> for examples.</p>
<p><img src="Shapley.png" height = "500" width="500" alt="Explanation of Mahalanobis distance for six observations"></p>
<p><a href="https://cran.r-project.org/package=SpatialfdaR">SpatialfdaR</a> v1.0.0: Provides functions to that implement finite element analysis methods to spatial functional data analysis. See <a href="https://rss.onlinelibrary.wiley.com/doi/abs/10.1111/rssb.12009">Sangalli et al. (2013)</a> and <a href="https://www.sciencedirect.com/science/article/pii/S0047259X17302944?via%3Dihub">Bernardi et al. (2018)</a> for background and the <a href="https://cran.r-project.org/web/packages/SpatialfdaR/vignettes/Meuse.html">vignette</a> for an example.</p>
<h3 id="time-series">Time Series</h3>
<p><a href="https://cran.r-project.org/package=dfms">dfms</a> v0..1.3: Provides a user friendly and computationally efficient approach to estimate linear Gaussian dynamic factor models using Kalman filter and EM algorithm methods. See <a href="https://www.sciencedirect.com/science/article/abs/pii/S030440761100039X?via%3Dihub">Doz et al. (2011)</a> and <a href="https://onlinelibrary.wiley.com/doi/10.1002/jae.2306">Banbura & Modugno (2014)</a> for background and the <a href="https://cran.r-project.org/web/packages/dfms/vignettes/introduction.html">vignette</a> for examples.</p>
<p><img src="dfms.png" height = "500" width="500" alt="Euro time series models"></p>
<h3 id="utilities">Utilities</h3>
<p><a href="https://cran.r-project.org/package=ExclusionTable">ExclusionTable</a> v1.0.0: Provides functions for creating tables of excluded observations by reporting the number before and after each <code>subset()</code> call together with the number of observations that have been excluded. See the <a href="https://cran.r-project.org/web/packages/ExclusionTable/vignettes/ExclusionTable_vignette.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=shiny.tailwind">shiny.tailwind</a> v0.2.2: Allows <a href="https://tailwindcss.com/">TailwindCSS</a> to be used in Shiny apps with just-in-time compiling including custom <code>CSS</code> with <code>@apply</code> directive, and custom tailwind configurations. See <a href="https://cran.r-project.org/web/packages/shiny.tailwind/readme/README.html">README</a> for examples.</p>
<h3 id="visualization">Visualization</h3>
<p><a href="https://cran.r-project.org/package=AlphaHull3D">AlphaHull3D</a> v1.1.0: Provides functions to compute the <a href="https://en.wikipedia.org/wiki/Alpha_shape">alpha hull</a> of a set of points (informallly: the shape formed by these points) in 3D space. See <a href="https://cran.r-project.org/web/packages/AlphaHull3D/readme/README.html">README</a> for some visualizations, and also have a look at the related packages <a href="https://cran.r-project.org/package=MeshesTools"><code>MeshesTools</code></a>, and <a href="https://cran.r-project.org/package=PolygonSoup"><code>PolygonSoup</code></a>.</p>
<p><img src="tiger.gif" height = "500" width="500" alt="Alpha hull of points forming a torus"></p>
<p><a href="https://cran.r-project.org/package=bangladesh">bangladesh</a> v1.0.0: Provides <code>sf</code> objects, shape files, and functions to draw regional chorpleth maps for Bangladesh. See the <a href="https://cran.r-project.org/web/packages/bangladesh/vignettes/introduction.html">vignette</a>.</p>
<p><img src="bangladesh.png" height = "500" width="500" alt="District level chorpleth plot of Bangladesh"></p>
<p><a href="https://cran.r-project.org/package=ggstats">ggstats</a> v0.1.0: Provides functions to create forest plots of regression model coefficients along with new statistics to compute proportions, weighted mean and cross-tabulation statistics, as well as new geometries to add alternative background color to a plot. There are vignettes on <a href="https://cran.r-project.org/web/packages/ggstats/vignettes/ggcoef_model.html">plotting coefficients</a> and on computing <a href="https://cran.r-project.org/web/packages/ggstats/vignettes/stat_cross.html">cross-tabulation</a>, <a href="https://cran.r-project.org/web/packages/ggstats/vignettes/stat_prop.html">custom proportions</a>, and <a href="https://cran.r-project.org/web/packages/ggstats/vignettes/stat_weighted_mean.html">weighted means</a>.</p>
<p><img src="ggstats.png" height = "400" width="400" alt="Forest plot"></p>
<p><a href="https://cran.r-project.org/package=jagshelper">jagshelper</a> v0.1.11: Provides tools to streamline Bayesian analyses in <code>JAGS</code>including functions for extracting output, streamlining assessment of convergence, and producing summary plots. See the <a href="https://cran.r-project.org/web/packages/jagshelper/vignettes/jagshelper-vignette.html">vignette</a> for examples.</p>
<p><img src="jagshelper.png" height = "500" width="500" alt="JAGS trace plots"></p>
<p><a href="https://cran.r-project.org/package=roughsf">roughsf</a> v1.0.0: Provides functions to draw maps, including “sketchy”, hand-drawn-like maps using the Javascript library <a href="https://roughjs.com/"><code>Roughjs</code></a>. See <a href="https://cran.r-project.org/web/packages/roughsf/readme/README.html">README</a> for examples.</p>
<p><img src="roughjs.png" height = "600" width="800" alt="Sketchy world map"></p>
<script>window.location.href='https://rviews.rstudio.com/2022/11/28/october-2022-top-40-new-cran-packages/';</script>
Analyzing Projected Calculations Using R
https://rviews.rstudio.com/2022/11/21/projected-inventory-calculations-using-r-2/
Mon, 21 Nov 2022 00:00:00 +0000https://rviews.rstudio.com/2022/11/21/projected-inventory-calculations-using-r-2/
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/core-js/shim.min.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/react/react.min.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/react/react-dom.min.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/reactwidget/react-tools.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/htmlwidgets/htmlwidgets.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/reactable-binding/reactable.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/jquery/jquery.min.js"></script>
<link href="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/jquery-sparkline/jquery.sparkline.css" rel="stylesheet" />
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/jquery-sparkline/jquery.sparkline.js"></script>
<script src="/2022/11/21/projected-inventory-calculations-using-r-2/index_files/sparkline-binding/sparkline.js"></script>
<p><br>
<em>Nicolas Nguyen works in the Supply Chain industry, in the area of Demand and Supply Planning, S&OP and Analytics, where he enjoys developing solutions using R and Shiny. Outside his job, he teaches data visualization in R at the Engineering School EIGSI and Business School Excelia in the city of La Rochelle, France.</em></p>
<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p>Demand & Supply Planning requires forecasting techniques to determine the inventory needed to fulfill future orders. We can build end-to-end supply chain monitoring processes with R to identify potential issues and run scenario testing.</p>
<p>In a 3-part series, I will walk through a Demand & Supply Planning workflow.</p>
<ol style="list-style-type: decimal">
<li>In October, we published the first post, <a href="https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/">Using R for Projected Inventory Calculations in Demand & Supply Planning</a>. It is an introduction to projected inventory and coverage methodology. Check it out if you haven’t read it yet!</li>
<li>This post, Analyzing Projected Calculations Using R, presents an analysis of a demo dataset using the <strong>planr package</strong>.</li>
<li>The final post, Visualizing Projected Calculations with reactable and Shiny, will answer the question: how would you present your results to your boss once the analysis is done?</li>
</ol>
<p>By the end of the series, you will understand how and why to use R for Demand & Supply Planning calculations. Let’s continue!</p>
<div id="the-problem-we-aim-to-solve" class="section level2">
<h2>The “problem” we aim to solve</h2>
<p>In Demand & Supply Planning, we often need to calculate <strong>projected inventories</strong> (inventory needed to fulfill future orders) and <strong>projected coverages</strong> (demand needed to cover periods of time). In my previous post, we discussed the methodology behind these calculations. If you haven’t read it, <a href="https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/">click here</a>!</p>
<p>This post will focus on analyzing a demo dataset using the <code>proj_inv()</code> function from the <a href="https://github.com/nguyennico/planr"><strong>planr package</strong></a>. This function calculates projected inventories and coverages with also some analysis features. Then, we can apply the projected inventories & coverages methodology to analyze our data using R!</p>
</div>
<div id="demand-supply-planning-datasets" class="section level2">
<h2>Demand & Supply Planning datasets</h2>
<p>A typical Demand & Supply Planning dataset has the following basic elements, which are essential to calculate projected inventories & coverages:</p>
<ul>
<li>An Item (a SKU or a DFU) or a reference (a group/family of SKUs for example)</li>
<li>A Period</li>
<li>An Opening Inventories</li>
<li>Then a Demand and a Supply Plan</li>
</ul>
<p>We can also add more features, such as stocks parameters expressed in units, coverages, or a combination of both (for example, ensuring a minimum of one month coverage, and also at least two units of stocks).</p>
</div>
<div id="overview-of-the-demo-dataset" class="section level2">
<h2>Overview of the demo dataset</h2>
<p>To illustrate a typical Demand & Supply Planning dataset, we can use the demo dataset, [Blueprint_DB]. This dataset contains dummy data that displays common situations in Demand and Supply Planning (alerts, shortages, overstocks, etc.). [Blueprint_DB] also contains data for the most common type of coverage, minimum and maximum targets.</p>
<p>We can upload the dataset directly from the <a href="https://github.com/nguyennico/planr">planr package</a>:</p>
<pre class="r"><code>library(tidyr)
library(dplyr)
library(stringr)
library(lubridate)</code></pre>
<pre><code>##
## Attaching package: 'lubridate'</code></pre>
<pre><code>## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union</code></pre>
<pre class="r"><code>library(planr)
library(ggplot2)
Blueprint_DB <- planr::blueprint</code></pre>
<pre class="r"><code>glimpse(Blueprint_DB)</code></pre>
<pre><code>## Rows: 520
## Columns: 7
## $ DFU <chr> "Item 000001", "Item 000002", "Item 000003", "Item…
## $ Period <date> 2022-07-03, 2022-07-03, 2022-07-03, 2022-07-03, 2…
## $ Demand <dbl> 364, 1419, 265, 1296, 265, 1141, 126, 6859, 66, 38…
## $ Opening.Inventories <dbl> 6570, 5509, 2494, 7172, 1464, 9954, 2092, 17772, 1…
## $ Supply.Plan <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ Min.Stocks.Coverage <dbl> 4, 4, 4, 6, 4, 6, 4, 6, 4, 4, 4, 4, 4, 6, 4, 6, 4,…
## $ Max.Stocks.Coverage <dbl> 8, 6, 12, 6, 12, 6, 8, 10, 12, 12, 8, 6, 12, 6, 12…</code></pre>
<p>The dataset has seven fields: Demand Forecast Unit (DFU), Period, Demand, Opening Inventories, Supply Plan, Minimum Stocks Coverage, and Maximum Stocks Coverage. We can use a reactable table to look through all the information at once. This helps us get a sense of the distribution of the data and what it looks like for each variable over time. (Code for the table below is in the <a href="#appendix">Appendix</a>.)</p>
<div id="htmlwidget-1" class="reactable html-widget" style="width:auto;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-1">{"x":{"tag":{"name":"Reactable","attribs":{"data":{"DFU":["Item 000001","Item 000002","Item 000003","Item 000004","Item 000005","Item 000006","Item 000007","Item 000008","Item 000009","Item 000010"],"Total.Demand":[14923,25060,5975,28289,3108,54470,7676,114532,3177,7096],"Opening.Inventories":[6570,5509,2494,7172,1464,9954,2092,17772,1222,3411],"Supply.Plan":[6187,17927,3000,20000,1187,21660,6347,51450,791,4440],"Min.Stocks.Coverage":[4,4,4,6,4,6,4,6,4,4],"Max.Stocks.Coverage":[8,6,12,6,12,6,8,10,12,12],"Demand.Quantity":[[364,364,364,260,736,859,859,859,273,349,349,349,200,0,0,0,0,367,514,514,514,506,837,837,837,479,69,62,52,82,107,187,187,187,81,73,0,0,27,187,187,187,161,161,187,187,187,107,187,187,187,107],[1419,1419,1419,1014,721,841,841,841,1160,2427,2427,2427,1502,807,807,807,692,510,714,714,714,216,28,28,28,16,26,26,26,26,0,0,0,0,16,28,28,28,18,39,39,39,33,21,24,24,24,9,13,13,13,8],[265,265,265,189,29,34,34,34,23,42,42,42,50,178,178,178,152,24,34,34,34,41,72,72,72,42,243,243,243,243,90,156,156,156,150,145,145,145,83,145,145,145,124,46,53,53,53,70,145,145,145,83],[1296,1296,1296,926,678,791,791,791,560,1042,1042,1042,785,1329,1329,1329,1139,1452,2032,2032,2032,653,169,169,169,97,96,96,96,96,42,72,72,72,72,72,72,72,48,121,121,121,103,62,72,72,72,42,72,72,72,42],[265,265,265,189,59,69,69,69,40,69,69,69,49,69,69,69,59,49,69,69,69,49,69,69,69,40,31,31,31,31,18,31,31,31,31,31,31,31,18,31,31,31,26,26,31,31,31,18,31,31,31,18],[1141,1141,1141,815,1466,1711,1711,1711,943,1630,1630,1630,1176,1711,1711,1711,1466,1222,1711,1711,1711,489,823,702,697,919,816,608,726,716,532,904,978,698,990,617,880,938,779,713,628,959,617,561,656,949,843,558,971,821,627,955],[126,126,126,90,325,379,379,379,251,460,460,460,309,325,325,325,278,78,109,109,109,43,28,28,28,16,81,77,95,97,63,91,97,65,92,78,62,60,92,69,98,85,83,88,70,61,62,51,64,74,61,89],[6859,6859,6859,4900,1358,1585,1585,1585,2023,4191,4191,4191,3230,5841,5841,5841,5007,2452,3432,3432,3432,1999,2376,2376,2376,1358,744,850,500,903,802,596,683,864,768,713,637,688,670,759,918,773,722,867,655,994,689,777,742,576,776,687],[66,66,66,48,85,100,100,100,15,54,54,90,65,98,98,51,82,48,66,66,66,19,89,72,83,88,66,66,66,66,0,0,0,0,38,66,66,66,29,59,72,52,97,84,73,51,60,29,66,66,66,38],[380,380,380,272,169,197,197,197,93,151,151,151,103,117,117,117,100,70,97,97,97,81,123,123,123,71,271,271,271,271,77,134,134,134,96,67,67,67,39,73,73,73,63,110,128,128,128,45,62,62,62,36]],"Supply.Quantity":[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,5000,0,0,0,0,0,0,0,1187,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,10367,0,0,0,0,4753,0,0,0,0,1944,647,0,0,0,0,0,0,0,216,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,1187,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,7980,0,0,0,0,9576,0,0,0,0,4104,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,2593,0,0,0,0,0,0,0,0,0,107,540,0,0,0,0,0,107,0,0,0,0,0,0,0,3000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,12012,0,10000,0,0,0,1453,2244,0,0,0,16104,9504,0,0,0,0,0,0,0,133,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,527,0,0,0,0,0,0,0,264,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,600,0,0,0,0,0,0,1920,1920,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]},"columns":[{"accessor":"DFU","name":"Item","type":"character","footerStyle":{"fontWeight":"bold"},"minWidth":150},{"accessor":"Total.Demand","name":"Total Demand (units)","type":"numeric","footerStyle":{"fontWeight":"bold"},"aggregate":"sum","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}},"footer":"264,306","style":{"background":"yellow","fontWeight":"bold"}},{"accessor":"Opening.Inventories","name":"Opening Inventories (units)","type":"numeric","footerStyle":{"fontWeight":"bold"},"aggregate":"sum","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}},"footer":"57,660"},{"accessor":"Supply.Plan","name":"Supply Plan (units)","type":"numeric","footerStyle":{"fontWeight":"bold"},"aggregate":"sum","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}},"footer":"132,989"},{"accessor":"Min.Stocks.Coverage","name":"Min Stocks Coverage (periods)","type":"numeric","footerStyle":{"fontWeight":"bold"},"cell":[{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"6"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"6"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"6"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#32CD32FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"4"]}]}]}]},{"accessor":"Max.Stocks.Coverage","name":"Max Stocks Coverage (periods)","type":"numeric","footerStyle":{"fontWeight":"bold"},"cell":[{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"8"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"50%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"6"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"12"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"50%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"6"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"12"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"50%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"6"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"66.6666666666667%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"8"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"83.3333333333333%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"10"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"12"]}]}]},{"name":"div","attribs":{},"children":[{"name":"div","attribs":{"style":{"flexGrow":1,"borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","background":"#EEEEEE"}},"children":[{"name":"div","attribs":{"style":{"display":"flex","alignItems":"center","color":"black","fontSize":null,"fontWeight":"normal"}},"children":[{"name":"div","attribs":{"style":{"alignText":"right","display":"flex","alignItems":"center","justifyContent":"flex-end","borderTopLeftRadius":"0px","borderBottomLeftRadius":"0px","borderTopRightRadius":"0px","borderBottomRightRadius":"0px","boxShadow":null,"border":" ","background":"#FFA500FF","backgroundImage":null,"width":"100%","height":18,"transition":"width 1s ease","marginRight":"6px"}},"children":[]},"12"]}]}]}]},{"accessor":"Demand.Quantity","name":"Demand","type":"list","footerStyle":{"fontWeight":"bold"},"cell":[{"name":"WidgetContainer","attribs":{"key":"72cfaa63122f5ab8d7ff38af88c1a2e6"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-286176d9aaef22187807","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-286176d9aaef22187807"},"children":["{\"x\":{\"values\":[364,364,364,260,736,859,859,859,273,349,349,349,200,0,0,0,0,367,514,514,514,506,837,837,837,479,69,62,52,82,107,187,187,187,81,73,0,0,27,187,187,187,161,161,187,187,187,107,187,187,187,107],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"d6c37793c595d31280d022e42ad176d7"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-c8ca5b092cc0b1d827d8","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-c8ca5b092cc0b1d827d8"},"children":["{\"x\":{\"values\":[1419,1419,1419,1014,721,841,841,841,1160,2427,2427,2427,1502,807,807,807,692,510,714,714,714,216,28,28,28,16,26,26,26,26,0,0,0,0,16,28,28,28,18,39,39,39,33,21,24,24,24,9,13,13,13,8],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"9f40eb22c8ab2f3cdde3c2d68f5e46ee"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-2f8d3817a6cd0f0090ca","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-2f8d3817a6cd0f0090ca"},"children":["{\"x\":{\"values\":[265,265,265,189,29,34,34,34,23,42,42,42,50,178,178,178,152,24,34,34,34,41,72,72,72,42,243,243,243,243,90,156,156,156,150,145,145,145,83,145,145,145,124,46,53,53,53,70,145,145,145,83],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"b810fc56c1d7ba11067bc61458614835"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-2b434704c825c0c84d4a","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-2b434704c825c0c84d4a"},"children":["{\"x\":{\"values\":[1296,1296,1296,926,678,791,791,791,560,1042,1042,1042,785,1329,1329,1329,1139,1452,2032,2032,2032,653,169,169,169,97,96,96,96,96,42,72,72,72,72,72,72,72,48,121,121,121,103,62,72,72,72,42,72,72,72,42],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"d50d949d1e1dfde687cfd4a5cd3f7a58"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-49367c76be9de80e88b8","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-49367c76be9de80e88b8"},"children":["{\"x\":{\"values\":[265,265,265,189,59,69,69,69,40,69,69,69,49,69,69,69,59,49,69,69,69,49,69,69,69,40,31,31,31,31,18,31,31,31,31,31,31,31,18,31,31,31,26,26,31,31,31,18,31,31,31,18],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"2469dfd0697abbae86a8eb7feeef0cf1"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-19707e0c299c1fe7284f","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-19707e0c299c1fe7284f"},"children":["{\"x\":{\"values\":[1141,1141,1141,815,1466,1711,1711,1711,943,1630,1630,1630,1176,1711,1711,1711,1466,1222,1711,1711,1711,489,823,702,697,919,816,608,726,716,532,904,978,698,990,617,880,938,779,713,628,959,617,561,656,949,843,558,971,821,627,955],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"1761bac430fd3b5ac598602a6266c26f"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-9d22d078cf760b41a56a","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-9d22d078cf760b41a56a"},"children":["{\"x\":{\"values\":[126,126,126,90,325,379,379,379,251,460,460,460,309,325,325,325,278,78,109,109,109,43,28,28,28,16,81,77,95,97,63,91,97,65,92,78,62,60,92,69,98,85,83,88,70,61,62,51,64,74,61,89],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"97fac4b0c065ed9f20ced019fd143e20"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-7fd0683c3f56ce3a8b15","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-7fd0683c3f56ce3a8b15"},"children":["{\"x\":{\"values\":[6859,6859,6859,4900,1358,1585,1585,1585,2023,4191,4191,4191,3230,5841,5841,5841,5007,2452,3432,3432,3432,1999,2376,2376,2376,1358,744,850,500,903,802,596,683,864,768,713,637,688,670,759,918,773,722,867,655,994,689,777,742,576,776,687],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"125b46e4c01e00cc19b19361625bb699"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-f9a663ecc80b02dc9639","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-f9a663ecc80b02dc9639"},"children":["{\"x\":{\"values\":[66,66,66,48,85,100,100,100,15,54,54,90,65,98,98,51,82,48,66,66,66,19,89,72,83,88,66,66,66,66,0,0,0,0,38,66,66,66,29,59,72,52,97,84,73,51,60,29,66,66,66,38],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"b29ceff6d16ffc2c07a21d178084dacb"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-37fa2faf555c29f20e1e","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-37fa2faf555c29f20e1e"},"children":["{\"x\":{\"values\":[380,380,380,272,169,197,197,197,93,151,151,151,103,117,117,117,100,70,97,97,97,81,123,123,123,71,271,271,271,271,77,134,134,134,96,67,67,67,39,73,73,73,63,110,128,128,128,45,62,62,62,36],\"options\":{\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]}]},{"accessor":"Supply.Quantity","name":"Supply","type":"list","footerStyle":{"fontWeight":"bold"},"cell":[{"name":"WidgetContainer","attribs":{"key":"07b138716a3cf41be9130b5b5fa9edb3"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-d212a496ae9cb2324936","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-d212a496ae9cb2324936"},"children":["{\"x\":{\"values\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,5000,0,0,0,0,0,0,0,1187,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"9ea7597f50490c1f2c3f98af110e1ccd"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-d658f03f5bcac23a434d","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-d658f03f5bcac23a434d"},"children":["{\"x\":{\"values\":[0,0,0,10367,0,0,0,0,4753,0,0,0,0,1944,647,0,0,0,0,0,0,0,216,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"dba73d4bf4f78a11ad8472476864cc6e"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-abfd96274ffd65cae594","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-abfd96274ffd65cae594"},"children":["{\"x\":{\"values\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"658b79ee13aa9116c0a38a51b303eecc"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-cdfdec785fa2e5219a34","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-cdfdec785fa2e5219a34"},"children":["{\"x\":{\"values\":[0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"ddaf59c2449cc8d76f0862ff3844d3fe"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-a19a8aa6d6f30ba116bf","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-a19a8aa6d6f30ba116bf"},"children":["{\"x\":{\"values\":[0,0,0,0,0,0,0,0,1187,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"1768fb15b7a64f3bece8fe3ce1cb7d3a"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-0bbc09fb98b19a55d2d5","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-0bbc09fb98b19a55d2d5"},"children":["{\"x\":{\"values\":[0,0,0,7980,0,0,0,0,9576,0,0,0,0,4104,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"51d76a1a07dbcd8280542a734bdd1345"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-eed665fade302e045ecd","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-eed665fade302e045ecd"},"children":["{\"x\":{\"values\":[0,0,0,2593,0,0,0,0,0,0,0,0,0,107,540,0,0,0,0,0,107,0,0,0,0,0,0,0,3000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"e54ee6a6dfa6e45afe6d65e5fa99d348"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-2a75f575441b7c127711","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-2a75f575441b7c127711"},"children":["{\"x\":{\"values\":[0,0,12012,0,10000,0,0,0,1453,2244,0,0,0,16104,9504,0,0,0,0,0,0,0,133,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"e941a1979383ecbaa24bfeda0327ea65"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-e83738cc4e541489fafb","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-e83738cc4e541489fafb"},"children":["{\"x\":{\"values\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,527,0,0,0,0,0,0,0,264,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]},{"name":"WidgetContainer","attribs":{"key":"f9565d840b83278dcd3a1e0a5a509292"},"children":[{"name":"Fragment","attribs":[],"children":[{"name":"span","attribs":{"id":"htmlwidget-8cd3e10c250baa0040e4","className":"sparkline html-widget"},"children":[]},{"name":"script","attribs":{"type":"application/json","data-for":"htmlwidget-8cd3e10c250baa0040e4"},"children":["{\"x\":{\"values\":[0,0,0,0,0,600,0,0,0,0,0,0,1920,1920,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"options\":{\"type\":\"bar\",\"height\":20,\"width\":60},\"width\":60,\"height\":20},\"evals\":[],\"jsHooks\":[]}"]}]}]}]}],"columnGroups":[{"name":"Demand & Supply Inputs","columns":["Total.Demand","Opening.Inventories","Supply.Plan"]},{"name":"Stocks Targets Parameters","columns":["Min.Stocks.Coverage","Max.Stocks.Coverage"]}],"defaultSorted":[{"id":"DFU","desc":false}],"defaultPageSize":20,"paginationType":"numbers","showPageInfo":true,"minRows":1,"compact":true,"dataKey":"b521d018f6d9685874155c418af25623"},"children":[]},"class":"reactR_markup"},"evals":[],"jsHooks":[]}</script>
<p>[<strong>Table 1:</strong> Display of [Blueprint_DB] Data by Column]</p>
<p>Let’s go through each of these columns.</p>
<ul>
<li><strong>DFU</strong>: this is a single product (also called SKU, “Storage Keeping Unit”) with certain characteristics. For example, a SKU sold in one particular distribution channel. In this dataset, we have <strong>10 items</strong>.</li>
</ul>
<pre class="r"><code>unique(Blueprint_DB$DFU)</code></pre>
<pre><code>## [1] "Item 000001" "Item 000002" "Item 000003" "Item 000004" "Item 000005"
## [6] "Item 000006" "Item 000007" "Item 000008" "Item 000009" "Item 000010"</code></pre>
<ul>
<li><strong>Period</strong>: the horizon of time during which we will project our inventories calculation. It could be monthly, weekly, daily (and so on) buckets, over a certain range, for example, 24 months or 52 weeks. In this case, it is a <strong>weekly</strong> bucket over <strong>52 weeks</strong>.</li>
</ul>
<pre class="r"><code>range(Blueprint_DB$Period)</code></pre>
<pre><code>## [1] "2022-07-03" "2023-06-25"</code></pre>
<ul>
<li><strong>Demand</strong>: the Demand Forecast for each period of time, expressed in units.
<ul>
<li>For example, this could be Sales Forecasts or Replenishment Forecasts (if we ship to one warehouse to replenish it).</li>
</ul></li>
</ul>
<p>Looking at the Demand, there’s a range from no demand for units to a demand of 6859 units.</p>
<pre class="r"><code>summary(Blueprint_DB$Demand)</code></pre>
<pre><code>## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 62 119 508 690 6859</code></pre>
<ul>
<li><strong>Opening Inventories</strong>: our available stocks at the beginning of the horizon, expressed in units.</li>
</ul>
<p>The first date in our Period is 2022-07-03. Let’s take a look at the summary statistics, where we can see the range of opening inventory from 1222 to 17,772 units:</p>
<pre class="r"><code>July_03 <- Blueprint_DB %>% filter(Period == "2022-07-03")
summary(July_03$Opening.Inventories)</code></pre>
<pre><code>## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1222 2192 4460 5766 7022 17772</code></pre>
<ul>
<li><strong>Supply Plan</strong>: the quantities that we will receive to replenish our stocks at a given time, expressed in units.</li>
</ul>
<p>The replenishment amount in the Supply Plan ranges from no replenishment to replenishment of over 16,000 units.</p>
<pre class="r"><code>summary(Blueprint_DB$Supply.Plan)</code></pre>
<pre><code>## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 0 0 256 0 16104</code></pre>
<ul>
<li><strong>Minimum Stocks Coverage</strong>: a parameter of minimum stocks expressed in the number of periods of coverage.
<ul>
<li>For example, if we put two months, we aim to maintain a minimum stock coverage of two months, based on the Demand Forecasts.</li>
</ul></li>
<li><strong>Maximum Stocks Coverage</strong>: a parameter of maximum stocks expressed in the number of coverage periods.
<ul>
<li>If we put six months, it means that we aim to maintain our stocks below the coverage of six months, based on the Demand Forecasts.</li>
</ul></li>
</ul>
<p>Some items, like “Item 000004” have the same min and max stocks coverage throughout the period. Other items, like “Item 000009” have variable min and max stocks coverage over time.</p>
<p>It’s always helpful to look at a specific item to better understand the data. We want to ensure it contains all the information that we need:</p>
<ul>
<li><strong>Dimensions</strong>: [DFU] and [Period]</li>
<li><strong>Demand and Supply Planning Values</strong>: [Demand] / [Opening Inventories] / [Supply Plan]</li>
<li><strong>(Target) Stocks Levels</strong>: [Min.Stocks.Coverage] and [Max.Stocks.Coverage]</li>
</ul>
<p>For example, let’s look closer at “Item 000008” and verify all the information is there:</p>
<pre class="r"><code>Item_000008 <- filter(Blueprint_DB, Blueprint_DB$DFU == "Item 000008")
summary(Item_000008)</code></pre>
<pre><code>## DFU Period Demand Opening.Inventories
## Length:52 Min. :2022-07-03 Min. : 500 Min. : 0
## Class :character 1st Qu.:2022-09-30 1st Qu.: 744 1st Qu.: 0
## Mode :character Median :2022-12-28 Median :1176 Median : 0
## Mean :2022-12-28 Mean :2203 Mean : 342
## 3rd Qu.:2023-03-27 3rd Qu.:3432 3rd Qu.: 0
## Max. :2023-06-25 Max. :6859 Max. :17772
## Supply.Plan Min.Stocks.Coverage Max.Stocks.Coverage
## Min. : 0 Min. :6 Min. :10
## 1st Qu.: 0 1st Qu.:6 1st Qu.:10
## Median : 0 Median :6 Median :10
## Mean : 989 Mean :6 Mean :10
## 3rd Qu.: 0 3rd Qu.:6 3rd Qu.:10
## Max. :16104 Max. :6 Max. :10</code></pre>
<p>Looking at our summary statistics, we see:</p>
<ul>
<li>Our [DFU] is “Item 000008”.</li>
<li>We have a [Period] of 52 weeks from 2022-07-03 until 2023-07-03.</li>
<li>The [Opening Inventory] is 17,772 units.</li>
<li>[Demand] ranges from 500 to 6859 units, with an average of 2203 units.</li>
<li>[Supply] ranges from 0 to 16,104 units, with an average of 989 units.</li>
<li>In this case, the [Min.Stocks.Coverage] coverage is constant at 6 units, and the [Max.Stocks.Coverage] is constant at 10.</li>
</ul>
<p>Great, we have what we need!</p>
<p>This was an overview of a standard, complete, and tidy database, ready to be used for a Demand & Supply planning calculation. All the needed elements are there, organized in three groups of data: Dimensions / Demand & Supply Planning Values / Stocks Levels. Now, we can move on to our calculations!</p>
</div>
<div id="calculation-of-the-projected-inventories" class="section level2">
<h2>Calculation of the Projected Inventories</h2>
<p>We are going to calculate two things, applying the methodology we saw previously (read about it in the <a href="https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/">previous post of the series</a>):</p>
<ul>
<li><strong>Projected Inventories</strong>
<ul>
<li>Definition: [Stocks at the beginning of a Period of time] - [Demand of the Period] + [Supply Plan to be received during this Period]</li>
<li>At the very beginning: [Stocks at the beginning of a Period of time] = [Opening Inventories]</li>
</ul></li>
<li><strong>Related Projected Coverages</strong>
<ul>
<li>Definition: how many periods of Demand (forecasts) do the Projected Inventories of a Period of time cover</li>
</ul></li>
</ul>
<p>Using R means that the analysis can be simple and fast. It provides us with a summary view of the portfolio, and then we can zoom in on the items with risks of shortages or overstocks.</p>
</div>
<div id="run-proj_inv" class="section level2">
<h2>Run <code>proj_inv()</code></h2>
<p>To see how simple and fast it can be to calculate projected inventories and coverages, let’s apply the function <code>proj_inv()</code> from the planr package to the whole demo dataset to create this summary view:</p>
<pre class="r"><code># Create a calculated database for the Projected Inventories @ DFU level
Calculated_DB <- proj_inv(
data = Blueprint_DB,
DFU = DFU,
Period = Period,
Demand = Demand,
Opening.Inventories = Opening.Inventories,
Supply.Plan = Supply.Plan,
Min.Stocks.Coverage = Min.Stocks.Coverage,
Max.Stocks.Coverage = Max.Stocks.Coverage
)</code></pre>
<p>Let’s have a look at the output’s column headers:</p>
<pre class="r"><code>colnames(Calculated_DB)</code></pre>
<pre><code>## [1] "DFU" "Period"
## [3] "Demand" "Opening.Inventories"
## [5] "Calculated.Coverage.in.Periods" "Projected.Inventories.Qty"
## [7] "Supply.Plan" "Min.Stocks.Coverage"
## [9] "Max.Stocks.Coverage" "Safety.Stocks"
## [11] "Maximum.Stocks" "PI.Index"
## [13] "Ratio.PI.vs.min" "Ratio.PI.vs.Max"</code></pre>
<p>After the calculation using <code>proj_inv()</code>, we have new columns that give us a complete database for automated analysis.</p>
<ul>
<li><strong>1st group: Calculated Columns</strong>
<ul>
<li><code>Projected.Inventories.Qty</code>: Calculation of projected inventories</li>
<li><code>Calculated.Coverage.in.Periods</code>: Calculation of coverages in number of periods</li>
<li><code>Safety.Stocks</code> and <code>Maximum.Stocks</code>: Projected Stocks Targets (minimum & maximum) in units, useful for further analysis</li>
</ul></li>
<li><strong>2nd group: Analysis Features</strong>
<ul>
<li>To automate screening and facilitate the decision taking process:
<ul>
<li><code>PI.Index</code>: Projected Inventories Index: basically, how the [projected inventories] are doing (OK, alert, shortage, overstocks)</li>
<li><code>Ratio.PI.vs.min</code>: A ratio [Projected Inventories] vs. [Minimum Stocks Target]: used with a threshold filter, it allows us to identify the relevant SKUs quickly</li>
<li><code>Ratio.PI.vs.Max</code>: A ratio [Projected Inventories] vs. [Maximum Stocks Target], same as above</li>
</ul></li>
</ul></li>
</ul>
<p>Once we have run <code>proj_inv()</code>, we can <strong>automate the screening of our demand & supply</strong>. We can quickly know if we need to change our inventories and how to do so. This is very powerful as it means we can easily adjust based on Demand & Supply.</p>
</div>
<div id="results-from-proj_inv" class="section level2">
<h2>Results from <code>proj_inv()</code></h2>
<p>Let’s revisit “Item 000008” using this new dataset with calculated columns using the reactable package:</p>
<div id="htmlwidget-2" class="reactable html-widget" style="width:auto;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-2">{"x":{"tag":{"name":"Reactable","attribs":{"data":{"DFU":["Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008","Item 000008"],"Period":["2022-07-03","2022-07-10","2022-07-17","2022-07-24","2022-07-31","2022-08-07","2022-08-14","2022-08-21","2022-08-28","2022-09-04","2022-09-11","2022-09-18","2022-09-25","2022-10-02","2022-10-09","2022-10-16","2022-10-23","2022-10-30","2022-11-06","2022-11-13","2022-11-20","2022-11-27"],"Demand":[6859,6859,6859,4900,1358,1585,1585,1585,2023,4191,4191,4191,3230,5841,5841,5841,5007,2452,3432,3432,3432,1999],"Opening.Inventories":[17772,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"Calculated.Coverage.in.Periods":[1.6,0.6,3.9,2.9,5.5,4.5,3.5,2.5,1.8,1.4,0.4,0,0,0.7,1.4,0.4,0,0,0,0,0,0],"Projected.Inventories.Qty":[10913,4054,9207,4307,12949,11364,9779,8194,7624,5677,1486,-2705,-5935,4328,7991,2150,-2857,-5309,-8741,-12173,-15605,-17604],"Supply.Plan":[0,0,12012,0,10000,0,0,0,1453,2244,0,0,0,16104,9504,0,0,0,0,0,0,0],"Min.Stocks.Coverage":[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6],"Max.Stocks.Coverage":[10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10],"Safety.Stocks":[23146,17872,13036,12327,15160,17766,19411,23667,27485,29135,29951,28212,28414,26005,23596,19754,17123,17047,15991,13917,11229,10080],"Maximum.Stocks":[35136,32468,28839,29780,34263,38519,41941,42808,44217,43458,42699,40507,39653,36188,32723,28240,23977,22375,19443,16914,14284,12881],"PI.Index":["Alert","Alert","Alert","Alert","Alert","Alert","Alert","Alert","Alert","Alert","Alert","Shortage","Shortage","Alert","Alert","Alert","Shortage","Shortage","Shortage","Shortage","Shortage","Shortage"],"Ratio.PI.vs.min":[0.47,0.23,0.71,0.35,0.85,0.64,0.5,0.35,0.28,0.19,0.05,-0.1,-0.21,0.17,0.34,0.11,-0.17,-0.31,-0.55,-0.87,-1.39,-1.75],"Ratio.PI.vs.Max":[0.31,0.12,0.32,0.14,0.38,0.3,0.23,0.19,0.17,0.13,0.03,-0.07,-0.15,0.12,0.24,0.08,-0.12,-0.24,-0.45,-0.72,-1.09,-1.37]},"columns":[{"accessor":"DFU","name":"DFU","type":"character"},{"accessor":"Period","name":"Period","type":"Date"},{"accessor":"Demand","name":"Demand","type":"numeric","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}}},{"accessor":"Opening.Inventories","name":"Opening Inventories","type":"numeric","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}}},{"accessor":"Calculated.Coverage.in.Periods","name":"Calculated Coverage in Periods","type":"numeric","style":{"background":"yellow"}},{"accessor":"Projected.Inventories.Qty","name":"Projected Inventories Qty","type":"numeric","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}},"style":{"background":"yellow"}},{"accessor":"Supply.Plan","name":"Supply Plan","type":"numeric","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}}},{"accessor":"Min.Stocks.Coverage","name":"Min.Stocks.Coverage","type":"numeric"},{"accessor":"Max.Stocks.Coverage","name":"Max.Stocks.Coverage","type":"numeric"},{"accessor":"Safety.Stocks","name":"Safety Stocks","type":"numeric","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}},"style":{"background":"lightgreen"}},{"accessor":"Maximum.Stocks","name":"Maximum Stocks","type":"numeric","format":{"cell":{"digits":0,"separators":true},"aggregated":{"digits":0,"separators":true}},"style":{"background":"lightgreen"}},{"accessor":"PI.Index","name":"PI Index","type":"character","style":{"background":"lightblue"}},{"accessor":"Ratio.PI.vs.min","name":"Ratio PI vs min","type":"numeric","style":{"background":"lightblue"}},{"accessor":"Ratio.PI.vs.Max","name":"Ratio PI vs Max'","type":"numeric","style":{"background":"lightblue"}}],"columnGroups":[{"name":"Calculation of Projected Inventories & Coverages","columns":["Calculated.Coverage.in.Periods","Projected.Inventories.Qty"]},{"name":"Projected Stocks Targets","columns":["Safety.Stocks","Maximum.Stocks"]},{"name":"Analysis Features","columns":["PI.Index","Ratio.PI.vs.min","Ratio.PI.vs.Max"]}],"defaultPageSize":10,"paginationType":"numbers","showPageInfo":true,"minRows":1,"highlight":true,"striped":true,"compact":true,"dataKey":"4d36232456dac5840d2dbc25cf962225"},"children":[]},"class":"reactR_markup"},"evals":[],"jsHooks":[]}</script>
<p><span class="smallcaps"><strong>Table 2:</strong> The results after applying the <code>proj_inv()</code> function.</span></p>
<p>The new columns in yellow, green, and blue colors have been calculated and added to the original database. We can quickly scan through “Item 000008” for any particular period and notice information such as:</p>
<ul>
<li>The calculated coverage on 2022-07-03 is 1.6 (based on Upcoming Demand, we expect our inventory to last 1.6 weeks). The next week, it is 0.6.</li>
<li>From 2022-07-03 to 2022-09-11, we should be on Alert that we will fall below our minimum stock inventory. On 2022-09-18, we fall into shortage.</li>
</ul>
<p>We can find specific numbers for each Period by scrolling through the table. That is just from <code>proj_inv()</code>, without having to do any manual calculations or corrections.</p>
<p>Outside the analysis features, <code>proj_inv()</code> is very fast. Below are calculations of the speed on a Windows 10 x64 release. If we manage a portfolio of 200 SKUs over a 52 weeks horizon (weekly bucket), the calculation and analysis are done in only 5 seconds. The calculation is still pretty fast, up to 500 SKUs, which makes it quite handy if we want to run some simulations straight in Shiny.</p>
<div class="figure">
<img src="image008.png" alt="" />
<p class="caption">Chart of a classic range and size of Demand Planning or S&OP Portfolio</p>
</div>
<p>When we work on the S&OP (Sales & Operations Planning) Process, we work at an aggregated level (production families of products) and in monthly buckets. There are limited numbers of items and the horizon is typically 24 months. We can use the <code>proj_inv()</code> function to quickly calculate and analyze the projected inventories & coverages through a (sometimes complex) supply chain network at the same time.</p>
</div>
<div id="learn-more" class="section level2">
<h2>Learn more</h2>
<p>Thank you for reading this walkthrough of applying <code>proj_inv()</code> on a Demand & Supply Planning dataset! I hope you see what is needed to run projected inventory calculations, and how a single function in R can provide important information on projected inventories and coverages.</p>
<p>The reactable package makes quick, easy, pretty tables that are easy to sort and scan. What if we want to show more visual information, like color highlighting and charts?</p>
<p>…let’s find out in the next blog post..!</p>
<p>In the meantime, here are some useful links:</p>
<ul>
<li>Previous post: <a href="https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/">Using R for Projected Inventory Calculations in Demand & Supply Planning</a></li>
<li><strong>planr package</strong> GitHub repository: <a href="https://github.com/nguyennico/planr" class="uri">https://github.com/nguyennico/planr</a></li>
<li>URL for a Shiny app showing a demo of the <code>proj_inv()</code> and <code>light_proj_inv()</code> functions: <a href="https://niconguyen.shinyapps.io/Projected_Inventories/">Demo: app proj_inv() function (shinyapps.io)</a></li>
</ul>
</div>
<div id="appendix" class="section level2">
<h2>Appendix</h2>
<p>Code for the reactable table summarising Blueprint_DB:</p>
<pre class="r"><code>library(sparkline)
#-------------------
# Create Value_DB
#-------------------
# aggregation
tab_scan <- blueprint %>% select(DFU, Demand, Opening.Inventories, Supply.Plan,
Min.Stocks.Coverage,
Max.Stocks.Coverage) %>%
group_by(DFU) %>%
summarise(Total.Demand = sum(Demand),
Opening.Inventories = sum(Opening.Inventories),
Supply.Plan = sum(Supply.Plan),
Min.Stocks.Coverage = mean(Min.Stocks.Coverage),
Max.Stocks.Coverage = mean(Max.Stocks.Coverage)
)
# Get results
Value_DB <- tab_scan
#-------------------
# Create Sparklines for Demand
#-------------------
# replace missing values by zero
blueprint$Demand[is.na(blueprint$Demand)] <- 0
# aggregate
tab_scan <- blueprint %>%
group_by(DFU,
Period) %>%
summarise(Quantity = sum(Demand))
# generate Sparkline
Sparkline_Demand_DB <- tab_scan %>%
group_by(DFU) %>%
summarise(Demand.Quantity = list(Quantity))
#-------------------
# Create Sparklines for Supply Plan
#-------------------
# replace missing values by zero
blueprint$Supply.Plan[is.na(blueprint$Supply.Plan)] <- 0
# aggregate
tab_scan <- blueprint %>%
group_by(DFU,
Period) %>%
summarise(Quantity = sum(Supply.Plan))
# generate Sparkline
Sparkline_Supply_DB <- tab_scan %>%
group_by(DFU) %>%
summarise(Supply.Quantity = list(Quantity))
#----------------------------------------
# Link both databases
tab_scan <- left_join(Value_DB, Sparkline_Demand_DB)
tab_scan <- left_join(tab_scan, Sparkline_Supply_DB)
# Get Results
Overview_DB <- tab_scan
reactable(
tab_scan,
compact = TRUE,
defaultSortOrder = "asc",
defaultSorted = c("DFU"),
defaultPageSize = 20,
columns = list(
`DFU` = colDef(name = "Item", minWidth = 150),
`Opening.Inventories` = colDef(
name = "Opening Inventories (units)",
aggregate = "sum",
footer = function(values)
formatC(
sum(values),
format = "f",
big.mark = ",",
digits = 0
),
format = colFormat(separators = TRUE, digits = 0)
#style = list(background = "yellow",fontWeight = "bold")
),
`Total.Demand` = colDef(
name = "Total Demand (units)",
aggregate = "sum",
footer = function(values)
formatC(
sum(values),
format = "f",
big.mark = ",",
digits = 0
),
format = colFormat(separators = TRUE, digits = 0),
style = list(background = "yellow", fontWeight = "bold")
),
`Supply.Plan` = colDef(
name = "Supply Plan (units)",
aggregate = "sum",
footer = function(values)
formatC(
sum(values),
format = "f",
big.mark = ",",
digits = 0
),
format = colFormat(separators = TRUE, digits = 0)
),
`Min.Stocks.Coverage` = colDef(
name = "Min Stocks Coverage (periods)",
cell = data_bars(tab_scan,
#round_edges = TRUE
#value <- format(value, big.mark = ","),
#number_fmt = big.mark = ",",
fill_color = "#32CD32",
#fill_opacity = 0.8,
text_position = "outside-end")
),
`Max.Stocks.Coverage` = colDef(
name = "Max Stocks Coverage (periods)",
cell = data_bars(tab_scan,
#round_edges = TRUE
#value <- format(value, big.mark = ","),
#number_fmt = big.mark = ",",
fill_color = "#FFA500",
#fill_opacity = 0.8,
text_position = "outside-end")
),
Demand.Quantity = colDef(
name = "Demand",
cell = function(value, index) {
sparkline(tab_scan$Demand.Quantity[[index]])
}
),
Supply.Quantity = colDef(
name = "Supply",
cell = function(values) {
sparkline(values, type = "bar")
}
)
),
# close columns list
defaultColDef = colDef(footerStyle = list(fontWeight = "bold")),
columnGroups = list(
colGroup(
name = "Demand & Supply Inputs",
columns = c("Total.Demand", "Opening.Inventories", "Supply.Plan")
),
colGroup(
name = "Stocks Targets Parameters",
columns = c("Min.Stocks.Coverage", "Max.Stocks.Coverage")
)
)
) # close reactable</code></pre>
</div>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/11/21/projected-inventory-calculations-using-r-2/';</script>
September 2022: "Top 40" New CRAN Packages
https://rviews.rstudio.com/2022/10/27/september-2022-top-40-new-cran-packages/
Thu, 27 Oct 2022 00:00:00 +0000https://rviews.rstudio.com/2022/10/27/september-2022-top-40-new-cran-packages/
<p>Two hundred and two new packages made it to CRAN in September. Here are my “Top 40” selections in fourteen categories: Computational Methods, Data, Genomics, Machine Learning, Mathematics, Medicine, Pharmacology, Psychology, Science, Social Science, Statistics, Time Series, Utilities, and Visualization.</p>
<h3 id="computational-methods">Computational Methods</h3>
<p><a href="https://cran.r-project.org/package=kimfilter">kimfilter</a> v1.0.0: Provides an <code>Rcpp</code> implementation of the multivariate Kim filter, which combines the Kalman and Hamilton filters for state probability inference. The filter is designed for state space models and can handle missing values and exogenous data in the observation and state equations. See <a href="https://direct.mit.edu/books/book/3265/State-Space-Models-with-Regime-SwitchingClassical">Kim et al. (1999)</a> for details and the <a href="https://cran.r-project.org/web/packages/kimfilter/vignettes/kimfilter_vignette.html">vignette</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=SparseChol">SparseChol</a> v0.1.1: Provides a <code>C++</code> implementation of sparse LDL decomposition of symmetric matrices and solvers as described in <a href="https://fossies.org/linux/SuiteSparse/LDL/Doc/ldl_userguide.pdf">Davis (2016)</a>. See <a href="https://cran.r-project.org/web/packages/SparseChol/readme/README.html">README</a> for an example.</p>
<h3 id="data">Data</h3>
<p><a href="https://cran.r-project.org/package=allhomes">allhomes</a> v0.3.0: Provides tools to extract past sales data for specific suburbs and years from the <a href="https://www.allhomes.com.au/">Australian property</a> website including the address and property details, date, price, block size and unimproved value of properties. See <a href="https://cran.r-project.org/web/packages/allhomes/readme/README.html">README</a> to get started.</p>
<p><a href="https://cran.r-project.org/package=kgp">kgp</a> 1.1.0: Provides access to the metadata about populations and data about samples from the 1000 Genomes Project, including the 2,504 samples sequenced for the Phase 3 release and the expanded collection of 3,202 samples with 602 additional trios. The data is described in <a href="https://www.nature.com/articles/nature15393">Auton et al. (2015)</a> and <a href="https://www.cell.com/cell/fulltext/S0092-8674(22)00991-6?_returnURL=https%3A%2F%2Flinkinghub.elsevier.com%2Fretrieve%2Fpii%2FS0092867422009916%3Fshowall%3Dtrue">Byrska-Bishop et al. (2022)</a>, and raw data is available <a href="http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/">here</a>. See <a href="https://arxiv.org/abs/2210.00539">Turner (2022)</a> for details and look <a href="https://stephenturner.github.io/kgp/">here</a> for examples.</p>
<p><img src="kgp.png" height = "300" width="500" alt="Map showing locations of 1000 Genomes Phase 3 populations"></p>
<p><a href="https://cran.r-project.org/package=eHDPrep">eHDPrep</a> v1.2.1: Provides a tool for the preparation and enrichment of health datasets for analysis including functions to assess data quality and enable semantic enrichment of a dataset by discovering metavariables from relationships among input variables determined from user-provided ontologies. See the <a href="https://cran.r-project.org/web/packages/eHDPrep/vignettes/Introduction_to_eHDPrep.pdf">vignette</a>.</p>
<h3 id="genomics">Genomics</h3>
<p><a href="https://cran.r-project.org/package=refdb">refdb</a> v0.1.1: Implements a reference database manager offering a set of functions to import, organize, clean, filter, audit and export reference genetic data and includes functions to download sequence data from <a href="https://www.boldsystems.org/">Bold Systems</a> and <a href="https://www.ncbi.nlm.nih.gov/genbank/">NCBI GenBank</a>. There is an <a href="https://cran.r-project.org/web/packages/refdb/vignettes/intro_refdb.html">Introduction</a> and a vignette on <a href="https://cran.r-project.org/web/packages/refdb/vignettes/ncbi_bold.html">Downloading and combining data</a>.</p>
<p><img src="refdb.png" height = "300" width="500" alt="Plot of taxonomic coverage"></p>
<p><a href="https://cran.r-project.org/package=RestoreNet">RestoreNet</a> v1.0: Implements a random-effects stochastic model that starts from an Ito-type equation describing the dynamics of cells duplication, death and differentiation at clonal level to detect clonal dominance events in gene therapy studies. See <a href="https://www.biorxiv.org/content/10.1101/2022.05.31.494100v1">Del Core et al., (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/RestoreNet/vignettes/RestoreNet.pdf">vignette</a> for the math and examples.</p>
<h3 id="machine-learning">Machine Learning</h3>
<p><a href="https://cran.r-project.org/package=DynForest">DynForest</a> v1.0.0: Implements a random forests model that uses multiple longitudinal predictors to make survival predictions for individual subjects. See <a href="https://arxiv.org/abs/2208.05801">Devaux et al.(2022)</a> for the details and the <a href="https://cran.r-project.org/web/packages/DynForest/vignettes/DynForest_surv.html">vignette</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=multiview">multiview</a> v0.4: Provides functions to fit cooperative learning models which are supervised learning models for multiple sets of features (“views”), as described in <a href="https://arxiv.org/abs/2112.12337">Ding et al. (2022)</a>. See the <a href="https://cran.r-project.org/web/packages/multiview/vignettes/multiview.pdf">vignette</a> for an introduction.</p>
<p><img src="multiview.png" height = "300" width="500" alt="Plot of model coefficients by L1 Norm for two different views"></p>
<p><a href="https://cran.r-project.org/package=survex">survex</a> v0.1.1: Implements methods for explaining survival models. Methods include <em>SurvSHAP(t)</em> as described in <a href="https://arxiv.org/abs/2208.11080">Krzyzinski et al. (2022)</a>, <em>SurvLIME</em> introduced in <a href="https://www.sciencedirect.com/science/article/abs/pii/S0950705120304044?via%3Dihub">Kovalev et al. (2020)</a>, as well as methods described in <a href="https://www.taylorfrancis.com/books/mono/10.1201/9780429027192/explanatory-model-analysis-przemyslaw-biecek-tomasz-burzykowski">Biecek et al. (2021)</a>. See the vignettes <a href="https://cran.r-project.org/web/packages/survex/vignettes/custom-explainers.html">Creating custom extensions</a> and <a href="https://cran.r-project.org/web/packages/survex/vignettes/survex-usage.html">Package usage</a>.</p>
<p><img src="survex.png" height = "400" width="400" alt="Brier Score and AUC plots"></p>
<p><a href="https://cran.r-project.org/package=voice">voice</a> v0.4.14: Provides general purpose tools for voice analysis, speaker recognition and mood inference. See the<a href="https://cran.r-project.org/web/packages/voice/vignettes/voicegnette_R.html">vignette</a> for an example.</p>
<h3 id="mathematics">Mathematics</h3>
<p><a href="https://cran.r-project.org/package=collatz">collatz</a> v1.0.0: Provides functions to explore the <a href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz conjecture</a> including the ability to retrieve the hailstone sequence, the stopping time, total stopping time and tree-graph. There are four vignettes including: <a href="https://cran.r-project.org/web/packages/collatz/vignettes/collatz.html">collat</a>, <a href="https://cran.r-project.org/web/packages/collatz/vignettes/hailstones.html">Hailstone Sequences</a>, and <a href="https://cran.r-project.org/web/packages/collatz/vignettes/treegraphs.html">Tree Graphs</a>.</p>
<p><a href="https://cran.r-project.org/package=greta.dynamics">greta.dynamics</a> v0.2.0: Implements a <a href="https://joss.theoj.org/papers/10.21105/joss.01601"><code>greta</code></a> extension for analyzing transition matrices and ordinary differential equations representing dynamical systems. Have a look at the <a href="https://cran.r-project.org/web/packages/greta.dynamics/vignettes/iterate-matrix-example.html">iterate-matrix</a> and <a href="https://cran.r-project.org/web/packages/greta.dynamics/vignettes/ode-solve-example.html">ode-solve</a> examples.</p>
<h3 id="medicine">Medicine</h3>
<p><a href="https://cran.r-project.org/package=historicalborrow">historicalborrow</a> v1.0.4: Implements a hierarchical model and a mixture model to borrow historical control data from other studies to better characterize the control response a study. See <a href="https://onlinelibrary.wiley.com/doi/10.1002/pst.1589">Viele et al. (2013)</a> for a discussion of the methods and the vignettes <a href="https://cran.r-project.org/web/packages/historicalborrow/vignettes/methods.html">Methods</a> and <a href="https://cran.r-project.org/web/packages/historicalborrow/vignettes/usage.html">Usage</a>.</p>
<p><img src="historicalborrow.png" height = "300" width="500" alt="Plot of posterior response of borrow model against benchmark models for two arms of a trial."></p>
<p><a href="https://cran.r-project.org/package=nphRCT">nphRCT</a> v0.1.0: Provides functions to perform a stratified weighted log-rank test in a randomized controlled trial which can be visualized as a difference in average score on the two treatment arms. See <a href="https://arxiv.org/abs/1807.11097v1">Magirr and Burman (2018)</a>, <a href="https://arxiv.org/abs/2007.04767v1">Magirr (2020)</a>, and <a href="https://arxiv.org/abs/2201.10445v1">Magirr (2022)</a> for a description of the tests and the vignettes <a href="https://cran.r-project.org/web/packages/nphRCT/vignettes/explanation.html">Survival tests as differences-of-means</a> and <a href="https://cran.r-project.org/web/packages/nphRCT/vignettes/weighted_log_rank_tests.html]">The weighted log-rank test</a> for examples.</p>
<p><img src="nphRCT.png" height = "300" width="300" alt="Survival plots with Lof Rank Test Scores"></p>
<h3 id="pharmacology">Pharmacology</h3>
<p><a href="https://cran.r-project.org/package=rPBK">rPBK</a> v0.2.0: Provides functions to fit and simulate any kind of physiologically-based kinetic model which allows for multiple compartments, links between pairs of compartments, and links between compartments and the external medium. See <a href="https://www.biorxiv.org/content/10.1101/2022.04.29.490045v3">Charles et al. (2022)</a> for background and the <a href="https://cran.r-project.org/web/packages/rPBK/vignettes/Examples.html">vignette</a> for examples.</p>
<p><img src="rPBK.png" height = "300" width="300" alt="Concentration Plots"></p>
<p><a href="https://cran.r-project.org/package=xhaz">xhaz</a> v2.0.1: Provides functions to fit relative survival regression models with or without proportional excess hazards and with the additional possibility to correct for background mortality by one or more parameters. See <a href="https://journals.sagepub.com/doi/10.1177/0962280218823234">Touraine et al. (2020)</a>, <a href="https://bmcmedresmethodol.biomedcentral.com/articles/10.1186/s12874-020-01139-z">Mba et al. (2020)</a>, and <a href="https://bmcmedresmethodol.biomedcentral.com/articles/10.1186/s12874-019-0747-3">Goungounga et al. (2019)</a> for a description of the models and the <a href="https://cran.r-project.org/web/packages/xhaz/vignettes/introduction.html">vignette</a> for an introduction.</p>
<p><img src="xhaz.png" height = "400" width="400" alt="Survival plots for different models"></p>
<h3 id="psychology">Psychology</h3>
<p><a href="https://cran.r-project.org/package=rempsyc">rempsyc</a> v0.0.9: Provides convenience functions for Psychology including functions to customize plots and tables following the style of the American Psychological Association which are exportable to Microsoft Word. There are nine vignettes including <a href="https://cran.r-project.org/web/packages/rempsyc/vignettes/contrasts.html">Test linear regression assumptions</a>, <a href="https://cran.r-project.org/web/packages/rempsyc/vignettes/assumptions.html">Planned Contrasts Analyses</a>, and <a href="https://cran.r-project.org/web/packages/rempsyc/vignettes/scatter.html">Publication-ready scatter plots</a>.</p>
<p><img src="rempsyc.png" height = "500" width="500" alt="Formatted plots of regression tests"></p>
<h3 id="science">Science</h3>
<p><a href="https://cran.r-project.org/package=Karen">Karen</a> v1.0: Implements a stochastic framework that combines biochemical reaction networks with extended Kalman filter and Rauch-Tung-Striebel smoothing allowing biologists to investigate the dynamics of cell differentiation from high-dimensional clonal tracking data subject to measurement noise, false negative errors, and systematically unobserved cell types. See <a href="https://www.biorxiv.org/content/10.1101/2022.07.08.499353v1">Del Core et al. (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/Karen/vignettes/Karen.pdf">vignette</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=LMD">LMD</a> v1.0.0: Implements Local Mean Decomposition, an iterative and self-adaptive approach for demodulating, processing, and analyzing multi-component amplitude modulated and frequency modulated signals. See <a href="https://royalsocietypublishing.org/doi/10.1098/rsif.2005.0058">Smith (2005)</a> for background and the <a href="https://cran.r-project.org/web/packages/LMD/vignettes/Getting_Started_with_LMD.html">vignette</a> to get started.</p>
<p><img src="LMD.png" height = "300" width="500" alt="Plots of LMD decomposition of a simulated signal"></p>
<p><a href="https://cran.r-project.org/package=oceanexplorer">oceanexplorer</a> v0.0.2: Provides tools to explore the <a href="https://www.noaa.gov/">NOAA</a> <a href="https://www.ncei.noaa.gov/products/world-ocean-atlas">world ocean atlas</a> including functions to extract <a href="https://www.unidata.ucar.edu/software/netcdf/">NetCDF</a> data and visualize physical and chemical parameters. A <code>shiny</code> app allows interactive exploration. Look <a href="https://www.ncei.noaa.gov/products/world-ocean-atlas">here</a> for background information and see the <a href="https://cran.r-project.org/web/packages/oceanexplorer/vignettes/oceanexplorer.html">vignette</a> for examples.</p>
<p><img src="ocean.png" height = "300" width="500" alt="World map showing ocean PO4 levels"></p>
<p><a href="https://cran.r-project.org/package=WormTensor">WormTensor</a> v0.1.0: Implements a toolkit to detect clusters from distance matrices calculated between the cells of multiple animals (<a href="https://en.wikipedia.org/wiki/Caenorhabditis_elegans">Caenorhabditis elegans</a>) from input time-series matrices. Includes functions to generate, cluster, and visualize distance matrices, and to retrieve calculated distance matrices from <a href="https://figshare.com/">figshare</a>. See the <a href="https://cran.r-project.org/web/packages/WormTensor/vignettes/WormTensor.html">vignette</a>.</p>
<p><img src="WormTensor.png" height = "500" width="500" alt="Plot of cluster consistency colored by consistency"></p>
<h3 id="social-science">Social Science</h3>
<p><a href="https://cran.r-project.org/package=demcon">demcon</a> v0.3.0: Implements an open-source toolkit developed by <a href="https://www.isciences.com/">ISciences</a> and the <a href="https://www.dante-project.org/#:~:text=Previous%20Next-,The%20DANTE%20Project%20%2D%20open%20science%20tools%20to%20advance%20environment%2Dsecurity,political%20instability%2C%20and%20humanitarian%20response.">DANTE Project</a> for exploring popular political, institutional, and constitutional datasets with the goal of reducing barriers to entry in political science research by automating common acquisition and pre-processing procedures. This package focuses on the <a href="https://www.v-dem.net/vdemds.html">V-Dem dataset</a>. There are four vignettes including <a href="https://cran.r-project.org/web/packages/demcon/vignettes/constitution-datasets.html">A Brief Review of Constitutional Datasets</a> and <a href="https://cran.r-project.org/web/packages/demcon/vignettes/ccode-considerations.html">Country Coding Considerations for Dataset Harmonization</a>.</p>
<p><img src="demcon.png" height = "300" width="500" alt="Maps showing political boundaries of Yemen over time"></p>
<p><a href="https://cran.r-project.org/package=sdam">sdam</a> v1.1.4: Provides tools for performing social dynamics and complexity analyses about the Ancient Mediterranean in the context of the <a href="https://sdam-au.github.io/sdam-au/">SDAM</a> project based at the Department of History and Classical Studies at Aarhus University. There are vignettes on <a href="https://cran.r-project.org/web/packages/sdam/vignettes/Dates.html">Dates</a>, <a href="https://cran.r-project.org/web/packages/sdam/vignettes/Encoding.html">Re-encoding people</a>, <a href="https://cran.r-project.org/web/packages/sdam/vignettes/Intro.html">Datasets</a>, and <a href="https://cran.r-project.org/web/packages/sdam/vignettes/Maps.html">Maps and Networks</a>.</p>
<p><img src="sdam.png" height = "400" width="400" alt="Map showing the roads of the Roman Empire"></p>
<h3 id="statistics">Statistics</h3>
<p><a href="https://cran.r-project.org/package=adjustedCurves">adjustedCurves</a> v0.9.0: Provides functions to estimate and plot confounder-adjusted survival curves using either direct adjustment, inverse probability weighting, empirical likelihood estimation, or targeted maximum likelihood estimation. See <a href="https://arxiv.org/abs/2203.10002v1">Denz et. al (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/adjustedCurves/vignettes/introduction.html">vignette</a> for an introduction.</p>
<p><img src="adjustedCurves.png" height = "300" width="500" alt="Adjusted survival curves"></p>
<p><a href="https://cran.r-project.org/package=CovRegRF">CovRegRF</a> 1.0.1: Implements a method that uses <a href="https://cran.r-project.org/package=randomForestSRC">random forests</a> to estimate the covariance matrix of a multivariate response given a set of covariates as described in in <a href="https://cran.r-project.org/package=CovRegRF">Alakus et al. (2022)</a>. The <a href="https://cran.r-project.org/web/packages/CovRegRF/vignettes/CovRegRF.html">vignette</a> provides an example.</p>
<p><a href="https://cran.r-project.org/package=greta.gp">greta.gp</a> v0.2.0: Provides the syntax to create and combine full rank or sparse Gaussian process kernels in <code>greta</code>. See <a href="https://joss.theoj.org/papers/10.21105/joss.01601">Golding (2019)</a> for background on <code>greta</code> and the <a href="https://cran.r-project.org/web/packages/greta.gp/vignettes/getting-started.html">vignette</a> to get started.</p>
<p><img src="greta.png" height = "300" width="500" alt="Plot of posterior samples"></p>
<p><a href="https://cran.r-project.org/package=fwb">fwb</a> v0.1.1: Implements the fractional weighted bootstrap (aka the Bayesian bootstrap) to be used as a drop-in for functions in the <code>boot</code> package. The fractional weighted bootstrap involves drawing weights randomly that are applied to the data rather than resampling units from the data. See <a href="https://www.tandfonline.com/doi/abs/10.1080/00031305.2020.1731599?journalCode=utas20">Xu et al. (2020)</a> for the theory and <a href="https://cran.r-project.org/web/packages/fwb/readme/README.html">README</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=glmmrBase">glmmrBase</a> v0.1.2: Provides the R6 classes <code>Covariance</code>, <code>MeanFunction</code> and <code>Model</code> to allow for the flexible specification of generalized linear mixed models, and also functions to produce relevant matrices, values, and analyses. See <a href="https://cran.r-project.org/web/packages/glmmrBase/readme/README.html">README</a> for details.</p>
<p><a href="https://cran.r-project.org/package=rocbc">rocbc</a> v0.1.1: Provides functions for inferences and comparisons around the AUC, the Youden index, the sensitivity at a given specificity level, the optimal operating point of the ROC curve, and the Youden based cutoff. See <a href="https://onlinelibrary.wiley.com/doi/10.1002/bimj.201700107">Bantis et al. (2018)</a> and <a href="https://onlinelibrary.wiley.com/doi/10.1002/bimj.202000128">Bantis et al. (2021</a> and the <a href="https://onlinelibrary.wiley.com/doi/10.1002/bimj.202000128">vignette</a> for examples.</p>
<p><img src="rocbc.png" height = "400" width="400" alt="ROC curves"></p>
<p><a href="https://cran.r-project.org/package=vglmer">vglmer</a> v1.0.2: Provides functions to estimate hierarchical models using mean-field variational Bayes which can accommodate models with an arbitrary number of random effects and requires no integration to estimate. See <a href="https://projecteuclid.org/journals/bayesian-analysis/volume-17/issue-2/Fast-and-Accurate-Estimation-of-Non-Nested-Binomial-Hierarchical-Models/10.1214/21-BA1266.full">Goplerud (2022)</a> for details and <a href="https://cran.r-project.org/web/packages/vglmer/readme/README.html">README</a> for an example.</p>
<h3 id="time-series">Time Series</h3>
<p><a href="https://cran.r-project.org/package=bsvars">bsvars</a> v1.0.0: Implements MCMC algorithms for Bayesian estimation of Structural Vector Autoregressive (SVAR) models including a wide range of SVAR models. See <a href="https://www.sciencedirect.com/science/article/abs/pii/S0165188920300324?via%3Dihub"> Lütkepohl & Woźniak (2020)</a>, <a href="https://www.sciencedirect.com/science/article/abs/pii/S0165188902001689?via%3Dihub">Waggoner & Zha (2003)</a> for background.</p>
<p><a href="https://cran.r-project.org/package=gasmodel">gasmodel</a> v0.1.0: Provides functions to estimate, forecast and simulate generalized autoregressive score (GAS) models of <a href="https://onlinelibrary.wiley.com/doi/10.1002/jae.1279">Creal, Koopman, and Lucas (2013)</a> and <a href="https://www.cambridge.org/core/books/dynamic-models-for-volatility-and-heavy-tails/896F9D5220C4DD2CA675846F888F0BF0">Harvey (2013)</a>. There are two case study vignettes <a href="https://cran.r-project.org/web/packages/gasmodel/vignettes/case_durations.html">Bookshop Orders</a> and <a href="https://cran.r-project.org/web/packages/gasmodel/vignettes/case_rankings.html">Hockey Rankings</a> and another on <a href="https://cran.r-project.org/web/packages/gasmodel/vignettes/distributions.html">Probability Distributions</a>.</p>
<p><a href="https://cran.r-project.org/package=kalmanfilter">kalmanfilter</a> v2.0.0: Uses <code>Rcpp</code> to implement a multivariate Kalman filter for state space models that can handle missing values and exogenous data in the observation and state equations. See <a href="https://direct.mit.edu/books/book/3265/State-Space-Models-with-Regime-SwitchingClassical">Kim & Nelson (1999)</a> for details and the <a href="https://cran.r-project.org/web/packages/kalmanfilter/vignettes/kalmanfilter_vignette.html">vignette</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=MultiGlarmaVarSel">MultiGlarmaVarSel</a> v1.0: Provides functions to perform variable selection in high-dimensional sparse <a href="https://www.routledgehandbooks.com/doi/10.1201/b19485-5#:~:text=3.1%20Introduction,values%20of%20the%20observed%20process.">GLARMA models</a>. See <a href="https://arxiv.org/abs/2208.14721">Gomtsyan et al. (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/MultiGlarmaVarSel/vignettes/MultiGlarmaVarSel.pdf">vignette</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=VedicDateTime">VedicDateTime</a> v0.1.1: Provides functions to facilitate conversion between the Gregorian and Vedic calendar systems. See <a href="https://arxiv.org/abs/2111.03441">Bokde (2021)</a> and <a href="https:archive.org/details/PanchangamCalculations">Ramakumar (2011)</a> and the <a href="https://cran.r-project.org/web/packages/VedicDateTime/vignettes/VedicDateTime.pdf">vignette</a> for an overview with examples.</p>
<p><img src="Vedic.png" height = "500" width="300" alt= "tithi workflow"></p>
<h3 id="utilities">Utilities</h3>
<p><a href="https://cran.r-project.org/package=bundle">bundle</a> v0.1.0P Provides functions to serialize model objects with a consistent interface. See the <a href="https://cran.r-project.org/web/packages/bundle/vignettes/bundle.html">vignette</a> to get started.</p>
<p><img src="bundle.png" height = "300" width="500" alt= "Schematic of bundle serialization workflow"></p>
<p><a href="https://cran.r-project.org/package=r2resize">r2resize</a> v1.3: Implements an automatic resizing toolbar for containers, images and tables for <code>markdown</code>, <code>rmarkdown</code> and <code>quarto</code> documents. There is <a href="https://cran.r-project.org/web/packages/r2resize/vignettes/introduction_r2resize.html">Welcome</a> vignette and another on <a href="https://cran.r-project.org/web/packages/r2resize/vignettes/resizable_containers_split_screen_r2resize.html">New features</a>.</p>
<p><img src="r2resize.gif" height = "300" width="500" alt= "Schematic of bundle serialization workflow"></p>
<h3 id="visualization">Visualization</h3>
<p><a href="https://cran.r-project.org/package=figuRes2">figuRes2</a> v1.0.0: Provides functions and supporting documentation to streamline a variety of figure production tasks. There are vignettes on <a href="https://cran.r-project.org/web/packages/figuRes2/vignettes/basics.html">Basics</a>, <a href="https://cran.r-project.org/web/packages/figuRes2/vignettes/forest-plots.pdf">Forest plots</a>, <a href="https://cran.r-project.org/web/packages/figuRes2/vignettes/km.pdf">KM plots</a>, and <a href="https://cran.r-project.org/web/packages/figuRes2/vignettes/large-scale.pdf">Production Workflows</a>.</p>
<p><img src="figuRes2.png" height = "400" width="400" alt= "Scatter plot with marginal distributions"></p>
<p><a href="https://cran.r-project.org/package=openairmaps">openairmaps</a> v0.5.1: Combines <code>openair</code> air quality maps with <code>leaflet</code> to plot site maps with directional analysis figures such as polar plots, and air mass trajectories. See <a href="https://cran.r-project.org/web/packages/openairmaps/readme/README.html">README</a> for examples.</p>
<p><img src="openair.png" height = "300" width="500" alt= "Directional plots on map of London"></p>
<script>window.location.href='https://rviews.rstudio.com/2022/10/27/september-2022-top-40-new-cran-packages/';</script>
Using R in Inventory Management and Demand Forecasting
https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/
Thu, 20 Oct 2022 00:00:00 +0000https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/
<p><br>
<em>Nicolas Nguyen works in the Supply Chain industry, in the area of Demand and Supply Planning, S&OP and Analytics, where he enjoys developing solutions using R and Shiny. Outside his job, he teaches data visualization in R at the Engineering School EIGSI and Business School Excelia in the city of La Rochelle, France.</em></p>
<div id="introduction" class="section level2">
<h2>Introduction</h2>
<p>Demand & Supply Planning requires forecasting techniques to determine the inventory needed to fulfill future orders. With R, we can build end-to-end supply chain monitoring processes to identify potential issues and run scenario testing.</p>
<p>In a 3-part series, I will walk through a Demand & Supply Planning workflow:</p>
<ol style="list-style-type: decimal">
<li>Using R in Inventory Management and Demand Forecasting: an introduction of projected inventory and coverage methodology (this post)</li>
<li>Analyzing Projected Inventory Calculations Using R: an analysis of a demo dataset using the <code>planr</code> package</li>
<li>Visualizing Projected Calculations with <code>reactable</code> and <code>shiny</code>: once the analysis is done, how would you present your results to your boss?</li>
</ol>
<p>By the end of the series, you will understand how and why to use R for Demand & Supply Planning calculations. Let’s begin!</p>
</div>
<div id="the-problem-we-aim-to-solve" class="section level2">
<h2>The “problem” we aim to solve</h2>
<p>When we work in Demand & Supply Planning, it’s pretty common that we need to calculate <strong>projected inventories</strong> (and related <strong>projected coverages</strong>). We often have three options to perform this calculation, using:</p>
<ol style="list-style-type: decimal">
<li>an APS (Advanced Planning System) software</li>
<li>an ERP, such as SAP or JDE</li>
<li>and of course…Excel!</li>
</ol>
<p>All are fine and have different pros and cons. For example, we simply sometimes don’t have all the data in our ERP either APS, like when we work with third-party distributors or we want to model a supply chain network that relies on different systems with unconnected data.</p>
<p><strong>How about using R to perform these calculations?</strong> How simple and fast could they be? And, could we do more than just the calculations?</p>
<p>For example, could we get an analysis of the projected situation of a portfolio (as an output of a function), so we don’t have to look at each product one by one and can instead:</p>
<ul>
<li>Easily get a summary view of the portfolio?</li>
<li>Then zoom on the products with risks of shortages or overstocks?</li>
</ul>
<!-- I added this little intro paragraph about the series of posts -->
<p>In a series of posts, I will demonstrate how R can help us in Demand & Supply planning. This first post introduces the <code>proj_inv()</code> and <code>light_proj_inv()</code> functions for projected inventory and coverage calculations.</p>
<ul>
<li><code>proj_inv():</code> to calculate projected inventories and coverages with some analysis features</li>
<li><code>light_proj_inv():</code> to calculate projected inventories and coverages (only)
<ul>
<li>Runs faster than the previous function (as it’s lighter and doesn’t provide any analysis features)</li>
</ul></li>
</ul>
<p>With R, we have an efficient way to run end-to-end supply chain monitoring processes.</p>
</div>
<div id="methodology" class="section level2">
<h2>Methodology</h2>
<div id="how-to-calculate-projected-inventories" class="section level3">
<h3>How to calculate projected inventories</h3>
<p>First, let’s have a look at an example of how to calculate projected inventories. Consider that the field Demand = Sales Forecasts.</p>
<ol style="list-style-type: decimal">
<li>We start with some <strong>Opening Inventory</strong> of 1000 units.</li>
<li>During month M, we sell 100 units (the Demand). At the end of the 1st period (Month M), the inventory is 900 units.</li>
<li>Then, there’s a demand of 800 units at the end of the following period (Month M+1).</li>
<li>During the period (Month M+2), we get a Supply of 400 units, and sell 100: it is now 1100 units in stock.</li>
</ol>
<p>That’s all, this is how we calculate projected inventories ☺</p>
<p><img src="how%20to%20calculate%20a%20projected%20inventories.PNG" width="500" /></p>
<p><span class="smallcaps"><strong>Figure 1:</strong> Describes the mechanism of the calculation of projected inventories based on Opening Inventories, Demand and Supply</span></p>
</div>
<div id="how-to-calculate-projected-coverages" class="section level3">
<h3>How to calculate projected coverages</h3>
<p>Now, let’s have a look at how to calculate projected coverages. The idea: we look forward.</p>
<p>We consider the projected inventories at the end of a period and evaluate the related coverage based on the <strong>Upcoming Demand</strong>. See the example below:</p>
<p><img src="how%20to%20calculate%20projected%20coverages.PNG" width="600" /></p>
<p><span class="smallcaps"><strong>Figure 2:</strong> Description of the calculation of projected coverages, considering the inventories at a point in time and the Upcoming Demand</span></p>
<p>If we use Excel, we often see a “shortcut” to estimate the related coverages, like considering an average of the Demand over the next 3 or 6 months. This can lead to incorrect results if the Demand is not constant (if we have some seasonality or a strong trend, for example). <strong>However, these calculations become very easy through the <code>proj_inv()</code> and <code>light_proj_inv()</code> functions.</strong></p>
</div>
</div>
<div id="projected-inventory-calculations-in-r" class="section level2">
<h2>Projected inventory calculations in R</h2>
<p>Now, let’s see how the above is done using two functions from the <strong>planr package</strong>. First, let’s create a tibble of data for the example shown above (we will cover <code>Min.Stocks.Coverage</code> and <code>Max.Stocks.Coverage</code> more thoroughly in another post):</p>
<pre class="r"><code># Install the planr package
# remotes::install_github("nguyennico/planr")
library(planr)
library(dplyr)
Planr_Example <-
tibble::tribble(
~DFU, ~Period, ~Demand, ~Opening.Inventories, ~Supply.Plan, ~Min.Stocks.Coverage, ~Max.Stocks.Coverage,
"Item0001", "2022-01-01", 100L, 1000L, 0L, 0L, 0L,
"Item0001", "2022-02-01", 100L, 0L, 0L, 0L, 0L,
"Item0001", "2022-03-01", 100L, 0L, 400L, 0L, 0L,
"Item0001", "2022-04-01", 800L, 0L, 0L, 0L, 0L,
"Item0001", "2022-05-01", 100L, 0L, 0L, 0L, 0L,
"Item0001", "2022-06-01", 300L, 0L, 0L, 0L, 0L,
"Item0001", "2022-07-01", 100L, 0L, 400L, 0L, 0L
)</code></pre>
<p>Now apply the <code>proj_inv()</code> function:</p>
<pre class="r"><code>Calculated_Inv <- proj_inv(
data = Planr_Example,
DFU = DFU,
Period = Period,
Demand = Demand,
Opening.Inventories = Opening.Inventories,
Supply.Plan = Supply.Plan,
Min.Stocks.Coverage = Min.Stocks.Coverage,
Max.Stocks.Coverage = Max.Stocks.Coverage
)</code></pre>
<p>We can look at the output, which provides a lot of useful information including projected inventories and coverages:</p>
<pre class="r"><code>glimpse(Calculated_Inv)</code></pre>
<pre><code>## Rows: 7
## Columns: 14
## Groups: DFU [1]
## $ DFU <chr> "Item0001", "Item0001", "Item0001", "It…
## $ Period <chr> "2022-01-01", "2022-02-01", "2022-03-01…
## $ Demand <dbl> 100, 100, 100, 800, 100, 300, 100
## $ Opening.Inventories <int> 1000, 0, 0, 0, 0, 0, 0
## $ Calculated.Coverage.in.Periods <dbl> 2.9, 1.9, 2.7, 1.7, 0.7, 0.0, 99.0
## $ Projected.Inventories.Qty <dbl> 900, 800, 1100, 300, 200, -100, 200
## $ Supply.Plan <int> 0, 0, 400, 0, 0, 0, 400
## $ Min.Stocks.Coverage <int> 0, 0, 0, 0, 0, 0, 0
## $ Max.Stocks.Coverage <int> 0, 0, 0, 0, 0, 0, 0
## $ Safety.Stocks <dbl> 0, 0, 0, 0, 0, 0, NA
## $ Maximum.Stocks <dbl> 0, 0, 0, 0, 0, 0, NA
## $ PI.Index <chr> "OverStock", "OverStock", "OverStock", …
## $ Ratio.PI.vs.min <dbl> 0, 0, 0, 0, 0, 0, NA
## $ Ratio.PI.vs.Max <dbl> 0, 0, 0, 0, 0, 0, NA</code></pre>
<p>Focusing on the <code>Projected.Inventories.Qty</code> column, we see that it matches our example calculation in Figure 1.</p>
<pre class="r"><code>Calculated_Inv %>%
select(Projected.Inventories.Qty)</code></pre>
<pre><code>## # A tibble: 7 × 2
## # Groups: DFU [1]
## DFU Projected.Inventories.Qty
## <chr> <dbl>
## 1 Item0001 900
## 2 Item0001 800
## 3 Item0001 1100
## 4 Item0001 300
## 5 Item0001 200
## 6 Item0001 -100
## 7 Item0001 200</code></pre>
<p>We can also take a look at projected coverage. It matches our example calculation in Figure 2: the opening coverage is 2.9 months.</p>
<pre class="r"><code>Calculated_Inv %>%
select(Calculated.Coverage.in.Periods)</code></pre>
<pre><code>## # A tibble: 7 × 2
## # Groups: DFU [1]
## DFU Calculated.Coverage.in.Periods
## <chr> <dbl>
## 1 Item0001 2.9
## 2 Item0001 1.9
## 3 Item0001 2.7
## 4 Item0001 1.7
## 5 Item0001 0.7
## 6 Item0001 0
## 7 Item0001 99</code></pre>
<p>Very easy to calculate!</p>
<!-- I removed the examples of complex task and linked to the appendix -->
<p>The <code>proj_inv()</code> and <code>light_proj_inv()</code> functions can also be used and combined to perform more complex tasks. I’ve described several use cases in the <a href="#appendix">appendix</a>.</p>
<p>Moving forward, these functions form the basis for the classic <strong>DRP (Distribution Requirement Planning)</strong> calculation, where, based on some parameters (usually minimum and maximum levels of stock, a reorder quantity, and a frozen horizon), we calculate a Replenishment Plan.</p>
</div>
<div id="conclusion" class="section level2">
<h2>Conclusion</h2>
<p>Thank you for reading this introduction of projected inventories and coverages in Demand & Supply Planning! I hope that you enjoyed reading how this methodology translate into R.</p>
<div id="ascm-formerly-apics-guidelines" class="section level3">
<h3>ASCM (formerly APICS) guidelines</h3>
<p>In the beginning of 2019, the Association for Supply Chain Management (ASCM) published <a href="https://www.ascm.org/ascm-insights/sop-and-the-digital-supply-chain/">an article about the usage of R (and Python) in Supply Chain Planning</a>, and more precisely for the Sales & Operations Planning (S&OP) process, which is related to Demand and Supply Planning.</p>
<p><img src="make%20jump.PNG" width="600" /></p>
<p><span class="smallcaps"><strong>Figure 3:</strong> An extract from the ASCM article regarding the S&OP and Digital Supply Chain. It shows how R and Python are becoming more and more used for demand & supply planning and are great tools to run a S&OP process.</span></p>
<p>In the example above, we can see how R helps build the digital environment useful to run the S&OP process, which involves a lot of data processing. The <strong>planr package</strong> aims to support this process by providing functions that calculate projected inventories.</p>
</div>
<div id="stay-tuned-for-more-on-projected-calculations-using-r" class="section level3">
<h3>Stay tuned for more on projected calculations using R</h3>
<p>Thank you for reading the introduction on how to use R for projected inventory calculations in Demand & Supply Planning! I hope you enjoyed this introduction to the <strong>planr package</strong>.</p>
<p>My series of posts will continue with:</p>
<ul>
<li>Analyzing Projected Calculations Using R (using a demo dataset)</li>
<li>Visualizing Projected Calculations with reactable and Shiny (or, what your boss wants to see)</li>
</ul>
<p>In the meantime, check out these useful links:</p>
<ul>
<li>planr package GitHub repository: <a href="https://github.com/nguyennico/planr" class="uri">https://github.com/nguyennico/planr</a></li>
<li>URL for a Shiny app showing a demo of the <code>proj_inv()</code> and <code>light_proj_inv()</code> functions: <a href="https://niconguyen.shinyapps.io/Projected_Inventories/">Demo: app proj_inv() function (shinyapps.io)</a></li>
</ul>
<!-- Here is the appendix -->
</div>
</div>
<div id="appendix" class="section level2">
<h2>Appendix: Use cases and examples</h2>
<p>The <code>proj_inv()</code> and <code>light_proj_inv()</code> functions can easily be used and combined to perform more complex tasks, such as:</p>
<ul>
<li>Modeling of a Supply Chain Network</li>
<li>Calculation of projected inventories from Raw Materials to Finished Goods</li>
<li>A multi-echelon distribution network: from a National Distribution Center to Regional Wholesalers to Retailers</li>
</ul>
<p>Becoming a useful tool:</p>
<ul>
<li>To build an End-to-End Supply Chain monitoring process</li>
<li>To support the S&OP (Sales and Operations Planning) process, allowing us to run some scenarios quickly:
<ul>
<li>Change of Sales plan</li>
<li>Change of Supply (Production) plan</li>
<li>Change of stock level parameters</li>
<li>Change of Transit Time</li>
<li>Etc.</li>
</ul></li>
</ul>
<p>Here are some detailed use cases for the functions.</p>
<div id="third-party-distributors" class="section level3">
<h3>Third-party distributors</h3>
<p>We sometimes work with third-party distributors to distribute our products. A common question is: how much stock do our partners hold?</p>
<p>If we have access to their opening inventories and Sales IN & OUT Forecasts, we can quickly calculate the projected inventories by applying the <code>proj_inv()</code> or <code>light_proj_inv()</code> functions. Then, we anticipate any risks of shortages or overstocks, and create a collaborative workflow.</p>
<p><img src="sales%20IN%20sales%20OUT.PNG" width="500" /></p>
<p><span class="smallcaps"><strong>Figure 4:</strong> Illustration of a SiSo (Sales IN Sales OUT) situation. We have some stocks held at a storage location, for example, a third-party distributor, and know what will be sold out of this location (the sales out) and what will be replenished to it (the sales in), as well as the opening inventory. The aim is to calculate the projected inventories and coverages at this location.</span></p>
</div>
<div id="from-raw-materials-to-finished-goods" class="section level3">
<h3>From raw materials to finished goods</h3>
<p>In the example below, we produce olive oil (but it could be shampoo, liquor, etc.).</p>
<p>We start with a raw material, the olive oil, that we use to fill up different sizes of bottles (35cl, 50cl, etc…), on which we then apply (stick) a label (and back label). There are different labels, depending on the languages (markets where the products are sold).</p>
<p>Once we have a labelled bottle, we put it inside an outer box, ready to be shipped and sold. There are different dimensions of outer boxes, where we can put, for examplem 4, 6 or 12 bottles. <strong>They are the Finished Goods.</strong></p>
<p>We have two groups of products here:</p>
<ul>
<li>Finished Goods</li>
<li>Semi-Finished: at different steps, filled bottle (not yet labelled) or labelled bottle</li>
</ul>
<p>We might be interested in <strong>looking at the projected inventories at different levels / steps of the manufacturing process:</strong></p>
<ul>
<li>Finished Goods</li>
<li>Raw Materials: naked bottles, labels, or liquid (olive oil)</li>
<li>Semi-Finished Products</li>
</ul>
<p>For this, we can apply the <code>proj_inv()</code> or <code>light_proj_inv()</code> functions on each level of analysis.</p>
<p><img src="from%20raw%20materials%20to%20FG.PNG" width="600" /></p>
<p><span class="smallcaps"><strong>Figure 5:</strong> Illustration of a production flow, starting from raw material (liquid of olive oil) which fills bottles (of different countenances) and then labelled with different stickers. The labelled bottles are placed inside different outer boxes, which are the finished goods (called SKU -Stock Keeping Unit - ) .</span></p>
</div>
<div id="multi-echelon-networks" class="section level3">
<h3>Multi-echelon networks</h3>
<p>In the example below, we are looking at the distribution network within a country.</p>
<p>The products are stored at different locations:</p>
<ul>
<li>At a Central Stock: managed by the company selling the products, for example, a National Distribution Center.</li>
<li>At some third parties:
<ul>
<li>Who buy those products to distribute and sell them in more specific areas or regions</li>
<li>A network of Wholesalers and Sub-Wholesalers</li>
</ul></li>
</ul>
<p>If we have access to the data of the 3rd parties, such as [Opening Inventories] and [Sales IN & OUT Forecasts], we could apply the <code>proj_inv()</code> or <code>light_proj_inv()</code> functions on each level and visualize the complete projected inventories within the Distribution Network.</p>
<p><img src="multi%20echelons%20network.PNG" width="500" /></p>
<p><span class="smallcaps"><strong>Figure 6:</strong> Illustration of a distribution network, within a country, with different levels. The first level (level 1) is the main storage location, from which the products are shipped to the wholesalers (level 2), which then supply their local partners, identified here as Sub-Wholesalers (level 3). The aim is to visualize (and manage) the inventories (also Demand & Supply) throughout the whole network.</span></p>
</div>
<div id="from-production-capacity-to-sales" class="section level3">
<h3>From production capacity to sales</h3>
<p>In the example below, we have one or several Factories (within the box “Production Capacities”) which supply a [Global Stocks], which is then used to supply markets and a [Regional Stocks] directly. The [Regional Stocks] is then supplying other markets and a Third Party Distributor.</p>
<p><strong>We want to manage the Monthly S&OP process:</strong></p>
<ul>
<li>Linking Sales & Manufacturing Operations through simple modeling.</li>
<li>To balance Demand & Supply over the medium-long term horizon.</li>
<li>Visualizing some impacts through the whole distribution network</li>
</ul>
<p><strong>And make some simulations and drive some decisions:</strong></p>
<ul>
<li>Change of Sales Plan</li>
<li>Change of Supply Plan</li>
<li>Change of Inventories Level</li>
<li>Change of Transit Lead Time</li>
<li>Change of Product Mix</li>
<li>Etc.</li>
</ul>
<p>We could apply the <code>proj_inv()</code> or <code>light_proj_inv()</code> functions on each level and visualize the complete projected inventories within the Distribution Network.</p>
<p><img src="from%20production%20capacities%20to%20sales.PNG" width="500" /></p>
<p><span class="smallcaps"><strong>Figure 7:</strong> Illustration of a distribution network with a wider geographical presence. The first level (level 1) is the global storage location; it receives products from some factories and holds stocks that are used to supply several markets in the world, and also a regional stock, which is level 2. Then the regional stock is used to supply other markets, usually closer geographically, which is level 3. As described in the picture, the markets can be affiliates (where the stocks belong to the company) and third-party distributors.</span></p>
</div>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/10/20/projected-inventory-calculations-using-r-1/';</script>
Money, Money, Money: RConcillation
https://rviews.rstudio.com/2022/10/05/cash-flow-rconciliation/
Wed, 05 Oct 2022 00:00:00 +0000https://rviews.rstudio.com/2022/10/05/cash-flow-rconciliation/
<p><em>Dr. Maria Prokofieva is a member of the R / Business working group which is promoting the use of R in accounting, auditing, and actuarial work. She is also a professor at the Victoria University Business School in Australia and works with CPA Australia.</em></p>
<p>We continue with our series for “nerdy” accountants who want to diverge from Excel and master the power and beauty of R automation by looking at one of the most important areas of ANY business! Cash!</p>
<p>Cash management is a really critical issue for both business owners and people like me who are trying not to look at recent interest rates jumps.</p>
<p>Cash management includes cash collection, handling, and usage of cash (spending!). It is essential to have <strong>enough</strong> cash to cover immediate expenses, fund business growth and have working capital. Or in simple terms, you need to have enough cash to pay for your coffee, cover your mortgage repayment and invest in that <a href="https://www.tesla.com/en_au/model3">Tesla Model 3</a></p>
<p><img src="tesla.jpeg" height = "300" width="400" alt="Red Tesla Model 3"></p>
<p>Cash analysis is an important step to assess companies short-term liquidity, evaluate working capital and make decisions about investments.</p>
<p>Today, we are going to have a look at the step that comes before cash flow visualization. Much much earlier…. Before we are able to put cash flow items on a nice graph, we need to obtain those cash flow items “somehow”.</p>
<p>Accountants don’t have cash flow data by default, and there is no magic way to get it. Rather, it is necessary to go transaction by transaction, classify items, group them, collate them, and double-check that they actually occurred! We need to make sure that we are not double-charged as well as we are not underpaying or omitting any of our payments and they are all included in the list.</p>
<p>We start backwards from this very list and we dig into doing bank reconciliation and in particular, looking at our (business) bank statement. This is indeed a very useful exercise, not only in regards to your business but also for your own expense management.</p>
<p>For this post, we will work through a very simple example, just looking at a bank statement and poking around. It is a “personal” bank statement that comes from <a href="https://www.kaggle.com/datasets/sandhaya4u/august-bank-statement-sandhaya">Kaggle</a></p>
<pre class="r"><code>cf<-read_csv("bank_st.csv")</code></pre>
<pre><code>## Rows: 107 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Date, Day, Type, Category
## dbl (3): Debit Amount, Credit Amount, Closing Balance
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.</code></pre>
<pre class="r"><code>cf%>%head()</code></pre>
<pre><code>## # A tibble: 6 × 7
## Date Day Type Category `Debit Amount` `Credit Amount` `Closing Balan…`
## <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 1/8/2018 Wedne… Debit Shopping 2500 0 174656.
## 2 1/8/2018 Wedne… Debit Shopping 324 0 174332.
## 3 2/8/2018 Thurs… None None 0 0 174332.
## 4 3/8/2018 Friday Debit Shopping 404. 0 173928.
## 5 4/8/2018 Satur… Debit Shopping 100 0 173828.
## 6 4/8/2018 Satur… Debit Shopping 1395 0 172433.</code></pre>
<p>This is a typical bank statement you can view in your bank account where each row is a transaction for a particular reporting period (e.g. month). We do not have the name of the second party for the transactions (e.g. the name of the store or the company that credited/debited the account), but all transactions have been classified - which can be seen under <code>Category</code>.</p>
<p>The dataset has <code>Debit Amount</code>, which is what you were charged, and <code>Credit Amount</code>, which is what you were paid. The <code>Closing Balance</code> is a running balance that shows the amount of cash in your account after the transaction. The most important parts of that <code>Closing Balance</code> are the initial and final numbers and they are used to reconcile (= match) balances in your own “books” (accounting books!= accounting records). If those number do not match, we investigate individual closing balances for the transactions to identify where we were overpaid or underpaid.</p>
<p>Let’s look closer at the data: it is not messy, but not ideal…</p>
<p>Column names have blanks and they do not play well in functions, so let’s use <code>clean_names()</code> from <code>janitor</code> package to make them more R friendly</p>
<pre class="r"><code>cf<-cf%>%
clean_names()
cf%>%head()</code></pre>
<pre><code>## # A tibble: 6 × 7
## date day type category debit_amount credit_amount closing_balance
## <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 1/8/2018 Wednesday Debit Shopping 2500 0 174656.
## 2 1/8/2018 Wednesday Debit Shopping 324 0 174332.
## 3 2/8/2018 Thursday None None 0 0 174332.
## 4 3/8/2018 Friday Debit Shopping 404. 0 173928.
## 5 4/8/2018 Saturday Debit Shopping 100 0 173828.
## 6 4/8/2018 Saturday Debit Shopping 1395 0 172433.</code></pre>
<p>That’s better! so now all variables are in small letters and have snake_case!</p>
<pre class="r"><code>names(cf)</code></pre>
<pre><code>## [1] "date" "day" "type" "category"
## [5] "debit_amount" "credit_amount" "closing_balance"</code></pre>
<p>Let’s explore the data and do some simple <strong>counting</strong> - yes, we love to count!</p>
<p>First, what is the closing balance and how does it change during the month? But before we do so, let’s have a close look at the <code>date</code> column. In the first twenty rows you can see there are a few issues as some dates include single vs. double for days and two-digit vs. four-digit for year. It is also in a string format.</p>
<pre class="r"><code>class(cf$date)</code></pre>
<pre><code>## [1] "character"</code></pre>
<pre class="r"><code>cf$date[1:20]</code></pre>
<pre><code>## [1] "1/8/2018" "1/8/2018" "2/8/2018" "3/8/2018" "4/8/2018" "4/8/2018"
## [7] "4/8/2018" "4/8/2018" "4/8/2018" "5/8/2018" "6/8/2018" "6/8/2018"
## [13] "7/8/2018" "8/8/2018" "9/8/2018" "10/8/2018" "10/8/2018" "11/8/2018"
## [19] "11/8/2018" "11/8/2018"</code></pre>
<p>To fix this, let’s convert to the date type and fix the formatting with <code>lubridate</code> package.</p>
<pre class="r"><code>cf$date<-dmy(cf$date)</code></pre>
<p>Now, let’s see the spend per each billing date. We exclude the days with no spend:</p>
<pre class="r"><code>cf%>%
group_by(date)%>%
summarise(spend=sum(debit_amount))%>%
filter(spend!=0)%>%
ggplot(aes(date, spend))+
geom_line()</code></pre>
<p><img src="/2022/10/05/cash-flow-rconciliation/index_files/figure-html/unnamed-chunk-7-1.png" width="672" /></p>
<p>Now, let’s see the type of categories we have.</p>
<pre class="r"><code>cf%>%count(category, sort=TRUE)</code></pre>
<pre><code>## # A tibble: 10 × 2
## category n
## <chr> <int>
## 1 Shopping 46
## 2 None 21
## 3 ATM 9
## 4 Interest 8
## 5 Entertainment 7
## 6 Medical 5
## 7 Travel 4
## 8 Restaurant 3
## 9 Rent 2
## 10 Salary 2</code></pre>
<p>This <code>None</code> category does not look right…. What is there?</p>
<pre class="r"><code>cf%>% filter(category=="None")%>%
head()</code></pre>
<pre><code>## # A tibble: 6 × 7
## date day type category debit_amount credit_amount closing_balance
## <date> <chr> <chr> <chr> <dbl> <dbl> <dbl>
## 1 2018-08-02 Thursday None None 0 0 174332.
## 2 2018-08-05 Sunday None None 0 0 162098.
## 3 2018-08-08 Wednesday None None 0 0 158597.
## 4 2018-08-21 Tuesday None None 0 0 91343.
## 5 2018-08-24 Friday None None 0 0 61755.
## 6 2018-08-26 Sunday None None 0 0 38441.</code></pre>
<p>It looks like the majority of these entries are not really transactions, but a closing balance. Do we need to include them? Probably not. Let’s confirm that they are not transactions and have <code>debit_amount</code> and <code>credit_amount</code> as zero</p>
<pre class="r"><code>cf%>% filter(category=="None")%>%
filter(debit_amount!=0 | credit_amount!=0)</code></pre>
<pre><code>## # A tibble: 0 × 7
## # … with 7 variables: date <date>, day <chr>, type <chr>, category <chr>,
## # debit_amount <dbl>, credit_amount <dbl>, closing_balance <dbl></code></pre>
<p>and it is a good idea to exclude them</p>
<pre class="r"><code>cf<-cf%>%filter(category!="None")</code></pre>
<p>Let’s see which day has the most number of transactions and which category is the most used one (what is the money drainer!):</p>
<pre class="r"><code>cf%>%count(day, sort=TRUE)</code></pre>
<pre><code>## # A tibble: 7 × 2
## day n
## <chr> <int>
## 1 Saturday 36
## 2 Friday 11
## 3 Thursday 10
## 4 Sunday 9
## 5 Wednesday 8
## 6 Monday 7
## 7 Tuesday 5</code></pre>
<pre class="r"><code>cf%>%count(category, sort=TRUE)</code></pre>
<pre><code>## # A tibble: 9 × 2
## category n
## <chr> <int>
## 1 Shopping 46
## 2 ATM 9
## 3 Interest 8
## 4 Entertainment 7
## 5 Medical 5
## 6 Travel 4
## 7 Restaurant 3
## 8 Rent 2
## 9 Salary 2</code></pre>
<p>Well, good, but does not look nice? So let’s “paint it”. (We look at spending where credited amount is $0 per category.)</p>
<pre class="r"><code>plot4<-cf%>%filter(credit_amount==0)%>%
group_by(day)%>%
summarise(day_spend=sum(debit_amount),
n=n())%>%
ggplot(aes(x=fct_reorder(day, desc(day_spend)),
y=day_spend))+
geom_col()+
labs(x = "Days", y = "$ value",
title ="Cash across days")+
theme(
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.text.x = element_text(angle = 90),
plot.title = element_textbox(hjust = 0.5,
width = unit(0.5, "npc"),
margin = margin(b = 15)) )
(plot1|plot2)/(plot3|plot4)</code></pre>
<p><img src="/2022/10/05/cash-flow-rconciliation/index_files/figure-html/unnamed-chunk-14-1.png" width="672" /></p>
<p>For a real business, this amount of Saturday transactions would raise a red flag, but this data is from personal records, so it looks like someone is having a blast after a busy week :)</p>
<p>Also, with <code>category</code> that <code>None</code> does not sound right…. it is the second highest so… I would really investigate what sort of <code>None</code> is that <code>None</code>…</p>
<p>Well, what are out total earn and which days we are paid and what for?</p>
<pre class="r"><code>cf%>%filter(credit_amount>0)%>%
count(category)</code></pre>
<pre><code>## # A tibble: 2 × 2
## category n
## <chr> <int>
## 1 Interest 8
## 2 Salary 2</code></pre>
<p>It looks like we have only two major category - interest and salary. Let’s see what brings more money</p>
<pre class="r"><code>cf%>%filter(credit_amount>0)%>%
group_by(category)%>%
summarise(category_total=sum(credit_amount))</code></pre>
<pre><code>## # A tibble: 2 × 2
## category category_total
## <chr> <dbl>
## 1 Interest 4050.
## 2 Salary 500508</code></pre>
<p>Well, it is still salary! but would be sooo good if it is our passive income that drives the cash flows!</p>
<p>Let’s see the balance for the month…</p>
<pre class="r"><code>balance<-sum(cf$credit_amount)-sum(cf$debit_amount)
balance</code></pre>
<pre><code>## [1] 268715</code></pre>
<p>Woohoo! Our balance is positive, so we managed to grow our wealth!</p>
<p>Indeed, it is a very simple example, but a good foundation to start your R experience in accounting!</p>
<p>Done for today: we are ready for bank RConciliation. Stay tuned!
….</p>
<div id="references" class="section level2">
<h2>References</h2>
<p><a href="https://www.kaggle.com/datasets/sandhaya4u/august-bank-statement-sandhaya" class="uri">https://www.kaggle.com/datasets/sandhaya4u/august-bank-statement-sandhaya</a></p>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/10/05/cash-flow-rconciliation/';</script>
August 2022: "Top 40" New CRAN Packages
https://rviews.rstudio.com/2022/09/26/august-2022-top-40-new-cran-packages/
Mon, 26 Sep 2022 00:00:00 +0000https://rviews.rstudio.com/2022/09/26/august-2022-top-40-new-cran-packages/
<p>One hundred ninety-four new package made it to CRAN in August. Here are my “Top 40” picks in thirteen categories: “Computational Methods, Data, Epidemiology, Genomics, Insurance, Machine Learning, Mathematics, Medicine, Pharmaceutical Applications, Statistics, Time Series, Utilities, and Visualization.</p>
<h3 id="computational-methods">Computational Methods</h3>
<p><a href="https://cran.r-project.org/package=brassica">brassica</a> v1.0.1: Executes <code>BASIC</code> programs from the 1970s for historical and educational purposes. This enables famous examples of early machine learning, artificial intelligence, natural language processing, cellular automata, and so on, to be run in their original form. See <a href="https://cran.r-project.org/web/packages/brassica/vignettes/BASIC.pdf">BASIC</a>.</p>
<p><a href="https://cran.r-project.org/package=MultiStatM">MultistatM</a> v1.1.0: Provides algorithms to build set partitions and commutator matrices used in the construction of multivariate d-variate Hermite polynomials. See the <a href="https://cran.r-project.org/web/packages/MultiStatM/vignettes/Introduction.html">vignette</a>.</p>
<h3 id="data">Data</h3>
<p><a href="https://cran.r-project.org/package=hubeau">hubeau</a> v0.3.1: functions to retrieve data from <a href="https://hubeau.eaufrance.fr/">Hub’Eau</a> the free and public French National APIs on water. See the <a href="https://cran.r-project.org/web/packages/hubeau/hubeau.pdf">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=tinytiger">tinytiger</a> v0.0.4: Download geographic shapes from the United States Census Bureau <a href="https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html">TIGER/Line Shapefiles</a>. See the <a href="https://cran.r-project.org/web/packages/tinytiger/vignettes/tinytiger.html">vignette</a>.</p>
<h3 id="epidemiology">Epidemiology</h3>
<p><a href="https://cran.r-project.org/package=disbayes">disbayes</a> v1.0.0: Provides functions to estimate incidence and case fatality for a chronic disease, given partial information, using a multi-state model. See <a href="https://arxiv.org/abs/2111.14100">Jackson et al. (2021)</a> for a description of the methods and the <a href="https://cran.r-project.org/web/packages/disbayes/vignettes/disbayes.html">vignette</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=insectDisease">insectDiseases</a> v1.2.1: Provides the <a href="https://edwip.ecology.uga.edu/">Ecological Database of the Worlds Insect Pathogens</a> created by David Onstad. See the <a href="https://cran.r-project.org/web/packages/insectDisease/vignettes/dataManip.pdf">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=nncc">nncc</a> v1.0.0: Provides nearest-neighbors matching and analysis of case-control data. See <a href="https://journals.lww.com/epidem/Abstract/2022/09000/Nearest_Neighbors_Matching_for_Case_Control_Study.5.aspx">Cui et al. (2022)</a> for background and the <a href="https://cran.r-project.org/web/packages/nncc/vignettes/nncc.html">vignette</a> for examples.</p>
<p><img src="nncc.png" height = "300" width="500" alt="Distance density plot"></p>
<h3 id="genomics">Genomics</h3>
<p><a href="https://cran.r-project.org/package=epitopR">epitopR</a> v0.1.2: Offers a suite of tools to predict peptide MHC (major histocompatibility complex) presentation in the context of both human and mouse. Results are based on half maximal inhibitory concentration as queried through the <a href="http://tools.iedb.org/mhcii/">immune epitope database API</a>. See <a href="https://academic.oup.com/nar/article/47/D1/D339/5144151?login=false">Vita et al. (2018)</a> for background and the <a href="https://cran.r-project.org/web/packages/epitopR/vignettes/mhcII-hu.html">vignette</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=geneHapR">geneHapR</a> v1.1.1: Provides functions to import genome variants data and perform gene haplotype Statistics, visualization and phenotype association. There is an <a href="https://cran.r-project.org/web/packages/geneHapR/vignettes/Introduction_of_geneHapR.html">Introduction</a>, and there are vignettes on <a href="https://cran.r-project.org/web/packages/geneHapR/vignettes/geneHapR_data.html">Data</a>, and <a href="https://cran.r-project.org/web/packages/geneHapR/vignettes/workflow.html">Workflow</a>.</p>
<p><img src="geneHapR.png" height = "300" width="500" alt="Workflow diagram"></p>
<p><a href="https://cran.r-project.org/package=genieBPC">geniePBC</a> v1.0.0: Linked to The American Association Research Project Genomics Evidence Neoplasia Information Exchange <a href="https://www.aacr.org/professionals/research/aacr-project-genie/the-aacr-project-genie-biopharma-collaborative-bpc/">(GENIE) BioPharma Collaborative</a>, this package provides an interface to the data corresponding to each release from <a href="https://www.synapse.org/">Synapse</a> and to prepare datasets for analysis. There are several vignettes including <a href="https://cran.r-project.org/web/packages/genieBPC/vignettes/drug_regimen_sunburst_vignette.html">drug regimen sunburst</a> and <a href="https://cran.r-project.org/web/packages/genieBPC/vignettes/pull_data_synapse_vignette.html">pull data synapse</a>.</p>
<p><img src="genieBPC.png" height = "300" width="500" alt="Sunburst plot showing 3 lines of treatment"></p>
<p><a href="https://cran.r-project.org/package=slendr">slendr</a> v0.3.0: Implements a framework for simulating spatially explicit genomic data which leverages real cartographic information for programmatic and visual encoding of spatiotemporal population dynamics on real geographic landscapes. Population genetic models are then automatically executed using a custom built-in simulation ‘SLiM’ script as described in <a href="https://academic.oup.com/mbe/article/36/3/632/5229931?login=false">Haller et al. (2019)</a>. There are several vignettes including <a href="https://cran.r-project.org/web/packages/slendr/vignettes/vignette-01-tutorial.html">A Basic Tutorial</a>, <a href="https://cran.r-project.org/web/packages/slendr/vignettes/vignette-03-interactions.html">Programming Dispersion Dynamics</a>, and <a href="https://cran.r-project.org/web/packages/slendr/vignettes/vignette-05-tree-sequences.html">Tree-sequence processing</a>.</p>
<p><img src="slendr.png" height = "300" width="500" alt="Network of ancestral links"></p>
<h3 id="insurance">Insurance</h3>
<p><a href="https://cran.r-project.org/package=actxps">actxps</a> v0.2.0: Supports actuarial experience studies with functions to prepare data, create studies and perform exposure calculations as described in: <a href="https://www.soa.org/49378a/globalassets/assets/files/research/experience-study-calculations.pdf">Atkinson & McGarry (2016)</a>. Look <a href="https://github.com/mattheaphy/actxps/">here</a> for an example.</p>
<p><img src="actxps.png" height = "300" width="500" alt="Shiny app for surrender experience study"></p>
<h3 id="machine-learning">Machine Learning</h3>
<p><a href="https://cran.r-project.org/package=aorsf">aorsf</a> v0.0.2: Provides functions to fit, interpret, and predict with oblique random survival forests. See <a href="https://arxiv.org/abs/2208.01129">Jaeger et al. (2022)</a> for methods to accelerate and interpret oblique random survival forest models. There is an <a href="https://cran.r-project.org/web/packages/aorsf/vignettes/aorsf.html">Introduction</a> and there are vignettes on <a href="https://cran.r-project.org/web/packages/aorsf/vignettes/oobag.html">Predictions</a> and <a href="https://cran.r-project.org/web/packages/aorsf/vignettes/pd.html">PD and ICE Curves</a>.</p>
<p><img src="aorsf.png" height = "300" width="500" alt="Risk ratio curve over time"></p>
<p><a href="https://cran.r-project.org/package=calibrationband">calibrationband</a> v0.2.1: Provides functions to assess the calibration of probabilistic classifiers using confidence bands for monotonic functions, and also facilitate constructing inverted goodness-of-fit tests whose rejection allows for a sought-after conclusion of a sufficiently well-calibrated model. See <a href="https://arxiv.org/abs/2203.04065">Dimitriadis et al. (2022)</a> for details and <a href="https://cran.r-project.org/web/packages/calibrationband/readme/README.html">README</a> for an example.</p>
<p><img src="cb.png" height = "500" width="500" alt="Plot of calibration curve vs. predicted probability"></p>
<p><a href="https://cran.r-project.org/package=kernelshap">kernelshap</a> v0.2.0: Multidimensional version of the iterative Kernel SHAP algorithm from game theory that has become popular for interpreting Machine Learning Models. <a href="http://proceedings.mlr.press/v130/covert21a">Covert & Lee (2021)</a> for details and <a href="https://cran.r-project.org/web/packages/kernelshap/readme/README.html">README</a> for an example.</p>
<p><img src="kernelshap.svg" height = "300" width="500" alt="Shap value plot for iris data set"></p>
<p><a href="https://cran.r-project.org/package=mlim">mlim</a> v0.0.9: Uses automated machine learning techniques to fine-tune a Elastic Net, Gradient Boosting, Random Forest, Deep Learning, Extreme Gradient Boosting, or Stacked Ensemble machine learning model for imputing the missing observations of each variable. See <a href="https://cran.r-project.org/web/packages/mlim/readme/README.html">README</a> for examples.</p>
<p><img src="mlim.png" height = "500" width="300" alt="mlim workflow"></p>
<p><a href="https://cran.r-project.org/package=tidytags">tidytags</a> v1.0.2: Facilitates the analysis of Twitter data by coordinates the simplicity of collecting tweets over time with a <a href="https://tags.hawksey.info/">Twitter Archiving Google Sheet</a> and the utility of the <a href="https://docs.ropensci.org/rtweet/"><code>rtweet</code></a> package for processing and preparing Twitter metadata. There is a <a href="https://cran.r-project.org/web/packages/tidytags/vignettes/setup.html">Getting Started Guide</a> and a vignette on using <a href="https://cran.r-project.org/web/packages/tidytags/vignettes/tidytags-with-conf-hashtags.html">conference hashtags</a>.</p>
<p><img src="tidytags.png" height = "500" width="400" alt="Network plot showing popularity of tweets"></p>
<h3 id="mathematics">Mathematics</h3>
<p><a href="https://cran.r-project.org/package=ambit">ambit</a> v0.1.2: Provides tools to simulate and estimate various types of <a href="https://link.springer.com/chapter/10.1007/978-3-642-18412-3_2">ambit processes</a>, including trawl processes and weighted <a href="https://link.springer.com/chapter/10.1007/978-3-319-94129-5_8">trawl processes</a>. There is a vignette on <a href="https://cran.r-project.org/web/packages/ambit/vignettes/vignette1_simulation.html">Simulating trawl processes</a> and another on estimating the <a href="https://cran.r-project.org/web/packages/ambit/vignettes/vignette2_trawlfct_estimation.html">Trawl function</a>.</p>
<p><img src="ambit.png" height = "400" width="500" alt="Plot of trawl process"></p>
<p><a href="https://cran.r-project.org/package=rTensor2">rTensor2</a> v0.1.1: Provides a set of tools for basic tensor operators including eigenvalue decomposition, the QR decomposition and LU decompositions, the inverse of a tensor, and the transpose of a symmetric tensor. (A tensor in this context is a multidimensional array.) See <a href="https://www.sciencedirect.com/science/article/pii/S0024379515004358">Kernfeld et al. (2015)</a> for background.</p>
<h3 id="medicine">Medicine</h3>
<p><a href="https://cran.r-project.org/package=RIbench">RIbench</a> v1.0.1: Provides a benchmark suite of tools for indirect methods of <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2556592/">reference interval</a> estimation. See the <a href="https://cran.r-project.org/web/packages/RIbench/vignettes/RIbench_package.html">vignette</a>.</p>
<p><img src="RIbench.png" height = "600" width="700" alt="Boxplots split by pathological fraction or sample size for a certain distribution type"></p>
<p><a href="https://cran.r-project.org/package=spiro">spiro</a> v0.1.1: Provides functions to import, process, summarize and visualize raw data from metabolic carts. See <a href="https://link.springer.com/article/10.2165/11319670-000000000-00000">Robergs, Dwyer, and Astorino (2010)</a> for details and the vignettes <a href="https://cran.r-project.org/web/packages/spiro/vignettes/import_processing.html">Importing & Processing</a> and <a href="https://cran.r-project.org/web/packages/spiro/vignettes/summarizing_plotting.html">Summarizing & Plotting</a>.</p>
<p><img src="spiro.png" height = "400" width="600" alt="Multiple plots from cardiopulmonary exercise testing"></p>
<h3 id="pharmaceutical-applications">Pharmaceutical Applications</h3>
<p><a href="https://cran.r-project.org/package=gtreg">gtreg</a> v0.1.1: Provides functions that leverage the <code>gtsummary</code> package to creates tables suitable for regulatory agency submissions. See the <a href="https://cran.r-project.org/web/packages/gtreg/vignettes/counting-methods.html">vignette</a> on adverse event counting methods.</p>
<p><a href="https://cran.r-project.org/package=tidyCDISC">tidyCDISC</a> v0.1.0: Implements a drag and drop <code>Shiny</code> application to allow users to construct [ADaM](<a href="https://www.cdisc.org/adam-course#:~:text=The%20Analysis%20Data%20Model%20(ADaM,wide%20variety%20of%20analysis%20methods.">https://www.cdisc.org/adam-course#:~:text=The%20Analysis%20Data%20Model%20(ADaM,wide%20variety%20of%20analysis%20methods.</a>) and <a href="https://www.cdisc.org">CDISC</a> compliant tables and plots for studying population and patient level data. See the <a href="https://cran.r-project.org/web/packages/tidyCDISC/vignettes/getting_started.html">vignette</a> for more information and look here to run a simulation.</p>
<p><img src="tidyCDISC.png" height = "400" width="600" alt="Data entry page for Shiny app"></p>
<h3 id="statistics">Statistics</h3>
<p><a href="https://cran.r-project.org/package=cassowaryr">cassowaryr</a> v2.0.0: Computes a range of scatterplot diagnostics (scagnostics) on pairs of numerical variables in a data set including the graph and association-based scagnostics described in <a href="https://www.tandfonline.com/doi/abs/10.1198/106186008X320465">Wilkinson & Graham (2008)</a> <a href="doi:10.1198/106186008X320465">doi:10.1198/106186008X320465</a> and the association-based scagnostics described by <a href="https://www.dr.hut-verlag.de/978-3-8439-3092-5.html">Grimm (2016)</a>. See the <a href="https://cran.r-project.org/web/packages/cassowaryr/vignettes/cassowaryr.html">vignette</a>.</p>
<p><img src="cassowaryr.png" height = "600" width="400" alt="Scagnostic plots"></p>
<p><a href="https://cran.r-project.org/package=contsurvplot">contsurvplot</a> v0.1.1: Provides tools to visualize the causal effect of a continuous variable on a time-to-event outcome including survival area plots, survival contour plots, survival quantile plots and 3D surface plots. See <a href="https://arxiv.org/abs/2208.04644v1">Denz & Timmesfeld (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/contsurvplot/vignettes/introduction.html">vignette</a> for examples.</p>
<p><img src="contsurvplot.png" height = "300" width="500" alt="Plot of survival area curves"></p>
<p><a href="https://cran.r-project.org/package=copre">copre</a> v0.1.0: Provides functions for Bayesian nonparametric density estimation using Martingale posterior distributions and includes the Copula Resampling (CopRe) algorithm, a Gibbs sampler for the marginal Mixture of Dirichlet Process (MDP) model, and an extension for full uncertainty quantification via a new Polya completion algorithm. See <a href="https://arxiv.org/abs/2206.08418">Moya & Walker (2022)</a>, <a href="https://arxiv.org/abs/2103.15671">Fong et al. (2021)</a>, and <a href="https://www.tandfonline.com/doi/abs/10.1080/01621459.1995.10476550">Escobar & West (1995)</a> for background and <a href="https://cran.r-project.org/web/packages/copre/readme/README.html">README</a> for an example .</p>
<p><img src="copre.png" height = "300" width="500" alt="Plot of mixture distributions"></p>
<p><a href="https://CRAN.R-project.org/package=InteractionPoweR">InteractionPoweR</a> v0.1.1: Provides functions for power analysis of regression models which tests the interaction of two independent variables on a single dependent variable. See the <a href="https://psyarxiv.com/5ptd7/">tutorial</a> and <a href="https://cran.r-project.org/web/packages/InteractionPoweR/readme/README.html">README</a> to get started.</p>
<p><a href="https://cran.r-project.org/package=singR">singR</a> v0.1.1: Implements the SING algorithm to extract joint and individual non-Gaussian components from two datasets. See <a href="https://projecteuclid.org/journals/annals-of-applied-statistics/volume-15/issue-3/Simultaneous-non-Gaussian-component-analysis-SING-for-data-integration-in/10.1214/21-AOAS1466.full">Risk & Gaynanova (2021)</a> for the theory and the <a href="https://cran.r-project.org/web/packages/singR/vignettes/singR-tutorial.html">vignette</a> for examples.</p>
<p><img src="singR.png" height = "400" width="600" alt="Multiple plots showing joint loadings"></p>
<p><a href="https://CRAN.R-project.org/package=SIRthresholded">SIRthresholded</a> v1.0.0: Implements a version of the <a href="https://en.wikipedia.org/wiki/Sliced_inverse_regression">Sliced Inverse Regression</a> method which may be used for variable selection. See the <a href="https://cran.r-project.org/web/packages/SIRthresholded/vignettes/SIRthresholded.html">vignette</a>.</p>
<p><img src="SIRthresh.png" height = "400" width="400" alt="Plots showing thresholded regularization paths"></p>
<p><a href="https://cran.r-project.org/package=sparseR">sparseR</a> v0.2.0: Implements ranked sparsity methods, including penalized regression methods such as the sparsity-ranked lasso, its non-convex alternatives, and elastic net, as well as the sparsity-ranked Bayesian Information Criterion. See <a href="https://link.springer.com/article/10.1007/s10182-021-00431-7">Peterson and Cavanaugh (2022)</a> for background and the <a href="https://cran.r-project.org/web/packages/sparseR/vignettes/sparseR.html">vignette</a> for an overview.</p>
<p><img src="sparseR.png" height = "300" width="500" alt="Plot of parameter estimate vs log of penalty"></p>
<p><a href="https://cran.r-project.org/package=spmodel">spmodel</a> v0.1.0:
Provides functions to fit, summarize, and predict a variety of spatial statistical models. Modeling features include anisotropy, random effects, partition factors and big data approaches. There is an <a href="https://cran.r-project.org/web/packages/spmodel/vignettes/basics.pdf">Overview</a>, a <a href="https://cran.r-project.org/web/packages/spmodel/vignettes/guide.pdf">Detailed Guide</a> and a vignette on <a href="https://cran.r-project.org/web/packages/spmodel/vignettes/technical.pdf">Technical Details</a>.</p>
<p><a href="https://cran.r-project.org/package=TRexSelector">TRexSelector</a> v0.0.1: Provides functions to perform fast variable selection in high-dimensional settings while controlling the false discovery rate at a user-defined target level. See <a href="https://arxiv.org/abs/2110.06048">Machkour et al. (2021)</a> for background and the <a href="https://cran.r-project.org/web/packages/TRexSelector/vignettes/TRexSelector_usage_and_simulations.htm">vignette</a> for an overview.</p>
<p><img src="TRex.png" height = "400" width="600" alt="Diagram of TRexSelector Framework"></p>
<p><a href="https://cran.r-project.org/package=VAJointSurv">VAJointSurv</a> v0.1.0: Provides functions to estimate joint marker (longitudinal) and survival (time-to-event) outcomes using variational approximations which allow for correlated error terms and multiple types of survival outcomes which may be left-truncated, right-censored, and recurrent. See the <a href="https://cran.r-project.org/web/packages/VAJointSurv/vignettes/VAJointSurv.html">vignette</a> for some theory and examples.</p>
<p><img src="VAJoint.png" height = "400" width="600" alt="Plots of estimated population means with pointwise confidence intervals"></p>
<h3 id="time-series">Time Series</h3>
<p><a href="https://cran.r-project.org/package=gmwmx">gmwmx</a> v1.0.2: Implements the Generalized Method of Wavelet Moments with Exogenous Inputs estimator (GMWMX) presented in <a href="https://arxiv.org/abs/2206.09668">Cucci et al. (2022)</a>. There are vignettes on <a href="https://cran.r-project.org/web/packages/gmwmx/vignettes/load_estimate_compare_models.html">Estimating and comparing models</a>, <a href="https://cran.r-project.org/web/packages/gmwmx/vignettes/remove_outliers_hector.html">Removing extreme values in time series</a>, <a href="https://cran.r-project.org/web/packages/gmwmx/vignettes/simulate_data.html">Generating data</a>, and <a href="https://cran.r-project.org/web/packages/gmwmx/vignettes/simulation_study.html">Simulation</a>.</p>
<p><img src="gmwmx.png" height = "300" width="500" alt="Plot of functional model of a time series"></p>
<h3 id="utilities">Utilities</h3>
<p><a href="https://cran.r-project.org/package=countdown">countdown</a> v0.4.0: Provides a simple countdown timer for slides and <code>HTML</code> documents written in <code>RMarkdown</code> or <code>Quarto</code> and with <code>Shiny</code>. See <a href="https://cran.r-project.org/web/packages/countdown/readme/README.html">README</a> for an example.</p>
<p><img src="countdown.gif" height = "300" width="500" alt="Countdown clock"></p>
<p><a href="https://cran.r-project.org/package=D4TAlink.light">D4TAlink.light</a> v2.2.9: Provides workload management tools to facilitate structuring R&D activities to comply with FAIR principles as discussed by <a href="https://direct.mit.edu/dint/article/2/1-2/10/10017/FAIR-Principles-Interpretations-and-Implementation">Jacobsen et al. (2017)</a> and with <a href="https://qscompliance.com/wp-content/uploads/2019/01/ALCOA-Principles.pdf">ALCOA+ principles</a> as proposed by the FDA. See the <a href="https://cran.r-project.org/web/packages/D4TAlink.light/vignettes/D4TAlink_basics.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=tinkr">tinkr</a> v0.1.0: Provides functions to convert <code>Markdown</code> and <code>RMarkdown</code> files to <code>XML</code> and back to allow their editing with <code>xml2</code> (XPath) instead of numerous complicated regular expressions. See the <a href="https://cran.r-project.org/web/packages/tinkr/vignettes/tinkr.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=typetracer">typetracer</a> v0.1.1: The <code>R</code> language includes a set of defined types, but has been described as being “absurdly dynamic” (<a href="https://dl.acm.org/doi/10.1145/3340670.3342426">Turcotte & Vitek (2019)</a>, and lacks tools to specify which types are expected by an expression. <code>typetracer</code>provides functions to extract detailed information on the properties of parameters passed to <code>R</code> functions. See the <a href="https://cran.r-project.org/web/packages/typetracer/vignettes/nse.html">vignette</a>.</p>
<h3 id="visualization">Visualization</h3>
<p><a href="https://cran.r-project.org/package=atime">atime</a> v2022.9.16: Provides functions for computing and visualizing <a href="https://en.wikipedia.org/wiki/Asymptotic_computational_complexity">comparative asymptotic timings</a> of different algorithms and code versions. Also includes functionality for comparing empirical timings with expected references such as linear or quadratic. There are several vignettes including <a href="https://cran.r-project.org/web/packages/atime/vignettes/git.html">Comparing git versions</a>, <a href="https://cran.r-project.org/web/packages/atime/vignettes/optseg.html">Optimal segmentation examples</a>, and <a href="https://cran.r-project.org/web/packages/atime/vignettes/regex.html">Regular Expression examples</a>.</p>
<p><img src="atime.png" height = "600" width="400" alt="Time comparison plots"></p>
<p><a href="https://cran.r-project.org/package=ggsurvfit">ggsurvfit</a> v0.1.0: Extends <code>ggplot2</code> to ease the creation of publication ready survival plots. See the vignettes <a href="https://cran.r-project.org/web/packages/ggsurvfit/vignettes/gallery.html">Gallery</a> and <a href="https://cran.r-project.org/web/packages/ggsurvfit/vignettes/themes.html">Themes</a>.</p>
<p><img src="ggsurvfit.png" height = "400" width="400" alt="Annotated Survival Plot"></p>
<p><a href="https://cran.r-project.org/package=oblicubes">oblicubes</a> v0.1.2: Extends the <a href="https://github.com/coolbutuseless/isocubes"><code>isocubes</code></a> package to provide three-dimensional rendering for <code>grid</code> and <code>ggplot2</code> graphics using cubes and cuboids drawn with an oblique projection. See the <a href="https://cran.r-project.org/web/packages/oblicubes/vignettes/oblicubes.html">vignette</a>.</p>
<p><img src="oblicubes.png" height = "400" width="400" alt="Textured rendering of 3D object with multiple holes"></p>
<p><a href="https://CRAN.R-project.org/package=ordr">ordr</a> v0.1.0: Provides a <code>tidyverse</code> extension for ordinations and biplots. Ordination comprises several multivariate techniques including principal components analysis which rely on eigen-decompositions or singular value decompositions of pre-processed numeric matrix data. The overlay of the resulting shared coordinates on a scatterplot is called a biplot. See <a href="https://link.springer.com/book/10.1007/1-4020-2236-0">Roux & Rouanet (2005)</a> for background. See the vignettes on <a href="https://cran.r-project.org/web/packages/ordr/vignettes/cmds-variables.html">Covariance Data</a> and <a href="https://cran.r-project.org/web/packages/ordr/vignettes/ordr.html">Ordination</a>.</p>
<p><img src="ordr.png" height = "500" width="500" alt="Example of a biplot"></p>
<script>window.location.href='https://rviews.rstudio.com/2022/09/26/august-2022-top-40-new-cran-packages/';</script>
Automate a Twitter bot with the rtweet package and RStudio Connect
https://rviews.rstudio.com/2022/09/13/automate-a-twitter-bot-with-rtweet-and-rstudio-connect/
Tue, 13 Sep 2022 00:00:00 +0000https://rviews.rstudio.com/2022/09/13/automate-a-twitter-bot-with-rtweet-and-rstudio-connect/
<p>When developing the promotion plan for the <a href="https://www.rstudio.com/conference/2022/2022-conf-talks/">many exciting talks at rstudio::conf(2022)</a>, we thought of using the <a href="https://docs.ropensci.org/rtweet/index.html"><code>rtweet</code> package</a> by Michael W. Kearney to create a <a href="https://en.wikipedia.org/wiki/Twitter_bot">Twitter bot</a> to automate Tweet announcements when a presentation was about to start. As it turned out, we did not end up using this process, but we thought it would be helpful to share how this can be done with <code>rtweet</code> v1.0.2 and RStudio Connect.</p>
<p><code>retweet</code> allows users to use Twitter from R, and the function <code>rtweet::post_tweet()</code> allows users to share status updates on their Twitter feed without leaving RStudio (or the IDE of our choice). Once you have the Tweets you would like to post, the question is: how can you automate it so you don’t have to watch the clock anytime you want to make an announcement? One option is to use <a href="https://www.rstudio.com/products/connect/">RStudio Connect</a>, RStudio’s publishing platform which hosts data science content such as Shiny apps, Jupyter notebooks, APIs, etc. that is created in either R or Python. For this application, RStudio Connect’s ability to rerun R Markdown documents on a schedule is crucial.</p>
<p>The major steps in our workflow are:</p>
<ol style="list-style-type: decimal">
<li><a href="#create-a-spreadsheet-with-the-talk-schedule">Create a spreadsheet with the talk schedule</a></li>
<li><a href="#clean-table-and-automate-tweet-creation">Clean table and automate Tweet creation</a></li>
<li><a href="#authenticate-r-and-twitter">Authenticate R and Twitter</a></li>
<li><a href="#schedule-r-markdown-documents-on-rstudio-connect">Schedule R Markdown documents on RStudio Connect</a></li>
</ol>
<p>(Note the files are also available on <a href="https://github.com/rstudio-marketing/rstudio-conf-2022-bot">GitHub</a>).</p>
<div id="create-a-spreadsheet-with-the-talk-schedule" class="section level2">
<h2>Create a spreadsheet with the talk schedule</h2>
<p>First, we create a spreadsheet with the relevant information on the talks. Here is an example using dummy data:</p>
<table style="width:100%;">
<colgroup>
<col width="7%" />
<col width="7%" />
<col width="38%" />
<col width="19%" />
<col width="12%" />
<col width="11%" />
<col width="1%" />
</colgroup>
<thead>
<tr class="header">
<th>day</th>
<th>start</th>
<th>title</th>
<th>speaker</th>
<th>twitter_name</th>
<th>image</th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>July 27</td>
<td>10:00AM</td>
<td>30 tips to improve your datascience</td>
<td>André Cardoso Azevedo</td>
<td><span class="citation">@fake_twitter1</span></td>
<td>thumbnail.jpg</td>
<td></td>
</tr>
<tr class="even">
<td>July 27</td>
<td>11:00AM</td>
<td>5 drinks to combine with data science</td>
<td>Marie Wolf</td>
<td><span class="citation">@fake_twitter2</span></td>
<td>thumbnail.jpg</td>
<td></td>
</tr>
<tr class="odd">
<td>July 27</td>
<td>11:30AM</td>
<td>Data science techniques that changed my life forever</td>
<td>Jasna Šahbaz</td>
<td><span class="citation">@fake_twitter3</span></td>
<td>thumbnail.jpg</td>
<td></td>
</tr>
<tr class="even">
<td>July 27</td>
<td>12:00PM</td>
<td>10 videos about data science that will make you laugh</td>
<td>Dennis R. Everhart</td>
<td><span class="citation">@fake_twitter4</span></td>
<td>thumbnail.jpg</td>
<td></td>
</tr>
</tbody>
</table>
<p><br>
Using this starting-off point:</p>
<ul>
<li>We want to merge the <code>day</code> and <code>start</code> columns to create a <code>date-time</code> variable that specifies the time zone. This is important because we want to publish the Tweet in the time zone of the conference, which may differ from the time zone in which we’re creating this project!</li>
<li>We want to automate as much of the tweet-creation process as possible using R. This will help us avoid manual work if we want to add rows to our table later on.</li>
</ul>
</div>
<div id="clean-table-and-automate-tweet-creation" class="section level2">
<h2>Clean table and automate Tweet creation</h2>
<p>Let’s begin with the following packages:</p>
<pre class="r"><code>library(rtweet)
library(dplyr)
library(lubridate)</code></pre>
<p>Now, we can load our data:</p>
<pre class="r"><code>dat <-
data.frame(
stringsAsFactors = FALSE,
day = c("July 27", "July 27", "July 27", "July 27"),
start = c("10:00:00", "11:00:00", "11:30:00", "12:00:00"),
title = c("30 tips to improve your datascience",
"5 drinks to combine with data science",
"Data science techniques that changed my life forever",
"10 videos about data science that will make you laugh"),
speaker = c("André Cardoso Azevedo",
"Marie Wolf",
"Jasna Šahbaz",
"Dennis R. Everhart"),
twitter_name = c("@fake_twitter1",
"@fake_twitter2",
"@fake_twitter3",
"@fake_twitter4"),
image = c("thumbnail.jpg",
"thumbnail.jpg",
"thumbnail.jpg",
"thumbnail.jpg")
)</code></pre>
<p>As mentioned above, we might be in a place with a different time zone than the conference location. We want to ensure that our Twitter bot posts status updates at the right time in the appropriate time zone.</p>
<p>Let’s specify the time zone in our <code>date-time</code> variable. To find out what it is called, we can see the complete list of time zone names in R using <code>OlsonNames()</code>:</p>
<pre class="r"><code># Check timezone names
OlsonNames() %>%
as_tibble() %>%
dplyr::filter(stringr::str_detect(value, "US/")) # filtering for US-only</code></pre>
<pre><code>## # A tibble: 12 × 1
## value
## <chr>
## 1 US/Alaska
## 2 US/Aleutian
## 3 US/Arizona
## 4 US/Central
## 5 US/East-Indiana
## 6 US/Eastern
## 7 US/Hawaii
## 8 US/Indiana-Starke
## 9 US/Michigan
## 10 US/Mountain
## 11 US/Pacific
## 12 US/Samoa</code></pre>
<p>We create an object <code>s2</code> that prints the current time in our desired time zone:</p>
<pre class="r"><code>s <- Sys.time()
s2 <- format(s, format = "%F %R %Z", tz = "US/Eastern")
s2</code></pre>
<pre><code>## [1] "2022-09-13 13:30 EDT"</code></pre>
<p>Now, we create a new table <code>cleaned_dat</code> with the <code>day</code> and <code>start</code> columns merged into a single <code>date-time</code> object. We set the <code>tz</code> argument to use the appropriate time zone.</p>
<pre class="r"><code>cleaned_dat <-
dat %>%
dplyr::mutate(date = lubridate::mdy_hms(paste0(day, ", 2022 ",
start, " EDT"),
tz = "US/Eastern"))</code></pre>
<p>Let’s add on to our <code>mutate()</code> pipeline to automate the Tweet message, which should read:</p>
<pre><code>Happening now! [title]: [speaker] [twitter_name]
Stream here: url goes here.</code></pre>
<p>The <code>\n</code> creates a line break.</p>
<pre class="r"><code>cleaned_dat <-
cleaned_dat %>%
dplyr::mutate(
script =
paste0(
"Happening now! ",
title,
": ",
speaker,
" ",
twitter_name,
"\n",
"\n",
"Stream here: ",
"url goes here",
"\n",
"\n"
),
.keep = "unused"
)</code></pre>
<p>This table contains all of the talks. Let’s create a table that filters to show only talks happening this minute.</p>
<pre class="r"><code>filtered_dat <-
cleaned_dat %>%
filter(date(date) == date(s2) &
hour(date) == hour(s2) &
minute(date) == minute(s2))</code></pre>
</div>
<div id="authenticate-r-and-twitter" class="section level2">
<h2>Authenticate R and Twitter</h2>
<p>To use the API, all <code>rtweet</code> users must authenticate their Twitter accounts. The <code>rtweet</code> documentation has a <a href="https://docs.ropensci.org/rtweet/articles/auth.html">comprehensive vignette on authentication</a>. The high-level points are:</p>
<ul>
<li>Apply for “Elevated” access to the API on the <a href="https://developer.twitter.com/">Twitter Developer Portal</a></li>
<li>Generate an “Access token and secret”</li>
<li>Save the API key, API secret key, access key, and access secret key in your R environment</li>
</ul>
<p>Once we’ve finished these steps, we can authenticate a bot that takes action on our behalf. We reference the keys that we’ve saved in our R environment:</p>
<pre class="r"><code>rbot_token <- rtweet::rtweet_bot(
api_key = Sys.getenv("RBOT_TWITTER_API_KEY"),
api_secret = Sys.getenv("RBOT_TWITTER_API_SECRET"),
access_token = Sys.getenv("RBOT_TWITTER_ACCESS_KEY"),
access_secret = Sys.getenv("RBOT_TWITTER_ACCESS_SECRET")
)</code></pre>
<p>As our last step, we use <code>rtweet::post_tweet()</code> to post updates to our authenticated Twitter account. In addition to text, <code>post_tweet()</code> can also upload images to Twitter. We can specify them using the <code>media</code> argument.</p>
<p>We want this only to occur when there’s a talk starting at the current time. To accomplish this, we can create an <code>if</code> statement that checks to see if the table is empty. If it is not empty, then it posts the Tweet.</p>
<pre class="r"><code>if (dim(filtered_dat)[1] > 0) {
for (i in 1:dim(dat3)[1]) {
rtweet::post_tweet(
status = dat3$script[i],
media = dat3$image[i],
token = rbot_token
)
}
}</code></pre>
</div>
<div id="schedule-r-markdown-documents-on-rstudio-connect" class="section level2">
<h2>Schedule R Markdown documents on RStudio Connect</h2>
<p>We can save the code above in a single R Markdown document and <a href="https://colorado.rstudio.com/rsc/content/1f9c240f-4bbf-4c13-9c68-e5bb386dd577">deploy it to RStudio Connect</a>:</p>
<p><img src="image1.png" alt="RStudio Connect deployment window allowing us to deploy an R Markdown document with source code" />
On RStudio Connect, we can schedule an R Markdown document to rerun at specific intervals. For this example, we can set it to run every minute. The R Markdown document reruns, filters the table based on the time, and posts a status update if there is a talk happening in the current minute.</p>
<p><img src="image2.png" alt="RStudio Connect deployed R Markdown document with scheduling options listed on the side. The document is set to rerun every 1 minute." />
With that, our Twitter bot is set up, authenticated, and has the information that it needs to post status updates based on our talk schedule.</p>
</div>
<div id="learn-more" class="section level2">
<h2>Learn more</h2>
<p>As mentioned above, there are various ways of automating a Twitter bot with R. RStudio Connect is a convenient choice as it deploys R Markdown documents and all associated files. It’s easy to set up and provides precise control over the schedule.</p>
<p>Another option is to use GitHub Actions:</p>
<ul>
<li><a href="https://github.com/matt-dray/londonmapbot">Matt Dray created a Twitter bot to post {leaflet} maps</a></li>
<li><a href="https://oscarbaruffa.com/twitterbot/">Oscar Baruffa built a bot to share R-related books</a></li>
</ul>
<p>Check out the <a href="https://github.com/rstudio-marketing/rstudio-conf-2022-bot">GitHub repository for this blog post</a> for an example of the R Markdown file. Happy Tweeting!</p>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/09/13/automate-a-twitter-bot-with-rtweet-and-rstudio-connect/';</script>
Beneath and Beyond the Cox Model
https://rviews.rstudio.com/2022/09/06/deep-survival/
Tue, 06 Sep 2022 00:00:00 +0000https://rviews.rstudio.com/2022/09/06/deep-survival/
<p>The Cox Proportional Hazards model has so dominated survival analysis over the past forty years that I imagine quite a few people who regularly analyze survival data might assume that the Cox model, along with the Kaplan-Meier estimator and a few standard parametric models, encompass just about everything there is to say about the subject. It would not be surprising if this were true because it is certainly the case that these tools have dominated the teaching of survival analysis. Very few introductory textbooks look beyond the Cox Model and the handful of parametric models built around Gompertz, Weibull and logistic functions. But why do Cox models work so well? What is the underlying theory? How do all the pieces of the standard survival tool kit fit together?</p>
<p>As it turns out, Kaplan-Meier estimators, the Cox Proportional Hazards model, Aalen-Johansen estimators, parametric models, multistate models, competing risk models, frailty models and almost every other survival analysis technique implemented in the vast array of R packages comprising the CRAN <a href="https://cran.r-project.org/web/views/Survival.html">Survival Task View</a>, are supported by an elegant mathematical theory that formulates time-to-event analyses as stochastic counting models. The theory is about thirty years old. It was initiated by Odd Aalen in his 1975 Berkeley PhD dissertation, developed over the following twenty years largely by Scandinavian statisticians and their collaborators, and set down in more or less complete form in two complementary textbooks [5 and 9] by 1993. Unfortunately, because of its dependency on measure theory, martingales, stochastic integrals and other notions from advanced mathematics, it does not appear that the counting process theory of survival analysis has filtered down in a form that is readily accessible by practitioners.</p>
<p>In this rest of this post, I would like to suggest a path for getting a working knowledge of this theory by introducing two very readable papers, which taken together, provide an excellent overview of the relationship of counting processes to some familiar aspects of survival analysis.</p>
<p>The first paper, <em>The History of applications of martingales in survival analysis</em> by Aalen, Andersen, Borgan, Gill, and Keiding [4] is a beautiful historical exposition of the counting process theory by master statisticians who developed a good bit of the theory themselves. Read through this paper in an hour of so and you will have an overview of the theory, see elementary explanations for some of the mathematics involved, and gain a working idea of how the major pieces of the theory fit together how they came together.</p>
<p>The second paper, <em>Who needs the Cox model anyway?</em> [7], is actually a teaching <em>note</em> put together by Bendix Carstensen. It is a lesson with an attitude and the R code to back it up. Carstensen demonstrates the equivalence of the Cox model to a particular Poisson regression model. Working through this <em>note</em> is like seeing a magic trick and then learning how it works.</p>
<p>The following reproduces a portion of Carstensen’s <em>note</em>. I provide some commentary and fill in a few elementary details in the hope that I can persuade you that it is worth the trouble to spend some time with it yourself.</p>
<p>Carstensen use the North Central Cancer Treatment Group lung cancer survival data set which is included in the <code>survival</code> package for his examples.</p>
<pre><code>## # A tibble: 228 × 10
## inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 3 306 2 74 1 1 90 100 1175 NA
## 2 3 455 2 68 1 0 90 90 1225 15
## 3 3 1010 1 56 1 0 90 90 NA 15
## 4 5 210 2 57 1 1 90 60 1150 11
## 5 1 883 2 60 1 0 100 90 NA 0
## 6 12 1022 1 74 1 1 50 80 513 0
## 7 7 310 2 68 2 2 70 60 384 10
## 8 11 361 2 71 2 2 60 80 538 1
## 9 1 218 2 53 1 1 70 80 825 16
## 10 7 166 2 61 1 2 70 70 271 34
## # … with 218 more rows</code></pre>
<p>It may not be obvious at first because there is no subject ID column, but this data frame contains one row for each of 228 subjects. The first column is an institution code. <code>time</code> is the time of death or censoring. <code>status</code> is the censoring indicator. The remaining columns are covariates. I select <code>time</code>, <code>status</code>, <code>sex</code> and <code>age</code>, drop the others from the our working data frame, and then replicate Carstensen’s preprocessing in a tidy way. The second line of <code>mutate()</code> adds a small number to each event time to avoid ties.</p>
<pre class="r"><code>set.seed(1952)
lung <- lung %>% select(time, status, age, sex) %>%
mutate(sex = factor(sex,labels=c("M","F")),
time = time + round(runif(nrow(lung),-3,3),2))</code></pre>
<p>To get a feel for the data we fit a Kaplan-Meier Curve stratified by sex.</p>
<pre class="r"><code>surv.obj <- with(lung, Surv(time, status == 2))
fit.by_sex <- survfit(surv.obj ~ sex, data = lung, conf.type = "log-log")
autoplot(fit.by_sex,
xlab = "Survival Time (Days) ",
ylab = "Survival Probabilities",
main = "Kaplan-Meier plot of lung data by sex") +
theme(plot.title = element_text(hjust = 0.5))</code></pre>
<p><img src="/2022/09/06/deep-survival/index_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<p>Next, following Carstensen, I fit the baseline Cox model to be used in the model comparisons below.</p>
<pre class="r"><code>m0.cox <- coxph( Surv( time, status==2 ) ~ age + sex, data=lung )
summary( m0.cox )</code></pre>
<pre><code>## Call:
## coxph(formula = Surv(time, status == 2) ~ age + sex, data = lung)
##
## n= 228, number of events= 165
##
## coef exp(coef) se(coef) z Pr(>|z|)
## age 0.01705 1.01720 0.00922 1.85 0.0643 .
## sexF -0.52033 0.59433 0.16751 -3.11 0.0019 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## age 1.017 0.983 0.999 1.036
## sexF 0.594 1.683 0.428 0.825
##
## Concordance= 0.603 (se = 0.025 )
## Likelihood ratio test= 14.4 on 2 df, p=7e-04
## Wald test = 13.8 on 2 df, p=0.001
## Score (logrank) test = 14 on 2 df, p=9e-04</code></pre>
<p>The hazard ratios for <code>age</code> and <code>sexF</code> are given in the output column labeled <em>exp(coef)</em>. As Carstensen points out mortality increases by 1.7% per year of age at diagnosis and that women have 40% lower mortality than men.</p>
<p>Carstensen next shows that this model can be exactly replicated by a particular and somewhat peculiar Poisson model. Doing this requires a shift in how time is conceived. In the Kaplan-Meier estimator and the Cox model, time is part of the response vector. In the counting process formulation, time is a covariate. Time is divided into many small intervals of length <em>h</em> in which an individuals “exit status” , <em>d</em> is recorded. <em>d</em> will be 1 if death occurred or 0 otherwise. The <em>h</em> intervals represent an individual’s risk time. The pair (<em>d</em>, <em>h</em>) are used to calculate an empirical rate for the process which corresponds to the theoretical rate:</p>
<blockquote>
<p>λ(t) = lim<sub>h→0</sub> <strong>P</strong>[event in (t, t + h)| at risk at time t]/h (*)</p>
</blockquote>
<p>The first step in formulating a Poisson model is to set up a data structure that will allow for this more nuanced treatment of time. The function <code>Lexis</code> from the <a href="http://bendixcarstensen.com/Epi/"><code>Epi</code></a> package creates an object of class Lexis, a data frame with columns that will be used to distinguish event time (death or censoring time) from the time intervals in which subjects are at risk for the event. Collectively, these intervals span period from when the first until the last recorded time.</p>
<pre class="r"><code>Lung <- Epi::Lexis( exit = list( tfe=time ),
exit.status = factor( status, labels=c("Alive","Dead") ),
data = lung )</code></pre>
<pre><code>## NOTE: entry.status has been set to "Alive" for all.
## NOTE: entry is assumed to be 0 on the tfe timescale.</code></pre>
<pre class="r"><code>head(Lung)</code></pre>
<pre><code>## lex.id tfe lex.dur lex.Cst lex.Xst time status age sex
## 1 0 308.7 Alive Dead 308.7 2 74 M
## 2 0 457.4 Alive Dead 457.4 2 68 M
## 3 0 1008.6 Alive Alive 1008.6 1 56 M
## 4 0 212.1 Alive Dead 212.1 2 57 M
## 5 0 885.5 Alive Dead 885.5 2 60 M
## 6 0 1023.7 Alive Alive 1023.7 1 74 M</code></pre>
<p>The new variables are:</p>
<ol style="list-style-type: decimal">
<li>lex.id - Subject ID</li>
<li>tfe - Time from entry at the beginning of the follow-up interval</li>
<li>lex.dur - Duration of the follow-up interval</li>
<li>lex.Cst - Entry status (Alive in our case)</li>
<li>lex.Xst - Exit status at the end of the follow-up interval: tfe + lex.dur (Either Alive or Dead in our case)</li>
</ol>
<p>Next, the <code>time</code> variable is sorted to produce a vector of endpoints for the at risk intervals and a new <em>time-split</em> Lexis data frame is created using the <code>splitMulti()</code> function from the <a href="https://github.com/FinnishCancerRegistry/popEpi"><code>popEpi</code></a> package.</p>
<pre class="r"><code>Lung.s <- splitMulti( Lung, tfe=c(0,sort(unique(Lung$time))) )
head(Lung.s)</code></pre>
<pre><code>## lex.id tfe lex.dur lex.Cst lex.Xst time status age sex
## 1 0.00 7.67 Alive Alive 308.7 2 74 M
## 1 7.67 1.88 Alive Alive 308.7 2 74 M
## 1 9.55 0.23 Alive Alive 308.7 2 74 M
## 1 9.78 0.57 Alive Alive 308.7 2 74 M
## 1 10.35 2.25 Alive Alive 308.7 2 74 M
## 1 12.60 0.45 Alive Alive 308.7 2 74 M</code></pre>
<pre class="r"><code>summary( Lung.s )</code></pre>
<pre><code>##
## Transitions:
## To
## From Alive Dead Records: Events: Risk time: Persons:
## Alive 25941 165 26106 165 69632 228</code></pre>
<p><code>tfe</code> tracks the time from entry into the study. This is calendar time.</p>
<p>Carstensen then fits a Cox model to both the Lexis data set and the time-split Lexis data set and notes that the results match the original baseline Cox model. This is as one would expect since the three different data frames contain the same information. Nevertheless, it is a pleasant surprise that the <code>coxph()</code> and <code>Surv()</code> functions are flexible enough to assimilate the three different input data formats.</p>
<pre class="r"><code>mL.cox <- coxph( Surv( tfe, tfe+lex.dur, lex.Xst=="Dead" ) ~ age + sex, eps=10^-11, iter.max=25, data=Lung )
mLs.cox <- coxph( Surv( tfe, tfe+lex.dur, lex.Xst=="Dead" ) ~ age + sex, eps=10^-11, iter.max=25, data=Lung.s )
round( cbind( ci.exp(m0.cox), ci.exp(mL.cox), ci.exp(mLs.cox) ), 6 )</code></pre>
<pre><code>## exp(Est.) 2.5% 97.5% exp(Est.) 2.5% 97.5% exp(Est.) 2.5% 97.5%
## age 1.0172 0.999 1.0357 1.0172 0.999 1.0357 1.0172 0.999 1.0357
## sexF 0.5943 0.428 0.8253 0.5943 0.428 0.8253 0.5943 0.428 0.8253</code></pre>
<p>Now, Carstensen executes what would seem to be a very strange modeling maneuver. He turns calender time, <code>tfe</code> into a factor and fits a Cox model with <code>tfe</code> as a covariate.</p>
<pre class="r"><code>mLs.pois.fc <- glm( cbind(lex.Xst=="Dead",lex.dur) ~ 0 + factor(tfe) + age + sex, family=poisreg, data=Lung.s ) </code></pre>
<p>An important technical point is that the time intervals in equation (*) above do not satisfy the independence assumption for a Poisson regression model. Nevertheless, the standard <code>glm()</code> machinery can be used to fit the model because, as Carstensen demonstrates, the likelihood function for the conditional probabilities is proportional to the partial likelihood function of the Cox model.</p>
<pre class="r"><code>cbind( ci.exp(mLs.cox),ci.exp( mLs.pois.fc, subset=c("age","sex") ) )</code></pre>
<pre><code>## exp(Est.) 2.5% 97.5% exp(Est.) 2.5% 97.5%
## age 1.0172 0.999 1.0357 1.0172 0.999 1.0357
## sexF 0.5943 0.428 0.8253 0.5943 0.428 0.8253</code></pre>
<p>Carstensen concludes that this demonstrates that the Cox model is equivalent to a specific Poisson model which has one rate parameter for each time internal, and emphasizes that this is not a new result. He notes that the equivalence was demonstrated some time ago, theoretically by Theodore Holford [10], and in practice, by John Whitehead [14]. Also, in a vignette [15] for the <code>survival</code> package Zhong et al. state that this <em>trick</em> may be used to approximate a Cox model.</p>
<p>Carstensen then demonstrates that more practical Poisson models can be fit by using splines to decrease the number of at risk intervals. The first uses a spline basis with arbitrary knot locations and the second fits a penalized spline <code>gam</code> model.</p>
<p>splines</p>
<pre class="r"><code>t.kn <- c(0,25,100,500,1000)
mLs.pois.sp <- glm( cbind(lex.Xst=="Dead",lex.dur) ~ Ns(tfe,knots=t.kn) + age + sex, family=poisreg, data=Lung.s ) </code></pre>
<p>Penalized splines</p>
<pre class="r"><code>mLs.pois.ps <- mgcv::gam( cbind(lex.Xst=="Dead",lex.dur) ~ s(tfe) + age + sex, family=poisreg, data=Lung.s ) </code></pre>
<p>Carstensen finishes up this portion of his analysis by noting the similarity of the estimates of age and sex effects from the different models.</p>
<pre class="r"><code>ests <-
rbind( ci.exp(m0.cox),
ci.exp(mLs.cox),
ci.exp(mLs.pois.fc,subset=c("age","sex")),
ci.exp(mLs.pois.sp,subset=c("age","sex")),
ci.exp(mLs.pois.ps,subset=c("age","sex")) )
cmp <- cbind( ests[c(1,3,5,7,9) ,],
ests[c(1,3,5,7,9)+1,] )
rownames( cmp ) <-
c("Cox","Cox-split","Poisson-factor","Poisson-spline","Poisson-penSpl")
colnames( cmp )[c(1,4)] <- c("age","sex")
round( cmp,5 )</code></pre>
<pre><code>## age 2.5% 97.5% sex 2.5% 97.5%
## Cox 1.017 0.9990 1.036 0.5943 0.4280 0.8253
## Cox-split 1.017 0.9990 1.036 0.5943 0.4280 0.8253
## Poisson-factor 1.017 0.9990 1.036 0.5943 0.4280 0.8253
## Poisson-spline 1.016 0.9980 1.035 0.5993 0.4316 0.8322
## Poisson-penSpl 1.016 0.9983 1.035 0.6021 0.4338 0.8358</code></pre>
<p>This demonstration provides some convincing evidence that both parametric and non-parametric models are part of a single underlying theory! When you think about it, this is an astonishing idea. To further explore the counting process theory of survival models, I provide a definition of Aalen’s multiplicative intensity model and a list of references below that I hope you will find helpful.</p>
<p>Finally, there is much more to Carstensen’s note than I have presented. He goes on to provide a fairly complete analysis of the lung data while looking at cumulative rates, survival, practical time splitting, time varying coefficients and more ideas along the way.</p>
<div id="appendix-multiplicative-intensity-model" class="section level3">
<h3>Appendix: Multiplicative Intensity Model</h3>
<p>For some direct insight into how the Cox Proportional Hazards model fits into the counting process theory have a look at Odd Aalen’s definition of the multiplicative intensity model. Aalan begins his landmark 1978 paper <em>Nonparametric Inference For a Family of Counting Processes]</em> [1] by defining the fundamental components of his multiplicative intensity model.</p>
<p>Let <strong>N</strong> = (N<sub>1</sub>, . . . N<sub>k</sub>) be a multivariate counting process which is a collection of univariate counting processes on the interval [0,t] each of which counts events in [0,t]. The N<sub>i</sub> may depend on each other. Let σ(F<sub>t</sub>) be the sigma algebra which represents the collection of all events that can be determined to have happened by time, t. Let <strong>α</strong> = α<sub>1</sub>, . . . α</sub> be an unknown, non-negative function and let <strong>Y</strong> = (Y<sub>1</sub>, . . . Y<sub>k</sub>) be a process observable over [0,t].</p>
<p>Define Λ<sub>i</sub>(t) = lim<sub>h→0</sub>E(N<sub>i</sub>(t + h) - N<sub>i</sub>(t) | F<sub>t</sub> )/h i = 1, … k, to be the the intensity process of the counting process <strong>N</strong>.</p>
<p>Then the multiplicative intensity model is defined to be:
<strong>Λ<sub>i</sub>(t) = α<sub>i</sub>(t)Y<sub>i</sub>(t)</strong>.</p>
<p>This last line certainly looks like the Cox model, and it is not to difficult to confirm that this is indeed the case. You can find the gory details in <em>Fleming and Harrington</em> [9 p 126] or comprehensive monograph by <em>Andersen et al.</em> [5 p481].</p>
</div>
<div id="references" class="section level3">
<h3>References</h3>
<p>I believe that the following references (annotated with a few comments) comprise a reasonable basis from gaining familiarity with the counting process approach to survival modeling.</p>
<ol style="list-style-type: decimal">
<li><p><a href="https://www.jstor.org/stable/2958850">Aalen (1978)</a> Odd O. Aalen <em>Nonparametric Inference For a Family of Counting Processes</em>. The Annals of Statistics 1978, vol 6, no 4, 701-726 <em>This is the ‘Ur’ paper for the multiplicative intensity process. At least the first half should be approachable with some knowledge of measure theory and conditional expectation.</em></p></li>
<li><p><a href="https://www.jstor.org/stable/4615704?read-now=1&seq=1#metadata_info_tab_contents">Aalen & Johansen (1978)</a> Odd O. Allen and Soren Johansen. <em>An Empirical Transition Matrix for Non-homogenous Markov Chains Based on Censored Observations</em>. Scand J Statistics 5: 141-150, 1978. <em>This is the source of the Aalen-Johansen estimator. The <code>etm</code> package provides an implementation.</em></p></li>
<li><p><a href="https://www.amazon.com/Survival-Event-History-Analysis-Statistics/dp/0387202870/ref=sr_1_1?crid=1XEV3T73GK527&keywords=Survival+and+Event+History+Analysis%3B+A+Process+Point+of+View&qid=1662492084&sprefix=survival+and+event+history+analysis+a+process+point+of+view%2Caps%2C119&sr=8-1">Aalen et al. (2008)</a> Odd O. Aalen, Ørnulf Borgan and Håkon K. Gjessing. <em>Survival and Event History Analysis; A Process Point of View</em> Springer Verlag 2008. <em>This is definitely the text to read first. It is comprehensive, takes a modern point of view, is well written, and introduces the difficult mathematics without all of the technical details that often slow down the process of learning some new mathematics.</em></p></li>
<li><p><a href="https://www.jehps.net/juin2009/Aalenetal.pdf">Aalen et al. (2009)</a>. Odd O. Aalen, Per Kragh Andersen, Ørnulf Borgan, Richard D. Gill and Niels Keiding. <em>History of applications of martingales in survival analysis</em> vol 5, no 1, June 2009</p></li>
<li><p><a href="https://www.amazon.com/Statistical-Counting-Processes-Springer-Statistics/dp/0387978720/ref=sr_1_1?crid=YA0D7DHM43ZC&keywords=Statistical+Models+Based+on+Counting+Processes&qid=1662492269&sprefix=statistical+models+based+on+counting+processes%2Caps%2C124&sr=8-1">Andersen et al. (1993)</a> Per Kragh Andersen, Ørnulf Borgan, Richard D. Gill, Niels Keiding. <em>Statistical Models Based on Counting Processes</em>. Springer-Verlag, 1993 <em>This text presents numerous examples along with a discussion of the theory and emphasizes parametric models.</em></p></li>
<li><p><a href="https://www.duo.uio.no/bitstream/handle/10852/10287/1/stat-res-03-97.pdf">Borgan (1997)</a>. Ørnulf Borgan <em>Three contributions to the Encyclopedia of Biostatistics: The Nelson-Aalen, Kaplan-Meier, and Aalen-Johansen estimators</em> - <em>Very clear summaries.</em></p></li>
<li><p><a href="http://bendixcarstensen.com/WntCma.pdf">Carstensen (2019)</a> Bendex Carstensen. <em>Who needs the Cox model anyway?</em></p></li>
<li><p><a href="http://www.biecek.pl/statystykamedyczna/cox.pdf">Cox (1972)</a> <em>Regression Models and Life-Tables</em> JRSS Vol. 34, No.2, 187-200</p></li>
<li><p><a href="https://www.amazon.com/Counting-Processes-Survival-Analysis-Fleming/dp/0471769886/ref=sr_1_1?crid=2CXVSTHAPQ3AG&keywords=Counting+Processes+%26+Survival+Analysis&qid=1662492407&sprefix=counting+processes+%26+survival+analysis%2Caps%2C120&sr=8-1">Fleming & Harrington (1991)</a>. Thomas R. Fleming and David P. Harrington. <em>Counting Processes & Survival Analysis</em>, John Wiley & Sons, Inc. 1991 <em>This text book develops all of the math needed and goes on to study non-parametric models including the Cox model.</em></p></li>
<li><p><a href="https://www.jstor.org/stable/2529747">Holford</a>. <em>Life table with concomitant information. Biometrics</em>, 32:587{597, 1976.</p></li>
<li><p><a href="https://shariq-mohammed.github.io/files/cbsa2019/1-intro-to-survival.html">Mohammed (2019)</a>. <em>Introduction to Survival Analysis using R</em></p></li>
<li><p><a href="https://cran.r-project.org/web/packages/survival/vignettes/survival.pdf">Threneau (2022)</a>. <em>The survival package</em> (vignette)</p></li>
<li><p><a href="https://www.jstor.org/stable/2336057">Therneau et al. (1990)</a>. <em>Martingale based residuals for survival models</em>. Biometrika 77, 147-160. <em>Martingale residuals appear to be the one use case where martingales openly surface in the survival calculations.</em></p></li>
<li><p><a href="https://rss.onlinelibrary.wiley.com/doi/abs/10.2307/2346901">Whitehead (1980)</a>. <em>Fitting Cox’s regression model to survival data using GLIM</em>. Applied Statistics, 29(3):268{275, 1980.</p></li>
<li><p><a href="https://cran.r-project.org/web/packages/survival/vignettes/approximate.pdf">Zhong et al. (2019)</a>. <em>Approximating a Cox Model</em>. This is a <code>survival</code> package vignette.</p></li>
</ol>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/09/06/deep-survival/';</script>
Looking at cash flows
https://rviews.rstudio.com/2022/09/02/looking-at-cash-flows/
Fri, 02 Sep 2022 00:00:00 +0000https://rviews.rstudio.com/2022/09/02/looking-at-cash-flows/
<script src="/2022/09/02/looking-at-cash-flows/index_files/htmlwidgets/htmlwidgets.js"></script>
<script src="/2022/09/02/looking-at-cash-flows/index_files/d3/d3.min.js"></script>
<script src="/2022/09/02/looking-at-cash-flows/index_files/sankey/sankey.js"></script>
<script src="/2022/09/02/looking-at-cash-flows/index_files/sankeyNetwork-binding/sankeyNetwork.js"></script>
<p><em>Dr. Maria Prokofieva is a member of the R / Business working group which is promoting the use of R in accounting, auditing, and actuarial work. She is also a professor at the Victoria University Business School in Australia and works with CPA Australia.</em></p>
<p>Let’s talk about cash flows!</p>
<p>We continue our series of actuarial and accounting posts where we strive to interest the data science community in using their R skills for the actuarial and accounting applications. We also hope to help some actuaries and accountants with their R skills.</p>
<p>Cash flow is a concept that is important to every business and household. It is difficult to over estimate the importance of disclosing and properly communicating the cash flow as an essential of running any enterprise. This is especially true in times of recession when cash flow is the elephant in the room. Nobody really wants to talk about it, but making cash flow analysis easier to understand and interpret would help almost everyone. To get the maximum impact from a cash flow analysis it is not only important to demonstrate that it has been truly and fairly reported (in accounting terminology), but also to help consumers of cash flow reports intuitively grasp the the meaning of what the numbers are showing.</p>
<p>So what is the problem with the way we normally communicate information about cash flow? Well, look at the image below and check your pulse. How excited did you get? Can you make any sense of it at all with just a flash look?</p>
<p><img src="cashflows.png" alt="Cash flow table" height="500" width="600"/></p>
<p>Actually, it’s incredibly insightful if you know what to look for, but for an non-accounting person (with powers to make decisions), it may not be.</p>
<p>Now look at this example<span class="math inline">\(^1\)</span> of a personal cash flow!</p>
<p><img src="https://ppcexpo.com/blog/wp-content/uploads/2022/05/cash-flow-chart-16.jpg" alt="Sankey chart from the ppcexpo.com blog" height="300" width="500"/></p>
<p>These numbers start talking to me in one insightful flow showing in a second where all the money goes! We all know that a picture is worth a thousand words, but if its millions of dollars, it’s truly priceless.</p>
<p>This type of chart is called a <a href="https://www.ifu.com/e-sankey/sankey-diagram/"><strong>sankey</strong></a> chart. Sankey charts are used to show material, energy and cost flows. You can view some awesome visualizations made with the <code>networkD3</code> package <a href="https://r-graph-gallery.com/sankey-diagram.html">here</a>. So, showing cash flow is a perfect example of what they were designed for. It is not all common in the actuarial or accounting worlds, but, honestly, it is not that common to see any visualizations in financial reports, - well, apart from happy customers in annual reports which, as we all know, is a marketing thing.</p>
<p>Let’s take a look at how the flow diagram above might be reproduced in R. There are several ways to do this and several packages (for example: <code>networkD3</code>, and <code>diagrammerR</code>) available to help. We will use a very simple dataset, but it could be easily extended to include additional transactional data: different sources of income, types of income, etc. We could also look at inflows and outflows, classify them into types of business activities and automate this tedious, manual task to present a nice chart to our stakeholders.</p>
<p>But. let’s start with … this simple one! And let’s use the <a href="https://cran.r-project.org/web/packages/networkD3"><code>networkD3</code></a></p>
<pre class="r"><code>tidyverse.quiet = TRUE
networkD3.quiet = TRUE
library(tidyverse)</code></pre>
<pre><code>## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──</code></pre>
<pre><code>## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.7 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1</code></pre>
<pre><code>## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()</code></pre>
<pre class="r"><code>library(networkD3)</code></pre>
<p>Sankey diagrams visualize <strong>flows</strong> as connections from one <strong>node</strong> to another. In our case, the flows are distinct types of cash income that will flow into expenses.</p>
<p>For our example, we will use a simple data set with data that has already been classified into <code>source</code> and <code>target</code>.</p>
<pre class="r"><code>data <- read_csv("cf_up.csv", show_col_types = FALSE)
head(data)</code></pre>
<pre><code>## # A tibble: 6 × 3
## source target value
## <chr> <chr> <dbl>
## 1 Salary Earned Income 494
## 2 Salary Earned Income 677
## 3 Salary Earned Income 758
## 4 Salary Earned Income 933
## 5 Salary Earned Income 649
## 6 Salary Earned Income 825</code></pre>
<p><em>sources</em> are nodes that initiate the flow and <em>targets</em> are the nodes that finish the flow.</p>
<p>In this particular example, the amount of cash receipts have been matched with a particular cash spending type. In real life, you would not expect this data matching to have already been done for you as most likely your cash flow records just show type of cash flow (cash receipt vs. cash payment) and the amount. We will save the data munging required to transform a typical cash flow dataset into something that can be used to build the Sankey diagram for a future post.</p>
<p><code>data</code> is a <em>links</em> dataframe with source, target and value columns. For example, $494 of salary was used to pay tax: salary is the earned income and payment of tax is a deduction. In this case the source is the <em>Salary</em> item, the target is <em>Earned income</em> and the value is 494. <em>Earned income</em>is also a source node that has <em>Income</em> (i.e. a broader category) target. <em>Income</em> is then distributed to expenses, i.e target category <em>Deduction</em> which is the later becomes a source node for <em>Income tax</em> target.</p>
<p>Here are the unique sources in our data:</p>
<pre class="r"><code>unique(data$source)</code></pre>
<pre><code>## [1] "Salary" "Credit Card Reward" "Dividends"
## [4] "Interest" "Earned Income" "Passive Income"
## [7] "Passive income" "Income" "Deduction"
## [10] "Core Expenses" "Financial Independence" "Disposable Income"</code></pre>
<p>And, here are the unique targets.</p>
<pre class="r"><code>unique(data$target)</code></pre>
<pre><code>## [1] "Earned Income" "Passive Income" "Passive income"
## [4] "Income" "Deduction" "Core Expenses"
## [7] "Financial Independence" "Disposable Income" "Income Tax"
## [10] "Social Justice" "Bill Expenses" "Food"
## [13] "Personal Care" "Transportation" "Pension"
## [16] "Investment" "Real Estate" "Emergency Fund"
## [19] "Leisure"</code></pre>
<p>To create a cash flow diagram with the <code>sankeyNetwork()</code> function from the <code>networkD3</code> package we also need an additional data frame, <code>nodes</code> which contains the list of receipts, types of receipts, types of spending and cash payments.</p>
<pre class="r"><code>nodes <- data.frame(
name=c(as.character(data$source),
as.character(data$target)) %>% unique()
)
head(nodes)</code></pre>
<pre><code>## name
## 1 Salary
## 2 Credit Card Reward
## 3 Dividends
## 4 Interest
## 5 Earned Income
## 6 Passive Income</code></pre>
<p>Also, because we cannot use nodes names in the function, we need to replace our connections with id, i.e. <code>IDsource</code> and <code>IDtarget</code></p>
<pre class="r"><code>data$IDsource <- match(data$source, nodes$name)-1
data$IDtarget <- match(data$target, nodes$name)-1</code></pre>
<p>Now, we can draw our cash flow diagram.</p>
<pre class="r"><code>p <- sankeyNetwork(Links = data,
Nodes = nodes,
Source = "IDsource",
Target = "IDtarget",
Value = "value",
NodeID = "name",
units = '$',
sinksRight=TRUE,
# LinkGroup="source"
fontSize = 10,
nodeWidth = 30
)</code></pre>
<pre><code>## Links is a tbl_df. Converting to a plain data frame.</code></pre>
<pre class="r"><code>p</code></pre>
<div id="htmlwidget-1" style="width:672px;height:480px;" class="sankeyNetwork html-widget"></div>
<script type="application/json" data-for="htmlwidget-1">{"x":{"links":{"source":[0,0,0,0,0,0,0,0,1,2,3,4,4,4,4,4,4,4,4,5,6,6,7,7,7,7,7,7,7,7,7,7,7,8,8,9,9,9,9,10,10,10,11,11],"target":[4,4,4,4,4,4,4,4,5,6,6,7,7,7,7,7,7,7,7,7,7,7,8,8,9,9,9,9,10,10,10,11,11,12,13,14,15,16,17,18,19,20,21,22],"value":[494,677,758,933,649,825,536,392,287,262,147,494,677,758,933,649,825,536,392,287,262,147,494,677,758,933,649,825,536,392,287,262,147,494,677,758,933,649,825,536,392,287,262,147]},"nodes":{"name":["Salary","Credit Card Reward","Dividends","Interest","Earned Income","Passive Income","Passive income","Income","Deduction","Core Expenses","Financial Independence","Disposable Income","Income Tax","Social Justice","Bill Expenses","Food","Personal Care","Transportation","Pension","Investment","Real Estate","Emergency Fund","Leisure"],"group":["Salary","Credit Card Reward","Dividends","Interest","Earned Income","Passive Income","Passive income","Income","Deduction","Core Expenses","Financial Independence","Disposable Income","Income Tax","Social Justice","Bill Expenses","Food","Personal Care","Transportation","Pension","Investment","Real Estate","Emergency Fund","Leisure"]},"options":{"NodeID":"name","NodeGroup":"name","LinkGroup":null,"colourScale":"d3.scaleOrdinal(d3.schemeCategory20);","fontSize":10,"fontFamily":null,"nodeWidth":30,"nodePadding":10,"units":"$","margin":{"top":null,"right":null,"bottom":null,"left":null},"iterations":32,"sinksRight":true}},"evals":[],"jsHooks":[]}</script>
<p>There it is! In just a few lines of code you can turn a table that only an expert can read into a visualization that might capture the imagination of someone forced to read a financial document.</p>
<div id="references" class="section level3">
<h3>References</h3>
<ol style="list-style-type: decimal">
<li>PPCexpo. How to Create a Cash Flow Chart? Easy to Follow Steps. Available at <a href="https://ppcexpo.com/blog/cash-flow-chart" class="uri">https://ppcexpo.com/blog/cash-flow-chart</a> , Aug 31, 2022</li>
</ol>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/09/02/looking-at-cash-flows/';</script>
July 2022: "Top 40" New CRAN Packages
https://rviews.rstudio.com/2022/08/29/july-2022-top-40-new-cran-packages/
Mon, 29 Aug 2022 00:00:00 +0000https://rviews.rstudio.com/2022/08/29/july-2022-top-40-new-cran-packages/
<p>Ninety-four new packages stuck to CRAN in July. Here are my “Top 40” selections in thirteen categories: Climate Modeling, Computational Methods, Data, Ecology, Genomics, Machine Learning, Mathematics, Medicine, Networks, Proteomics, Statistics, Utilities, and Visualization.</p>
<h3 id="climate-modeling">Climate Modeling</h3>
<p><a href="https://cran.r-project.org/package=climetrics">climetrics</a> v1.0-5: Provides a framework that facilitates the spatio-temporal analysis of climate dynamics through exploring and measuring different dimensions of climate change in space and time. See the <a href="https://cran.r-project.org/web/packages/climetrics/vignettes/climetrics.pdf">vignette</a>.</p>
<p><img src="climetrics.png" height = "500" width="500" alt="Plot of changes in climate extremes over portion of Europe"></p>
<p><a href="https://cran.r-project.org/package=HurreconR">HurreconR</a> v1.0: Implements the HURRECON model which estimates wind speed, wind direction, enhanced Fujita scale wind damage, and duration of EF0 to EF5 winds as a function of hurricane location and maximum sustained wind speed. See <a href="https://esajournals.onlinelibrary.wiley.com/doi/abs/10.1890/0012-9615%282001%29071%5B0027%3ALARIOH%5D2.0.CO%3B2">Boose et al. (2001)</a> and <a href="https://esajournals.onlinelibrary.wiley.com/doi/abs/10.1890/02-4057">Boose et al. (2004)</a> for background, and the <a href="https://cran.r-project.org/web/packages/HurreconR/vignettes/overview.html">vignette</a> for an overview.</p>
<p><a href="https://cran.r-project.org/package=TrenchR">TrenchR</a> v0.1.0: Provides tools for translating environmental change into organism response. The biophysical modeling tools include both general models for heat flows and specific models to predict body temperatures for a variety of ectothermic taxa. See <a href="https://link.springer.com/book/10.1007/978-1-4612-6024-0">Gates (1980)</a> for background. There are vignettes on <a href="https://cran.r-project.org/web/packages/TrenchR/vignettes/AllometryAndConversionsTutorial.html">Allometries and conversions</a>, <a href="https://cran.r-project.org/web/packages/TrenchR/vignettes/MicroclimateTutorial.html">Estimating microclimates</a>, and <a href="https://cran.r-project.org/web/packages/TrenchR/vignettes/TeTutorial.html">Estimating body temperatures</a>.</p>
<p><img src="TrenchR.png" height = "400" width="600" alt="Plot of azimuth angle variation over the year"></p>
<h3 id="computational-methods">Computational Methods</h3>
<p><a href="https://cran.r-project.org/package=elastes">elastes</a> v0.1.6: Provides functions to compute functional elastic shape means over sets of open planar curves using a novel approach where planar curves are treated as complex functions. Also, a full Procrustes mean is estimated from the corresponding smoothed Hermitian covariance surface. See <a href="https://onlinelibrary.wiley.com/doi/10.1111/biom.13706">Steyer et al. (2022)</a> and <a href="https://arxiv.org/abs/2203.10522">Stöcker et. al. (2022)</a> for background and the <a href="https://cran.r-project.org/web/packages/elastes/vignettes/elastes.html">vignette</a> for examples.</p>
<p><img src="elastes.png" height = "400" width="400" alt="Plot of smooth polynomial mean"></p>
<p><a href="https://cran.r-project.org/package=ino">ino</a> v0.1.0: Provides a comprehensive toolbox for comparing different initialization strategies when performing numerical optimization. There is an <a href="https://cran.r-project.org/web/packages/ino/vignettes/introduction.html">Introduction</a> and a <a href="https://cran.r-project.org/web/packages/ino/vignettes/example_hmm.html">vignette</a> with an HMM example.</p>
<h3 id="data">Data</h3>
<p><a href="https://cran.r-project.org/package=giedata">giedata</a> v0.1.0: Provides functions to access the API for <a href="https://agsi.gie.eu/">GIE</a>, Europe’s Gas Infrastructure database. See <a href="https://cran.r-project.org/web/packages/giedata/readme/README.html">README</a> to get started.</p>
<h3 id="ecology">Ecology</h3>
<p><a href="https://cran.r-project.org/package=rgrass">rgrass</a> v0.3-3: Implements a new interface to the <a href="https://grass.osgeo.org/">GRASS</a> geographical information system that supports both starting R from within the GRASS environment, or running a free-standing R session in a temporary GRASS location. There is an <a href="https://cran.r-project.org/web/packages/rgrass/vignettes/use.html">Introduction</a> and a <a href="https://cran.r-project.org/web/packages/rgrass/vignettes/coerce.html">vignette</a> on object formats.</p>
<p><a href="https://cran.r-project.org/package=riverconn">riverconn</a> v0.3.22: Provides functions to calculate indices for river network connectivity. See <a href="https://iopscience.iop.org/article/10.1088/1748-9326/abcb37">Jumani et al. (2021)</a> for a review of the incdices and <a href="https://www.sciencedirect.com/science/article/pii/S1364815222001748?via%3Dihub">Baldan et al. (2022)</a> for a list of package capabilities and architecture. Have a look at the <a href="https://cran.r-project.org/web/packages/riverconn/vignettes/Tutorial.html">vignette</a> for examples.</p>
<p><img src="riverconn.png" height = "400" width="300" alt="Plots of river connectivity graphs"></p>
<h3 id="genomics">Genomics</h3>
<p><a href="https://cran.r-project.org/package=dcifer">dcifer</a> v1.1.1: Implements Dcifer (Distance for complex infections: fast estimation of relatedness), an identity by descent based method to calculate genetic relatedness between polyclonal infections from biallelic and multiallelic data. See <a href="https://cran.r-project.org/web/packages/dcifer/vignettes/vignetteDcifer.pdf">Gerlovina et al. (2022)</a> for the details, and the <a href="https://cran.r-project.org/web/packages/dcifer/vignettes/vignetteDcifer.pdf">vignette</a> for an example.</p>
<p><img src="dcifer.png" height = "400" width="400" alt="Plot of pairwise relatedness for infection strains. Points representing significantly related strains are outlined"></p>
<p><a href="https://cran.r-project.org/package=qPCRtools">qPCRtools</a> v0.1.1: Provides methods to calculate the amplification efficiency of genes, a crucial step in the qPCR process. See the <a href="https://cran.r-project.org/web/packages/qPCRtools/vignettes/qPCRtools.html">vignette</a>.</p>
<p><img src="qPCRtools.png" height = "400" width="400" alt="Box plots for relative gene expression distributions"></p>
<p><a href="https://cran.r-project.org/package=scAnnotate">scAnnotate</a> v0.0.4: Implements a data-driven cell type annotation tool for single-cell RNA sequencing data. See <a href="https://www.biorxiv.org/content/10.1101/2022.02.19.481159v2">Ji et al. (2022)</a> for details and the <a href="https://cran.r-project.org/web/packages/scAnnotate/vignettes/Introduction.html">vignette</a> for an introduction.</p>
<h3 id="machine-learning">Machine Learning</h3>
<p><a href="https://cran.r-project.org/package=cito">cito</a> v1.0.0: Provides functions for building and training custom neural networks using <code>torch</code>. See the <a href="https://cran.r-project.org/web/packages/cito/vignettes/Introduction_to_cito.html">vignette</a>.</p>
<p><img src="cito.png" height = "400" width="400" alt="Structure plot of a generated neural network"></p>
<p><a href="https://cran.r-project.org/package=etree">etree</a> v0.1.0: Provides functions to implement <em>Energy Trees</em>, statistical models that perform classification and regression with structured and mixed-type data. See <a href="https://arxiv.org/abs/2207.04430">Giubilei et al. (2022)</a> for a description of Energy Trees and the vignettes <a href="https://cran.r-project.org/web/packages/etree/vignettes/etree-vignette-eforest.html">eforest</a> and <a href="https://cran.r-project.org/web/packages/etree/vignettes/etree-vignette.html">etree</a> for examples.</p>
<p><img src="etree.png" height = "500" width="500" alt="Plot of an Energy Tree"></p>
<p><a href="https://cran.r-project.org/package=LDABiplots">LDABiplots</a> v0.1.2: Provides tools to extract, explore, analyze, and visualize news published on the web by digital newspapers using Latent Dirichlet and machine learning algorithms. See <a href="https://jmlr.org/papers/volume3/blei03a/blei03a.pdf">Ble et al. (2003)</a> and <a href="https://academic.oup.com/biomet/article-abstract/58/3/453/233361?redirectedFrom=fulltext&login=false">Gabriel (1971)</a> for background. There are <a href="https://cran.r-project.org/web/packages/LDABiplots/vignettes/Tutorial_LDABiplots_English.html">English</a> and <a href="https://cran.r-project.org/web/packages/LDABiplots/vignettes/Tutorial_LDABiplots_Spanish.html">Spanish</a> versions of the vignette.</p>
<p><a href="https://cran.r-project.org/package=mildsvm">mildsvm</a> v0.4.0: Implements a support vector machine classifier for weakly supervised, multiple instance data. See <a href="https://arxiv.org/abs/2206.14704">Kent and Yu (2022)</a> and <a href="https://proceedings.neurips.cc/paper/2012/file/9bf31c7ff062936a96d3c8bd1f8f2ff3-Paper.pdf">Muandet et al. (2012)</a> for the theory and <a href="https://cran.r-project.org/web/packages/mildsvm/readme/README.html">README</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=nestedcv">nestedcv</a> v0.2.3: Provides functions to perform nested cross-validation as described in <a href="https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1977.tb01603.x">Stone (1977)</a> for lasso and elastic-net regularized linear models for <code>glmnet</code>. See the <a href="https://cran.r-project.org/web/packages/nestedcv/vignettes/nestedcv.html">vignette</a>.</p>
<p><img src="nestedcv.svg" height = "400" width="400" alt="Block diagram for nested cross validation"></p>
<h3 id="mathematics">Mathematics</h3>
<p><a href="https://cran.r-project.org/package=delaunay">delaunay</a> v1.1.0: Provides functions to construct and visualize 2D and 3D <a href="https://en.wikipedia.org/wiki/Delaunay_triangulation">Delaunay triangulations</a>. See <a href="https://cran.r-project.org/web/packages/delaunay/readme/README.html">README</a> for some visual examples.</p>
<p><img src="delaunay.png" height = "350" width="350" alt="3D Delaunay triangulation"></p>
<h3 id="medicine">Medicine</h3>
<p><a href="https://cran.r-project.org/package=activAnalyzer">activeAnalyzer</a> v1.0.4: Provides a tool to analyse <a href="https://www.sciencedirect.com/topics/medicine-and-dentistry/actigraphy">Actigraphy</a> accelerometer data using PROactive Physical Activity in COPD (chronic obstructive pulmonary disease) instruments. See the <a href="https://cran.r-project.org/web/packages/activAnalyzer/vignettes/activAnalyzer.html">vignette</a> for examples.</p>
<p><img src="activeAnalyzer.png" height = "350" width="350" alt="Plots of actigraphydata"></p>
<p><a href="https://cran.r-project.org/package=pedbp">pedbp</a> v1.0.0: Provides data and utilities for estimating pediatric blood pressure percentiles by sex, age, and height. See <a href="https://publications.aap.org/pediatrics/article-abstract/128/Supplement_5/S213/31442/Expert-Panel-on-Integrated-Guidelines-for?redirectedFrom=fulltext">Lo et al. (2013)</a> and <a href="https://publications.aap.org/hospitalpediatrics/article-abstract/12/6/590/188139/Machine-Learning-Approach-to-Predicting-Absence-of?redirectedFrom=fulltext">Martin et al. (2022)</a> for background, and the <a href="https://publications.aap.org/hospitalpediatrics/article-abstract/12/6/590/188139/Machine-Learning-Approach-to-Predicting-Absence-of?redirectedFrom=fulltext">vignette</a> for an overview.</p>
<p><img src="pedbp.png" height = "400" width="400" alt="Plot showing median blood pressure by age for different heights based on percentiles for age"></p>
<p><a href="https://cran.r-project.org/package=tipmap">tipmap</a> v 0.1.7: Implements tipping point analysis for clinical trials using Bayesian dynamic borrowing via robust meta-analytic predictive priors as described in <a href="https://onlinelibrary.wiley.com/doi/10.1002/pst.2093">Best et al. (2021)</a>.</p>
<h3 id="networks">Networks</h3>
<p><a href="https://cran.r-project.org/package=ergm.multi">ergm.multi</a> v0.1.0: Provides a set of extensions for the <code>ergm</code> package to fit multilayer, multiplex, and multirelational networks as well as samples of multiple networks. See <a href="https://link.springer.com/article/10.1007/s11336-020-09720-7">Krivitsky et al. (2020)</a> and <a href="https://arxiv.org/abs/2202.03685">Krivitsky et, al. (2022)</a> for the details and the <a href="https://cran.r-project.org/web/packages/ergm.multi/vignettes/Goeyvaerts_reproduction.html">vignette</a> for an extended example.</p>
<p><img src="ergm.png" height = "400" width="500" alt="Pearson residuals vs. fitted values"></p>
<p><a href="https://cran.r-project.org/package=Families">Families</a> v1.0.1: Provides tools to study kinship networks, grand parenthood, and double burden (presence of children and oldest old parents) in virtual population produced by <a href="https://cran.r-project.org/package=VirtualPop"><code>VirtualPop</code></a>. See the <a href="https://cran.r-project.org/web/packages/Families/vignettes/Families_Virtual.html">vignette</a> for examples.</p>
<p><img src="Families.png" height = "500" width="600" alt="Distribution of age of child with reference to distributions of events in mothers life"></p>
<h3 id="proteomics">Proteomics</h3>
<p><a href="https://cran.r-project.org/package=promor">promor</a> v0.1.0: Implements a comprehensive set of tools for label-free proteomics data analysis and machine learning modeling including differential expression analysis, predictive modeling and performance assessment. Data from <a href="https://www.maxquant.org/">MaxQuant</a> may be used. See the <a href="https://cran.r-project.org/web/packages/promor/vignettes/intro_to_promor.html">vignette</a> for an introduction.</p>
<p><img src="promor.png" height = "400" width="600" alt="Block diagram of promor workflow"></p>
<h3 id="statistics">Statistics</h3>
<p><a href="https://cran.r-project.org/package=GPCERF">GPCERF</a> v0.1.0: Provides a non-parametric Bayesian framework based on Gaussian process priors for estimating causal effects of a continuous exposure and detecting change points in the causal exposure response curves using observational data. See <a href="https://arxiv.org/abs/2105.03454">Ren et al. (2021)</a>. Have a look at the <a href="https://cran.r-project.org/web/packages/GPCERF/vignettes/GPCERF.html">Introduction</a> and the vignettes <a href="https://cran.r-project.org/web/packages/GPCERF/vignettes/Full-Gaussian-Processes.html">Full Gaussian Process</a> and <a href="https://cran.r-project.org/web/packages/GPCERF/vignettes/Nearest-neighbor-Gaussian-Processes.html">Nearest-neighbor Gaussian Process</a>.</p>
<p><img src="GPCERF.png" height = "350" width="350" alt="Plots of CERF vs. Exposure level"></p>
<p><a href="https://cran.r-project.org/package=lnmCluster">lnmCluster</a> v0.3.1: Extends the logistic normal multinomial (LNM) clustering model proposed by <a href="https://arxiv.org/abs/2011.06682">Fang and Subedi (2020)</a> to provide LNM clustering for compositional data. Details of model assumptions and interpretation can be found in the papers <a href="https://arxiv.org/abs/2101.01871">Tu & Subedi (2021)</a> and <a href="https://onlinelibrary.wiley.com/doi/10.1002/sam.11555">Tu & Subedi (2022)</a>. See the <a href="https://cran.r-project.org/web/packages/lnmCluster/vignettes/lnm-bicluster.html">vignette</a> for an example.</p>
<p><a href="https://cran.r-project.org/package=tlars">tlars</a> v0.0.1: Provides functions to compute the solution path of the Terminating-LARS (T-LARS) algorithm. See <a href="https://arxiv.org/abs/2110.06048">Machkour et al. 2022</a>, <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-32/issue-2/Least-angle-regression/10.1214/009053604000000067.full">Efron et al. (2004)</a> and <a href="https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1996.tb02080.x">Tibshirani (1996)</a> for the theory, and the <a href="https://cran.r-project.org/web/packages/tlars/vignettes/tlars_variable_selection.html">vignette</a> for examples.</p>
<h3 id="utilities">Utilities</h3>
<p><a href="https://cran.r-project.org/package=codebookr">codebookr</a> v0.1.5: Provides functions to create code books (i.e. data dictionaries) directly from a data frame. See <a href="https://cran.r-project.org/web/packages/codebookr/readme/README.html">README</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=datadictionary">datadictionary</a> v0.1.0: Provides tools to creates a data dictionary from any dataset in an R environment. It includes functions to add variable labels and write to Excel.</p>
<p><a href="https://cran.r-project.org/package=dtrackr">dtrackr</a> v0.2.4: Provides tools to track and document <code>dplyr</code> data pipelines. As you filter, mutate, and join your way through a data set, functions seamlessly track data flow and generate publication ready documentation of the data pipeline. See the vignettes <a href="https://cran.r-project.org/web/packages/dtrackr/vignettes/consort-example.html">Consort statment example</a>, <a href="https://cran.r-project.org/web/packages/dtrackr/vignettes/dtrackr-options.html">Configuration example</a>, <a href="https://cran.r-project.org/web/packages/dtrackr/vignettes/dtrackr.html">Basic Operation</a>, and <a href="https://cran.r-project.org/web/packages/dtrackr/vignettes/joining-pipelines.html">Joining data pipelines</a>.</p>
<p><img src="dtrackr.svg" height = "500" width="600" alt="Flowchart of a pipeline"></p>
<p><a href="https://cran.r-project.org/package=howler">howler</a> v0.2.0: Enables audio interactivity within <code>shiny</code> applications using <code>howler.js</code>. See the <a href="https://cran.r-project.org/web/packages/howler/vignettes/howler.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=ixplorer">ixplorer</a> v0.2.2: Provides tools to create and view tickets in <a href="https://gitea.io/en-us/">gitea</a>, a self-hosted <code>git</code> service, using an RStudio addin. It includes helper functions to publish documentation and use <code>git</code>. There are several vignettes including <a href="https://cran.r-project.org/web/packages/ixplorer/vignettes/ixplorer_basics.html">ixplorer basics</a> and <a href="https://cran.r-project.org/web/packages/ixplorer/vignettes/credentials.html">Credential management</a>.</p>
<p><a href="https://cran.r-project.org/package=nextGenShinyApps">nextGenShinyApps</a> v1.5: Provides responsive tools for designing and developing <code>Shiny</code> dashboards and applications. The scripts and style sheets are based on <a href="https://jquery.com/"><code>jQuery</code></a> and <a href="https://getbootstrap.com/"><code>Bootstrap</code></a>. See the <a href="https://cran.r-project.org/web/packages/nextGenShinyApps/vignettes/introduction_to_nextgenshinyapps.html">vignette</a> for examples.</p>
<p><img src="nextGen.png" height = "500" width="600" alt="Example of a shiny app page"></p>
<p><a href="https://cran.r-project.org/package=nplyr">nplyr</a> v0.1.0: Provides functions for manipulating nested data frames in a list-column using <code>dplyr</code> without first having to <code>unnest()</code>them. See the <a href="https://cran.r-project.org/web/packages/nplyr/vignettes/Use-case-for-nplyr.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=renderthis">renderthis</a> v0.1.0: Provides tools to render slides to different formats, including <code>html</code>, <code>pdf</code>, <code>png</code>, <code>gif</code>, <code>pptx</code>, and <code>mp4</code>, as well as tool to make a <code>png</code> file of the first slide of a presentation that is re-sized for sharing on social media. There is an <a href="https://cran.r-project.org/web/packages/renderthis/vignettes/renderthis.html">Overview</a> and a <a href="https://cran.r-project.org/web/packages/renderthis/vignettes/renderthis-setup.html">vignette</a> on basic usage.</p>
<p><a href="https://cran.r-project.org/package=video">video</a> video: 0.1.0: Enables video interactivity within <code>shiny</code> applications using <code>video.js</code>. See the <a href="https://cran.r-project.org/web/packages/video/vignettes/video.html">vignette</a>.</p>
<h3 id="visualization">Visualization</h3>
<p><a href="https://cran.r-project.org/package=ensModelVis">ensModelVis</a> v0.1.0: Provides a function to display model fits for multiple models and their ensembles. There are vignettes for <a href="https://cran.r-project.org/web/packages/ensModelVis/vignettes/ClassificationEg.html">Classification</a> and <a href="https://cran.r-project.org/web/packages/ensModelVis/vignettes/RegressionEg.html">Regression</a>.</p>
<p><img src="ensModelVis.png" height = "500" width="500" alt="Plot of prediction accuracy for an ensemble"></p>
<p><a href="https://cran.r-project.org/package=ggpackets">ggpackets</a> v0.2.0: Provides tools to create groups of <code>ggplot2</code> layers that can be easily migrated from one plot to another, reducing redundant code and improving the ability to format many plots that draw from the same source. See the <a href="https://cran.r-project.org/web/packages/ggpackets/vignettes/ggpackets.html">Getting Started Guide</a> and the vignettes <a href="https://cran.r-project.org/web/packages/ggpackets/vignettes/composing-functions.html">Composing Templates & Functions</a> and <a href="https://cran.r-project.org/web/packages/ggpackets/vignettes/miscellaneous-examples.html">Misc Examples</a>.</p>
<p><img src="ggpackets.png" height = "400" width="400" alt="Plot of growth vs. age for multiple seeds built from template"></p>
<p><a href="https://cran.r-project.org/package=ggseqplot">ggseqplot</a> v0.7.2: Provides wrappers to render <code>TraMinR</code> sequence plots in <code>ggplot2</code>. See the <a href="https://cran.r-project.org/web/packages/ggseqplot/vignettes/ggseqplot.html">vignette</a>.</p>
<p><img src="ggseqplot.png" height = "400" width="600" alt="Plot of Months vs. Sequences"></p>
<p><a href="https://cran.r-project.org/package=RcppColors">RcppColors</a> v0.1.1: Provides <code>C++</code> header files to deal with color conversion from color spaces to hexadecimal with <code>Rcpp</code>, and exports some color mapping functions to R. Look <a href="https://github.com/stla/RcppColorshttps://github.com/stla/RcppColors">here</a> for examples.</p>
<p><img src="RcppColors.gif" height = "400" width="400" alt="Multicolored rotating sphere"></p>
<p><a href="https://cran.r-project.org/package=xadmix">xadmix</a> 1.0.0: Provides functions that provide a quick way of subsetting genomic admixture data and generating customizable stacked barplots. See the <a href="https://cran.r-project.org/web/packages/xadmix/vignettes/xadmix-manual.html">vignette</a>.</p>
<p><img src="xadmix.png" height = "400" width="600" alt="Admixture barplots for individuals from various countries"></p>
<script>window.location.href='https://rviews.rstudio.com/2022/08/29/july-2022-top-40-new-cran-packages/';</script>
June 2022: "Top 40" New CRAN Packages
https://rviews.rstudio.com/2022/07/29/june-2022-top-40-new-cran-packages/
Fri, 29 Jul 2022 00:00:00 +0000https://rviews.rstudio.com/2022/07/29/june-2022-top-40-new-cran-packages/
<p>One hundred eighty-nine new packages made it to CRAN in June. Here are my “Top 40” selections in eleven categories: Computational Methods, Data, Ecology, Genomics, Machine Learning, Mathematics, Medicine, Statistics, Time Series, Utilities, and Visualizations.</p>
<h3 id="computational-methods">Computational Methods</h3>
<p><a href="https://cran.r-project.org/package=itp">itp</a> v1.2.0: Implements the interpolate, truncate, project root-finding algorithm developed by <a href="https://dl.acm.org/doi/10.1145/3423597">Oliveira & Takahashi (2021)</a>. The <a href="https://cran.r-project.org/web/packages/itp/vignettes/itp-vignette.html">vignette</a> provides an overview.</p>
<p><a href="https://cran.r-project.org/package=QR">QR</a> v0..1.3: Provides a function to perform QR factorization without pivoting to a real or complex matrix. It is based on <a href="https://netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html">LAPACK</a>. See the <a href="https://cran.r-project.org/web/packages/QR/vignettes/QR.html">vignette</a>.</p>
<p><a href="https://cran.r-project.org/package=qsplines">qsplines</a> v1.0.0: Provides functions to create quaterion splines. See <a href="https://dl.acm.org/doi/10.1145/54852.378511">Barry & Goldman (1988)</a> and <a href="https://dl.acm.org/doi/10.1145/964965.808575">Kochanek & Bartels (1984)</a> for the details and look <a href="https://github.com/stla/qsplines">here</a> for an example.</p>
<p><img src="qsplines.gif" height = "400" width="400" alt="Plot of Kochanek-Bertels spline illustrating varying continuity"></p>
<p><a href="https://CRAN.R-project.org/package=VMDecomp">VMDecomp</a> v1.0.1: Implements the <a href="https://www.mathworks.com/help/wavelet/ref/vmd.html">variational mode decomposition</a> and two-dimensional variational mode decomposition algorithm. See <a href="https://ieeexplore.ieee.org/document/6655981">Dragomiretskiy & Zosso (2014)</a> for background and the <a href="https://cran.r-project.org/web/packages/VMDecomp/vignettes/variatonal_mode_decomposition.html">vignette</a> for examples.</p>
<p><img src="VMDecomp.jpeg" height = "300" width="500" alt="Plot of original and processed ECG signal"></p>
<h3 id="data">Data</h3>
<p><a href="https://cran.r-project.org/package=cmhc">cmch</a> v0.2.0: Implements a wrapper around the <a href="https://www.cmhc-schl.gc.ca/">Canadian Mortgage and Housing Corporation</a> web interface and enables programmatic and reproducible access to a wide variety of housing data. See the <a href="https://cran.r-project.org/web/packages/cmhc/vignettes/basic_usage.html">vignette</a> for examples.</p>
<p><img src="cmch.png" height = "350" width="350" alt="Plot of city of Vancouver housing faceted by type of dwelling"></p>
<p><a href="https://cran.r-project.org/package=EDIutils">EDIutils</a> v1.0.1: Implements a client for the <a href="https://portal.edirepository.org/nis/home.jsp">Environmental Data Initiative</a> repository REST API and provides access to ecological data and metadata. There are five short vignettes: <a href="https://cran.r-project.org/web/packages/EDIutils/vignettes/evaluate_and_upload.html">Evaluate & upload</a>, <a href="https://cran.r-project.org/web/packages/EDIutils/vignettes/retrieve_citations.html">Citation Metrics</a>, <a href="https://cran.r-project.org/web/packages/EDIutils/vignettes/retrieve_downloads.html">Download Metrics</a>, <a href="https://cran.r-project.org/web/packages/EDIutils/vignettes/search_and_access.html">Search andaccess</a>, and <a href="https://cran.r-project.org/web/packages/EDIutils/vignettes/tests_requiring_authentication.html">Tests</a>.</p>
<p><a href="https://cran.r-project.org/package=globaltrends">globaltrends</a> v0.0.12: Provides functions to access global search volumes from the <a href="https://trends.google.com/trends/?geo=US">Google Trends</a> portal. This <a href="https://www.ssrn.com/abstract=3969013">working paper</a> outlines the package’s methodological foundations and potential applications. See the <a href="https://cran.r-project.org/web/packages/globaltrends/vignettes/globaltrends.html">vignette</a> to get started.</p>
<p><img src="globaltrends.png" height = "350" width="500" alt="Plot of internationalization trends for Facebook"></p>
<p><a href="https://cran.r-project.org/package=kaigiroku">kaigiroku</a> v0.5: Allows users to search and download data from the <a href="https://kokkai.ndl.go.jp/api.html">API for Japanese Diet</a> proceedings. Look <a href="https://github.com/amatsuo/kaigiroku">here</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=NasdaqDataLink">NasdaqDataLink</a> v1.0.0: Provides functions to interact directly with the <a href="https://docs.data.nasdaq.com/">Nasdaq Data Link API</a> and obtain data in a number of formats. Look <a href="https://data.nasdaq.com/tools/r">here</a> for API documentation and <a href="https://github.com/nasdaq/data-link-r">here</a> for package information.</p>
<p><a href="https://cran.r-project.org/package=stortingscrape">stortingscrape</a> v0.1.1: Provides functions for retrieving data from the Norwegian Parliament, through the <a href="https://data.stortinget.no/">Norwegian Parliament API</a>. See the <a href="https://cran.r-project.org/web/packages/stortingscrape/vignettes/stortingscrape.html">vingette</a> for an introduction.</p>
<h3 id="ecology">Ecology</h3>
<p><a href="https://cran.r-project.org/package=PointedSDMs">PointedSDMs</a> v1.0.6: Provides tools to build integrated species distribution models and includes tools to run spatial cross-validation and plotting. See <a href="https://www.cell.com/trends/ecology-evolution/fulltext/S0169-5347(19)30255-1?_returnURL=https%3A%2F%2Flinkinghub.elsevier.com%2Fretrieve%2Fpii%2FS0169534719302551%3Fshowall%3Dtrue">Issac et al. (2020)</a> for and introduction to the methods. There is a <a href="https://cran.r-project.org/web/packages/PointedSDMs/vignettes/Setophaga.html">Setophaga Example</a> and an example for the <a href="https://cran.r-project.org/web/packages/PointedSDMs/vignettes/Solitary_tinamou.html">Solitary Tinamou</a>.</p>
<p><a href="https://cran.r-project.org/package=restoptr">restoptr</a> v1.0.1: Implements a flexible framework for ecological restoration planning that aims to identify priority areas for restoration efforts using optimization algorithms described in <a href="https://besjournals.onlinelibrary.wiley.com/doi/10.1111/1365-2664.13803">Justeau-Allaire et al. 2021</a>. See the <a href="https://cran.r-project.org/web/packages/restoptr/vignettes/restoptr.html">vignette</a> to get started.</p>
<h3 id="genomics">Genomics</h3>
<p><a href="https://cran.r-project.org/package=scapGNN">scapGNN</a> v0.1.1: Implements a single cell active pathway analysis tool based on the graph neural network algorithm described in <a href="https://ieeexplore.ieee.org/document/4700287">Scarselli et al. (2009)</a> and <a href="https://arxiv.org/abs/1609.02907v4">Kipf & Welling (2017)</a>. This may be used to construct a gene-cell association network, infer pathway activity scores from different single cell modalities data and more. See the <a href="https://cran.r-project.org/web/packages/scapGNN/vignettes/vignette.html">vignette</a> for an overview and examples.</p>
<p><img src="scapGNN.png" height = "600" width="400" alt="A schematic overview of the scapGNN framework"></p>
<p><a href="https://cran.r-project.org/package=SRTsim">SRTsim</a> v0.99.2: Implements an independent, reproducible, and flexible <a href="https://www.nature.com/articles/s41592-020-01033-y">Spatially Resolved Transcriptomics</a> simulation framework that can be used to facilitate the development analytical methods and for a wide variety of SRT-specific analyses. See the <a href="https://cran.r-project.org/web/packages/SRTsim/vignettes/SRTsim.html">vignette</a>.</p>
<p><img src="SRTsim.png" height = "600" width="400" alt="Multiple plots of gene expression patterns"></p>
<p><a href="https://cran.r-project.org/package=xQTLbiolinks">xQTLbiolinks</a> v1.1.1: Implements tools to query, download, and visualize of molecular quantitative trait locus and gene expression data from public resources through the <a href="https://gtexportal.org/home/api-docs/index.html">GTEx API</a>. There is a <a href="https://cran.r-project.org/web/packages/xQTLbiolinks/vignettes/Quick_start.html">Quick Start Guide</a> and vignettes on <a href="https://cran.r-project.org/web/packages/xQTLbiolinks/vignettes/Colocalization_analysis_with_xQTLbiolinks.html">Colocalization</a>, <a href="https://cran.r-project.org/web/packages/xQTLbiolinks/vignettes/eQTL_Specificity.html">Specivicity</a>, and <a href="https://cran.r-project.org/web/packages/xQTLbiolinks/vignettes/visualization.html">Visualization</a>.</p>
<h3 id="machine-learning">Machine Learning</h3>
<p><a href="https://cran.r-project.org/package=agua">agua</a> v0.0.1: Enables users to specify <code>h2o</code> as an engine for several <code>tidymodels</code> modeling methods. See <a href="https://cran.r-project.org/web/packages/agua/readme/README.html">README</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=MagmaClustR">MagmaClustR</a> V1.0.0: Implements two main algorithms, called Magma (<a href="https://link.springer.com/article/10.1007/s10994-022-06172-1">Leroy et al. (2022)</a> and MagmaClust (<a href="https://arxiv.org/abs/2011.07866">Leroy et al. (2020)</a>), using a multi-task Gaussian processes (GP) model to perform predictions for supervised learning problems. See <a href="https://cran.r-project.org/web/packages/MagmaClustR/readme/README.html">README</a> for examples.</p>
<p><img src="Magma.gif" height = "400" width="600" alt=" Scatter plot with evolving predictor. "></p>
<p><a href="https://cran.r-project.org/package=openai">openai</a> v0.1.0: Provides a wrapper for <a href="https://beta.openai.com/docs/introduction">OpenAI API endpoints</a> including engines, completions, edits, files, fine-tunes, embeddings and legacy searches, classifications, and answers endpoints. See <a href="https://cran.r-project.org/web/packages/openai/readme/README.html">README</a> to get started.</p>
<p><a href="https://cran.r-project.org/package=sketching">sketching</a> v0.1.0: Provides functions to construct sketches of data via random subspace embeddings. See <a href="https://arxiv.org/abs/2007.07781">Lee & Ng (2022)</a> for the theory and the <a href="https://cran.r-project.org/web/packages/sketching/vignettes/sketching_vignette.html">vignette</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=webmorphR">webmorphR</a> v0..1.1: Provides functions to create reproducible image stimuli, specialised for face images with <a href="https://users.aber.ac.uk/bpt/jpsychomorph/">psychomorph</a> or <a href="https://webmorph.org/">webmorph</a> templates. See <a href="https://cran.r-project.org/web/packages/webmorphR/readme/README.html">README</a> to get started.</p>
<p><img src="webmorphR.jpeg" height = "400" width="600" alt="Image of face with template."></p>
<h3 id="mathematics">Mathematics</h3>
<p><a href="https://cran.r-project.org/package=GeneralizedWendland">GeneralizedWendland</a> v0.5-2: Implements the fully parameterized generalized Wendland covariance function for use in Gaussian process models, as well as multiple methods for approximating it via covariance interpolation. The available methods are linear interpolation, polynomial interpolation, and cubic spline interpolation. See <a href="https://arxiv.org/abs/2008.02904">Bevilacqua et al. (2022)</a> and the <a href="https://cran.r-project.org/web/packages/GeneralizedWendland/vignettes/GeneralizedWendland.pdf">vignette</a> for examples.</p>
<p><img src="GW.png" height = "500" width="500" alt="Absolute error of interpolated Wendland correlation function relative to exact method"></p>
<p><a href="https://cran.r-project.org/package=jacobi">jacobi</a> v2.0.0: Evaluates Jacobi theta functions and related functions including the Weierstrass elliptic function, the Weierstrass sigma function, the Weierstrass zeta function, the Klein j-function, the Dedekind eta function, the lambda modular function, Jacobi elliptic functions, Neville theta functions, and the Eisenstein series for real and complex variables. Look <a href="https://github.com/stla/jacobi">here</a> for some images.</p>
<p><img src="jacobi.gif" height = "400" width="400" alt="Animated Costa surface"></p>
<h3 id="medicine">Medicine</h3>
<p><a href="https://cran.r-project.org/package=clinicalsignificance">clinicalsignificance</a> v1.0.0: Implements the clinical significance algorithm proposed by <a href="https://www.sciencedirect.com/science/article/abs/pii/S0005789484800027?via%3Dihub">Jacobson et al. (1984)</a> to determine if an intervention has a meaningful practical effect. There is a <a href="https://cran.r-project.org/web/packages/clinicalsignificance/vignettes/clinicalsignificance.html">Getting Started Guide</a> and vignettes on <a href="https://cran.r-project.org/web/packages/clinicalsignificance/vignettes/clinical-significance-cutoffs.html">Cutoffs</a> and <a href="https://cran.r-project.org/web/packages/clinicalsignificance/vignettes/clinical-significance-plot.html">Plots</a>.</p>
<p><img src="cs.png" height = "400" width="600" alt="Scatter plot for interpreting clinical significance when lower score corresponds to beneficial outcome."></p>
<p><a href="https://cran.r-project.org/package=PlatformDesign">PlatformDesign</a> v1.0.1: Provides functions to calculate design parameters for an optimal two-period, multi-arm platform design allowing pre-planned deferred arms to be added during the trial. See <a href="https://www.tandfonline.com/doi/abs/10.1080/01621459.1955.10501294">Dunnett (1955)</a> for background and the <a href="https://cran.r-project.org/web/packages/PlatformDesign/vignettes/PlatformDesign.html">vignette</a> for some theory and examples.</p>
<p><img src="PD.png" height = "600" width="400" alt="Schema for a two-period 2+2 arm platform trial"></p>
<h3 id="statistics">Statistics</h3>
<p><a href="https://cran.r-project.org/package=bayesassurance">bayesassurance</a> v0.1.0: Provides functions to compute Bayesian assurance under various settings characterized by different assumptions and objectives, including precision-based conditions, credible intervals, and goal functions. See <a href="https://arxiv.org/abs/2112.03509">Pan & Banerjee (2021)</a> for the theory. There are vignettes for using <a href="https://cran.r-project.org/web/packages/bayesassurance/vignettes/Vignette_1.html">closed form solutions</a>, the <a href="https://cran.r-project.org/web/packages/bayesassurance/vignettes/Vignette_2.html">conjugate linear model</a>, and <a href="https://cran.r-project.org/web/packages/bayesassurance/vignettes/Vignette_3.html">precision based conditions</a>.</p>
<p><img src="bayesassurance.png" height = "400" width="600" alt="Power assurance curves for difference in proportions "></p>
<p><a href="https://cran.r-project.org/package=DSSP">DSSP</a> v0.1.1: Provides functions to draw samples from the direct sampling spatial prior model as described in <a href="https://arxiv.org/abs/1906.05575">White, Sun, & Speckman (2019)</a>. See the <a href="https://cran.r-project.org/web/packages/DSSP/vignettes/dssp.html">vignette</a> for examples.</p>
<p><img src="DSSP.png" height = "400" width="600" alt="Plots comparing predicted and true values"></p>
<p><a href="https://cran.r-project.org/package=edibble">edibble</a> v0.1.0: Implements a system to facilitate designing comparative experiments using the grammar of experimental designs. See the <a href="https://emitanaka.org/edibble-book/">edibble-book</a> for documentation.</p>
<p><img src="edibble.png" height = "500" width="100%" alt="Level graph for a split plot design"></p>
<p><a href="https://cran.r-project.org/package=mixgb">mixgb</a> v0.1.0: Implements a method for multiple imputation using <a href="https://xgboost.readthedocs.io/en/stable/">XGBoost</a>, bootstrapping and predictive mean matching as described in <a href="https://arxiv.org/abs/2106.01574">Deng and Lumley (2021)</a>. There is an <a href="https://cran.r-project.org/web/packages/mixgb/vignettes/Using-mixgb.html">Introduction</a> and a vignette on <a href="https://cran.r-project.org/web/packages/mixgb/vignettes/Imputing-newdata.html">Imputing new data with a saved imputer</a>.</p>
<p><a href="https://cran.r-project.org/package=outerbase">outerbase</a> v0.1.0: Implements in new method for high-dimensional regression using outer product models. See <a href="https://www.tandfonline.com/doi/abs/10.1080/01621459.2014.900250">Plumlee (2014)</a> and <a href="https://academic.oup.com/biomet/article-abstract/108/3/749/5923289?redirectedFrom=fulltext&login=false">Plumlee et al. (2021)</a> for background. There is a <a href="https://cran.r-project.org/web/packages/outerbase/vignettes/gettingstarted.html">Getting started guide</a>, a <a href="https://cran.r-project.org/web/packages/outerbase/vignettes/basebasics.html">Base walkthrough</a>, and vignettes on <a href="https://cran.r-project.org/web/packages/outerbase/vignettes/learning.html">Learning from data</a> and <a href="https://cran.r-project.org/web/packages/outerbase/vignettes/speed.html">Speeding up inference</a>.</p>
<p><a href="https://cran.r-project.org/package=PFIM">PFIM</a> v5.0: Provides functions to evaluate or optimize designs for nonlinear mixed effects models using the Fisher Information matrix. See <a href="https://academic.oup.com/biomet/article-abstract/84/2/429/234027?redirectedFrom=fulltext&login=false">Malle & Baccar D (1997)</a> and <a href="https://onlinelibrary.wiley.com/doi/10.1002/sim.2910">Retout et al. (2007)</a> for background and the vignettes <a href="https://cran.r-project.org/web/packages/PFIM/vignettes/Example01.html">Design evaluation and optimixation (01)</a>, <a href="https://cran.r-project.org/web/packages/PFIM/vignettes/Example02.html">Design evaluation and optimixation (02)</a>, and <a href="https://cran.r-project.org/web/packages/PFIM/vignettes/LibraryOfModels.html">Library of models</a> for examples.</p>
<p><a href="https://cran.r-project.org/package=VirtualPop">VirtualPop</a> v1.0.2: Provides functions to generate lifespans and fertility histories in continuous time using individual-level state transition (multi-state) models and data. See the vignettes on <a href="https://cran.r-project.org/web/packages/VirtualPop/vignettes/MultistateLH.html">Simulation of life histories</a>, <a href="https://cran.r-project.org/web/packages/VirtualPop/vignettes/Piecewise_exponential.html">Sampling from waiting time distributions</a>, <a href="https://cran.r-project.org/web/packages/VirtualPop/vignettes/Tutorial.html">Simulation of individual fertility careers</a>, and <a href="https://cran.r-project.org/web/packages/VirtualPop/vignettes/Validation.html">Validation</a>.</p>
<p><img src="VirtualPop.png" height = "300" width="500" alt="Plot of simulated ages at death, US 2019"></p>
<h3 id="time-series">Time Series</h3>
<p><a href="https://cran.r-project.org/package=kssa">kssa</a> v0.0.1: Implements the known sub-sequence algorithm described in <a href="https://www.sciencedirect.com/science/article/pii/S2468550X21001696?via%3Dihub">Benavides et al. (2022)</a>, which helps to automatically identify and validate the best method for missing data imputation in a time series. Look <a href="https://github.com/pipeben/kssa">here</a> for examples.</p>
<p><img src="kssa.png" height = "400" width="600" alt="Box plots comparing multiple methods"></p>
<p><a href="https://cran.r-project.org/package=ts2net">ts2net</a> v0.1.0: Implements methods to transform time series into networks, a technique which may be useful for complex systems modeling, time series data mining, or time series analysis using networks. For an introduction to the topic and descriptions of the methods see <a href="https://www.sciencedirect.com/science/article/pii/S000437020600083X?via%3Dihub">Mitchell (2006)</a>, <a href="https://link.springer.com/book/10.1007/978-3-319-17290-3">Silva & Zhao (2016)</a>, and <a href="https://wires.onlinelibrary.wiley.com/doi/10.1002/widm.1404">Silva et al. (2021)</a>. See <a href="https://cran.r-project.org/web/packages/ts2net/readme/README.html">README</a> to get started.</p>
<p><img src="ts2net.jpeg" height = "400" width="600" alt="Box plots comparing multiple methods"></p>
<h3 id="utilities">Utilities</h3>
<p><a href="https://cran.r-project.org/package=cppcheckR">cppchedkR</a> Allows users to run <a href="https://cppcheck.sourceforge.io/">Cppcheck</a> on <code>C/C++</code> files as an R command or an RStudio addin. See <a href="https://cran.r-project.org/web/packages/cppcheckR/index.html">README</a>.
<img src="CppcheckR.gif" height = "500" width="600" alt="Time series rendered as networks">.</p>
<p><a href="https://cran.r-project.org/package=gtExtras">gtExtras</a> v0.4.1: Provides additional functions for creating tables with <code>gt</code>. See <a href="https://cran.r-project.org/web/packages/gtExtras/readme/README.html">README</a> for examples.</p>
<p><img src="gtExtras.png" height = "500" width="600" alt="Table with highlighted cells">.</p>
<h3 id="visualization">Visualization</h3>
<p><a href="https://cran.r-project.org/package=ggpie">ggpie</a> v0.2.2: Provides functions for creating pie, donut and rose pie plots with <code>ggplot2</code>. See the <a href="https://cran.r-project.org/web/packages/ggpie/vignettes/ggpie.html">vignette</a>.</p>
<p><img src="ggpie.png" height = "300" width="500" alt="Fancy pie chart"></p>
<p><a href="https://cran.r-project.org/package=ggtrace">ggtrace</a> v0.2.0: Provides <code>ggplot2</code> geoms that allow groups of data points to be outlined or highlighted for emphasis. See the vignettes <a href="https://cran.r-project.org/web/packages/ggtrace/vignettes/geom-line-trace.html">Trace lines</a> and <a href="https://cran.r-project.org/web/packages/ggtrace/vignettes/geom-point-trace.html">Trace points</a>.</p>
<p><img src="ggtrace.png" height = "350" width="350" alt="Cluster chart with three outlined clusters"></p>
<p><a href="https://cran.r-project.org/package=Morphoscape">Morphoscape</a> v1.0.0: Implements adaptive landscape methods first described by <a href="https://www.tandfonline.com/doi/full/10.1080/02724634.2016.1111225">Polly et al. (2016)</a> for the integration, analysis and visualization of biological trait data on a phenotypic morphospace which are typically defined by shape metrics. See the <a href="https://cran.r-project.org/web/packages/Morphoscape/vignettes/Morphoscape.html">vignette</a>.</p>
<p><img src="morpho.png" height = "300" width="500" alt="Shaded landscape plots with legend"></p>
<p><a href="https://cran.r-project.org/package=r3js">r3js</a> v0.0.1: Provides R and <code>JavaScript</code> functions to allow <code>WebGL</code>-based 3D plotting using the <code>three.js</code> library. See the vignettes: <a href="https://cran.r-project.org/web/packages/r3js/vignettes/getting-started.html">Getting Started</a>, <a href="https://cran.r-project.org/web/packages/r3js/vignettes/plot-from-scratch.html">Creating a plot from scratch</a>, and <a href="https://cran.r-project.org/web/packages/r3js/vignettes/using-groupings.html">Grouping plot elements</a>.</p>
<p><img src="r3js.png" height = "300" width="500" alt="3D interactive scatter plot with point shadows projected on plane"></p>
<p><a href="https://cran.r-project.org/package=rgl2gltf">rgl2gltf</a> v1.0.0: Provides functions to work with <a href="https://en.wikipedia.org/wiki/GlTF">glTF</a> files which are used to describe 3D models. See the <a href="https://cran.r-project.org/web/packages/rgl2gltf/vignettes/shininess.html">vignette</a> for examples..</p>
<p><img src="rgl2gltf.png" height = "500" width="600" alt="3D rendering of an engine part">.</p>
<p><a href="https://cran.r-project.org/package=shapviz">shapviz</a> v0.2.0: Provides functions to visualize SHapley Additive exPlanations (<a href="https://shap.readthedocs.io/en/latest/index.html">SHAP</a>), such as waterfall plots, force plots, various types of importance plots, and dependence plots. See <a href="https://proceedings.neurips.cc/paper/2017/file/8a20a8621978632d76c43dfd28b67767-Paper.pdf">Lundberg & Lee (2017)</a> for background and the <a href="https://cran.r-project.org/web/packages/shapviz/vignettes/shapviz.html">vignette</a> for examples.</p>
<p><img src="shapviz.png" height = "300" width="500" alt="Beeswarm plot showing feature value vs. SHAP value for features of diamonds data set"></p>
<script>window.location.href='https://rviews.rstudio.com/2022/07/29/june-2022-top-40-new-cran-packages/';</script>
Shiny showcase at rstudio::conf(2022)
https://rviews.rstudio.com/2022/07/20/shiny-showcase-at-rstudio-conf-2022/
Wed, 20 Jul 2022 00:00:00 +0000https://rviews.rstudio.com/2022/07/20/shiny-showcase-at-rstudio-conf-2022/
<p><img src="shiny2.png" height = "500" width="100%" alt="rstudio::conf Shiny Talks Schedule"></p>
<p>Beginning with the invitation-only 2016 <a href="https://www.rstudio.com/resources/shiny-dev-con-2016/">Shiny Developer Conference</a>, <a href="https://shiny.rstudio.com/">Shiny</a> has played a prominent part in all RStudio conferences, and <a href="https://www.rstudio.com/conference/">rstudio::conf(2022)</a> is no exception. Two workshops and eighteen talks showcase Shiny’s multiple, ever-increasing capabilities. What started out as a way to introduce R’s interactive statistical computations to the web has grown into a production-grade tool that supports serious data science workflows and facilitates the communication of data-generated insights throughout large organizations in both industry and government.</p>
<p>Here is your Shiny guide to rstudio::conf(2022). But before you attend the show or see the movie, you may want to have a look at the <a href="https://mastering-shiny.org/">book</a>.</p>
<p>Keynotes and talks will be livestreamed on the <a href="https://www.rstudio.com/conference/">rstudio::conf(2022) website</a>, free and open to all. No registration is required. If you would like, you can sign up to get access to our Discord server to meet and chat with attendees during conf.</p>
<p>On July 27-28th, head to the conference website to watch the livestreams and ask questions alongside other attendees.</p>
<h3 id="keynotes">Keynotes</h3>
<ol>
<li><a href="https://www.rstudio.com/conference/2022/keynotes/past-future-shiny/">The Past and Future of Shiny</a></li>
</ol>
<h3 id="workshops">Workshops</h3>
<ol>
<li><p><a href="https://shinyprod.com/">Building Production-Quality Shiny Applications</a></p></li>
<li><p><a href="https://rstudio-conf-2022.github.io/get-started-shiny/">Getting Started with Shiny</a></p></li>
</ol>
<h3 id="talks">Talks</h3>
<ol>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/r-shiny-conception-to-cloud/">R Shiny - From Conception to the Cloud</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/optimal-allocation-of-covid-19/">Optimal allocation of COVID-19 vaccines in West Africa - A Shiny success story</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/r-markdown-rstudio-connect-r/">R Markdown + RStudio Connect + R Shiny: A Recipe for Automated Data Processing, Error Logging, and Process Monitoring</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/made-entire-e-commerce-platform/">I made an entire e-commerce platform on Shiny</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/let-mobile-shine-leveraging-css/">Let your mobile shine - Leveraging CSS concepts to make shiny apps mobile responsive</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/shinyslack-connecting-slack-teams/">{shinyslack}: Connecting Slack Teams to Shiny Apps</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/leafdown-interactive-multi-layer-maps/">leafdown: Interactive multi-layer maps in Shiny apps</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/say-hello-to-multilingual-shiny/">Say Hello! to Multilingual Shiny Apps</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/cross-industry-anomaly-detection-solutions/">Cross-Industry Anomaly Detection Solutions with R and Shiny</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/running-shiny-without-server/">Running Shiny without a server</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/new-way-to-build-shiny/">A new way to build your Shiny app’s UI</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/creating-design-system-for-shiny/">Creating a Design System for Shiny and RMarkdown</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/shiny-dashboards-for-biomedical-research/">Shiny Dashboards for Biomedical Research Funding</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/dashboard-builder/">Dashboard-Builder: Building Shiny Apps without writing any code</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/introducing-rhino-shiny-application-framework/">Introducing Rhino: Shiny application framework for enterprise</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/robust-framework-for-automated-shiny/">A Robust Framework for Automated Shiny App Testing</a></p></li>
<li><p><a href="https://www.rstudio.com/conference/2022/talks/shinytest2-unit-testing-for-shiny/">{shinytest2}: Unit testing for Shiny applications</a></p></li>
</ol>
<script>window.location.href='https://rviews.rstudio.com/2022/07/20/shiny-showcase-at-rstudio-conf-2022/';</script>
R is for actuaRies
https://rviews.rstudio.com/2022/07/12/r-is-for-actuaries/
Tue, 12 Jul 2022 00:00:00 +0000https://rviews.rstudio.com/2022/07/12/r-is-for-actuaries/
<script src="/2022/07/12/r-is-for-actuaries/index_files/kePrint/kePrint.js"></script>
<link href="/2022/07/12/r-is-for-actuaries/index_files/lightable/lightable.css" rel="stylesheet" />
<p><em>Dr Maria Prokofieva is a member of the <a href="https://github.com/RConsortium/RBusiness">R / Business</a> working group which is promoting the use of R in accounting, auditing, and actuarial work. She is also a professor at the Victoria University Business School in Australia and works with CPA Australia.</em></p>
<div id="what-is-actuarial-science" class="section level4">
<h4>What is actuarial science</h4>
<p>Actuarial data science lies at the intersection of math and business studies, combining statistical knowledge and methods from insurance and finance areas. Compared to data scientists, actuaries focus more on finance and business knowledge, while still collecting and analyzing data.</p>
<p>The profession is in high demand, and according to the Bureau of Labor Statistics (BLS), it is expected that actuary jobs will a enjoy 24% increase from 2020-30. This is much faster than the average for all occupations. Moreover, the median salary for an actuary is estimated to be over $100,000.</p>
<p>The focus of the field is on assessing the likelihood of future events, particularly in business settings (especially finance and insurance) to plan for outcomes and mitigate risks. With this in mind, probability analysis and statistics are applied to very many areas, such as predicting the number of children for a health insurance or the payout of the life insurance policy. Some common tasks for actuaries include calculating premium rates for mortality and morbidity products, assessing likelihood of financial loss or return, business risk consulting, pension and retirement planning and many more. Basically, actuaries perform any tasks that include risk modeling, be that in insurance, financial planning or energy and environment. Later in this post, we will go through some examples of those!</p>
<p>Reviewing particular applications across areas, we can mention:</p>
<ul>
<li>Insurance in such areas as life insurance, credit and mortgage insurance, key person insurance for small business, long term care insurance, health savings accounts. The focus here is on analysis of mortality, production of life tables, calculation of compound interest for life insurance, annuities and endowment contingencies.</li>
</ul>
<pre class="r"><code># Using imaginator package for individual claim simulation
# extract from the vignette
set.seed(12345)
tbl_policy <- policies_simulate(2, 2001:2005)
tbl_claim_transaction <- claims_by_wait_time(
tbl_policy,
claim_frequency = 2,
payment_frequency = 3,
occurrence_wait = 10,
report_wait = 5,
pay_wait = 5,
pay_severity = 50)
kableExtra::kbl(tbl_claim_transaction[1:8,],
caption = "Wait-time modelling with policies simulation") %>%
kableExtra::kable_classic(full_width = F, html_font = "Cambria")</code></pre>
<table class=" lightable-classic" style="font-family: Cambria; width: auto !important; margin-left: auto; margin-right: auto;">
<caption>
<span id="tab:unnamed-chunk-2">Table 1: </span>Wait-time modelling with policies simulation
</caption>
<thead>
<tr>
<th style="text-align:left;">
policy_effective_date
</th>
<th style="text-align:left;">
policy_expiration_date
</th>
<th style="text-align:right;">
exposure
</th>
<th style="text-align:right;">
policyholder_id
</th>
<th style="text-align:right;">
claim_id
</th>
<th style="text-align:left;">
occurrence_date
</th>
<th style="text-align:left;">
report_date
</th>
<th style="text-align:right;">
number_of_payments
</th>
<th style="text-align:left;">
payment_date
</th>
<th style="text-align:right;">
payment_amount
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
2001-05-23
</td>
<td style="text-align:left;">
2002-05-22
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2001-06-02
</td>
<td style="text-align:left;">
2001-06-07
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-06-12
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-05-23
</td>
<td style="text-align:left;">
2002-05-22
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2001-06-02
</td>
<td style="text-align:left;">
2001-06-07
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-06-17
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-05-23
</td>
<td style="text-align:left;">
2002-05-22
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
2001-06-02
</td>
<td style="text-align:left;">
2001-06-07
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-06-22
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-05-23
</td>
<td style="text-align:left;">
2002-05-22
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2001-06-02
</td>
<td style="text-align:left;">
2001-06-07
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-06-12
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-05-23
</td>
<td style="text-align:left;">
2002-05-22
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2001-06-02
</td>
<td style="text-align:left;">
2001-06-07
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-06-17
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-05-23
</td>
<td style="text-align:left;">
2002-05-22
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
2001-06-02
</td>
<td style="text-align:left;">
2001-06-07
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-06-22
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-02-21
</td>
<td style="text-align:left;">
2002-02-20
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-03-03
</td>
<td style="text-align:left;">
2001-03-08
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-03-13
</td>
<td style="text-align:right;">
50
</td>
</tr>
<tr>
<td style="text-align:left;">
2001-02-21
</td>
<td style="text-align:left;">
2002-02-20
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-03-03
</td>
<td style="text-align:left;">
2001-03-08
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
2001-03-18
</td>
<td style="text-align:right;">
50
</td>
</tr>
</tbody>
</table>
<pre class="r"><code># Using MortalityTables package - Mortality tables
# extract from the vignette
mortalityTables.load("Austria_Annuities")
mortalityTables.load("Austria_Census")
plotMortalityTables(
title="Using dimensional information for mortality tables",
mort.AT.census[c("m", "w"), c("1951", "1991", "2001", "2011")]) +
aes(color = as.factor(year), linetype = sex) + labs(color = "Period", linetype = "Sex")+
scale_fill_brewer(palette="PiYG")</code></pre>
<p><img src="/2022/07/12/r-is-for-actuaries/index_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
<ul>
<li>Life insurance and social insurance. Main tasks in this area include analysis of rates of disability, mordibity, mortality, fertility, etc., analysis of factors (such as georgaphy and consumer characteristics) on usage of medical services and procedures.</li>
</ul>
<pre class="r"><code># Using MortalityTables package
# extract from the vignette
mortalityTables.load("Austria_Annuities")
# Get the cohort death probabilities for Austrian Annuitants born in 1977:
qx.coh1977 = deathProbabilities(AVOe2005R.male, YOB = 1977)
# Get the period death probabilities for Austrian Annuitants observed in the year 2020:
qx.per2020 = periodDeathProbabilities(AVOe2005R.male, Period = 2020)
# Get the cohort death probabilities for Austrian Annuitants born in 1977 as a mortalityTable.period object:
table.coh1977 = getCohortTable(AVOe2005R.male, YOB = 1977)
# Get the period death probabilities for Austrian Annuitants observed in the year 2020:
table.per2020 = getPeriodTable(AVOe2005R.male, Period = 2020)
# Compare those two in a plot:
plot(table.coh1977, table.per2020, title = "Comparison of cohort 1977 with period 2020", legend.position = c(1,0))+
scale_fill_brewer(palette="PiYG")</code></pre>
<p><img src="/2022/07/12/r-is-for-actuaries/index_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<ul>
<li>Pension: design, funding, accounting, administration, and maintenance or redesign of pension plans with valuation and modelling for various factors that may influence the calculation and payout</li>
</ul>
<pre class="r"><code># Using lifecontingencies package
# Extract from vignette
# Calculation example for the benefit reserve for a deferred annuity-due on a policyholder aged 25 when the annuity is deferred until age 65.
yearlyRate <- 12000
irate <- 0.02
APV <- yearlyRate*axn(soa08Act, x=25, i=irate,m=65-25,k=12)
levelPremium <- APV/axn(soa08Act, x=25,n=65-25,k=12)
annuityReserve<-function(t) {
out<-NULL
if(t<65-25) out <- yearlyRate*axn(soa08Act, x=25+t,
i=irate, m=65-(25+t),k=12)-levelPremium*axn(soa08Act,
x=25+t, n=65-(25+t),k=12) else {
out <- yearlyRate*axn(soa08Act, x=25+t, i=irate,k=12)
}
return(out)
}
years <- seq(from=0, to=getOmega(soa08Act)-25-1,by=1)
annuityRes <- numeric(length(years))
for(i in years) annuityRes[i+1] <- annuityReserve(i)
dataAnnuityRes <- data.frame(years=years, reserve=annuityRes)
dataAnnuityRes%>%ggplot(aes(years, reserve))+
geom_line(color="blue")+
labs(x = "Years", y = "Amount",
title ="Deferred annuity benefit reserve")</code></pre>
<p><img src="/2022/07/12/r-is-for-actuaries/index_files/figure-html/unnamed-chunk-5-1.png" width="672" /></p>
<p>and many more! Just look at those examples!</p>
<p>Historically, actuarial science comes from the mathematical area (no surprise here!) and stems back to 17th century when developments in mathematics in Europe coincided with the growth in demands to have more precise estimation in risks in burial, life insurance and annuities calculations. This was the start of developing techniques for life tables (hail to John Graunt, the father of demography) and discounting values for present value calculation which is one of the keystone concepts in today’s finance and accounting. The field was developing very quickly but the computational side became more and more complex: without computers, this was a tedious task. But…</p>
</div>
<div id="why-acturial-science-needs-r" class="section level3">
<h3>Why acturial science needs R</h3>
<p>Long gone those days when all calculations were done by hand, table and god blessing… What is in use currently in the field?</p>
<p>Apparently… Excel still has its dominance (if not reign?) …</p>
<p>In March 2022 the Casualty Actuarial Society (CAS) released <a href="https://www.casact.org/article/cas-releases-results-actuarial-technology-survey">results and analysis</a> from its first survey on technology used by actuaries. With responses from over 1,200 participants, the results suggest that more than 94.3% of respondents use Excel, and at least once a day, but! it is more than just one tool! With this in mind there is a strong demand for new skills- in R (47.2%), Python (39.1%) and SQL (30.8%).</p>
<p>To support this, the recent results (2020) of the “wasted time” <a href="https://slopesoftware.com/2021/01/15/wasted-time-survey-2020-results/">survey</a> show a striking outcome that actuaries waste most of their time…</p>
<ul>
<li><p>waiting for excel to process the results</p></li>
<li><p>copying data from a model</p></li>
<li><p>recreating prior model values</p></li>
<li><p>waiting for vendor support</p></li>
</ul>
<p>and quite a few of other tasks that could be easily resolved with open source and replicable modeling approach..</p>
<pre class="r"><code>survey<-read_csv("survey_actuaries.csv")
survey%>%pivot_longer(-Tasks, names_to="Time", values_to="Score")%>%
group_by(Tasks) %>%
mutate(sum_response = sum(Score))%>%
ungroup()%>%
ggplot(aes(x=fct_reorder(Tasks, sum_response), Score, fill=Time))+
geom_col(show.legend = TRUE)+
coord_flip()+
scale_fill_brewer(palette="PiYG")+
labs(y = "Responses", x = "Tasks",
title ="Data and model management tasks - wasted time")</code></pre>
<p><img src="/2022/07/12/r-is-for-actuaries/index_files/figure-html/unnamed-chunk-6-1.png" width="672" /></p>
<p>What are the barriers? TIME! (80.5% of actuaries indicated so).. but what else is missing?</p>
</div>
<div id="learning-resources" class="section level3">
<h3>Learning resources</h3>
<p>Learning resources is always a problem to move people to use available tools. Actuarial (data) science is not the exception. Good news is that there are some to start using R for actuarial data as well as there are some materials available to build further resources.</p>
<p>The available learning resources start with Introduction to R. This is a general category that includes the resources to get familiar with R, RStudio and main R packages (e.g. <code>tidyverse</code>).</p>
<p><a href="https://r4ds.had.co.nz/">R for Data Science</a></p>
<p><a href="https://rstudio.cloud/learn/primers">RStudio.cloud Primers</a></p>
<p>A well known list built by the enthusiastic and supportive R community: RStudio Education <a href="https://education.rstudio.com/">education.rstudio.com</a></p>
<p>In the meantime, there is a growing treasure trove of R resources developed by enthusiastic R Actuaries that address specific issues.</p>
<p>The work of the <a href="https://www.actuarialdatascience.org/">“Data Science” group</a> of the Swiss Association of Actuaries (SAA) is amazing - lots of resources has been prepared, including <a href="https://www.actuarialdatascience.org/ADS-Lectures/Courses/">lectures</a> and <a href="https://www.actuarialdatascience.org/ADS-Tutorials/">hands-on tutorials in R</a>.</p>
</div>
<div id="common-and-specific-r-packages-used" class="section level3">
<h3>Common and specific R packages used</h3>
<p>Apart from educational resources, specialized packages are available to the community, including:</p>
<ul>
<li><p><a href="https://cran.r-project.org/package=raw">raw: R Actuarial Workshops</a></p></li>
<li><p><a href="https://cran.r-project.org/package=actuar">actuar: Actuarial Functions and Heavy Tailed Distributions</a></p></li>
<li><p><a href="https://cran.r-project.org/package=ChainLadder">chainLadder: Statistical Methods and Models for Claims Reserving in General Insurance</a></p></li>
<li><p><a href="https://cran.r-project.org/package=finCal">finCal: Time Value of Money, Time Series Analysis and Computational Finance</a></p></li>
<li><p><a href="https://cran.r-project.org/package=imaginator">imaginator: Simulate General Insurance Policies and Losses</a></p></li>
<li><p><a href="https://cran.r-project.org/package=MortalityLaws">MortalityLaws: Parametric Mortality Models, Life Tables and HMD</a></p></li>
</ul>
<p>Such packages are scattered across CRAN and github as there is not currently a task view for actuarial data science at CRAN (hint!)…</p>
<p>There is a great potential in the actuarial data science and R / Business would love to invite the R passionate community to start a dialogue on promoting and developing R resources in this area!</p>
</div>
<script>window.location.href='https://rviews.rstudio.com/2022/07/12/r-is-for-actuaries/';</script>