Statistics Toolkit
Build an app that takes a dataset of numbers and calculates mean, median, mode, standard deviation, variance, range, permutations, and combinations.
🎯 Learning Goals
- ▹ Understand measures of Central Tendency and Dispersion
- ▹ Calculate Variance and SD from raw data
- ▹ Master Combinatorics (Permutation & Combination)
- ▹ Build logic to parse comma-separated text into lists
🌎 Why This Matters
Statistics is how we make sense of the world — from predicting election results to testing new medicines. In the age of 'Big Data', being able to analyze a dataset is one of the most valuable skills you can have.
📖Understanding Statistics Basics
Theory MasterclassStatistics is the science of collecting, organizing, and analyzing data to draw conclusions. Mean (Average): Add all values and divide by count. Mean = Σx / n Median: The middle value when data is sorted. If even count, average the two middle values. Mode: The value that appears most frequently. A dataset can have no mode, one mode, or multiple modes. Range: Difference between the largest and smallest values. Range = max - min Variance: Measures how spread out the data is. Var = Σ(x - mean)² / n Standard Deviation: Square root of variance. SD = √Variance Permutation: Number of ways to arrange r items from n items (order matters). P(n,r) = n! / (n-r)! Combination: Number of ways to choose r items from n items (order doesn't matter). C(n,r) = n! / (r! × (n-r)!)
Mathematical Foundation
🎨Part A — Designer View (UI Design)
Open MIT App Inventor → Switch to Designer view. Follow each step below to build the interface.
1. Screen & Header Setup
• Click **Screen1** in Components. • Set **Title** to "Statistics Toolkit" in Properties. • Set **AlignHorizontal** to Center. • Set **BackgroundColor** to Black.
2. Input for Numbers
• Drag a **Label** (User Interface). Set text to "Enter numbers (comma separated):". • Drag a **TextBox**. Rename it to 'InputTxt'. • Set **Hint** to "e.g. 10, 20, 30" and **Width** to 'Fill Parent'. • Ensure **NumbersOnly** is NOT checked (since we need commas).
3. Action Buttons
• Drag a **HorizontalArrangement** (Layout). • Drag 3 **Buttons** inside. • Rename: 'MeanBtn', 'MedianBtn', 'ModeBtn'. • Change their **Text** to "MEAN", "MEDIAN", "MODE". • Give each button a distinct color (Red, Green, Blue).
4. Result Display
• Drag a **Label** to the bottom. • Rename it to 'ResultLbl'. • Set **FontSize** to 20, **Text** to "Answer shown here", and **TextColor** to Yellow.
🧩Part B — Blocks View (Logic & Calculation)
Switch to Blocks view. Now add the logic that makes your app actually work.
1. Switch to Blocks
• Click the **Blocks** button at the top right of the screen. • This is where we tell our app how to handle data.
2. Splitting the Text into a List
• Click the **Variables** drawer (Orange). Drag 'initialize global DataList to'. • Go to the **Text** drawer (Bright Green). Drag out the 'split at' block. • Connect them: [initialize global DataList to] [split at] [InputTxt.Text] [at] [","] (use a Text box with a comma).
3. Calculating the Mean (Average)
• Drag 'when MeanBtn.Click' (Gold). • From **Control** (Dark Orange), drag the 'for each item in list' block. • For every item, add it to a 'Sum' variable using the Blue **Math** [+] block. • To get the answer: [set ResultLbl.Text to] [get global Sum] / [length of list] [get global DataList].
4. Error Safety
• Use an **if...then** block from **Control** (Orange). • Snap it at the very top of your logic. • Check: 'if [InputTxt.Text] is empty' (from **Text** drawer). • Then use **Notifier1.ShowMessageDialog** to say: "Please enter numbers first!".
🧪Testing Your App
- ✓Test with dataset: 1, 2, 3, 4, 5 → Mean=3, Median=3, no mode
- ✓Test with dataset: 2, 2, 3, 4 → Mode=2
- ✓Test: 5P2 = 20, 5C2 = 10
- ✓Test with a single number → Mean = Median = Mode = that number
- ✓Test with negative numbers: -3, -1, 0, 2, 5
🚀Bonus Challenges
Extra credit — impress your instructor
- ★Add a bar chart visualization using Canvas component
- ★Support entering data by clicking 'Add' button instead of commas
- ★Add quartile calculations (Q1, Q2, Q3) and IQR
- ★Show a frequency distribution table for the dataset