Problem Solving

EDS 214: Analytical Workflows and Scientific Reproducibility


Day 3 Morning | August 27th, 2025

This morning, you’ll learn how to…


  • Solve complex problems by creating tiny problems
  • Apply unit testing principles to verify your solution

So Far…


Schaefer et al. (2000) use a moving average

The data have non-uniform intervals

There are thousands of rows

Problem Solving Approach


  1. Create a tiny example
  2. Solve the tiny example by hand
  3. Identify the minimum information to solve
  4. Put the solution in a function
  5. Verify your solution with the tiny example
  6. Apply the function to the full problem

Instructions


  1. Form groups of 3-4
  2. Choose 1 (and only 1) member to use RStudio
  3. Everyone else close your laptops
  4. Fork eds-214-workflows-reproducibility/problem-solving (I’ll show you how)
  5. Clone the repo

Tiny Example


  • Small enough to see all at once
  • Simple enough to solve by hand
  • Just enough detail to represent the problem
  1. Create a tiny example in the workbook (link in script)

  2. Shape your example like a data frame

  3. Ask yourselves:

  • Is it small enough to see all at once?
  • Is it simple enough to solve by hand?
  • Does it represent the problem?

Solve by Hand


  • Use an independent solution (e.g., spreadsheet)
  • Solving by hand forces you to understand the problem
  • Now you have a rubric!

In your same groups:

  1. Add a column to your tiny example

  2. Solve the problem by hand in the new column

  3. Double-check your work

Minimum Information


  • Identify the minimum information you need to solve the problem once
  • List the variables you need to know
  • Remove any information you don’t need

As a group, make a list of the variables you need to solve the problem once

Put the Solution in a Function


  • Your minimum information becomes parameters
  • Convert your hand solution into code
  • REMEMBER - this is the solution for one case
  • This is the hard part!
  1. One (and only one) member of your group opens RStudio

  2. Create a new script

  3. Write the function

  • What’s its name?
  • What are the parameters?
  • What does the body look like?

Verify Your Solution


  • Run your solution on one case in the tiny example
  • Check your function’s output against the hand solution
  • Debug as needed

(If necessary) Install googlesheets4 package

sheet_url <- "https://docs.google.com/spreadsheets/d/1X-SltNKUaZH0zVWSUkC8sUrrlhPEPAd-6tBmbcihCSw"
tiny_problem <- googlesheets4::read_sheet(sheet_url, sheet = "Example")

Call your function on one case in the tiny example

Do not debug yet!

Apply Your Function


  • Choose how to apply your function
    • apply(), sapply(), mutate(), for()
  • Apply your function to the tiny example and verify
  • Apply your function to the full dataset

REPEAT UNTIL SOLVED

  • How will you apply your function?
  • Write the solution for the entire tiny example
  • Check your results

Problem Solving Recap


  1. Create a tiny example
  2. Solve the tiny example by hand
  3. Identify the minimum information to solve
  4. Put the solution in a function
  5. Verify your solution with the tiny example
  6. Apply the function to the full problem