Team 4

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 Masterclass
"

Statistics 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

fxMean = Ξ£x / n
fxVariance = Ξ£(x - mean)Β² / n
fxStandard Deviation = √Variance
fxP(n,r) = n! / (n-r)!
fxC(n,r) = n! / (r! Γ— (n-r)!)

🎨Part A β€” Designer View (UI Design)

Open MIT App Inventor β†’ Switch to Designer view. Follow each step below to build the interface.

1

Set up the main screen

Set Screen1 title to "Statistics Toolkit". Dark background with modern styling.

2

Create data input area

Add a Label: "Enter numbers separated by commas" Add a TextBox named DataInput with Hint "e.g., 5, 12, 7, 3, 9, 12" Set MultiLine = true and Width = Fill Parent. This lets users enter an entire dataset at once.

3

Add calculation buttons

Add rows of buttons using HorizontalArrangements: Row 1: "Mean", "Median", "Mode" Row 2: "Std Dev", "Variance", "Range" Row 3: "Calculate All" The "Calculate All" button runs every calculation and displays all results.

4

Create Permutation/Combination section

Add a separator Label: "β€” Permutation & Combination β€”" Add a HorizontalArrangement: TextBox for n, Label "P/C", TextBox for r Add 2 Buttons: "nPr" and "nCr"

5

Create result display

Add a Label: "Results" as header. Add ResultLabel with FontSize 16 and MultiLine-like display. This shows formatted output of all statistical measures.

🧩Part B β€” Blocks View (Logic & Calculation)

Switch to Blocks view. Now add the logic that makes your app actually work.

1

Parse the comma-separated input into a list

When any calculate button is clicked: 1. Get the text from DataInput 2. Use "split text at" block with separator "," 3. This creates a list of text strings 4. Loop through the list and convert each to a number 5. Store in a global list variable called "dataList" This is the most important step β€” all calculations use this list.

2

Calculate Mean

Create a procedure "calculateMean": 1. Initialize sum = 0 2. Use "for each item in list" loop 3. Add each item to sum 4. mean = sum / length(dataList) Display: "Mean = " + mean

3

Calculate Median

Create a procedure "calculateMedian": 1. Sort the list (use a simple bubble sort with nested loops) 2. Find the middle index: mid = length(list) / 2 3. If length is odd: median = item at position (mid + 1) 4. If length is even: median = (item at mid + item at mid+1) / 2 Tip: To sort in App Inventor, you need to manually implement sorting using loops and swapping.

4

Calculate Mode

Create a procedure "calculateMode": 1. Create two lists: "uniqueValues" and "frequencies" 2. Loop through dataList 3. For each value, check if it's already in uniqueValues 4. If yes, increment its frequency. If no, add it with frequency 1. 5. Find the maximum frequency 6. The value(s) with maximum frequency = mode

5

Calculate Variance and Standard Deviation

Create a procedure "calculateVariance": 1. First calculate the mean 2. Initialize sumSquaredDiff = 0 3. Loop through dataList: diff = item - mean sumSquaredDiff = sumSquaredDiff + (diff Γ— diff) 4. variance = sumSquaredDiff / length(dataList) 5. stdDev = sqrt(variance)

6

Build the Factorial helper for P and C

Create a procedure "factorial" with parameter n: 1. If n <= 1, return 1 2. Else: result = 1, loop from 1 to n, multiply result by each number 3. Return result This is needed for nPr and nCr calculations.

7

Calculate nPr and nCr

When nPrButton.Click: P = factorial(n) / factorial(n - r) When nCrButton.Click: C = factorial(n) / (factorial(r) Γ— factorial(n - r)) Show error if r > n: "r cannot be greater than n!"

8

Build 'Calculate All' button

When CalculateAllButton.Click: Run all procedures and format the output: "Mean: 7.5 Median: 7 Mode: 12 Range: 9 Variance: 10.25 Std Dev: 3.2"

πŸ§ͺ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