--- title: "Get started with tidyvisor" vignette: > %\VignetteIndexEntry{Get started with tidyvisor} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ``` tidyvisor is a statistical advisor: the chief statistician of a study. It advises at every stage: | Stage | Ask | tidyvisor gives | |---|---|---| | Planning | `tv_practice("plan")` | good practice: question, unit of replication, randomisation, pre-registration | | Before fieldwork | `tv_power(...)` | samples, traps or sites needed | | With the data | `tidyvisor(data, ...)` | a data audit, the analysis, the test and the code | | With the result | `tidyvisor(result)` | the result in plain sentences, the diagnostics and what to do next | | Reporting | `tv_practice("report", field = ...)` | the reporting guideline and what to share | It always gives its reasons, so its advice can be checked and overruled. ```{r} library(tidyvisor) ``` ## Plan the study ```{r} tv_practice("plan", design = "experiment") ``` How many replicates? Suppose a difference of 5 units matters and the standard deviation is about 8: ```{r} tv_power("two_groups", delta = 5, sd = 8)$checks ``` ## Audit the data Give the data, and as much of the design as you know. The `ChickWeight` data record the weight of 50 chicks on four diets, weighed repeatedly: ```{r} tidyvisor(ChickWeight, question = "design", response = "weight", group = "Diet", unit = "Chick", time = "Time") ``` The audit finds the unit of replication (the chick, not the row), the repeated measurements over time, and suggests a mixed model. With no question at all, tidyvisor audits whatever it is given: ```{r} tidyvisor(airquality)$checks ``` ## Choose the analysis and check its assumptions ```{r} tidyvisor(InsectSprays, response = "count", group = "spray") ``` ## Explain the result ```{r} m <- lm(mpg ~ wt + hp, data = mtcars) tidyvisor(m) ``` ## After the overall test A significant test with three or more groups says that the groups are not all alike, not which differ. tidyvisor says whether to go on to post hoc comparisons, which ones suit the test, and, when the result is not significant, why not to test every pair. ```{r} kw <- kruskal.test(count ~ spray, data = InsectSprays) tidyvisor(kw)$sections$`After the overall test` ``` ## Write it up for the paper Each interpretation ends with a sentence for the Results, the figure and the table to make (with code that uses your column names and saves the figure at a journal's column width), and what the Methods must state. ```{r} tidyvisor(kw)$sections$`For the paper` ``` The rules for publication, from figures to the software citation, are in the reporting stage of `tv_practice()`: ```{r} tv_practice("report") ``` ## Save the advice Keep the advice with the analysis: `tv_save()` writes it to a file, a heading for each piece in a `.md` file, plain text otherwise. It works in the RStudio console, where `capture.output()` and `sink()` record nothing, and on the advice of the companion packages too. `format()` returns the advice as text. ```{r save} f <- tempfile(fileext = ".md") tv_save(tv_power("two_groups", delta = 5, sd = 8), file = f) head(readLines(f), 12) ``` ## Advisors from the companion packages The same `tidyvisor()` serves the companion packages, which register their own advisors when installed: [tidydiversity](https://tidydiversity.in4metrix.dev/) for community ecology (diversity, ordination, multivariate tests) and [tidymapr](https://tidymapr.in4metrix.dev/) for spatial ecology (species distributions, invasions, the spread of epidemics, range shifts) and [tidyepidemio](https://tidyepidemio.in4metrix.dev/) for epidemiology (outbreaks, associations, survival, diagnostic tests, surveillance, causal effects). `advisors()` lists what is available: ```{r} advisors() ```