Course Syllabus & Teaching Plan

Python for Psychological Inquiry

A Problem-Solving Approach to Programming

Unit 1 of 4

The philosophy of computing

"How does a computer understand what I mean?"
6 hours CO1

This unit begins not with Python, but with a question: what does it actually mean to give instructions? Students discover that programming is a discipline of precision and that the challenge of writing code for a computer mirrors, in an illuminating way, the challenge of writing methods sections for psychology experiments.

1.0

Setting up an IDEs and Code Editors for Python

Section Overview

The session targets to set up environments and code editors on students' devices ahead of the Python elective. The focus here would be to get confortable with the layout of different enviornments and code editors. Students would perform the activity in groups to ensure all students get to experience the process and replicate it on their own devices.

Topics Covered

  • What does coding in Python mean
  • Introduction to the Python environments: Jupyter Notebooks, Anaconda, and VS Code
  • Components of a code editor
  • Understanding directories and navigating files

Classroom Activity

  • Groups decide their prefered environment and set up on all their devices
  • Groups compare layout between enviornments and share pros and cons
  • Live demo: setting up a directory in VS Code
  • Live demo: starting a new notebook with Google Colab
  • Live demo: running Python from the machine terminal
1.1

What Is an Algorithm? Thinking Before Typing

Section Overview

The session opens without a computer. Students are given a psychology scenario — scoring a questionnaire — and asked to write out, in plain English, the complete set of steps needed to go from raw responses to a final score. Groups compare their versions and discover where ambiguity crept in.

Topics Covered

  • Definition and properties of an algorithm: unambiguous, finite, correct
  • The gap between human intention and machine instruction
  • Why computers need precision that humans take for granted
  • Writing and running a first Python statement; understanding the REPL

Classroom Activity

  • Unplugged activity: groups write the algorithm for "compute the average Likert score from 10 responses, excluding any blank items"
  • Groups compare algorithms; instructor facilitates discussion of where they differ and what each difference implies
  • Live demo: show how Python executes each instruction one at a time
R to Python Bridge: Students will recognise the REPL from RStudio's console. R and Python are both interpreted languages — you write a line, the machine runs it. The syntax will look different, but the underlying philosophy is the same.
1.2

Variables, Types, and the Psychology of Categories

Section Overview

Variables are introduced not as 'boxes that store things' but as names we give to things so we can refer to them later. The four core data types are mapped directly onto students' existing knowledge of levels of measurement and data types from R.

Topics Covered

  • Variables: assignment, naming conventions, reassignment
  • Integers and floats: when precision matters (age vs. reaction time in milliseconds)
  • Strings: representing names, categories, and text responses
  • Booleans: true/false as the basis of all decision-making
  • type() and simple type conversion
  • Connecting Python types to levels of measurement: nominal (str), ordinal (int), interval/ratio (float)

Classroom Activity

  • Students are given a printed dataset card (5 participants, each with age, gender, anxiety_score, above_threshold) and decide which Python type to use for each variable
  • Live coding: building the dataset as individual variables, then discussing why this approach becomes unworkable at 500 participants
Discussion: Is a Likert scale score an integer or a float? Does it matter? What about storing someone's grade as 'A' versus as 4? This connects directly to measurement-level concepts from statistics.
1.3

Decisions and Conditions: The If-Then Logic of Classification

Section Overview

Conditional logic is presented as the computational version of diagnostic reasoning. Students build increasingly complex classifiers, encountering the concepts of mutual exclusivity and exhaustiveness along the way.

Topics Covered

  • if, elif, else: structure and indentation
  • Comparison operators: ==, !=, <, >, <=, >=
  • Logical operators: and, or, not
  • Nesting conditions vs. chaining elif
  • The concept of a decision boundary and its arbitrariness

Classroom Activity

  • Students implement the PHQ-9 scoring rubric as a Python function returning a severity category (minimal, mild, moderate, moderately severe, severe)
  • Extension: add validation logic — what should the function return if the score is negative, or greater than 27?
Ethical Touchpoint: Classification systems in psychology have real consequences. A person is not the same as their score, and a cut-off is a convention, not a truth. Code that implements a classification makes the arbitrariness of that convention invisible — a crucial point for future researchers.
1.4

