# Custom Statistics

The **Custom Statistics** tab allows you to manually design and run advanced statistical analyses.  
Unlike **Quick Statistics** (which automatically runs all valid tests), Custom Statistics lets you choose the exact variables and tests you want to perform.

![Custom Statistics — variable and test selection](assets/custom-stats.png)

---

## Workflow overview

### Specific Statistical Test

1. **Select Variables**  
   - Click **Select Variables** to open the selection dialog.  
   - Choose the variables you want to use for analysis.  
   - Selected variables are shown in the **Selected data** panel.  

   > ℹ️ As you add variables, the list of available statistical tests updates automatically.  
   > Only tests compatible with your current selection (or a subset of it) become available.

2. **Choose a Test**
   - Once variables are selected, click on a test from the **Statistical analysis panel**.
   - **Assumption-aware colouring**: Each test button is colour-coded based on whether your data meets the test's requirements:
     - 🟢 **Green** — All assumptions are met. The test is appropriate for your current variable selection.
     - 🟡 **Yellow** — Assumptions may be violated (e.g., normality not met for a parametric test). StatInsight detected that one or more variables may not satisfy the test's requirements. Hover over the button for details and a suggested non-parametric alternative.
     - 🔴 **Red** — Test cannot be applied. Typically when the sample size is too small (N < 10) or the selected variable types don't meet the test's minimum requirements.
   - Hover over any button to see a plain-language tooltip explaining the situation.

   **Supported tests:**

   | Category | Tests |
   |---|---|
   | **Categorical associations** | Chi-Squared Test |
   | **Two-group comparisons** | T-Test, Paired T-Test, Mann–Whitney U Test, Wilcoxon Signed-Rank Test |
   | **Multi-group comparisons** | ANOVA, Kruskal–Wallis H Test, Repeated Measures ANOVA, Friedman Test |
   | **Multi-factor designs** | Two-Way ANOVA, Scheirer–Ray–Hare Test |
   | **Covariate adjustment** | ANCOVA, MANOVA |
   | **Correlation** | Pearson, Spearman, Partial Pearson, Partial Spearman |
   | **Regression** | Simple Linear Regression, Theil–Sen Regression, Multiple Linear Regression, Multiple Logistic Regression, Multinomial Logistic Regression |
   | **Survival analysis** | Kaplan–Meier Analysis |
   | **Diagnostic** | ROC Curve Analysis |
   | **Automatic selection** | AutoPrediction |

3. **Configure the Test**  
   - Depending on the selected test, you may need to assign variables to roles (e.g., dependent variable, grouping variable, event indicator, time-to-event).  
   - The configuration area appears below the test selection panel.  
   - Example: For **Two-Way ANOVA**, choose one continuous dependent variable and two categorical factors.  

4. **Run the Test**  
   - Click the **Run** button.  
   - The analysis is performed and a result block appears in the results panel:  
     - **Left side**: Plain-language description + full statistical output (tables, p-values, effect sizes, pairwise comparisons).  
     - **Right side**: Plot (top) + automatically generated report text (bottom).

### Results panel controls

- **Search box** — type a variable name to show only results involving that variable.  
- **Show only significant** — hide results where p ≥ 0.05.  
- **Remove Statistic** — remove a single result block from the session.  
- **Remove All** — clear all results.

---

## Example: Two-Way ANOVA

![Two-Way ANOVA results with pairwise comparisons and interaction plot](assets/custom-stats-results.png)

- **Description (top left)**: Explains that Two-Way ANOVA examines the effects of two categorical variables on a continuous outcome, including their interaction.  
- **Detailed results (left)**: ANOVA table with F-values, p-values, and post-hoc pairwise comparisons.  
- **Visualization (right, top)**: Group means with confidence intervals.  
- **Report text (right, bottom)**: A narrative summary suitable for reports, with significant findings highlighted.  

---

## Find Predictor

   The **Find Predictor** feature helps you automatically identify which variables best predict your selected dependent variable.

   - After selecting your dependent variable (DV), you can click **Find Predictor** to automatically discover which variables in your dataset are the most important predictors of that DV.  
   - The system analyses **all remaining variables**, including:  
     - Continuous variables  
     - Binary variables  
     - Categorical factors  
   - A ranked list of predictors is shown, from strongest to weakest.  
   - You may then add the suggested predictors directly into the **Selected data** panel or continue selecting your own variables manually.

   > 💡 **Tip:** Find Predictor is useful when your dataset has many variables and you want guidance on which ones matter most.


### How it works

- Once you choose a **dependent variable**, click **Find Predictor**.  
- The app scans **all other variables** in your dataset and builds an appropriate model:  
  - **Regression models** for numeric outcomes  
  - **Classification models** for categorical outcomes  
- All variable types are supported:  
  - Numeric  
  - Binary  
  - Categorical with multiple levels  
  - Text/string categories (auto-encoded)

### What you get

- A **ranked list of predictors** by importance.  
- You can immediately select and apply those predictors to continue working in Custom Statistics.  
- This feature is extremely helpful for datasets with many potential predictors.

![AutoPrediction — predictor significance chart](assets/predict.png)

### Notes

- Predictor importance reflects **predictive power**, not necessarily causation.  
- Variables with excessive missing values may be excluded.  
- ID-like columns (e.g., user IDs, nearly-unique timestamps) are ignored to avoid misleading importance scores.

---

## Plot Editor

Each result block that includes a visualisation has an **Edit Plot** button. Click it to open the Plot Editor, which lets you:

- **Change the plot type** — switch between all chart styles available for that test (e.g., for an ANOVA result you can switch between boxplot, violin plot, raincloud, strip plot, error-bar chart, and more). The dropdown shows only chart types that are compatible with the current result.
- **Customise appearance** — edit title, axis labels, font sizes, legend settings, and plot dimensions.
- Changes are applied live in the preview.

> 💡 The **Change Plot Type** dropdown updates automatically based on the analysis type, so only compatible chart styles are offered. For example, a Chi-Squared result offers stacked bar, grouped bar, contingency heatmap, and mosaic plot.

![Plot Editor — customise titles, axes, colours, and dimensions](assets/plot-edit.png)

---

## Exporting results

- **Export Stats** — saves all results currently listed in the results panel to a `.docx` file. The app appends today's date to the filename automatically, and splits into multiple part files if there are more than 100 results.  
- See [Saving & Exporting](save_and_export.md) for full details on file naming and batching.

---

## Key differences from Quick Statistics

- **Quick Statistics** → runs everything automatically across all variable combinations.  
- **Custom Statistics** → you **choose** variables and tests, giving you full control.  
- Suitable for **targeted, hypothesis-driven analyses**.  

---

**Next:** [Saving & Exporting Projects](save_and_export.md)
