An open API service indexing awesome lists of open source software.

https://github.com/antoinesoetewey/statistics-202

Shiny app for simple linear regression by hand.
https://github.com/antoinesoetewey/statistics-202

linear-regression r shiny statistics

Last synced: about 1 month ago
JSON representation

Shiny app for simple linear regression by hand.

Awesome Lists containing this project

README

          

# statistics-202 — Simple Linear Regression

A Shiny app for performing simple linear regression both by hand and in R.

**Live app:** https://antoinesoetewey.shinyapps.io/statistics-202/

**Blog post:** https://statsandr.com/blog/a-shiny-app-for-simple-linear-regression-by-hand-and-in-r/

---

## Purpose and overview

This app is designed to help students understand and perform simple linear regression. Given a set of paired observations for two numeric variables ($x$ and $y$), the app estimates the regression line, displays step-by-step formulas for computing the coefficients by hand, and provides full R output alongside an interactive plot. It is intended as both a learning tool and a computation aid for introductory statistics courses.

---

## Key features

- **Data input** — Enter $x$ and $y$ values directly as comma-separated lists. Summary statistics (means and sample size) are displayed automatically.
- **By-hand computation** — Shows the OLS formulas for the slope ($\hat{\beta}_1$) and intercept ($\hat{\beta}_0$) with the computed values filled in, so students can follow each calculation step.
- **R output** — Displays the full `lm()` summary, including coefficient estimates, standard errors, t-statistics, p-values, $R^2$, and the F-statistic.
- **Interactive regression plot** — Renders a scatter plot with the fitted regression line via `ggplot2` and `plotly`. An optional confidence interval band can be toggled on or off.
- **Automatic interpretation** — Provides a plain-language interpretation of the estimated coefficients based on their statistical significance ($\alpha = 0.05$), including appropriate caveats.
- **Assumption checks** — A collapsible section displays the standard linear regression diagnostic plots (linearity, homoscedasticity, normality of residuals, influential observations) generated by the `performance` package.
- **Downloadable report** — Exports a self-contained HTML report (via R Markdown) that reproduces the analysis, with an option to include or hide the underlying R code.

---

## Running the app locally

**Prerequisites:** R ($\ge 4.0$) and the following packages:

```r
install.packages(c(
"shiny",
"shinythemes",
"ggplot2",
"plotly",
"DT",
"rmarkdown",
"knitr",
"pander",
"performance",
"see"
))
```

**Launch the app:**

```r
shiny::runGitHub("statistics-202", "AntoineSoetewey")
```

Or clone the repository and run locally:

```r
# In the project directory
shiny::runApp()
```

---

## Dependencies

| Package | Role |
|---|---|
| `shiny` | Web application framework |
| `shinythemes` | UI theme (Flatly) |
| `ggplot2` | Regression plot |
| `plotly` | Interactive plot rendering |
| `DT` | Interactive data table with export buttons |
| `rmarkdown` / `knitr` | Report generation |
| `pander` | Report formatting |
| `performance` / `see` | Regression assumption diagnostic plots |

---

## Part of a set of complementary Shiny apps

This app is part of a set of three complementary Shiny apps developed for students while the author was a teaching assistant at UCLouvain. All three apps are still actively used when teaching introductory statistics and probability courses.

- **statistics-101** — compute probabilities for the main probability distributions: https://github.com/AntoineSoetewey/statistics-101
- **statistics-201** — perform statistical inference on mean(s), proportion(s), and variance(s): https://github.com/AntoineSoetewey/statistics-201
- **statistics-202** — simple linear regression by hand: https://github.com/AntoineSoetewey/statistics-202 (this app)

## License

This project is licensed under the terms of the [MIT License](LICENSE).