Add usage vignette for htest #18
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| @@ -10,3 +10,246 @@ vignette: | | |||
| %\VignetteEngine{knitr::rmarkdown} | |||
| \usepackage[utf8]{inputenc} | |||
| --- | |||
There was a problem hiding this comment.
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}
---| knitr::opts_chunk$set( | ||
| collapse = TRUE, | ||
| comment = "#>" | ||
| ) |
There was a problem hiding this comment.
Kindly add:
fansi::set_knit_hooks(knitr::knit_hooks)after line 18
|
|
||
| ## 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. |
There was a problem hiding this comment.
When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote".
|
|
||
| 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 |
There was a problem hiding this comment.
Use panel tabset to showcase the comparison.
|
|
||
| ### 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: |
There was a problem hiding this comment.
When texts have special characters, e.g. function calls like prepare_test(), they must have backticks (`) which acts like a "quote".
| ## 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is better not written like this. Preferably you don't make it like a table. Better modify this or remove this part.
| ```{r} | ||
| sleep |> | ||
| define_model(extra ~ 1) |> | ||
| prepare_test(TTEST) |> | ||
| conclude() | ||
| ``` | ||
|
|
||
| ```{r} | ||
| sleep |> | ||
| define_model(extra ~ group + 1) |> | ||
| prepare_test(TTEST) |> | ||
| conclude() | ||
| ``` |
There was a problem hiding this comment.
Something like this uses panel tabset.
| 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. |
There was a problem hiding this comment.
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.
| ### 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. |
There was a problem hiding this comment.
The whole part of this is better being incremented or something in a panel tabset.
|
|
||
| ### 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: |
There was a problem hiding this comment.
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.
vignettes/usage/htest.Rmd