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/
This app is designed to help students understand and perform simple linear regression. Given a set of paired observations for two numeric variables (
-
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
ggplot2andplotly. 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
performancepackage. - 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.
Prerequisites: R (
install.packages(c(
"shiny",
"shinythemes",
"ggplot2",
"plotly",
"DT",
"rmarkdown",
"knitr",
"pander",
"performance",
"see"
))Launch the app:
shiny::runGitHub("statistics-202", "AntoineSoetewey")Or clone the repository and run locally:
# In the project directory
shiny::runApp()| 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 |
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)
This project is licensed under the terms of the Creative Commons Attribution 4.0 International License (CC BY 4.0). See LICENSE for more details.