From 35218fe0fd6bb66b3d0d2c6eb2360b1a26332016 Mon Sep 17 00:00:00 2001 From: Max Kuhn Date: Wed, 18 Nov 2026 12:44:48 -0500 Subject: [PATCH] first draft of deisng principles --- _quarto.yml | 5 + chicago-author-date-inline.csl | 684 +++++++++++++++++++++++++++++++++ design.qmd | 88 +++++ segue.bib | 20 + 4 files changed, 797 insertions(+) create mode 100644 chicago-author-date-inline.csl create mode 100644 design.qmd create mode 100644 segue.bib diff --git a/_quarto.yml b/_quarto.yml index ec0cd05..d724ff8 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -51,6 +51,8 @@ website: logo: assets/mark.svg logo-alt: "segue" left: + - text: "Design" + href: design.qmd - text: "Comparisons" href: comparisons/index.qmd - text: "Reference" @@ -134,3 +136,6 @@ format: fig-width: 7.5 fig-height: 4.2 fig-dpi: 160 + +bibliography: segue.bib +csl: chicago-author-date-inline.csl \ No newline at end of file diff --git a/chicago-author-date-inline.csl b/chicago-author-date-inline.csl new file mode 100644 index 0000000..fd41d1e --- /dev/null +++ b/chicago-author-date-inline.csl @@ -0,0 +1,684 @@ + + diff --git a/design.qmd b/design.qmd new file mode 100644 index 0000000..487308a --- /dev/null +++ b/design.qmd @@ -0,0 +1,88 @@ +--- +title: "Design Principles for segue" +--- + +This document describes the motivation and design goals of segue. It's not mandatory reading but should help users understand our goals and motivations. + +## Why Segue + +segue is not a technical marvel; it is repackaging existing tools in R and mostly focuses on non-technical aspects of software: + +- _discoverability_: make it easier to find what you need. +- _understandable_: make documentation and error messages helpful and informative. +- _compatibility_: how does it work relative to more familiar tools. +- _trustworthy_: explicitly describe how the code is validated. + +The package name implies that we are trying to get users somewhere they are not. Our motivation is to help users who are transitioning from SAS to R (perhaps not by choice). Moving between the two systems can be jarring, and segue can help someone getting started in R. While the package emphasizes closely reproducing previous SAS work, it is intended as a gateway to R. + +## Make R functions discoverable + +R code lives either in the base R packages (e.g., stats, tools, etc.) or in contributed packages. The latter contains the vast majority of the code that you will interface with. The problem with _both_ sources is that their interfaces are often unpredictable, inconsistent, and/or opaque. For example, as a graduate student new to the language, I looked for a matrix inversion function (maybe called `inv()`). _This does not exist_, but the function to solve a system of equations (`solve()`) can do it. + +R is based on the S language, and R and S have mostly the same syntax. S was first developed in the 1970s, and a lot has changed since then. segue takes the stance that most users work with data frames, so our interfaces use these instead of raw vectors. We also have more capacity for naming functions than in the previous century, so segue tries to be explicit. For example, it is difficult to know that the difference in test statistics produced by `binom.test()` and `prop.test()` from their names. We also optimize for tab-completion. + +R packages, on average, are not much better. For example, the code to sort a data frame by a variable (descending order) is very different: + +```r +# Base R +data_sorted <- data[, order(-data$x), drop = FALSE] + +# data.table package +data_sorted <- setorder[data, -x] + +# dplyr package +data_sorted <- arrange(data, desc(x)) +``` + +Packages also differ in implementation when it comes to statistical choices. For example, some hypothesis tests use continuity corrections by default, and others do not. + +Coming from SAS, this can be perplexing. SAS has the advantage of a single, monolithic way to compute models and statistics, so you never really have the option to use a different test configuration. + +## Better R interfaces + +Outside of images and text data, almost all data is tabular; rows are data instances or samples, and columns are variables. Most modern tools use a syntax centered on the general concept of a data frame. segue is centered around data frames. + +Base R can assume that the data interface should be vectors or summary statistics. For example, tests for a proportion have the interface: + +```r +binom.test(number_of_events, total_samples) +``` + +which is not helpful if your data are in columns of a data frame. Another example is that the function that does a Chi-squared test of association has the syntax: + +```r +# Abbreviated syntax: +chisq.test(x, y = NULL, ...) +``` + +and the help file states: + +- `x` can be "a numeric vector or matrix. `x` and `y` can also both be factors." (it can also be a table object). +- `y` is "a numeric vector; ignored if `x` is a matrix." + +That is helpful but barely actionable. + +The t-test function is slightly better since it has multiple interfaces: + +```r +# Vector-based interface +t.test(x, y = NULL, ...) + +# Formula-based interface, taking a data frame +t.test(formula, data, ...) +``` + +However, all interfaces preclude running these computations many times, conditional on some "by" variable. + +Interfaces for data analysis software are discussed in the ["Why Tidiness is Important for Modeling"](https://www.tmwr.org/base-r#tidiness-modeling) in the @tmwr. That references the idea of designing for humans described in @Wickham2019. These philosophical aspects of software design also inform segue's design. + +## Avoid "Right" and "Wrong" + +R and SAS can differ a lot in how they do computations. Some of these differences matter in a meaningful way; others don't. + +Our principle for segue is to + +- Don't view _any_ implementation as the gold standard. +- Accommodate both approaches whenever possible but choose a sensible default. +- Outline the differences in defaults and optional arguments. +- Investigate apples-to-apples numerical comparisons to give users a sense of how substantial any differences in results are. diff --git a/segue.bib b/segue.bib new file mode 100644 index 0000000..a61594c --- /dev/null +++ b/segue.bib @@ -0,0 +1,20 @@ +@article{ + Wickham2019, + doi = {10.21105/joss.01686}, + url = {https://doi.org/10.21105/joss.01686}, + year = {2019}, + publisher = {The Open Journal}, + volume = {4}, + number = {43}, + pages = {1686}, + author = {Wickham, Hadley and Averick, Mara and Bryan, Jennifer and Chang, Winston and McGowan, Lucy D'Agostino and François, Romain and Grolemund, Garrett and Hayes, Alex and Henry, Lionel and Hester, Jim and Kuhn, Max and Pedersen, Thomas Lin and Miller, Evan and Bache, Stephan Milton and Müller, Kirill and Ooms, Jeroen and Robinson, David and Seidel, Dana Paige and Spinu, Vitalie and Takahashi, Kohske and Vaughan, Davis and Wilke, Claus and Woo, Kara and Yutani, Hiroaki}, + title = {Welcome to the Tidyverse}, journal = {Journal of Open Source Software} +} + +@book{tmwr, + author = {Max Kuhn and Julia Silge}, + title = {\href{https://www.tmwr.org}{{Tidy Modeling with {R}}}}, + year = {2022}, + publisher = {O'Reilly Media, Inc.} +} +