Repetition and Loops: Automation as a Research Tool

Section Overview

Loops are introduced as the answer to the question: "What if I need to do this for every participant?" Students see that automation is not laziness — it is reproducibility.

Topics Covered

  • for loops over lists and ranges
  • Accumulators: building a running total or a collection
  • while loops: iterating until a condition changes
  • break and continue: controlling loop flow
  • enumerate() for tracking position
  • Nested loops: brief introduction with a concrete example

Classroom Activity

  • Given a list of 20 raw test scores, students write a for loop to compute the total and mean without using sum() or len() — building these from scratch with an accumulator
  • Extension: loop over the scores again to flag any score more than 1.5 SDs from the mean
  • Discussion: why two passes? Could this be done in one pass? What does this tell us about the structure of the computation?
1.5

Functions: Naming What You Mean

Section Overview

Functions are presented as a way of giving a name to a process — exactly as a researcher names a construct. Once defined, a function can be applied anywhere, ensuring consistency.

Topics Covered

  • def syntax, parameters, and return
  • The difference between printing and returning
  • Default parameter values
  • Docstrings: documenting what a function does, not how
  • Calling a function vs. defining it
  • Brief preview of the Python Standard Library as 'functions other people wrote'

Classroom Activity

  • Students refactor work from Sessions 1.2–1.4 into a small library of functions: compute_mean(scores), compute_sd(scores), classify_severity(score), flag_outliers(scores, threshold)
  • Pair exercise: swap code with a partner. Can you understand what each function does from its name and docstring alone?
Unit 1 Closing Reflection: Before this unit, most students experienced programming as typing commands. After this unit, they should experience it as designing a sequence of clearly named, intentional steps.

Unit 1 Section Summary

Section Topic Key Activities Deliverable
1.0 Setting up Python Environment Installing environment or code editor for Python Working IDE or Editor on device
1.1 Algorithms & Computing Unplugged algorithm design, REPL exploration Written algorithm for a scoring task
1.2 Variables and Data Types Dataset card exercise, live coding Typed variable annotations for a dataset
1.3 Conditions and Classification PHQ-9 classifier implementation Working if/elif/else classifier
1.4 Loops and Automation Score processing with accumulators Mean and outlier-flagging script
1.5 Functions and Abstraction Refactoring, peer code reading Documented function library
Unit 2 of 4

Understand and manipulate data structures

"How do I represent and explore what I have collected?"
6 hours CO2, CO3

Before any analysis can be trusted, the data must be understood. This unit addresses a truth that is often glossed over in methods training: real datasets are messy, and the decisions made during cleaning are analytical decisions with consequences.

2.0

Getting Started: Solving a Problem with Code

Section Overview

As students get familiar with computing and algorithms for simple data analytics, they face the need to understand problems before attempting to solve this right away. This section focuses on building flow charts and pseudo code to tackle data analytics challenges that students would face when dealing with social science research.

Topics Covered

  • Identifying the problem and breaking it down
  • Creating a simple flowchart to address the problem
  • Writing pseudo code to mimic the structure of the flow chart

Classroom Activity

  • Students are asked to form groups and understand sample problems in data science.
  • Guided coding: Each group builds a pseudo code to tackle their problem
Conceptual Bridge: Instead of jumpoing directly into the syntax of Python and the functions at the students' displosal, students are forced to solve problems using logical thinking and reasoning.
2.1

Collections: Lists, Dictionaries, and the Shape of Data

Section Overview

Students now confront the need to work with many values at once. This session introduces lists and dictionaries as the two fundamental collection types, and asks students to think carefully about which is the right choice for a given representation task.

Topics Covered

  • Lists: ordered, indexed, mutable — for sequences of same-kind data
  • List operations: append, remove, slicing, indexing, length
  • Dictionaries: key-value pairs — for structured records
  • Choosing between lists and dictionaries: a design decision, not a syntax question
  • Lists of dictionaries as a natural model for a dataset of participants
  • Tuples: briefly — when immutability matters

Classroom Activity

  • Students receive a paper participant record and represent it first as a list, then as a dictionary. A second participant is added — discussion follows about which representation scales more naturally
  • Guided coding: building a list of participant dictionaries and writing a loop to extract all ages
