Week 4

Exploratory Data Analyses

Instructors
Maclean Gaulin

What is exploratory Data analysis?

  • Initial analysis to understand data and its structure
  • Data types, distributions, statistics
  • Can illuminate data issues
  • Missing data, outliers, errors
  • Identify broad patterns or regularities
  • Relationships, clustering, temporal regularity
  • Build intuition and inform hypothesis development

Why use EDA?

  • “You can see a lot, just by looking” ~ Yogi Berra
  • EDA establishes understanding of the data before assumptions are made or complex modeling techniques are applied
  • More EDA now, fewer mistakes later
  • Finds “unknown unknowns”
  • Be curious and judgmental
  • Skepticism is important, look for errors, bias, misinformation, etc.

EDA Caveats

  • Confirmation Bias – the tendency to subconsciously identify, prefer, or interpret information in a way that confirms pre-existing beliefs or hypotheses
  • Look for patterns that contradict initial ideas or expectations
  • Require higher burden of proof for conclusions that align with priors
  • Correlation vs. Causation – relationships discovered with EDA do not necessarily entail causal (functional) relationships
  • Observing that two variables move together during EDA does not prove that one causes the other
  • Establishing causal relationships requires experiments or causal inference
  • Note: correlation is not causation, but they are highly correlated

Caution

  • “There are 3 kinds of lies: lies, damned lies, and statistics.” ~ Mark Twain
  • Visualizations can be misleading (intentionally or not)
  • Important to consider whether the interpretation of your visualization will be what is intended

Common Visualization mistakes

  • Visual distortion
  • Cherry-picking Data
  • Outlier treatment
  • Misleading Aggregations
  • Comparing Dissimilar Data

Visual Distortion

  • Truncation: Truncating axes can make variation appear greater or less
  • Scaling: Scaling axes by non-constant amounts distorts visual comparison
  • Log-scale axes are an example of well-understood non-constant scaling
  • Twin axes: A second axis can be misleading if using same units as first

Truncated Axes

Scaled Axes

Cherry-Picking Data

  • Including only those observations that support a specific conclusion or omitting contradictory evidence
  • Removing outliers without justification can present a cleaner, but potentially misleading, picture
  • Selecting sub-group may imply the results generalize to the full group

Misleading Aggregation

  • Using the mean for highly skewed data can be misleading, where the median might be better
  • Aggregating data can mask recent changes in trends

mean vs median

  • Median is “middle” of data
  • Data: https://www.cbo.gov/publication/60706#_idTextAnchor039

mean vs median

  • Median is “middle” of data
  • Mean (expected value) is weighted by values
  • Data: https://www.cbo.gov/publication/60706#_idTextAnchor039

mean vs median

  • Median is “middle” of data
  • Mean (expected value) is weighted by values
  • Be careful to assess what you believe your audience will interpret each to mean
  • Data: https://www.cbo.gov/publication/60706#_idTextAnchor039

Misleading Axis redux

Misleading Axis redux
  • Data: https://www.cbo.gov/publication/60706#_idTextAnchor039

Comparing Dissimilar Data

  • Comparing metrics that aren’t truly comparable (e.g., plotting levels and percentages on the same graph without clear labels)
  • Plotting spurious correlations together to imply a relationship
  • e.g., tylervigen.com/spurious-correlations

tylervigen.com/spurious-correlations

Spurious Correlations

Graphic 6
  • Credit Tyler Vigen

Exploring Data Quality

  • Missing data: drop observations, fill with default, interpolate based on some model
  • Input errors: unit errors, transcription errors (OCR, human input)
  • Processing errors: conversion logic errors (e.g. date formatting), calculation errors (e.g., divide by 0)
  • Duplicates: mistakes or informative
  • Outliers: caused by errors, uninformative observations, informative and necessary to understand

Multidimensional data

  • Multiple measurements for single observation
  • Journal entry – date, account info, names, amount, etc.
  • Consumer – demographics, location, interactions
  • Financials
  • Multidimensional due to computer representation
  • Location stored as latitude and longitude (& height?)
  • Text? Images?

Seeing beyond 2D

  • Visualization of three or more dimensions is difficult
  • 3D graphs can be hard to interpret without interactivity
  • Other features can be introduced (bubble size, color, etc.) but are less self-explanatory and more complex
  • Interactive visualizations can help by giving audience control over what they viewing
  • Can swap between dimensions being observed
  • Can incorporate time / motion

3D Example – 2D + categories

3D Example – 2D + categories

4D Example – 2D + Time + Size

4D Example – 2D + Time + Size

Interactive Visualization

  • Software to interact with data in predetermined ways
  • Set of parameters to adjust, visualization updates accordingly
  • Often web-based
Interactive Visualization

LLM/LMM Tangent

  • Prompted Sora for dashboard with interactive elements
  • Follow up prompt asking for added trendline

Caveats and Pitfalls

  • Overfitting – Insight found during EDA should be understood to be potentially limited to the specific “pull” of the dataset
  • Understand conditions of data to determine generalizability
  • Multicollinearity – highly correlated variablesidentified by EDA may be problematic in subsequentmodeling or testing

Example

  • You are given transaction data for a month
  • Date, Amount, Payee, Category, Vendor, Notes, Approver
  • Look at data
  • Columns, data types, missing values, etc.
  • Five-number analysis
  • Initial plots
  • Line plot of amount over time (Date)
  • Bar chart of count by payee, vendor, approver
  • Word-cloud of Category and Notes

The Data

DateAmountPersonellVendorNotesExpense_CategoryApprover
2024-01-1012,000Ben BlueInnovate Solutions Group LLCSynergy Project Kickoff FeeConsultingBen Blue
2024-01-0212,150Corporate Realty Partners LLCJanuary 2024 Office RentRentCharlie Brown
2024-01-1541,534Jennifer LeeInternal Transfer / Payroll ServiceSalary payment Jan 1-15SalariesCharlie Brown
2024-01-2541,582David BrownInternal Transfer / Payroll ServiceSalary payment Jan 16-31SalariesCharlie Brown
2024-01-1648,500Ben BlueApex Universal Consulting Inc.Market Research Analysis Q1ConsultingBen Blue

Familiarization with the data

  • Understanding the broader context of the data
  • Where did it come from?
  • How was it collected?
  • Are there known limitations or potential biases in the collection process?
  • This is where your accounting knowledge is key

Familiarization with the specific data

  • Understanding the dataset at hand
  • What do the variables represent?
  • What contextual information should be incorporated into understanding this data?
  • Is more data needed before use (merging)?

Initial Inspection

  • Examine the dataset’s dimensions (# of rows and columns)
  • Identify the data types of each variable
  • numerical continuous/discrete, categorical nominal/ordinal, date/time, text short/long
  • View rows of data to get a sense of the content and structure
  • Identify “special” columns like merge keys, unique IDs
  • Identify how missing observations are represented
  • Identify whether variables have default values
  • Investigate whether and how missings can be filled/imputed
  • Identify whether duplicates exist and can be removed

Look at data

DateAmountPersonellVendorNotesExpense_CategoryApprover
2024-01-1012,000Ben BlueInnovate Solutions Group LLCSynergy Project Kickoff FeeConsultingBen Blue
2024-01-0212,150Corporate Realty Partners LLCJanuary 2024 Office RentRentCharlie Brown
2024-01-1541,534Jennifer LeeInternal Transfer / Payroll ServiceSalary payment Jan 1-15SalariesCharlie Brown
2024-01-2541,582David BrownInternal Transfer / Payroll ServiceSalary payment Jan 16-31SalariesCharlie Brown
2024-01-1648,500Ben BlueApex Universal Consulting Inc.Market Research Analysis Q1ConsultingBen Blue
countmeanstdmin25%50%75%max
Date622024-01-152024-01-012024-01-082024-01-152024-01-232024-01-31
Amount623,6459,76211.075.8157.9469.348,500

Visual exploration

  • “There is no excuse for failing to plot and look” ~ John Tukey
  • Histograms: Understand the distribution of numerical variables, identify outliers
  • Box Plots: Visualize the distribution, central tendency, spread, and outliers of numerical data, possibly by category
  • Bar Charts: Compare categorical data
  • Scatter Plots: Investigate relationships between numerical variables
  • Line Charts: Show trends over time, across categories
  • Heatmaps: Visualize correlation matrices, missing values, etc.

amount over time

amount over time

Transactions by employee

Transactions by employee

Approvals by employee

Approvals by employee

Transactions by vendor

Transactions by vendor

Transactions by expense

Transactions by expense

Note field Wordcloud

Note field Wordcloud

Next steps: dig deeper

  • Start looking for abnormalities & outliers
  • Amounts by day of week (box plot)
  • Amounts over time by approver (line plot)
  • Distribution of amounts by approver (box plot)
  • Amounts by vendor (histogram)

Next Step: Day of Week

Next Step: Day of Week

Over Time by approver

Over Time by approver

Amounts by approver

Amounts by approver

Investigate Ben Blue

DateAmountPersonellVendorNotesCategoryApprover
2024-01-059,500Ben BlueGlobal Strategic Solutions Ltd.Phase 1 Strategic Review PaymentConsultingBen Blue
2024-01-087,651Ben BlueApex Universal Consulting Inc.Consulting Services - Project AlphaConsultingBen Blue
2024-01-1012,000Ben BlueInnovate Solutions Group LLCSynergy Project Kickoff FeeConsultingBen Blue
2024-01-128,500Ben BlueGlobal Strategic Solutions Ltd.Ongoing Strategic Support RetainerConsultingBen Blue
2024-01-1648,500Ben BlueApex Universal Consulting Inc.Market Research Analysis Q1ConsultingBen Blue
2024-01-199,800Ben BlueGlobal Strategic Solutions Ltd.Discreet Project SupportConsultingBen Blue
2024-01-228,000Ben BlueApex Universal Consulting Inc.Expedited Advisory FeeConsultingBen Blue
2024-01-269,100Ben BlueGlobal Strategic Solutions Ltd.Final Strategic Consultation JanConsultingBen Blue
2024-01-27150Emily JonesAmtrakTrain ticket E. Jones - Regional MeetingTravelBen Blue
2024-01-2788.90Emily JonesRegional Conference HotelsHotel E. Jones - Regional MeetingTravelBen Blue
2024-01-2875.20Emily JonesFine Dining Group LLCDinner E. Jones - Regional MeetingMeals & Ent.Ben Blue
2024-01-308,450Ben BlueApex Universal Consulting Inc.Final Jan Retainer - Project AlphaConsultingBen Blue

Project 1 – Due Sunday

  • Groups up to 5 optional
  • Deliverable pdf slide-deck
Exploratory Data Analyses