# Data Summary

The **Data Summary** tab gives you a quick overview of your dataset after it is loaded.  
Here you can inspect variables, review descriptive statistics, **define variable types**, and prepare your dataset for analysis.

<div style="display:flex;gap:12px;align-items:flex-start;margin:16px 0">
  <img src="assets/data-summary.png" style="width:48%;border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,0.15)" alt="Data Summary tab with variables and plots">
  <img src="assets/data-summary-grouped.png" style="width:48%;border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,0.15)" alt="Data Summary grouped by a categorical variable">
</div>

---

## Role of Data Summary

- When you load a dataset, StatInsight **automatically detects the type of each variable** (continuous, categorical, binary, or date).  
- These detected types are shown here and can be manually adjusted.  
- The chosen types are then used by:
  - **Quick Statistics** → to decide which statistical test to run between variable combinations.  
  - **Custom Statistics** → to build models correctly.  

> 💡 Always check and confirm variable types here before moving on.  

---

## Layout

- **Top navigation bar**
  - **All** — show every variable.
  - **Continuous** — filter only numeric variables.
  - **Categorical** — filter only categorical factors.
  - **Binary** — filter only binary variables.
  - **Date** — filter date-type variables.

- **Search box**  
  Located above the variable list. Start typing a variable name and the view updates instantly, showing only matches.  
  > 💡 Useful when working with large datasets containing many variables.

- **Variable blocks**
  Each variable in your dataset is displayed as a block containing:
  - **Descriptive statistics**  
    - **Continuous**: N, missing count, mean, SD, median, quartiles, outliers.  
    - **Categorical/Binary**: categories with counts and percentages.  
    - **Date**: number of entries, earliest (first) date, and latest (last) date.
  - **Plot** — default chart for the variable type, changeable via the **Edit Plot** button:
    - *Continuous*: histogram with KDE overlay
    - *Categorical / Binary*: bar chart
    - *Date*: area chart (frequency over time)
  - **Edit Plot button** — opens the Plot Editor for that variable's chart. You can change the chart style (e.g., switch from histogram to violin, ECDF, or strip plot for continuous variables; or from bar to pie, treemap, or lollipop for categorical) and customise titles, colours, and dimensions.
  - **Controls (buttons at bottom of block)**
    - **Change to Continuous** — recode categorical → numeric.
    - **Change to Categorical** — recode numeric → categorical.
    - **Change to Label** — mark variable as label (not used in analysis).
    - **Remove Outliers** — exclude detected outliers (continuous only). A **Restore Outliers** button appears after removal to undo the operation.
    - **Normality override** — StatInsight auto-tests normality. Two small buttons let you manually force the variable to be treated as **Normal** (green) or **Non-Normal** (red), overriding the automatic assessment. This affects which test StatInsight recommends in Quick Statistics.

- **Group-by selector (top of each variable block)**
  A dropdown lets you split the plot by a categorical variable. The default grouped chart is a **multi-boxplot** (for continuous) or **grouped bar chart** (for categorical/binary). Use **Edit Plot** on the grouped result to switch to violin plots, raincloud charts, ECDF plots, strip plots, and more.

  > 💡 The group-by list updates automatically when you change a variable's type — newly created categorical variables appear immediately.  
  > 💡 Grouped plots have their own Plot Editor: only chart types that preserve the grouping are offered in the dropdown.

- **Export options (top-right corner of tab)**
  - **Export displayed descriptives** — saves only the variables currently visible after applying filters and/or a search.  
    > Example: If you filter by **Continuous** and search for "Age", the export will contain only the descriptive stats for `Age`.  
  - **Export all descriptives** — save statistics for the entire dataset.  

---

## Quick workflow

1. Browse through **All variables** to get a dataset overview.  
2. Use the **tabs (Continuous/Categorical/Binary/Date)** to filter variable types.  
3. Use the **search box** to quickly find variables by name.  
4. Adjust variable types or clean data (e.g., remove outliers).  
5. Export summaries if needed.  
6. Proceed to **Quick Statistics** or **Custom Statistics** — they will use the variable types defined here.  

---

## Tips

- **Variable typing is critical**: Wrong types → wrong tests in Quick Statistics.
- **Normality override**: Use the green/red buttons to manually control normality status per variable when you know more than the automatic test can detect (e.g. clinical domain knowledge, large N where Shapiro-Wilk is overly sensitive).
- **Group-by for exploration**: Use the group-by selector to visually explore group differences before running formal tests.
- **Extreme outliers**: When a variable contains extreme outliers (data range > 10× the IQR range), StatInsight clips the histogram x-axis and shows an annotation with the number of out-of-view points and their min/max values. The underlying data is unchanged — use **Remove Outliers** if you want to exclude them.
- **Scroll behavior**: Scrolling works only when the mouse is inside the Data Summary panel, avoiding conflicts with the main page.
- **Variable name cleaning**: Special characters (spaces, `:`, etc.) are auto-cleaned. If duplicates occur, suffixes are added automatically.
- **Best practice**: Always verify variable types and names here before running analyses.  

---

**Next:** [Quick Statistics](quick-stats.md)
