# Simple Linear Regression

**Simple Linear Regression** models the linear relationship between one continuous predictor (X) and one continuous outcome (Y).

---

## 📌 When to Use
- One continuous predictor, one continuous outcome
- Both variables are approximately normally distributed
- The relationship is expected to be linear

> ⚠️ If normality is violated, use [Theil-Sen Regression](theil-sen.md) instead.

---

## 📐 Model

$$
Y = \beta_0 + \beta_1 X + \varepsilon
$$

Where:
- $\beta_0$ = intercept
- $\beta_1$ = slope (change in Y per unit increase in X)
- $\varepsilon$ = residual error

---

## 🔬 What StatInsight Reports
- Formula: `Y = (slope × X) + intercept`
- Slope with 95% CI
- R² (proportion of variance explained)
- p-value for slope significance
- Power analysis with sample size recommendation

---

## 🧩 Post-Hoc / Follow-Up
No post-hoc required. Check R² for effect size and the scatter plot with regression line for visual fit.

---

## 🧪 Assumptions
- Linearity between X and Y
- Normality of residuals
- Homoscedasticity (constant variance)
- Independent observations

---

## 🧠 Interpretation
- **Slope significant (p < 0.05)**: X is a meaningful predictor of Y
- **R²**: proportion of variance in Y explained by X (e.g. R² = 0.45 means X explains 45% of Y's variability)
- **95% CI for slope**: if it does not include 0, the relationship is significant

---

## 🐍 Python Implementation

```python
import statsmodels.api as sm

X = sm.add_constant(x)
model = sm.OLS(y, X).fit()
print(model.summary())
```

---

## 📎 Related Tests

[Theil-Sen Regression](theil-sen.md) — non-parametric alternative

[Spearman Correlation](/statistics/correlation/spearman.md) — non-parametric monotone association

[Multiple Linear Regression](multiple-linear.md)