Conceptual Bridge: In R, the dataframe was given to students from the start. Here, they are building up to it. Understanding why a dataframe is useful requires understanding what it replaces.
2.2

The Pandas DataFrame: Data as a Table

Section Overview

Pandas is introduced not as a library to be memorised but as a natural extension of what students just built. The session focuses on loading, inspecting, and understanding a dataset before touching it.

Topics Covered

  • import pandas as pd: the import statement and the alias convention
  • pd.read_csv(): loading real data
  • df.head(), df.tail(), df.shape, df.dtypes, df.info()
  • Accessing columns and rows: df['column'], df.iloc[], df.loc[]
  • Basic filtering: df[df['column'] > value]
  • df.describe(): descriptive statistics at a glance — and why glance is not enough

Classroom Activity

  • Students load a psychology dataset and answer a checklist of questions before performing any analysis: How many participants? What are the data types? Are there obvious outliers? Are there missing values?
  • Discussion: what would happen if we skipped these steps and ran an analysis immediately?
2.3

Missing Data: The Values That Are Not There

Section Overview

Missing data is one of the most consequential and most neglected topics in quantitative psychology training. This session treats it as a conceptual problem first — why is data missing, and does it matter how it went missing?

Topics Covered

  • What NaN means and how Python/pandas represents absence
  • Three mechanisms of missingness: MCAR, MAR, MNAR
  • df.isnull(), df.isnull().sum(): quantifying missingness
  • Strategies: listwise deletion (dropna), column removal, mean/median imputation
  • When each strategy is defensible — and when it is not
  • Documenting what you did and why: the research audit trail

Classroom Activity

  • Students compare two datasets: one with randomly missing data, one with data missing only for highest-anxiety participants. Could you tell the difference by looking at the NaN pattern alone?
  • Apply three different missingness strategies to the same dataset and compare descriptive statistics across the three resulting versions
Ethical Touchpoint: Deciding how to handle missing data is a scientific decision, not a cleaning chore. Both imputation and deletion should be reported transparently, as each carries assumptions about the world.
2.4

Descriptive Statistics from Scratch and from Libraries

Section Overview

This session revisits descriptive statistics — mean, median, mode, variance, standard deviation — and builds them from scratch in Python before using the library versions. The goal is not to memorise formulas but to understand what each statistic is actually doing to the data.

Topics Covered

  • Computing mean, median, and mode from a list using only base Python
  • Computing variance and standard deviation step by step: understanding the sum of squared deviations
  • sorted() for median; mode as the most common value
  • Verifying results with numpy and pandas
  • Population vs. sample standard deviation (ddof=0 vs ddof=1)
  • Percentiles and quartiles: what they tell us that the mean does not

Classroom Activity

  • Paired task: one student writes compute_variance(data, population=True), their partner writes compute_variance(data, population=False). They compare outputs and discuss when each is appropriate — reconnecting to the parameter vs. statistic distinction from the concurrent statistics course
  • Visual exploration: scatter plot of raw scores with a horizontal mean line and shaded SD region
2.5

Visualisation as Understanding, Not Decoration

Section Overview

Visualisation is introduced not as the last step in analysis but as an exploratory tool. Students produce histograms, box plots, and bar charts, spending significant time discussing what each plot reveals that a table of numbers does not — and what each conceals.

Topics Covered

  • The matplotlib anatomy: figure, axes, plot elements
  • Histogram: choosing bin width and what that choice implies
  • Box plot: five-number summary as a visual, interpreting whiskers and outliers
  • Bar chart for categorical data: frequency vs. proportion
  • Overlaying plots: comparing two distributions visually
  • Titles, labels, legends: what every plot must communicate

Classroom Activity

  • Students generate three visualisations of the same variable: narrow-bin histogram, wide-bin histogram, and box plot — then write a short reflection on what each emphasises and what it obscures
  • Group critique: pairs swap plots and give feedback on whether the visualisation would be clear to a first-time reader
Connection to R: Students have already made plots in R using ggplot2-style thinking. The transition is to understand the underlying figure-and-axes model that both R and Python use. The aesthetic choices are different; the conceptual model is structurally similar.

Unit 2 Section Summary

Section Topic Key Activities Deliverable
2.0 Flow charts and Pseudo Code Group discussion to solve data science problems Sample flow charts and pseduo code
2.1 Lists and Dictionaries Paper participant records, list vs dict comparison Participant collection in both formats
2.2 Pandas DataFrames Dataset inspection checklist exercise Pre-analysis inspection report
2.3 Missing Data MCAR vs MNAR comparison activity Missingness strategy comparison table
2.4 Descriptive Statistics From-scratch implementation, library verification compute_variance() function with both modes
2.5 Visualisation Three-plot reflection, peer critique Annotated plot set with written reflection
Unit 3 of 4

Identifying patterns and evidence in data

"How do I find signal within noise?"
8 hours CO3, CO4

This unit is where Python becomes a thinking tool rather than just a computing tool. Students use their conceptual vocabulary to investigate relationships and test ideas. The parallel statistics course is running live during this unit, so students will often encounter the same concept from two directions in the same week. This is intentional.

3.1

Probability and Simulation: Building Intuition for the p-Value

Section Overview

Before any hypothesis test is coded, this session uses simulation to build intuition for what a p-value actually represents. Students generate data under a null hypothesis thousands of times and observe how often they see a result as extreme as their observed one.

Topics Covered

  • Random number generation: random.random(), random.choice(), random.gauss()
  • Simulating coin flips, dice rolls, and then simulated experiments
  • The sampling distribution as an empirical object, not just a theoretical one
  • Counting how many simulations exceed an observed value: an intuitive p-value
  • Why 5,000 simulations give a different answer from 50
  • Connecting the simulation result to the formal p-value and alpha concepts

Classroom Activity

  • Students simulate: "If sleep quality has no effect on memory test scores (null hypothesis), how often would we see a difference as large as 8 points by chance?" They count the proportion of simulated differences ≥ 8 and compare to alpha = 0.05
  • Discussion: what changes if we set alpha to 0.01? What changes if our sample was larger?
Statistical Bridge: This simulation gives students a visceral sense of Type I and Type II errors — a Type I error is what happens when your 'extreme' result is actually one of the 5% of noise outcomes.
3.2

The t-Test: A Case Study in Implementing an Inferential Test

Section Overview

Rather than simply calling scipy.stats.ttest_ind(), students implement an independent samples t-test step by step. The library function is used at the end — for verification, not as the primary tool.

Topics Covered

  • Revisiting the hypothesis structure: null, alternate, one-tailed, two-tailed
  • The logic of the t-statistic: how different are the means, relative to how different we would expect by chance?
  • Step-by-step implementation: group means, group variances, pooled standard error, t-statistic
  • Degrees of freedom: what they count and why they matter
  • Verifying the manual result with scipy.stats.ttest_ind()
  • Effect size: why statistical significance is not the same as practical significance

Classroom Activity

  • Guided worksheet takes students through each step of the t-test computation; at each step they are asked: what would this number tell us if we stopped here?
  • Reflection: the library function returns the same numbers in one line. What do we lose by only ever using the library?
On the Paired t-Test: The paired t-test is introduced as a natural extension — instead of comparing two groups, we compare each participant to themselves across time, reducing to a test of whether the mean difference score is different from zero.
3.3

Correlation: Measuring the Direction and Strength of Relationships

Section Overview

Correlation is presented as a question about geometry as much as statistics: do these two variables move together? The session builds Pearson's r from its components before computing it with a library. Spearman's rho is introduced as what happens when we care about rank rather than magnitude.

Topics Covered

  • Covariance: the numerator of Pearson's r and what it captures
  • Why r is bounded between -1 and +1: the normalising role of standard deviations
  • Computing Pearson's r step by step, then with numpy.corrcoef()
  • Spearman's rho: computing ranks with scipy.stats.rankdata(), then correlating the ranks
  • When to use each: normality, outliers, and whether rank or magnitude is meaningful
  • The correlation matrix: representing many relationships at once

Classroom Activity

  • Students compute both Pearson's r and Spearman's rho for the same two variables in a dataset containing strong outliers, then discuss: which better represents the true relationship?
  • Scatter plot with correlation coefficient annotated: students produce this for three pairs of variables and rank them by strength, then discuss whether strong correlation implies importance
3.4

Correlation, Causation, and Confounds: Critical Thinking with Code

Section Overview

This session slows down to think about what a correlation coefficient actually means in the real world. Using datasets where strong correlations are artefacts of confounding variables, students practise the critical evaluation skills that separate a researcher from someone who runs functions on data.

Topics Covered

  • Classic spurious correlations and the third-variable problem
  • The concept of a confounding variable: what is the third thing?
  • Partial correlation: holding a third variable constant — conceptual introduction
  • Directionality: when A correlates with B, could B cause A?
  • The ecological fallacy: correlations at the group level may not apply to individuals
  • Implications for psychological research: media misinterpretation of correlation findings

Classroom Activity

  • Students identify a plausible confound in a dataset with a strong correlation, subset the data by that confound, and compute the correlation separately within each subset
  • Writing exercise: write a single paragraph a journalist might write about the finding, then a corrected version written by a researcher
3.5

Introduction to Regression and Chi-Square: Prediction and Independence

Section Overview

Simple linear regression as a natural extension of correlation — moving from describing a relationship to predicting a value — and chi-square as the tool for asking whether two categorical variables are related. Both are implemented at least partially from scratch.

Topics Covered

  • From correlation to regression: the line of best fit as a predictive model
  • The slope and intercept: what each means in the context of the variables
  • Residuals: the difference between prediction and reality
  • R-squared: what proportion of variance in Y is explained by X?
  • Chi-square: testing whether the distribution of one categorical variable is independent of another
  • Observed vs. expected frequencies; computing chi-square manually in Python

Classroom Activity

  • Regression: students implement the OLS formula for slope and intercept manually, plot the resulting line over a scatter plot, then use sklearn to verify
  • Chi-square: given a contingency table (gender × diagnosis), students compute expected frequencies and chi-square without scipy, then verify with it
Concurrent Statistics Link: Both regression and chi-square are being introduced simultaneously in the statistics course. This session gives students a concrete computational model that will deepen their understanding of the formal treatment they are receiving in parallel.

Unit 3 Section Summary

Section Topic Key Activities Deliverable
3.1 Probability and Simulation Null hypothesis simulation exercise Simulation script with p-value estimate
3.2 The t-Test Step-by-step guided implementation Annotated t-test worksheet and script
3.3 Correlation Pearson vs Spearman comparison, matrix Correlation analysis with plots
3.4 Causation and Confounds Confound identification, journalist vs researcher writing Short critical evaluation paragraph
3.5 Regression and Chi-Square OLS implementation, contingency table exercise Manual and library outputs compared
Unit 4 of 4

Responsible communication with programming

"How do I tell a story that is honest and clear?"
6 hours CO4

The final unit asks: now that you can compute things, can you communicate them honestly? This unit addresses reproducibility, visualisation ethics, writing for non-technical audiences, and the skills of reflection and synthesis. The capstone project draws on everything from the preceding three units.

4.1

Reproducibility: Writing Code That Others Can Run

Section Overview

Students discover how quickly an undocumented script becomes opaque — even to its own author — and learn the practices that make code a reproducible scientific artifact.

Topics Covered

  • Code comments: when to comment and what not to comment
  • Docstrings: documenting functions for others
  • Variable naming as documentation: why score_before_training > s1
  • The analysis pipeline as a sequence: import, inspect, clean, describe, analyse, visualise, interpret
  • Jupyter Notebooks as a format for literate programming
  • Setting a random seed for reproducibility in simulations
  • The replication crisis in psychology: a brief contextual discussion

Classroom Activity

  • Students receive a deliberately poorly documented script that performs a correct analysis. They reconstruct what it does, add appropriate comments and docstrings, rename variables, and reorganise it — without changing any analytical logic
  • Pair exercise: one student runs the partner's refactored script and records every point of confusion. These confusions become the agenda for a short revision
4.2

Visualisation Ethics: Honesty in Charts

Section Overview

Students build problematic visualisations deliberately, understand why they mislead, and then correct them. The goal is critical literacy as much as technical skill.

Topics Covered

  • Truncated y-axes: making small differences look large
  • Cherry-picking time windows in a time-series plot
  • Inappropriate chart types: 3D pie charts, dual-axis plots with arbitrary scales
  • Missing error bars or confidence intervals
  • Colour choices that mislead: gradients implying order where there is none
  • APA and ethical reporting standards for figures

Classroom Activity

  • 'Spot the Manipulation': students are shown six published-style charts containing at least one misleading choice each, and must identify the problem and suggest a correction
  • Fix it: students recreate two of these charts correctly in Python, writing a one-sentence APA-style caption for each
A misleading visualisation is not always the result of bad intent. Often it reflects a failure to think from the reader's perspective, or an uncritical acceptance of software defaults.
4.3

Writing for Two Audiences: Researchers and Non-Researchers

Section Overview

Students take a Python-generated analysis and write two interpretations of the same result: one for a peer reviewer, and one for a general reader. The exercise reveals how much translation is required and what is lost or gained in each version.

Topics Covered

  • What a results section should contain: statistic, df, p-value, effect size, direction
  • Translating statistical language for non-specialist audiences
  • Common misinterpretations: what a p-value is not, what 'no significant difference' does not mean
  • Reporting limitations: what the analysis cannot tell us
  • Connecting to ethical data reporting standards from the R programming course

Classroom Activity

  • Given output of a correlation analysis (r = 0.43, p = 0.02, n = 36), students write: (a) a formal APA-style results paragraph, and (b) a three-sentence plain-language explanation for a school newsletter
  • Pairs read each other's versions and discuss where the technical version is inaccessible and where the plain-language version has been oversimplified
4.4

End-to-End Pipeline: Applying the Full Workflow

Section Overview

A supervised capstone exercise. Students receive a dataset they have not seen before and a brief research question, and must apply the complete analytical pipeline working individually or in pairs.

Pipeline Steps

  1. Load and inspect the dataset: shape, types, missing values
  2. Clean: address issues found in step 1; document all decisions
  3. Describe: compute and display relevant descriptive statistics
  4. Visualise the distributions of key variables
  5. Formulate and test a hypothesis appropriate to the research question
  6. Visualise the relationship of interest
  7. Interpret: what does the analysis suggest? What can it not tell us?
  8. Reflect: what would you do differently with more time or more data?
Instructor Role: The instructor does not answer "how do I code X?" questions in this session. Instead, questions are redirected: "What are you trying to find out at this step? What would the answer look like?" This scaffolds independent problem-solving.
4.5

Reflection and the Bigger Picture

Section Overview

The final session steps back from code entirely. Students present their pipeline exercise briefly, share one thing that surprised them, and engage in a structured reflection on how computational thinking has changed how they think about statistics, measurement, and research.

Structure of the Section

  • Brief presentations: each student or pair shares one visualisation and one finding from Section 4.4 (20 minutes total)
  • Structured written reflection responding to the prompts below
  • Whole-group discussion: what concepts from statistics do you now understand differently?
  • Looking ahead: brief introduction to what Python can do that this course has not covered — NLP, web scraping, machine learning — as motivation for continued learning
Reflection Prompts
  1. Describe one concept from your statistics course that you now understand differently because of writing code to implement it.
  2. Describe a moment in this course when you were confused. What were you confused about? How did you resolve it?
  3. If you were to explain to a friend what 'computational thinking' means, what would you say?
  4. What is one thing you wish you had been told at the start of this course?
  5. What is one question about data or programming that this course has left you wanting to explore?
Closing Note: This course has not made you a programmer. It has done something more specific: it has given you a way of taking a problem apart, representing it precisely, and testing your understanding of it by trying to make a machine do it. The tools will change. The way of thinking does not have to.

Unit 4 Section Summary

Section Topic Key Activities Deliverable
4.1 Reproducibility Refactoring undocumented script, peer confusion audit Fully documented and reorganised script
4.2 Visualisation Ethics Spot the manipulation, fix-it exercise Two corrected charts with APA captions
4.3 Two Audiences Dual-audience writing exercise APA paragraph and plain-language version
4.4 End-to-End Pipeline Supervised novel dataset analysis Complete documented analysis notebook
4.5 Reflection and Discussion Mini-presentations, guided reflection Written reflection (300–400 words)