Check out Wikipedia's article on Data Science. Quoting from that article, I guess that
Statistics (or data science, if you want) is hot for good reason. Data is becoming easier and easier to come by and it's impact more and more pervasive. Think
That's quite a variety of fields! Maybe that's why I recently stumbled on this article (written by a physician) asserting that statistics may be the most important class that you'll ever take.
What if you're not interested in being a techie or a doctor or anything like that? What if you just want to be an ordinary person?
First off, if you complete your goal of obtaining a college degree, you're not exactly an "ordinary" person. By my estimates, barely 31% of US adults have a bachelor's degree or higher. Of course, only some fraction of those folks have taken a statistics class so, in a sense, you're already approaching the data elite!
You really need some level of quantitative literacy in general and statistical literacy in particular to be an informed citizen these days. Politics these days provides all kinds of examples. Here are just a few examples:
One major objective of this class to learn to deal with real world data. So let's start by taking a look at our class data.
Note that, as we go through these examples, we'll meet several important concepts from section 1.2 of our text whose title is Data Basics.
I've collected the results of our class survey and the last few lines look something like so:
import pandas as pd
df = pd.read_csv('../records/results-survey538927.csv')
df = df.drop(['Date submitted', 'Access code','Last page', 'Start language', 'Seed'], axis=1)
#df['Where is your hometown?'] = df['Where is your hometown?'].apply(lambda s: 'looks like: 35.6,-82.55')
df.tail()
Response ID | How old are you? | How tall are you? [Feet] | How tall are you? [Inches] | Are you left or right handed? | What is your gender (optional): | Choose your eye color | Choose your eye color [Other] | What is your major? | Where is your hometown? | |
---|---|---|---|---|---|---|---|---|---|---|
34 | 37 | 19 | 5 | 9 | Right | Male | Brown | NaN | Environmental Studies | 42.6123;-71.41414 |
35 | 38 | 21 | 5 | 10 | Right | Male | Blue | NaN | Computer science | 35.59925;-82.56157 |
36 | 39 | 19 | 6 | 5 | Right | Male | Brown | NaN | Management | 37.55376;-77.46026 |
37 | 40 | 30 | 6 | 1 | Right | Male | Hazel | NaN | Computer science | 30.07994;-95.41716 |
38 | 41 | 19 | 6 | 2 | Right | Male | Brown | NaN | Psychology | 29.51372;-95.44922 |
That's actual data, though I've set everyone's hometown to Asheville for privacy purposes.
The result of our import is called a data table or data frame.
Each row in a data table is called an observation and corresponds to a case in our study.
Each column corresponds to a variable or characteristic associated with the cases.
There are two main types of data and both types can be further classified into two sub-types.
We can get and understanding of what numerical data looks like by examining a histogram.
df['height'] = [r[1]['How tall are you? [Feet]'] + r[1]['How tall are you? [Inches]']/12 for r in df.iterrows()]
df.hist(['height','How old are you?'],grid=False, edgecolor='black', bins=5, figsize = (12,6));
Alernatively, we might look at box plot, that illustrates the so-called five-point summary of
min, 1st quartile, median, 3rd quartile, and max.
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
df.boxplot(['How old are you?'] , grid=False)
plt.subplot(1,2,2)
df.boxplot(['height'] , grid=False);
Lots of people seem to love pie charts for categorical data. I only favor pie charts when comparing two values of a categorical variable.
df['What is your gender (optional):'].value_counts().plot.pie(figsize=(8,8));
An better way to look at categorical data is with a bar chart, which makes it much easier to compare two values that are quite close to one another.
df['Choose your eye color'].value_counts().plot.bar(rot=0, figsize=(13,8));
Sometimes we'll want to find if there's a relationship between two variables. In the following side-by-side boxplot, we examine how the relationshipe between gender and height.
import seaborn as sns
pic = sns.catplot(
kind='box', x='What is your gender (optional):', y='height', data=df,
aspect = 1.5)
Geographic data is of tremendous importance and is often best illustrated on a map. Here's what the actual answers to the hometown question looks like:
import folium
import pandas as pd
from numpy import random
map = folium.Map(location = [35.6, -82.6], zoom_start = 5)
random.seed(1)
def s_to_pt(s):
pt = s.split(';')
return [float(pt[0]) + (random.random()-0.5)/20, float(pt[1]) + (random.random()-0.5)/20]
gb = df.groupby('Where is your hometown?').count()
for pt in df['Where is your hometown?']:
folium.Circle(s_to_pt(pt), 5000, fill=True, popup = pt).add_to(map)
map
One simple characterization of statistics is
the study of how to collect, analyze, and draw conclusions from data.
Note the three parts:
Collecting data often boils down to designing an experiment or observational study.
We'll talk a lot more about getting data next time.
The images we've seen today allow us to draw rough qualitative conclusions about the data we see. Quantiative analysis is more numerical. For example, 2 out of the 39 people in the class are left handed, or about 5.1%.
This is more precise information than we could glean from a pie chart.
Ultimately, we want to draw inferences or conclusions from data. To do so, it helps to have a little terminology:
The main question is: once you've computed a statistic from a sample, what might that tell you about the corresponding parameter for the whole population?
For example, I guess that 5.1% of our class is left handed. We could take that as an approximation to the number of left handed folks in the whole population. How accurate an approximation might we expect that to be?