Python Tutorial: Experimental Design in Python | Intro

Luke Hayden introduces experimental design and data visualization in Python. He covers exploratory data analysis, the plot9 package for grammar-of-graphics visualization, and three core plot types: scatter plots, box plots, and density plots using height, weight, and sex data.
Chapters
Hello, my name is Luke Hayden. In this course we're going to learn how to use data to answer questions and get reliable answers. We can use data to answer questions Does a drug work? Is one variable correlated with another? This course will teach you skills to help answer such questions. However, to get reliable answers, we will need to think scientifically, considering different groups and different experiments and making valid comparisons. This course will teach you how to understand the factors at work. We will learn a set of rigorous methods, including a number of statistical tests. First, we need to know what questions to ask here. Exploratory data analysis is very useful. For example, we can build graphs that make us wonder about whether our data contains a trend and then examine these with statistical tests. We'd encounter many types of variables and one way to classify them is as either discrete or continuous. A discrete variable can have a finite set of possible values, for example a binary true or false. A continuous variable can have an infinite number of values like a measurement. When plotting, we map these variables to different aspects of the plot. We can assign a variable to the x or y axis, or we can change the color using the fill or color arguments depending on the variable. In this course we'll be using the plot9 package to create plots. Plot9 uses a grammar of graphics approach, which makes it really easy and intuitive to use. We start with a PANDAS dataframe containing at least one variable of interest and pass it to the ggplot function. Then we define what aspects of the plot will correspond to which variable for the data frame with the I s function. Finally, we specify a geometry which is the basic form of our plot. In this course we'll primarily use scatter plots, box plots, and density plots. We need to ensure that we provide the mappings that the chosen geometry requires. Let's say we want to create some plots from a data set containing the height and weight of a group of people. First, let's look at a simple scatter plot which we can create using geompoint. With the scatter plot, each row in our data frame will correspond to one point and each axis will correspond to one variable. Additionally, we pass sex to the color argument to color the points according to sex. This simple plot has one point for each row of the data frame. To make a box plot, we'll assign our variable of interest height to the y axis. Then, by assigning the discrete variable sex to x and fill, we colour our boxes by sex. This plot provides an overview of our data and an estimate of the variability of our samples. The midline of the box is the median value of our distribution, and the top and bottom of the box contains half of all our samples. Lastly, we'll look at the density plot. Like the box plot, this gives us a handy view of distributions. The density plot is more visually complex, which is useful when our distribution of values is atypical. Here, the values of our variable of interest are along the x axis, and the density is plotted on the y axis, meaning that a higher peak indicates more samples of that value. As with the box plot, we can use a discrete variable to split our samples. Now it's your turn to practice creating.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







