Skip to content

Add usage vignette for htest #18

Open
rhiooo wants to merge 1 commit into
s7-stats:masterfrom
rhiooo:master
Open

Add usage vignette for htest #18
rhiooo wants to merge 1 commit into
s7-stats:masterfrom
rhiooo:master

Conversation

@rhiooo

@rhiooo rhiooo commented Jun 19, 2026

Copy link
Copy Markdown
  • Document the prepare_test()/via()/state_null()/conclude() pipeline
  • Cover TTEST (x_by, formula, pairwise) including boot/permute/contrast/multi variants and MU() claims
  • Cover CORTEST (rel, formula) including Spearman/Kendall variants and RHO() claims
  • Cover P_TEST (default, "prop" variant) including PI() claims and scaled claims
  • Document update() for recalibrating a lazy test pipeline
  • Mirror structure/tone of vignettes/usage/anova-mod.Rmd

vignettes/usage/htest.Rmd

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread vignettes/usage/htest.Rmd
@@ -10,3 +10,246 @@ vignette: |
%\VignetteEngine{knitr::rmarkdown}
\usepackage[utf8]{inputenc}
---

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly modify the YAML header. Must be:

---
title: "Example usages of {statim}"
subtitle: "Hypothesis Testing"
description: "Example use-cases"
output: 
    rmarkdown::html_vignette:
        toc: true
vignette: |
    %\VignetteIndexEntry{Hypothesis testing with statim}
    %\VignetteEngine{knitr::rmarkdown}
    \usepackage[utf8]{inputenc}
---

Comment thread vignettes/usage/htest.Rmd
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly add:

fansi::set_knit_hooks(knitr::knit_hooks)

after line 18

Comment thread vignettes/usage/htest.Rmd

## What inference am I declaring?

A hypothesis test in {statim} is built the same way a model is: a def_model (or expanded_model) is bound to a test specification rather than a model specification. prepare_test() attaches that specification, producing a test_lazy, which conclude() resolves into a cld_exec.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote".

Comment thread vignettes/usage/htest.Rmd

Every test object returned by conclude() stores a structured result class inheriting from class_stat_infer, so auto_tidy() and print() work the same way regardless of which test produced it.

## T-Test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use panel tabset to showcase the comparison.

Comment thread vignettes/usage/htest.Rmd

### One-sample and formula syntax

The formula implementation reads the response from the left-hand side. A bare ~ 1 runs a one-sample test against .mu; a grouping term runs the two-sample test; combining both runs each in turn:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote".

Comment thread vignettes/usage/htest.Rmd
Comment on lines +245 to +255
## Summary of the pipeline

| Step | Function | What it does |
|---|---|---|
| Define | define_model(formula) or define_model(prop(x, n)), etc. | Binds the model ID and data into a def_model |
| Prepare | prepare_test(TTEST), prepare_test(CORTEST), prepare_test(P_TEST) | Attaches the test spec lazily, returns test_lazy |
| Select method | via("boot"), via("contrast"), via("prop"), ... | Switches to a registered variant implementation |
| State a hypothesis | state_null(MU(...) ...), state_null(RHO(...) ...), state_null(PI() ...) | Declares the null hypothesis instead of passing raw arguments |
| Recalibrate | update(...) | Changes pending arguments without changing method or model ID |
| Fit | conclude() | Executes; returns cld_exec |
| Tidy | auto_tidy() | Extracts a tidy tibble from the result class | No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote". At least include the text which refers to the object produced by the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better not written like this. Preferably you don't make it like a table. Better modify this or remove this part.

Comment thread vignettes/usage/htest.Rmd
Comment on lines +62 to +74
```{r}
sleep |>
define_model(extra ~ 1) |>
prepare_test(TTEST) |>
conclude()
```

```{r}
sleep |>
define_model(extra ~ group + 1) |>
prepare_test(TTEST) |>
conclude()
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this uses panel tabset.

Comment thread vignettes/usage/htest.Rmd
conclude()
```

The formula path returns a tibble of t.test() results rather than a class_ttest_two, since it can hold a mixed set of one- and two-sample tests in a single call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote". At least include the text which refers to the object produced by the code.

Comment thread vignettes/usage/htest.Rmd
Comment on lines +78 to +98
### Variants: boot, permute, contrast, multi

via() swaps in an alternative implementation while keeping the rest of the pipeline intact. Each variant reads its own arguments:

```{r}
sleep |>
define_model(x_by(extra, group)) |>
prepare_test(TTEST) |>
via("boot", n = 2000) |>
conclude()
```

```{r}
sleep |>
define_model(x_by(extra, group)) |>
prepare_test(TTEST) |>
via("permute", n = 2000) |>
conclude()
```

"contrast" runs a Welch-Satterthwaite linear contrast test and is the variant used whenever state_null() carries weighted MU() terms (see below). "multi" accepts more than one grouping variable in a single call, returning one row of class_ttest_two per grouping variable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole part of this is better being incremented or something in a panel tabset.

Comment thread vignettes/usage/htest.Rmd

### Variants: boot, permute, contrast, multi

via() swaps in an alternative implementation while keeping the rest of the pipeline intact. Each variant reads its own arguments:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote". At least include the text which refers to the object produced by the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants