Data Analysis Workflows and R Programming Guide

Data Workflow and the LOCKMES Framework

  • Workflows consist of discrete, sequential steps that help organizations accomplish tasks and generate value.
  • Workflows are visually represented outside of class through flowcharts, diagrams, and checklists.
  • The structured approach to data analysis in R follows the acronym LOCKMES:
    • L — Look at your data:
    • Inspect the structure, dimensions, number of variables, and number of observations before performing analytical or statistical routines.
    • Identify the presence of missing data prior to executing code.
    • C — Clean the data:
    • Evaluate text and font properties within the dataset.
    • Rename column titles to appropriate formats.
    • Check for and eliminate unexpected or corrupted characters introduced during data import.
    • K / M — Handle Missing data:
    • Identify mechanisms and classifications of missing values rather than automatically deleting incomplete rows or cells.
    • Complete formal data imputation or processing workflows.
    • E — Explore the data through visualizations:
    • Construct graphical representations including histograms, box plots, bar charts, and frequency tables to observe data distributions.
    • S — Statistics:
    • Calculate summary measures such as means, counts, and proportions.
    • S — Summarize findings:
    • Draft clear, well-written analytical statements that contextualize statistical results, recognizing that writing is a core component of statistics.

Best Practices in R Programming

  • Object Assignment:
    • Avoid hard-coding constant numeric values directly into long script computations.
    • Assign computed values, vectors, and imported files to objects using assignment notation (<-) to increase computational efficiency and script reproducibility.
  • Regular Data Inspection:
    • Inspect output continuously throughout coding to confirm functions execute as intended and variables are not modified inadvertently.
  • Dataset Preservation:
    • Never make direct alterations to an original dataset.
    • Create working copies of datasets prior to modifying structure or creating derived variables to preserve raw baseline records.
  • Code Documentation:
    • Use comments (#) extensively to annotate code, detail analytical decisions, and document functional logic for external collaborators and future reference.

Data Types and Structural Inspection

  • Univariate Data Classifications:
    • Categorical Data: Visualized using pie charts, bar graphs, frequency tables, and relative frequency tables.
    • Quantitative Data: Visualized using histograms and box plots.
  • Metadata:
    • Variable descriptions and metadata provide explanatory background information detailing context, variable definitions, and measurement units.
  • Data Dimensions:
    • Observations: Represented by dataset rows (nn).
    • Variables: Represented by dataset columns.
  • Data Inspection Functions in R:
    • str(data_frame): Primary command for initial dataset assessment. Displays total observation count (rows), variable count (columns), column names, data classifications (e.g., numeric, character), and initial values.
    • dim(data_frame): Displays precise dimensions of a data frame returning row count followed by column count.
  • Missing Value Detection:
    • Missing values in R are denoted by the system logical indicator NA.
    • is.na(data_frame): Evaluates every cell in a dataset, returning a logical output (TRUE for missing, FALSE for non-missing).
    • sum(is.na(data_frame)): Sums the logical outputs where TRUE equals 11 and FALSE equals 00, returning the exact total count of NA values across the dataset.

Data Visualizations in R

Histograms

  • Base Syntax: hist(data_frame$variable) generates a default histogram with automated binning and a gray color scheme.
  • Essential Graphical Components:
    • Every graph must include an explicit title and labeled axes with units.
  • Histogram Arguments:
    • `main =