Skip to content

st-1989/Correlation_game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Correlation Game — Static Web App

A small static web app / mini-game that shows a scatter plot and challenges the player to estimate three correlation measures:

  • Pearson's r
  • Spearman's rho (rank correlation)
  • Kendall's tau

Win condition: all three estimates are within ±0.1 (configurable) of the actual values computed from the generated dataset.

This repository contains a lightweight, dependency-minimal implementation that runs entirely in the browser and is ready to be hosted on GitHub Pages or any static hosting.


What I built for you in this delivery

  • A ready-to-run static web app with:
    • index.html (UI + Chart.js from CDN)
    • style.css (simple responsive styling)
    • app.js (data generation, statistical computations, game logic, plotting)
  • A clear README with how it works and how to run it locally or deploy.

Scroll down for usage, customization notes, and the exact file contents included below.


How to use

  1. Clone or download the files to a folder.
  2. Open index.html in your browser (or push to GitHub and enable Pages).
  3. The app shows a scatter plot. Enter your estimates for Pearson r, Spearman rho, and Kendall tau and click "Submit".
  4. If each estimate is within ±0.1 (default), you win. The app shows the actual values and feedback.
  5. Click "New Plot" to generate another dataset.

Key features

  • Data generation uses a bivariate-normal construction so you can control the true Pearson correlation (randomized each round).
  • Pearson, Spearman, and Kendall calculations are implemented in plain JavaScript (no server).
  • Score checking is numeric and tolerant: you can configure the win threshold.
  • Plotting via Chart.js CDN for a simple interactive scatter visualization.
  • Mobile-friendly and accessible UI controls.

Math & Implementation Notes

  • Pearson's r: covariance / (sd_x * sd_y).
  • Spearman's rho: Pearson's r computed on ranks of x and y.
  • Kendall's tau: (C - D) / (n*(n-1)/2) where C is concordant pair count and D is discordant pair count (ties handled simply).
  • Dataset generation: x ~ N(0,1); y = rho * x + sqrt(1 - rho^2) * e (e ~ N(0,1)). This yields sample correlations near the specified rho.

Customize & Extend

  • Change sample size (default 50) in app.js.
  • Change the allowed error threshold (default ±0.1) with the "Tolerance" control.
  • Add difficulty levels (smaller tolerance, smaller sample size).
  • Replace Chart.js with D3 for richer interactions if desired.
  • Add scoreboard, timer, or multiplayer.

Files included

  • index.html
  • style.css
  • app.js

(Each file content is included in the repo root — see above.)


License

MIT


Thanks — I created a complete static web app you can run immediately.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors