Skip to content

rafalg1988-byte/Shiny-Monty-Hall-Simulator-and-Analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšช Monty Hall Simulator: A Statistical Approach

Professional Shiny application designed to simulate and analyze the famous Monty Hall Problem. This tool combines interactive gameplay with real-time Monte Carlo simulations and statistically sound inference through confidence intervals.


๐Ÿš€ Quick Start (How to run this project)

  1. Clone the repository to your local machine.

  2. Ensure you have the required R packages installed. Run this command in your R console:

  3. Open the project in RStudio.

  4. Open app.R and click the "Run App" button at the top of the editor.


๐Ÿ“Š Features

๐ŸŽฎ Interactive Game

Experience the classic game show scenario. The app allows users to empirically verify the paradox through direct gameplay by collecting, tabulating, and analyzing real-time statistics of "Stay" vs "Switch" strategies.

๐Ÿงช Science & Statistics

  • Monte Carlo Engine: Instantly run up to 1000 simulations to see the Law of Large Numbers in action. This provides a robust empirical confirmation of the 2/3 win probability when switching.
  • Mathematical Proof: A dedicated educational section within the app provides a rigorous step-by-step mathematical derivation of the paradox, bridging the gap between intuition and theory.
  • Confidence Intervals: Real-time statistical significance testing using Wilson Score or Wald methods.
  • Visual Analysis: Dynamic ggplot2 visualizations showing the convergence of results as the number of trials increases.

๐Ÿ“‚ Project Structure

โ”œโ”€โ”€ .gitignore              # Files ignored by Git (secrets, local logs)
โ”œโ”€โ”€ LICENSE                 # Usage terms and copyright
โ”œโ”€โ”€ README.md               # Project documentation and data schema
โ”œโ”€โ”€ Monty_Hall_App.Rproj    # RStudio project file
โ”œโ”€โ”€ app.R                   # Application entry point
โ”œโ”€โ”€ ui.R                    # User Interface definitions
โ”œโ”€โ”€ server.R                # Server-side logic and calculations
โ”œโ”€โ”€ global.R                # Global settings and API connections
โ”œโ”€โ”€ R/                      # Modular R scripts
โ”‚   โ”œโ”€โ”€ utils.R             # Helper functions (math & backend)
โ”‚   โ””โ”€โ”€ texts.R             # UI text constants and translations
โ””โ”€โ”€ www/                    # Static assets
    โ”œโ”€โ”€ styles.css          # Custom CSS styling
    โ””โ”€โ”€ *.wav               # Audio assets (click, win, loss)

๐Ÿ” Data Persistence & Security

The application is integrated with Google Sheets API via the googlesheets4 package to collect global statistics.

Google Sheets Schema

The application logs every event to a central database. For simulations, data is aggregated to optimize performance.

Column Name Description Example Values
timestamp Date and time of the event 2026-03-12 14:30:05
strategy Chosen strategy or action type stay, switch, simulation, RESET_ACTION
result Outcome or simulation summary Win, Loss, St:179/491 | Sw:329/509*
type Source of the event User, Sim_10, Sim_100, Sim_1000
session_id Unique identifier for the user session 7a6077d2...
prize_dist Prize distribution or summary Door 2, B1:35 | B2:32 | B3:33**

* Simulation Result Legend (St:W/T | Sw:W/T)

  • St (Stay): 179/491 means 179 wins out of 491 games where the "Stay" strategy was randomly assigned.
  • Sw (Switch): 329/509 means 329 wins out of 509 games where the "Switch" strategy was randomly assigned.

** Prize Distribution Legend (B1:X | B2:Y | B3:Z)

  • Shows how many times the prize (Car) was hidden behind Door 1 (B1), Door 2 (B2), and Door 3 (B3) during the entire simulation run.

  • Authentication: For security reasons, the .secrets/ directory and .Renviron file are not included in this repository.

  • Local Run: The app includes a fallback mechanism. If the Google Sheet is unavailable or credentials are missing, it will switch to a local session-based data frame to ensure the app remains functional for review.

๐Ÿ’ก Analytical Potential

The granular logging of every interaction (including RESET_ACTION and session_id) is designed not just for statistics, but for User Behavior Analysis:

  • Strategy Consistency: Analyzing whether users tend to stick to one strategy or change it after a loss.
  • Engagement Metrics: Tracking the number of manual games vs. large-scale simulations per session.
  • UX Auditing: Using reset logs and session timestamps to identify potential points of friction in the application flow.

โš–๏ธ License & Credits

  • Author: Rafaล‚ Gardian
  • Project: Monty Hall Paradox - Simulator & Statistical Analysis
  • Copyright: ยฉ 2026 Rafaล‚ Gardian. All Rights Reserved.

Usage Terms

This repository is published for demonstration and portfolio review purposes only.

  • Permission: You are granted permission to download and run this application locally for personal, educational, and evaluative purposes.
  • Prohibitions: You may not copy, modify, merge, publish, distribute, or sell the source code, UI design, or any assets of this project without express written permission from the author.

For inquiries regarding commercial licensing or collaboration, please contact me via LinkedIn.

About

๐Ÿšช Monty Hall Simulator: A professional R Shiny app featuring Monte Carlo engines, real-time statistical inference, and Google Sheets data logging.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors