diff --git a/.github/workflows/quarto-site.yaml b/.github/workflows/quarto-site.yaml new file mode 100644 index 0000000..e2b10e5 --- /dev/null +++ b/.github/workflows/quarto-site.yaml @@ -0,0 +1,79 @@ +name: Render and Publish + +on: + push: + branches: main + pull_request: + branches: main + workflow_dispatch: + +permissions: + contents: write + pages: write + +jobs: + build-deploy: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + # The reference pages and the installed package come from the same + # checkout, so the docs always match the code that runs the examples. + - name: Check out segue + uses: actions/checkout@v4 + with: + repository: posit-dev/segue + path: _packages/segue + + - name: Set up Quarto + uses: quarto-dev/quarto-actions/setup@v2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + r-version: release + use-public-rspm: true + + # Packages the pages run, plus packages that downlit links to. downlit + # links `pkg::fun()` to the function's page only when pkg is installed. + # dplyr, tidyr, ggplot2, broom, rlang, tibble and vctrs come in as + # dependencies of tidyverse or segue. + - name: Install R packages + uses: r-lib/actions/setup-r-dependencies@v2 + with: + packages: > + local::./_packages/segue + any::cli + any::downlit + any::gt + any::haven + any::knitr + any::modeldata + any::pak + any::pkgsite + any::rmarkdown + any::scales + any::tidyverse + any::xml2 + + - name: Build reference pages + run: Rscript _pkgsite/build.R _packages/segue + + # Pull requests only render, to check that the site builds. + - name: Render site + if: github.event_name == 'pull_request' + uses: quarto-dev/quarto-actions/render@v2 + + - name: Render and publish to GitHub Pages + if: github.event_name != 'pull_request' + uses: quarto-dev/quarto-actions/publish@v2 + with: + target: gh-pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index d9dedf5..936084f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ # stray vsub output when run from the repo root /*.log /*.lst +/_freeze/ diff --git a/README.md b/README.md index f25946c..e503a76 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The R code runs when the site is built, so you need R with segue installed: ```r pak::pak("posit-dev/segue") -install.packages(c("dplyr", "tidyr", "ggplot2", "knitr", "haven")) +install.packages(c("tidyverse", "gt", "scales", "cli", "knitr", "rmarkdown", "modeldata", "haven", "downlit", "xml2")) ``` Then, from this folder: @@ -23,7 +23,7 @@ Or preview with live reload: quarto preview ``` -Results are frozen in `_freeze/` (`freeze: auto`), so a page re-runs only when its source changes. +Locally, results are cached in `_freeze/` (`freeze: auto`), so a page re-runs only when its source changes. `_freeze/` is not committed: the GitHub Actions workflow in `.github/workflows/quarto-site.yaml` runs all the code on each push to `main` and publishes the site to the `gh-pages` branch. ## Data @@ -35,7 +35,7 @@ Rscript data-raw/prepare-data.R ../r-to-sas-comparisons ## Reference pages -The pages in `reference/` are written by [pkgsite](https://edgararuiz.github.io/pkgsite/) from segue's `.Rd` help files. Don't edit them by hand: rebuild them whenever segue's documentation changes. +The pages in `reference/` are written by [pkgsite](https://edgararuiz.github.io/pkgsite/) from segue's `.Rd` help files. Don't edit them by hand. The GitHub Actions workflow rebuilds them from the latest segue on every publish, so you only need to rebuild them locally to preview changes. ```r install.packages("pkgsite") diff --git a/_freeze/comparisons/binomial-exact-test/execute-results/html.json b/_freeze/comparisons/binomial-exact-test/execute-results/html.json deleted file mode 100644 index 3f201aa..0000000 --- a/_freeze/comparisons/binomial-exact-test/execute-results/html.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "hash": "3df7f616efe9b93446af76a45fbfbeb1", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Exact test for a proportion\"\nsubtitle: \"`PROC FREQ` with `EXACT BINOMIAL`, written in R with `bin_prop_test()`.\"\ndescription: \"Run the exact binomial test the way `PROC FREQ` does. R's `binom.test()` defines the two-sided p-value differently.\"\ncategories: [Binomial proportion, PROC FREQ]\nsas: \"PROC FREQ; EXACT BINOMIAL;\"\nr: \"bin_prop_test(y, method = \\\"exact_sas\\\")\"\nagreement: \"5.5e-14\"\nagreement-label: \"largest p-value difference in 11,466 tests\"\norder: 3\n---\n\n\n\n::: {.glance}\n::: {.sas-v}\n[SAS]{.k}\n[`PROC FREQ` with `EXACT BINOMIAL`]{.v}\n:::\n::: {.r-v}\n[R]{.k}\n[`segue::bin_prop_test(method = \"exact_sas\")`]{.v}\n:::\n::: {.agree-v}\n[Agreement with SAS]{.k}\n[p-values within 5.5e-14]{.v}\n:::\n:::\n\nWith small samples, many analysts use the exact binomial test instead of the score test. Base R has `binom.test()` for this, but its two-sided p-value is **not** the one `PROC FREQ` reports. `bin_prop_test()` with `method = \"exact_sas\"` gives the SAS p-value.\n\n## The analysis\n\n::: {.translation}\n::: {.pane .sas what=\"PROC FREQ\"}\n```sas\ndata trial;\n input response $ count;\ndatalines;\nyes 12\nno 28\n;\nrun;\n\nproc freq data=trial;\n tables response\n / binomial(p=0.25 level=\"yes\");\n exact binomial;\n weight count;\nrun;\n```\n:::\n\n::: {.pane .r what=\"segue\"}\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(segue)\n\nresponse <- factor(\n rep(c(\"yes\", \"no\"), c(12, 28)),\n levels = c(\"yes\", \"no\")\n)\n\nres <- bin_prop_test(\n response,\n method = \"exact_sas\",\n null_value = 0.25\n)\ntidy(res)[c(\"estimate\", \"statistic\", \"p.value\")]\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 1 × 3\n estimate statistic p.value\n \n1 0.3 12 0.570\n```\n\n\n:::\n:::\n\n:::\n:::\n\nThe arguments map the same way as for the [score test](binomial-score-test.qmd). The exact p-values are in the SAS variables `XP2_BIN`, `XPL_BIN` and `XPR_BIN`.\n\n## Why not `binom.test()`?\n\nBoth tests add up probabilities from the binomial distribution, but they define \"as extreme as the data\" differently for a two-sided test:\n\n- **SAS** doubles the smaller tail and caps the result at 1. This is called the *central* method.\n- **`binom.test()`** adds the probability of every outcome that is no more likely than the one you saw. This is called the *minimum likelihood* method.\n\nThe two agree only when the null value is 0.5, where the distribution is symmetric. For the trial above, the p-values are quite different:\n\n\n::: {.cell}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n\n
Method Two-sided p-value
SAS XP2_BIN, bin_prop_test(method = \"exact_sas\") 0.5697
binom.test(), bin_prop_test(method = \"exact\") 0.4668
\n\n`````\n:::\n:::\n\n\nIf you validate an R analysis against SAS output, use `method = \"exact_sas\"`. Use `method = \"exact\"` only when you want `binom.test()`'s definition.\n\n::: {.callout-note}\n## One-sided p-values can be missing\n\n`PROC FREQ` computes both tails but reports only the smaller one. The other variable is missing. `method = \"exact_sas\"` does the same and returns `NA` when you ask for the larger tail. `binom.test()` always returns the tail you ask for.\n:::\n\n## What R runs\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntranslate(res)\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\n── R Code template ─────────────────────────────────────────────────────────────\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stdout}\n\n```\nsegue::exact_binom_test_sas(x = 12L, n = 40L, alternative = \"two.sided\", \n p = 0.25)\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stderr}\n\n```\n\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stderr}\n\n```\n── SAS Code template ───────────────────────────────────────────────────────────\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stdout}\n\n```\nproc freq data=&dsn;\n tables resp / binomial;\n exact binomial;\nrun;\n```\n\n\n:::\n:::\n\n\n`exact_binom_test_sas()` takes the same arguments as `binom.test()`, so you can also call it with counts:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nexact_binom_test_sas(12, 40, p = 0.25)$p.value\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 0.5697112\n```\n\n\n:::\n:::\n\n\n## How close are the results?\n\nThe comparison ran `PROC FREQ` and `exact_binom_test_sas()` on every combination of 1 to 50 events and 2 to 50 patients, with null values 0.01, 0.25 and 0.5, and with each alternative: 11,466 tests in all. The R side runs again each time this page is built.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Difference between the R and SAS p-values for each test where both report one.](binomial-exact-test_files/figure-html/fig-exact-diff-1.png){#fig-exact-diff width=1200}\n:::\n:::\n\n\nThe p-values agree to within 5.5e-14. R and SAS use different algorithms for the binomial distribution, so the last few digits differ. The differences are random and small; they don't favor either program.\n\nSAS computes an upper tail as one minus a lower tail. When the upper tail is very small, this subtraction loses precision, and tails below about 1e-16 come out as exactly 0. `exact_binom_test_sas()` does the same subtraction, so it returns the same values.\n\n### Ties\n\nWhen the null value is 0.5 and the number of events is exactly half the patients, the two tails are equal, and rounding error decides which one is \"smaller\". In 14 of these tests, SAS reported the upper tail and R the lower one. The p-values are the same; only the variable that holds them differs.\n", - "supporting": [ - "binomial-exact-test_files" - ], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/comparisons/binomial-exact-test/figure-html/fig-exact-diff-1.png b/_freeze/comparisons/binomial-exact-test/figure-html/fig-exact-diff-1.png deleted file mode 100644 index e46d311..0000000 Binary files a/_freeze/comparisons/binomial-exact-test/figure-html/fig-exact-diff-1.png and /dev/null differ diff --git a/_freeze/comparisons/binomial-score-test/execute-results/html.json b/_freeze/comparisons/binomial-score-test/execute-results/html.json deleted file mode 100644 index ffbaf29..0000000 --- a/_freeze/comparisons/binomial-score-test/execute-results/html.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "hash": "714ac82e769994216f9932538edee5ce", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Score test for a proportion\"\nsubtitle: \"The default `PROC FREQ` binomial test, written in R with `bin_prop_test()`.\"\ndescription: \"Test whether a response rate equals a set value with the asymptotic score test that `PROC FREQ` runs by default.\"\ncategories: [Binomial proportion, PROC FREQ]\nsas: \"PROC FREQ; TABLES y / BINOMIAL;\"\nr: \"bin_prop_test(y, method = \\\"score\\\")\"\nagreement: \"1.2e-15\"\nagreement-label: \"largest p-value difference in 7,644 tests\"\norder: 2\n---\n\n\n\n::: {.glance}\n::: {.sas-v}\n[SAS]{.k}\n[`PROC FREQ` with `BINOMIAL`]{.v}\n:::\n::: {.r-v}\n[R]{.k}\n[`segue::bin_prop_test(method = \"score\")`]{.v}\n:::\n::: {.agree-v}\n[Agreement with SAS]{.k}\n[p-values within 1.2e-15]{.v}\n:::\n:::\n\nSuppose 12 of 40 patients respond to a treatment, and you want to test whether the response rate is 25%. In SAS, the `BINOMIAL` option of `PROC FREQ` runs an asymptotic test. It uses the variance under the null hypothesis, which makes it a *score test*. In R, `bin_prop_test()` with `method = \"score\"` gives the same p-values.\n\n## The analysis\n\n::: {.translation}\n::: {.pane .sas what=\"PROC FREQ\"}\n```sas\ndata trial;\n input response $ count;\ndatalines;\nyes 12\nno 28\n;\nrun;\n\nproc freq data=trial;\n tables response\n / binomial(p=0.25 level=\"yes\");\n weight count;\nrun;\n```\n:::\n\n::: {.pane .r what=\"segue\"}\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(segue)\n\nresponse <- factor(\n rep(c(\"yes\", \"no\"), c(12, 28)),\n levels = c(\"yes\", \"no\")\n)\n\nres <- bin_prop_test(\n response,\n method = \"score\",\n null_value = 0.25\n)\ntidy(res)[c(\"estimate\", \"statistic\", \"p.value\")]\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 1 × 3\n estimate statistic p.value\n \n1 0.3 0.533 0.465\n```\n\n\n:::\n:::\n\n:::\n:::\n\nHow the arguments map:\n\n| SAS | `bin_prop_test()` | Notes |\n|---|---|---|\n| `tables response` | `y = response` | A factor with two levels. |\n| `level=\"yes\"` | `event_level = \"yes\"` | The default is the first factor level. SAS uses the first level in sort order. |\n| `p=0.25` | `null_value = 0.25` | Both default to 0.5. |\n| `P2_BIN`, `PL_BIN`, `PR_BIN` | `alternative = \"two_sided\"`, `\"lesser\"`, `\"greater\"` | SAS reports all of them; R returns the one you ask for. |\n| `Z_BIN` | `statistic` | See the note below. |\n\n::: {.callout-note}\n## The test statistic\n\nSAS reports the Z statistic. `bin_prop_test()` calls `prop.test()`, which reports the chi-squared statistic, Z². The p-values are the same.\n:::\n\n## What R runs\n\n`translate()` shows the base R call that `bin_prop_test()` makes, next to a SAS template:\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntranslate(res)\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\n── R Code template ─────────────────────────────────────────────────────────────\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stdout}\n\n```\nstats::prop.test(x = 12L, n = 40L, alternative = \"two.sided\", \n p = 0.25, correct = FALSE)\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stderr}\n\n```\n\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stderr}\n\n```\n── SAS Code template ───────────────────────────────────────────────────────────\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stdout}\n\n```\nproc freq data={data set};\n tables {analysis column} / binomial(cl=score);\nrun;\n```\n\n\n:::\n:::\n\n\nThe R code is `prop.test()` with `correct = FALSE`. `prop.test()` applies a continuity correction by default, and `PROC FREQ` does not. If you call `prop.test()` yourself, remember to turn the correction off, or your p-values will be larger than SAS's.\n\n## How close are the results?\n\nThe comparison ran `PROC FREQ` and `bin_prop_test()` on every combination of 1 to 50 events and 2 to 50 patients, with null values 0.01, 0.25 and 0.5, and with each alternative. SAS's p-values were read into R bit for bit from the `.sas7bdat` file.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Difference between the R and SAS p-values for each test. Every difference is smaller than the rounding error of a double.](binomial-score-test_files/figure-html/fig-score-diff-1.png){#fig-score-diff width=1200}\n:::\n:::\n\n\nAll 7,644 p-values agree to within 1.2e-15. That is a difference in the 15th decimal place, which comes from the two programs doing the arithmetic in a different order.\n\nFor one-sided tests, `PROC FREQ` reports only the tail on the same side as the observed proportion and leaves the other one missing. Those cases are left out of the plot. `bin_prop_test()` always returns the tail you ask for.\n", - "supporting": [ - "binomial-score-test_files" - ], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/comparisons/binomial-score-test/figure-html/fig-score-diff-1.png b/_freeze/comparisons/binomial-score-test/figure-html/fig-score-diff-1.png deleted file mode 100644 index 1f40684..0000000 Binary files a/_freeze/comparisons/binomial-score-test/figure-html/fig-score-diff-1.png and /dev/null differ diff --git a/_freeze/comparisons/rounding/execute-results/html.json b/_freeze/comparisons/rounding/execute-results/html.json deleted file mode 100644 index 4eaf734..0000000 --- a/_freeze/comparisons/rounding/execute-results/html.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "hash": "32106ba6d263a7e7fa69e58135aa5214", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Rounding numbers\"\nsubtitle: \"SAS `ROUND()` and `w.d` formats, written in R with `sas_round()` and `sas_format()`.\"\ndescription: \"Why `round()` in R gives different answers than `ROUND()` in SAS, and how to get the SAS results in R.\"\ncategories: [Numbers, DATA step]\nsas: \"ROUND(x, 0.01) put x 8.2;\"\nr: \"sas_round(x, 2) sas_format(x, 2)\"\nagreement: \"99.95%\"\nagreement-label: \"of 57,944 ROUND() results identical\"\norder: 1\n---\n\n\n\n::: {.glance}\n::: {.sas-v}\n[SAS]{.k}\n[`ROUND(x, unit)`, `w.d` formats]{.v}\n:::\n::: {.r-v}\n[R]{.k}\n[`segue::sas_round()`, `segue::sas_format()`]{.v}\n:::\n::: {.agree-v}\n[Agreement with SAS]{.k}\n[99.95% of `ROUND()` results, 99.40% of `32.d` results]{.v}\n:::\n:::\n\nR's `round()` and SAS's `ROUND()` often give different answers. This is not a bug in either language. They follow different rules, and both work with numbers that the computer cannot store exactly. If you move a SAS program to R and use `round()`, some values in your tables can change in the last decimal place.\n\nsegue has two functions that give the SAS results in R:\n\n- `sas_round()` works like the SAS `ROUND()` function.\n- `sas_format()` prints numbers like a SAS `w.d` format, such as `8.2`.\n\n## Round to a whole number\n\n::: {.translation}\n::: {.pane .sas what=\"DATA step\"}\n```sas\ndata halves;\n input x;\n whole = round(x);\ndatalines;\n0.5\n1.5\n2.5\n-2.5\n;\nrun;\n```\n:::\n\n::: {.pane .r what=\"segue\"}\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(segue)\n\nx <- c(0.5, 1.5, 2.5, -2.5)\nsas_round(x)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 1 2 3 -3\n```\n\n\n:::\n:::\n\n:::\n:::\n\nSAS rounds a value that is exactly halfway to the number farther from zero, so 2.5 becomes 3. R's `round()` follows the IEC 60559 standard, which rounds halves to the even number, so 2.5 becomes 2:\n\n\n::: {.cell}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
x SAS ROUND(x) sas_round(x) round(x)
0.5 1 1 0
1.5 2 2 2
2.5 3 3 2
-2.5 -3 -3 -2
\n\n`````\n:::\n:::\n\n\n## Round to two decimal places\n\n::: {.translation}\n::: {.pane .sas what=\"DATA step\"}\n```sas\ndata cents;\n input x;\n cents = round(x, 0.01);\ndatalines;\n1.005\n2.675\n99.995\n;\nrun;\n```\n:::\n\n::: {.pane .r what=\"segue\"}\n\n::: {.cell}\n\n```{.r .cell-code}\nx <- c(1.005, 2.675, 99.995)\nsas_round(x, digits = 2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 1.01 2.68 100.00\n```\n\n\n:::\n:::\n\n:::\n:::\n\nHere the two languages differ for a second reason. The number 2.675 cannot be stored exactly as a binary double. The computer keeps the closest value it can, which is slightly less than 2.675:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsprintf(\"%.20f\", 2.675)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"2.67499999999999982236\"\n```\n\n\n:::\n:::\n\n\nR's `round(2.675, 2)` rounds that stored value, so the answer is 2.67. SAS treats values that are very close to halfway as halfway. The SAS documentation calls this \"fuzzing\". So `ROUND(2.675, 0.01)` is 2.68, which is the answer you get when you round by hand.\n\n\n::: {.cell}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
x SAS ROUND(x, 0.01) sas_round(x, 2) round(x, 2)
1.005 1.01 1.01 1.00
2.675 2.68 2.68 2.67
99.995 100.00 100.00 100.00
\n\n`````\n:::\n:::\n\n\n`sas_round()` takes either `digits`, as `round()` does, or `unit`, as `ROUND()` does. Use `unit` for units that are not powers of ten:\n\n::: {.translation}\n::: {.pane .sas what=\"DATA step\"}\n```sas\nquarter = round(x, 0.25);\n```\n:::\n\n::: {.pane .r what=\"segue\"}\n\n::: {.cell}\n\n```{.r .cell-code}\nsas_round(2.675, unit = 0.25)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 2.75\n```\n\n\n:::\n:::\n\n:::\n:::\n\n## Print numbers like a SAS format\n\nA SAS format such as `8.2` does **not** use `ROUND()`. It has its own rules, so segue has a separate function for it.\n\n::: {.translation}\n::: {.pane .sas what=\"PUT statement\"}\n```sas\ndata _null_;\n input x;\n put x 8.2;\ndatalines;\n1.005\n2.675\n99.995\n-0.001\n;\nrun;\n```\n:::\n\n::: {.pane .r what=\"segue\"}\n\n::: {.cell}\n\n```{.r .cell-code}\nx <- c(1.005, 2.675, 99.995, -0.001)\nsas_format(x, digits = 2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \" 1.01\" \" 2.68\" \"100.00\" \" -0.00\"\n```\n\n\n:::\n:::\n\n:::\n:::\n\nThree rules to keep in mind:\n\n- **Halfway values round up.** As with `ROUND()`, 2.675 prints as `2.68`. But formats use a much smaller tolerance than `ROUND()`, so `sas_format()` does not call `sas_round()`.\n- **Negative values keep their sign.** SAS prints `-0.001` as `-0.00`. `format(round(-0.001, 2), nsmall = 2)` gives `\"0.00\"`.\n- **At most 15 significant digits.** When a format needs more digits, SAS rounds to 15 significant digits and pads with zeros. `sas_format()` does the same.\n\n::: {.callout-note}\n## Check your `DECIMALCONV=` setting\n\nThese rules hold for the default SAS system option `DECIMALCONV=COMPATIBLE`. With `DECIMALCONV=STDIEEE`, SAS formats the exact binary value, so 2.675 prints as `2.67`. `sas_format()` reproduces `COMPATIBLE` only.\n\n\n::: {.cell}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
x 8.2 with COMPATIBLE 8.2 with STDIEEE sas_format(x, 2)
1.005 1.01 1.00 1.01
2.675 2.68 2.67 2.68
99.995 100.00 100.00 100.00
\n\n`````\n:::\n:::\n\n:::\n\n## How close are the results?\n\nThe comparison ran SAS's `ROUND()` on about 23,000 test values with 59 rounding units, then ran each R option on the same doubles. The values were read into R bit for bit from the SAS data sets, so any difference comes from the rounding and not from the inputs. The test values include every value with one decimal place in [-100, 100], every value with three decimal places in [-3, 3], and values a few units in the last place away from halfway points.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Share of SAS `ROUND(x, unit)` results that each R option reproduces exactly.](rounding_files/figure-html/fig-round-agreement-1.png){#fig-round-agreement width=1200}\n:::\n:::\n\n\n`sas_round()` gives the same double as SAS for every value with up to three decimal places. The few differences are values of 1e15 or more, or values divided by a tiny unit such as `1e-15`. Those numbers have more than 15 significant digits, and SAS is not exact there either: `ROUND(1000000000000000.5, 0.5)` is 1000000000000001, although that value is already a multiple of 0.5.\n\nFor formats, `sas_format()` matches SAS's `32.d` output for 99.40% of 100,516 results. `sprintf()` matches 96.98%. The differences are values within a few units in the last place of a halfway point, and values shown with 15 or more digits, where SAS's own digits are not consistent.\n\n## Other SAS rounding functions\n\nsegue does not have functions for these yet. The closest R functions are:\n\n| SAS | R | Notes |\n|---|---|---|\n| `ROUNDE(x, unit)` | none | Rounds halves to even, like `round()`, but with SAS's fuzzing. |\n| `ROUNDZ(x, unit)` | none | No fuzzing. `ROUNDZ(2.675, 0.01)` is still 2.68 because SAS divides by the unit first. |\n| `INT(x)` | `trunc(x)` | SAS treats values within 1e-12 of an integer as that integer. |\n| `FLOOR(x)`, `CEIL(x)` | `floor(x)`, `ceiling(x)` | Same fuzzing as `INT()`. `FLOOR(1 - 1e-12)` is 1. |\n| `INTZ`, `FLOORZ`, `CEILZ` | `trunc()`, `floor()`, `ceiling()` | No fuzzing. Identical except for subnormal numbers, which SAS treats as 0. |\n\n::: {.callout-tip}\n## Typing numbers in R tests\n\nR's parser can turn some decimal text into a slightly different double than SAS does. For example, `1e300` in R is a few units in the last place away from SAS's `1e300`. If you compare R and SAS results in a test, read the SAS values from a `.sas7bdat` file with `haven::read_sas()` instead of typing them.\n:::\n", - "supporting": [ - "rounding_files" - ], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/comparisons/rounding/figure-html/fig-round-agreement-1.png b/_freeze/comparisons/rounding/figure-html/fig-round-agreement-1.png deleted file mode 100644 index f005494..0000000 Binary files a/_freeze/comparisons/rounding/figure-html/fig-round-agreement-1.png and /dev/null differ diff --git a/_freeze/reference/bin_prop_test/execute-results/html.json b/_freeze/reference/bin_prop_test/execute-results/html.json deleted file mode 100644 index 57fc030..0000000 --- a/_freeze/reference/bin_prop_test/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "6fab323389c31d7ecbf4221632ca8198", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Test a Single Binomial Proportion\"\n---\n\n\n\n[Source: `R/bin_prop_test.R`](https://github.com/posit-dev/segue/blob/main/R/bin_prop_test.R){.ref-source}\n\n## Description\n\nConducts a basic hypothesis test for a single Binomial proportion. This is a wrapper around functions such as `binom.test()` but takes a factor vector with two levels.\n\n\n## Usage\n\n```r\nbin_prop_test(y, ...)\n\n## Default S3 method:\nbin_prop_test(y, ...)\n\n## S3 method for class 'factor'\nbin_prop_test(\n y,\n method = c(\"exact\", \"exact_sas\", \"score\"),\n event_level = NULL,\n null_value = 0.5,\n alternative = \"two_sided\",\n ...\n)\n```\n\n## Arguments\n\n+-------------+-------------------------------------------------------------+\n| Arguments | Description |\n+=============+=============================================================+\n| y | A factor vector with two levels. |\n+-------------+-------------------------------------------------------------+\n| ... | Not currently used. |\n+-------------+-------------------------------------------------------------+\n| method | A single character string with possible values: |\n| | |\n| | - `\"exact\"`: An exact test via `binom.test()`. |\n| | - `\"exact_sas\"`: An exact test via `exact_binom_test_sas()` |\n| | that emulates SAS's `Proc Freq` results. |\n| | - `\"score\"`: An asymptotic score test via `prop.test()`. |\n+-------------+-------------------------------------------------------------+\n| event_level | A single character value for the level of the factor that |\n| | corresponds to the event of interest. The default is the |\n| | first factor level. |\n+-------------+-------------------------------------------------------------+\n| null_value | A single number in `[0, 1]` for the proportion under the |\n| | null hypothesis. |\n+-------------+-------------------------------------------------------------+\n| alternative | A character value indicating the alternative hypothesis and |\n| | must be one of `\"two_sided\"`, `\"greater\"`, or `\"lesser\"`. |\n+-------------+-------------------------------------------------------------+\n\n## Details\n\nThis function performs one of several Frequentist hypothesis tests on a single Binomial proportion.\n\n### `method = \"exact\"`\n\nR’s `binom.test()` implements the exact test described in Section 1.4 of Agresti (2012). Once the data have been transformed into the number of events and the total number of non-missing values, the code using default argument values is\n\n```r\nbinom.test(num_events, num_total, alternative = \"two.sided\", p = 0.5)\n```\n\nThere is no corresponding `Proc Freq` code; there are several methodological differences between the exact test produced by SAS and `binom.test()`. Using the terminology of Fay (2010):\n\n1. One-sided p-values. Both use the same tail sums, $P(X \\le x)$ and $P(X \\ge x)$.\n\n- `binom.test()` returns whichever tail you ask for.\n- `Proc Freq` keeps only the smaller tail, in variables `XPL_BIN` or `XPR_BIN`, and leaves the other variable missing.\n\n1. Two-sided p-values.\n\n- `binom.test()` uses the “minlike” method (short for “minimum likelihood”): it adds the probabilities of every outcome no more likely than the observed one.\n- SAS uses the “central” method: twice the smaller tail, capped at 1. The two agree only when $p_0 = 0.5$, where the null distribution is symmetric.\n\n1. Numerical calculation (not a definition difference).\n\n- SAS’s right tail behaves as if it were computed as $1 - P(X \\le x - 1)$. That subtraction leaves an absolute error of about 1e-14.\n- R computes the upper tail directly.\n\n### `method = \"exact_sas\"`\n\nThis method mimics the results produced by:\n\n```\nproc freq data={data set};\n tables {analysis column} / binomial;\n exact binomial;\nrun;\n```\n\nIn the terms of Fay (2010), `Proc Freq` uses the “central” method: twice the smaller tail, capped at 1. This is also called “doubling” or “TST” by Hirji (2006).\n\n- One-sided p-values: only the smaller of the two tails is reported. If the requested tail is the larger one, the p-value is `NA`, as it is missing in SAS.\n- Two-sided p-value: twice the smaller tail, capped at 1 (the “central” method).\n- The right tail is computed as $1 - P(X \\le x - 1)$, as SAS does, so very small right tails lose precision and can be exactly 0.\n\nThe results agree with `Proc Freq` to about 1e-13 but are not identical to the last bit, because R and SAS use different algorithms for the binomial distribution function.\n\nThe underlying R function for this method is `[binom_test_sas()]`, which gives more details for the comparison to SAS.\n\n### `method = \"score\"`\n\nThe score test produces a Z statistic that uses the null value to compute the variance in the denominator. To compute a two-sided p-value, compare the square of the Z statistic to a chi-squared distribution with a single degree of freedom. For a one-sided test, use the Z statistic and compare it to the appropriate standard normal tail.\n\nThis method’s defaults does not use a continuity correction (*for SAS compatibility*) and is is equivalent to\n\n```r\nprop.test(num_events, num_total, alternative = \"two.sided\", p = 0.5, correct = FALSE)\n```\n\nThe equivalent SAS code is\n\n```\nproc freq data={data set};\n tables {analysis column} / binomial(cl=score);\nrun;\n```\n\nThe SAS output data set has `Z_BIN` (the statistic), `P2_BIN` (two-sided p-value), `PL_BIN` (left-sided p-value) and `PR_BIN` (right-sided p-value). `Proc Freq` only reports one of the two one-sided p-values for each test: the one in the direction of the observed deviation. The other is missing.\n\n| Sign of z | `PL_BIN` (`less`) | `PR_BIN` (`greater`) | `P2_BIN` (`two.sided`) |\n|:---|:---|:---|:---|\n| z > 0 | missing | reported | reported |\n| z \\< 0 | reported | missing | reported |\n| z = 0 | reported (0.5) | missing | reported |\n\nThe reported one-sided p-value is always the smaller tail, so it is never above 0.5. The larger tail is never produced. In the results, 3,822 of 11,466 rows are missing a p-value. Each of them is a one-sided test that points away from the data. No two-sided test’s p-value is missing. Some examples:\n\n| events | total | null p | z | alternative | p_value |\n|:---|:---|:---|:---|:---|:---|\n| 1 | 2 | 0.01 | 6.96 | greater | 1.6e-12 |\n| 1 | 2 | 0.01 | 6.96 | less | missing |\n| 1 | 2 | 0.01 | 6.96 | two.sided | 3.3e-12 |\n| 1 | 50 | 0.25 | -3.76 | greater | missing |\n| 1 | 50 | 0.25 | -3.76 | less | 8.6e-05 |\n| 1 | 50 | 0.25 | -3.76 | two.sided | 1.73e-04 |\n\nTo assess the level of equivalence, each was tested at three null values (0.01, 0.25, 0.5) and three alternatives, which gives 11,466 tests per language. SAS has no value for 3,822 one-sided tests. The comparison drops those, leaving 7,644 tests: 3,822 two-sided, 2,897 greater and 925 lesser. R has no missing p-values.\n\nThe two methods showed good concordance, with absolute differences ranging from -1.2e-15 to 8.3e-16.\n\n\n## Value\n\nAn object with classes `\"bin_prop_test\"` and `\"segue_object\"` with elements\n\n- `code`: contains code in R and SAS for `translate()`.\n- `results`: the results,\n- `data_characteristics`: characteristics of the data.\n- `options`: records options that were used by the function.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncog_ability <- modeldata::ad_data$Class\nstr(cog_ability)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n Factor w/ 2 levels \"Impaired\",\"Control\": 2 2 2 2 2 1 2 2 2 1 ...\n```\n\n\n:::\n\n```{.r .cell-code}\ntest_res <- bin_prop_test(cog_ability)\ntest_res\n\n# Can be tidied to obtain a tibble of results:\ntidy(test_res)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 1 × 8\n estimate statistic p.value parameter conf.low conf.high method alternative\n \n1 0.273 91 5.86e-17 333 0.226 0.325 Exact bi… two.sided \n```\n\n\n:::\n:::\n\n\n## See Also\n\n`binom.test()`, `prop.test()`, `broom::tidy.htest()`\n\n\n## References\n\nAgresti, A. 2013. *Categorical Data Analysis*. John Wiley and Sons Inc., Hoboken.\n\nFay, M. 2010. “Two-Sided Exact Tests and Matching Confidence Intervals for Discrete Data.” *The R Journal* 2 (1): 53–58. [doi:10.32614/RJ-2010-008](https://doi.org/10.32614/RJ-2010-008).\n\nHirji, K. 2006. *Exact Analysis of Discrete Data*. Chapman and Hall/CRC.\n\nCAMIS Working Group page on the Binomial Test: \n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/reference/convert_alternative/execute-results/html.json b/_freeze/reference/convert_alternative/execute-results/html.json deleted file mode 100644 index 53cc252..0000000 --- a/_freeze/reference/convert_alternative/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "c180ad6119dcd5e262a3bb32c3950ee0", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Convert the Alternative Hypothesis to the Values Used by Stats\"\n---\n\n\n\n[Source: `R/alternative.R`](https://github.com/posit-dev/segue/blob/main/R/alternative.R){.ref-source}\n\n## Description\n\nFunctions in this package use the values `\"two_sided\"`, `\"greater\"`, and `\"lesser\"` for the alternative hypothesis. The functions in the stats package (e.g., `stats::binom.test()`) use `\"two.sided\"`, `\"greater\"`, and `\"less\"`. This helper validates the value and converts it.\n\n\n## Usage\n\n```r\nconvert_alternative(alternative, call = rlang::caller_env())\n```\n\n## Arguments\n\n+-------------+---------------------------------------------------+\n| Arguments | Description |\n+=============+===================================================+\n| alternative | A single character string: one of `\"two_sided\"`, |\n| | `\"greater\"`, or `\"lesser\"`. |\n+-------------+---------------------------------------------------+\n| call | The execution environment used in error messages. |\n+-------------+---------------------------------------------------+\n\n\n\n## Value\n\nA single character string: one of `\"two.sided\"`, `\"greater\"`, or `\"less\"`.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\nconvert_alternative(\"two_sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"two.sided\"\n```\n\n\n:::\n\n```{.r .cell-code}\nconvert_alternative(\"lesser\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"less\"\n```\n\n\n:::\n:::\n\n\n\n\n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/reference/sas_format/execute-results/html.json b/_freeze/reference/sas_format/execute-results/html.json deleted file mode 100644 index dbf48e6..0000000 --- a/_freeze/reference/sas_format/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "6f6aafa9851e875c2e030c72d7b5c89b", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Format Numbers the Same Way as SAS\"\n---\n\n\n\n[Source: `R/sas_round.R`](https://github.com/posit-dev/segue/blob/main/R/sas_round.R){.ref-source}\n\n## Description\n\n`sas_format()` formats numbers with a fixed number of decimal places so that the printed values match the SAS `w.d` format (e.g., `8.2`).\n\n\n## Usage\n\n```r\nsas_format(x, digits = 0, ...)\n```\n\n## Arguments\n\n+-----------+------------------------------------------------------------+\n| Arguments | Description |\n+===========+============================================================+\n| x | A numeric vector. |\n+-----------+------------------------------------------------------------+\n| digits | A single whole number between 0 and 15 for the number of |\n| | decimal places to show. As in `round()`, and unlike |\n| | `format()`, this is the number of decimal places and not |\n| | the number of significant digits. |\n+-----------+------------------------------------------------------------+\n| ... | Formatting options, as in `format()`: `width`, `justify`, |\n| | `trim`, `big.mark`, `big.interval`, `small.mark`, |\n| | `small.interval`, `decimal.mark`, and `scientific`. |\n| | Scientific notation is not used unless `scientific = TRUE` |\n| | is passed, in which case the rounded values are formatted |\n| | with `format(digits = 15)`. |\n+-----------+------------------------------------------------------------+\n\n## Details\n\nSAS formats do not round with the `ROUND()` function, so `sas_format()` does not use `sas_round()`. With the default `DECIMALCONV=COMPATIBLE` system option, SAS:\n\n- Rounds `x * 10^digits` half away from zero. Values within a relative 1e-16 of a halfway point (about one unit in the last place) are treated as halfway, so `2.675` (stored as slightly less than 2.675) is shown as `2.68` with two decimal places.\n- Shows at most 15 significant digits. When more digits are needed, the number is first rounded to 15 significant digits and zeros are shown after them (`sas_format(123456789.123456, 10)` is `\"123456789.1234560000\"`).\n- Keeps the sign of negative numbers that round to zero, so `-0.4` is shown as `-0` and `-0.001` as `-0.00` with two decimal places.\n- Treats subnormal numbers (smaller than `.Machine$double.xmin`) as zero.\n\nThe tolerance is much smaller than the one used by `ROUND()`: `0.4999999999999982` is shown as `0`, but `sas_round(0.4999999999999982)` is 1. So `sas_format(x, digits)` can differ from `format(sas_round(x, digits), nsmall = digits)`.\n\nThese results were compared with about 100,000 results of the SAS `32.d` formats (SAS Viya, `V.04.00M0P060826`), including every value with up to four decimal places in a range around zero. They are identical except within a few units in the last place of a halfway point, where SAS's tolerance varies from value to value, and when 15 or more digits are shown, where SAS's digits are not consistent (`1/3` is shown as `0.333333333333330` with 15 decimal places).\n\nWith `DECIMALCONV=STDIEEE`, SAS formats the exact binary value instead (`2.675` is shown as `2.67`); `sas_format()` does not replicate that.\n\n\n## Value\n\nA character vector the same length as `x`. As with `format()`, the values share a common width and names are kept.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\nformat(round(1.005, 2), nsmall = 2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"1.00\"\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_format(1.005, digits = 2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"1.01\"\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_format(c(0.5, 1.5, 2.5, -2.5))\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \" 1\" \" 2\" \" 3\" \"-3\"\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_format(-0.4)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"-0\"\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_format(1234567.891, digits = 2, big.mark = \",\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"1,234,567.89\"\n```\n\n\n:::\n:::\n\n\n## See Also\n\n`sas_round()`\n\n\n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/reference/sas_proc/execute-results/html.json b/_freeze/reference/sas_proc/execute-results/html.json deleted file mode 100644 index 8dda900..0000000 --- a/_freeze/reference/sas_proc/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "689d3836ca6d26cbdbaa90ae865f8bf6", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Write SAS Code for a Procedure\"\n---\n\n\n\n[Source: `R/sas-proc.R`](https://github.com/posit-dev/segue/blob/main/R/sas-proc.R){.ref-source}\n\n## Description\n\nWrites the SAS code for one statistical procedure (proc) as text. Each statement is one argument: the argument name is the SAS keyword, and the value is the rest of the statement, written as you would write it in SAS. The most common statements, such as `model` and `class`, have their own arguments. Any other statement can also be passed by name.\n\n\n## Usage\n\n```r\nsas_proc(\n proc,\n ...,\n class = NULL,\n model = NULL,\n tables = NULL,\n var = NULL,\n by = NULL,\n where = NULL,\n data = \"&dsn\",\n options = NULL\n)\n```\n\n## Arguments\n\n+------------------+-------------------------------------------------------------+\n| Arguments | Description |\n+==================+=============================================================+\n| proc | A single string with the name of the proc, such as `\"freq\"` |\n| | or `\"mixed\"`. Any proc name works, but only the procs |\n| | listed in \"Default statements\" get default statements. |\n+------------------+-------------------------------------------------------------+\n| ... | Other statements, passed by name, such as `lsmeans`, |\n| | `strata`, or `output`. Their values work the same way as |\n| | for `class` and the other common statements. Use the same |\n| | name more than once to repeat a statement. |\n+------------------+-------------------------------------------------------------+\n| class, model, | Common statements. Each value is a string, or a character |\n| tables, var, by, | vector that is joined with spaces. Use a slash for |\n| where | statement options, as in SAS, for example `model = \"mpg = |\n| | wt / clb\"`. If you do not pass a statement, the proc |\n| | default is used, if there is one. Pass `NULL` to leave the |\n| | statement out. |\n+------------------+-------------------------------------------------------------+\n| data | A single string with the data set name, or `NULL` to leave |\n| | out `data=`. The default is the `&dsn` placeholder. The |\n| | data set must exist in SAS when you run the code, for |\n| | example after you import `mtcars` from a CSV file. |\n+------------------+-------------------------------------------------------------+\n| options | A character or numeric vector of options for the `proc` |\n| | line. Unnamed values are written as they are, and named |\n| | values are written as `name=value`. For example, `c(\"n\", |\n| | \"mean\", alpha = 0.05)` gives `n mean alpha=0.05`. |\n+------------------+-------------------------------------------------------------+\n\n## Details\n\nStatements are written in this order, no matter the order you pass them:\n\n1. `class`\n1. The main statement: `tables`, `var`, `model`, `time`, or `paired`\n1. All other statements, in the order you pass them\n1. `by`, `where`, `weight`, `freq`, and `id`\n1. `output`\n\nThe code ends with `quit;` for the interactive procs (`anova`, `catmod`, `glm`, and `reg`), and with `run;` for all other procs.\n\n## Default statements\n\nIf you leave out a statement that the proc needs, `sas_proc()` adds it. Default statements use SAS macro variables, such as `&row`, as placeholders for the variable names.\n\n| Proc | Default statements |\n|:---|:---|\n| `freq` | `tables &row*&col` |\n| `means`, `univariate` | `var &var` |\n| `ttest` | `class &group`, `var &var` |\n| `reg` | `model &outcome = &x` |\n| `glm` | `class &group`, `model &outcome = &group` |\n| `logistic` | `model &outcome(event='1') = &x` |\n| `mixed` | `class &trt &subj`, `model &outcome = &trt` |\n| `lifetest` | `time &time*&censor(0)` |\n| `phreg` | `model &time*&censor(0) = &trt` |\n\nOther procs have no default statements. To leave out a default statement, set it to `NULL`, for example `class = NULL`.\n\n\n## Value\n\nAn object of class `sas_proc`. Printing it shows the code with syntax colors. Use `as.character()` to get the code as plain text, for example to write it to a `.sas` file.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Default statements with placeholders\nsas_proc(\"freq\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nproc freq data=&dsn;\n tables &row*&col;\nrun;\n```\n\n\n:::\n\n```{.r .cell-code}\n# lm(mpg ~ wt + hp, data = mtcars), with confidence limits\nsas_proc(\"reg\", data = \"mtcars\", model = \"mpg = wt hp / clb\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nproc reg data=mtcars;\n model mpg = wt hp / clb;\nquit;\n```\n\n\n:::\n\n```{.r .cell-code}\n# t.test(mpg ~ am, data = mtcars, conf.level = 0.90)\nsas_proc(\n \"ttest\",\n data = \"mtcars\",\n class = \"am\",\n var = \"mpg\",\n options = c(alpha = 0.1)\n)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nproc ttest data=mtcars alpha=0.1;\n class am;\n var mpg;\nrun;\n```\n\n\n:::\n:::\n\n\n\n\n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/reference/sas_round/execute-results/html.json b/_freeze/reference/sas_round/execute-results/html.json deleted file mode 100644 index be78b7b..0000000 --- a/_freeze/reference/sas_round/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "1e5c82a78ca2ed5bf68edb86deb242fd", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Round Numbers the Same Way as SAS\"\n---\n\n\n\n[Source: `R/sas_round.R`](https://github.com/posit-dev/segue/blob/main/R/sas_round.R){.ref-source}\n\n## Description\n\n`sas_round()` replicates the SAS `ROUND()` function.\n\n\n## Usage\n\n```r\nsas_round(x, digits = 0, unit = 10^-digits)\n```\n\n## Arguments\n\n+-----------+-------------------------------------------------------------+\n| Arguments | Description |\n+===========+=============================================================+\n| x | A numeric vector. |\n+-----------+-------------------------------------------------------------+\n| digits | A single whole number between -15 and 15 for the number of |\n| | decimal places, as in `round()`. Negative values round to a |\n| | power of ten (e.g., `digits = -2` rounds to the nearest |\n| | hundred). |\n+-----------+-------------------------------------------------------------+\n| unit | A single positive number for the rounding unit (the |\n| | `rounding-unit` argument of the SAS function). The default, |\n| | `10^-digits`, is determined by `digits`. Use `unit` for |\n| | units that are not powers of ten, such as 0.25 or 1/7. |\n| | Supply only one of `digits` and `unit`. As in SAS, units at |\n| | or below `.Machine$double.xmin` (about 2.2e-308) are not |\n| | allowed. |\n+-----------+-------------------------------------------------------------+\n\n## Details\n\nR's `round()` and SAS's `ROUND()` can give different answers for two reasons:\n\n- When a value is halfway between two multiples of `unit`, `round()` returns the even multiple (e.g., `round(2.5)` is 2), while SAS returns the multiple farther from zero (3).\n- Many decimal values do not have an exact binary representation. For example, `1.005` is stored as slightly less than 1.005, so `round(1.005, 2)` is 1. SAS treats values that are within a small relative tolerance of the halfway point as being halfway (called \"fuzzing\"), so `ROUND(1.005, 0.01)` is 1.01.\n\n`sas_round()` follows the algorithm described in the SAS documentation:\n\n- `x / unit` is rounded half away from zero, after adding a tolerance of `min(1e-6, abs(x / unit) * 1e-12)` to its absolute value.\n- When `unit` is the reciprocal of an integer (e.g., 0.01 or 1/7), the rounded value of `x / unit` is divided by that integer so that the result matches the decimal value (`sas_round(0.33, 0.1)` is identical to `0.3`). As in SAS, `1 / unit` must be within 16 units in the last place of the integer.\n- When `unit` is not an integer but has at most four decimal places, the result is computed with integer arithmetic so that it also matches the decimal value.\n- Otherwise, the result is the rounded integer times `unit`. When that product is within a few units in the last place of a decimal with at most four decimal places, the decimal value is returned instead (`sas_round(0.0015, unit = 0.00015)` is identical to `0.0015`).\n- When `abs(x / unit)` is at least 2\\^52, `x` is returned unchanged.\n\nMissing values are returned as missing.\n\nThese results were compared with about 70,000 results of the SAS `ROUND()` function (SAS Viya, `V.04.00M0P060826`), including every value with up to three decimal places between -3 and 3, and every case in the package's tests. They are identical except when `abs(x)` or `abs(x / unit)` is 1e15 or more. There, values have more than 15 significant digits and SAS is not exact either: for example, `ROUND(1000000000000000.5, 0.5)` is 1000000000000001, although the value is already a multiple of 0.5.\n\n\n## Value\n\nA double vector the same length as `x`.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\nx <- c(0.5, 1.5, 2.5, -2.5)\nround(x)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 0 2 2 -2\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_round(x)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 1 2 3 -3\n```\n\n\n:::\n\n```{.r .cell-code}\nround(1.005, digits = 2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 1\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_round(1.005, digits = 2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 1.01\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_round(1234.5, digits = -2)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 1200\n```\n\n\n:::\n\n```{.r .cell-code}\nsas_round(pi, unit = 1 / 7) == 22 / 7\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] TRUE\n```\n\n\n:::\n:::\n\n\n\n\n## References\n\nSAS Institute Inc. \"ROUND Function.\" *SAS Functions and CALL Routines: Reference*.\n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/reference/tidy.segue_object/execute-results/html.json b/_freeze/reference/tidy.segue_object/execute-results/html.json deleted file mode 100644 index 9b70391..0000000 --- a/_freeze/reference/tidy.segue_object/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "f398f5eba76d7ddc437d5e8e40c2627f", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Turn a segue Object into a Tidy Tibble\"\n---\n\n\n\n[Source: `R/segue.R`](https://github.com/posit-dev/segue/blob/main/R/segue.R){.ref-source}\n\n## Description\n\nThis method tidies the original result, if it can.\n\n\n## Usage\n\n```r\n## S3 method for class 'segue_object'\ntidy(x, ...)\n```\n\n## Arguments\n\n+-----------+-----------------------------------------------------------+\n| Arguments | Description |\n+===========+===========================================================+\n| x | An object to be converted into a tidy `tibble::tibble()`. |\n+-----------+-----------------------------------------------------------+\n| ... | Additional arguments to tidying method. |\n+-----------+-----------------------------------------------------------+\n\n\n\n## Value\n\nA tibble.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncog_ability <- modeldata::ad_data$Class\ntest_res <- bin_prop_test(cog_ability)\ntidy(test_res)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 1 × 8\n estimate statistic p.value parameter conf.low conf.high method alternative\n \n1 0.273 91 5.86e-17 333 0.226 0.325 Exact bi… two.sided \n```\n\n\n:::\n:::\n\n\n\n\n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/reference/translate/execute-results/html.json b/_freeze/reference/translate/execute-results/html.json deleted file mode 100644 index 9d49f7c..0000000 --- a/_freeze/reference/translate/execute-results/html.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "hash": "972860b6119335be75febe71e00ec88e", - "result": { - "engine": "knitr", - "markdown": "---\ntitle: \"Show Code in R and SAS for an Analysis\"\n---\n\n\n\n[Source: `R/translate.R`](https://github.com/posit-dev/segue/blob/main/R/translate.R){.ref-source}\n\n## Description\n\nShow Code in R and SAS for an Analysis\n\n\n## Usage\n\n```r\ntranslate(x, ...)\n\n## Default S3 method:\ntranslate(x, ...)\n\n## S3 method for class 'segue_object'\ntranslate(x, ...)\n```\n\n## Arguments\n\n+-----------+--------------------+\n| Arguments | Description |\n+===========+====================+\n| x | An object |\n+-----------+--------------------+\n| ... | Not currently used |\n+-----------+--------------------+\n\n\n\n## Value\n\n`x` invisibly.\n\n\n## Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncog_ability <- modeldata::ad_data$Class\nstr(cog_ability)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n Factor w/ 2 levels \"Impaired\",\"Control\": 2 2 2 2 2 1 2 2 2 1 ...\n```\n\n\n:::\n\n```{.r .cell-code}\ntest_res <- bin_prop_test(cog_ability)\ntranslate(test_res)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nstats::binom.test(x = 91L, n = 333L, alternative = \"two.sided\", \n p = 0.5)\n```\n\n\n:::\n:::\n\n\n\n\n", - "supporting": [], - "filters": [ - "rmarkdown/pagebreak.lua" - ], - "includes": {}, - "engineDependencies": {}, - "preserve": {}, - "postProcess": true - } -} \ No newline at end of file diff --git a/_freeze/site_libs/clipboard/clipboard.min.js b/_freeze/site_libs/clipboard/clipboard.min.js deleted file mode 100644 index 1103f81..0000000 --- a/_freeze/site_libs/clipboard/clipboard.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * clipboard.js v2.0.11 - * https://clipboardjs.com/ - * - * Licensed MIT © Zeno Rocha - */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return b}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),r=n.n(e);function c(t){try{return document.execCommand(t)}catch(t){return}}var a=function(t){t=r()(t);return c("cut"),t};function o(t,e){var n,o,t=(n=t,o="rtl"===document.documentElement.getAttribute("dir"),(t=document.createElement("textarea")).style.fontSize="12pt",t.style.border="0",t.style.padding="0",t.style.margin="0",t.style.position="absolute",t.style[o?"right":"left"]="-9999px",o=window.pageYOffset||document.documentElement.scrollTop,t.style.top="".concat(o,"px"),t.setAttribute("readonly",""),t.value=n,t);return e.container.appendChild(t),e=r()(t),c("copy"),t.remove(),e}var f=function(t){var e=10?setTimeout((function(){e(r,n,s)}),1):(t.update(),n(s))}}},"./src/filter.js":function(t){t.exports=function(t){return t.handlers.filterStart=t.handlers.filterStart||[],t.handlers.filterComplete=t.handlers.filterComplete||[],function(e){if(t.trigger("filterStart"),t.i=1,t.reset.filter(),void 0===e)t.filtered=!1;else{t.filtered=!0;for(var r=t.items,n=0,s=r.length;nv.page,a=new g(t[s],void 0,n),v.items.push(a),r.push(a)}return v.update(),r}m(t.slice(0),e)}},this.show=function(t,e){return this.i=t,this.page=e,v.update(),v},this.remove=function(t,e,r){for(var n=0,s=0,i=v.items.length;s-1&&r.splice(n,1),v},this.trigger=function(t){for(var e=v.handlers[t].length;e--;)v.handlers[t][e](v);return v},this.reset={filter:function(){for(var t=v.items,e=t.length;e--;)t[e].filtered=!1;return v},search:function(){for(var t=v.items,e=t.length;e--;)t[e].found=!1;return v}},this.update=function(){var t=v.items,e=t.length;v.visibleItems=[],v.matchingItems=[],v.templater.clear();for(var r=0;r=v.i&&v.visibleItems.lengthe},innerWindow:function(t,e,r){return t>=e-r&&t<=e+r},dotted:function(t,e,r,n,s,i,a){return this.dottedLeft(t,e,r,n,s,i)||this.dottedRight(t,e,r,n,s,i,a)},dottedLeft:function(t,e,r,n,s,i){return e==r+1&&!this.innerWindow(e,s,i)&&!this.right(e,n)},dottedRight:function(t,e,r,n,s,i,a){return!t.items[a-1].values().dotted&&(e==n&&!this.innerWindow(e,s,i)&&!this.right(e,n))}};return function(e){var n=new i(t.listContainer.id,{listClass:e.paginationClass||"pagination",item:e.item||"
  • ",valueNames:["page","dotted"],searchClass:"pagination-search-that-is-not-supposed-to-exist",sortClass:"pagination-sort-that-is-not-supposed-to-exist"});s.bind(n.listContainer,"click",(function(e){var r=e.target||e.srcElement,n=t.utils.getAttribute(r,"data-page"),s=t.utils.getAttribute(r,"data-i");s&&t.show((s-1)*n+1,n)})),t.on("updated",(function(){r(n,e)})),r(n,e)}}},"./src/parse.js":function(t,e,r){t.exports=function(t){var e=r("./src/item.js")(t),n=function(r,n){for(var s=0,i=r.length;s0?setTimeout((function(){e(r,s)}),1):(t.update(),t.trigger("parseComplete"))};return t.handlers.parseComplete=t.handlers.parseComplete||[],function(){var e=function(t){for(var e=t.childNodes,r=[],n=0,s=e.length;n]/g.exec(t)){var e=document.createElement("tbody");return e.innerHTML=t,e.firstElementChild}if(-1!==t.indexOf("<")){var r=document.createElement("div");return r.innerHTML=t,r.firstElementChild}}},a=function(e,r,n){var s=void 0,i=function(e){for(var r=0,n=t.valueNames.length;r=1;)t.list.removeChild(t.list.firstChild)},function(){var r;if("function"!=typeof t.item){if(!(r="string"==typeof t.item?-1===t.item.indexOf("<")?document.getElementById(t.item):i(t.item):s()))throw new Error("The list needs to have at least one item on init otherwise you'll have to add a template.");r=n(r,t.valueNames),e=function(){return r.cloneNode(!0)}}else e=function(e){var r=t.item(e);return i(r)}}()};t.exports=function(t){return new e(t)}},"./src/utils/classes.js":function(t,e,r){var n=r("./src/utils/index-of.js"),s=/\s+/;Object.prototype.toString;function i(t){if(!t||!t.nodeType)throw new Error("A DOM element reference is required");this.el=t,this.list=t.classList}t.exports=function(t){return new i(t)},i.prototype.add=function(t){if(this.list)return this.list.add(t),this;var e=this.array();return~n(e,t)||e.push(t),this.el.className=e.join(" "),this},i.prototype.remove=function(t){if(this.list)return this.list.remove(t),this;var e=this.array(),r=n(e,t);return~r&&e.splice(r,1),this.el.className=e.join(" "),this},i.prototype.toggle=function(t,e){return this.list?(void 0!==e?e!==this.list.toggle(t,e)&&this.list.toggle(t):this.list.toggle(t),this):(void 0!==e?e?this.add(t):this.remove(t):this.has(t)?this.remove(t):this.add(t),this)},i.prototype.array=function(){var t=(this.el.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(s);return""===t[0]&&t.shift(),t},i.prototype.has=i.prototype.contains=function(t){return this.list?this.list.contains(t):!!~n(this.array(),t)}},"./src/utils/events.js":function(t,e,r){var n=window.addEventListener?"addEventListener":"attachEvent",s=window.removeEventListener?"removeEventListener":"detachEvent",i="addEventListener"!==n?"on":"",a=r("./src/utils/to-array.js");e.bind=function(t,e,r,s){for(var o=0,l=(t=a(t)).length;o32)return!1;var a=n,o=function(){var t,r={};for(t=0;t=p;b--){var j=o[t.charAt(b-1)];if(C[b]=0===m?(C[b+1]<<1|1)&j:(C[b+1]<<1|1)&j|(v[b+1]|v[b])<<1|1|v[b+1],C[b]&d){var x=l(m,b-1);if(x<=u){if(u=x,!((c=b-1)>a))break;p=Math.max(1,2*a-c)}}}if(l(m+1,a)>u)break;v=C}return!(c<0)}},"./src/utils/get-attribute.js":function(t){t.exports=function(t,e){var r=t.getAttribute&&t.getAttribute(e)||null;if(!r)for(var n=t.attributes,s=n.length,i=0;i=48&&t<=57}function i(t,e){for(var i=(t+="").length,a=(e+="").length,o=0,l=0;o=i&&l=a?-1:l>=a&&o=i?1:i-a}i.caseInsensitive=i.i=function(t,e){return i((""+t).toLowerCase(),(""+e).toLowerCase())},Object.defineProperties(i,{alphabet:{get:function(){return e},set:function(t){r=[];var s=0;if(e=t)for(;s { - // category is URI encoded in EJS template for UTF-8 support - category = decodeURIComponent(atob(category)); - if (categoriesLoaded) { - activateCategory(category); - setCategoryHash(category); - } -}; - -window["quarto-listing-loaded"] = () => { - // Process any existing hash - const hash = getHash(); - - if (hash) { - // If there is a category, switch to that - if (hash.category) { - // category hash are URI encoded so we need to decode it before processing - // so that we can match it with the category element processed in JS - activateCategory(decodeURIComponent(hash.category)); - } - // Paginate a specific listing - const listingIds = Object.keys(window["quarto-listings"]); - for (const listingId of listingIds) { - const page = hash[getListingPageKey(listingId)]; - if (page) { - showPage(listingId, page); - } - } - } - - const listingIds = Object.keys(window["quarto-listings"]); - for (const listingId of listingIds) { - // The actual list - const list = window["quarto-listings"][listingId]; - - // Update the handlers for pagination events - refreshPaginationHandlers(listingId); - - // Render any visible items that need it - renderVisibleProgressiveImages(list); - - // Whenever the list is updated, we also need to - // attach handlers to the new pagination elements - // and refresh any newly visible items. - list.on("updated", function () { - renderVisibleProgressiveImages(list); - setTimeout(() => refreshPaginationHandlers(listingId)); - - // Show or hide the no matching message - toggleNoMatchingMessage(list); - }); - } -}; - -window.document.addEventListener("DOMContentLoaded", function (_event) { - // Attach click handlers to categories - const categoryEls = window.document.querySelectorAll( - ".quarto-listing-category .category" - ); - - for (const categoryEl of categoryEls) { - // category needs to support non ASCII characters - const category = decodeURIComponent( - atob(categoryEl.getAttribute("data-category")) - ); - categoryEl.onclick = () => { - activateCategory(category); - setCategoryHash(category); - }; - } - - // Attach a click handler to the category title - // (there should be only one, but since it is a class name, handle N) - const categoryTitleEls = window.document.querySelectorAll( - ".quarto-listing-category-title" - ); - for (const categoryTitleEl of categoryTitleEls) { - categoryTitleEl.onclick = () => { - activateCategory(""); - setCategoryHash(""); - }; - } - - categoriesLoaded = true; -}); - -function toggleNoMatchingMessage(list) { - const selector = `#${list.listContainer.id} .listing-no-matching`; - const noMatchingEl = window.document.querySelector(selector); - if (noMatchingEl) { - if (list.visibleItems.length === 0) { - noMatchingEl.classList.remove("d-none"); - } else { - if (!noMatchingEl.classList.contains("d-none")) { - noMatchingEl.classList.add("d-none"); - } - } - } -} - -function setCategoryHash(category) { - setHash({ category }); -} - -function setPageHash(listingId, page) { - const currentHash = getHash() || {}; - currentHash[getListingPageKey(listingId)] = page; - setHash(currentHash); -} - -function getListingPageKey(listingId) { - return `${listingId}-page`; -} - -function refreshPaginationHandlers(listingId) { - const listingEl = window.document.getElementById(listingId); - const paginationEls = listingEl.querySelectorAll( - ".pagination li.page-item:not(.disabled) .page.page-link" - ); - for (const paginationEl of paginationEls) { - paginationEl.onclick = (sender) => { - setPageHash(listingId, sender.target.getAttribute("data-i")); - showPage(listingId, sender.target.getAttribute("data-i")); - return false; - }; - } -} - -function renderVisibleProgressiveImages(list) { - // Run through the visible items and render any progressive images - for (const item of list.visibleItems) { - const itemEl = item.elm; - if (itemEl) { - const progressiveImgs = itemEl.querySelectorAll( - `img[${kProgressiveAttr}]` - ); - for (const progressiveImg of progressiveImgs) { - const srcValue = progressiveImg.getAttribute(kProgressiveAttr); - if (srcValue) { - progressiveImg.setAttribute("src", srcValue); - } - progressiveImg.removeAttribute(kProgressiveAttr); - } - } - } -} - -function getHash() { - // Hashes are of the form - // #name:value|name1:value1|name2:value2 - const currentUrl = new URL(window.location); - const hashRaw = currentUrl.hash ? currentUrl.hash.slice(1) : undefined; - return parseHash(hashRaw); -} - -const kAnd = "&"; -const kEquals = "="; - -function parseHash(hash) { - if (!hash) { - return undefined; - } - const hasValuesStrs = hash.split(kAnd); - const hashValues = hasValuesStrs - .map((hashValueStr) => { - const vals = hashValueStr.split(kEquals); - if (vals.length === 2) { - return { name: vals[0], value: vals[1] }; - } else { - return undefined; - } - }) - .filter((value) => { - return value !== undefined; - }); - - const hashObj = {}; - hashValues.forEach((hashValue) => { - hashObj[hashValue.name] = decodeURIComponent(hashValue.value); - }); - return hashObj; -} - -function makeHash(obj) { - return Object.keys(obj) - .map((key) => { - return `${key}${kEquals}${obj[key]}`; - }) - .join(kAnd); -} - -function setHash(obj) { - const hash = makeHash(obj); - window.history.pushState(null, null, `#${hash}`); -} - -function showPage(listingId, page) { - const list = window["quarto-listings"][listingId]; - if (list) { - list.show((page - 1) * list.page + 1, list.page); - } -} - -function activateCategory(category) { - // Deactivate existing categories - const activeEls = window.document.querySelectorAll( - ".quarto-listing-category .category.active" - ); - for (const activeEl of activeEls) { - activeEl.classList.remove("active"); - } - - // Activate this category - const categoryEl = window.document.querySelector( - `.quarto-listing-category .category[data-category='${btoa( - encodeURIComponent(category) - )}']` - ); - if (categoryEl) { - categoryEl.classList.add("active"); - } - - // Filter the listings to this category - filterListingCategory(category); -} - -function filterListingCategory(category) { - const listingIds = Object.keys(window["quarto-listings"]); - for (const listingId of listingIds) { - const list = window["quarto-listings"][listingId]; - if (list) { - if (category === "") { - // resets the filter - list.filter(); - } else { - // filter to this category - list.filter(function (item) { - const itemValues = item.values(); - if (itemValues.categories !== null) { - const categories = decodeURIComponent( - atob(itemValues.categories) - ).split(","); - return categories.includes(category); - } else { - return false; - } - }); - } - } - } -}