Types of Variables
Section titled “Types of Variables”In statistics, there are two main types of variables: categorical (qualitative) variables and quantitative variables.
Categorical (qualitative) variables
Section titled “Categorical (qualitative) variables”A categorical variable sorts each case into a group or label. The values are usually words or codes (for example: blood type, favorite color, zip code used only as a label). With categorical data, we typically report counts or percents in each category.
Quantitative variables
Section titled “Quantitative variables”A quantitative variable is a variable with a numeric value and can be analyzed using arithmetic operations like differences, totals, and averages. Quantitative variables are split into:
- Discrete variables: countable “jumps” between values (number of siblings, number of text messages in a day). Usually this comes in the forms of integers, but is not limited to them.
- Continuous variables: in principle could take any value in an interval (height, time, temperature), though what we record is usually still rounded or binned (partitioned based on value) for convenience. Think of continuous variables as variables that can be expressed on a spectrum.
Types of Descriptive Methods
Section titled “Types of Descriptive Methods”Descriptive statistics means organizing and summarizing data we actually have, without yet jumping to conclusions about a larger world. For univariate data, we use tabular summaries (tables), graphical summaries (plots), and numerical summaries (means, spreads, and positions).
Tabular methods
Section titled “Tabular methods”Tables are the natural home for frequency: how often each value or category appears.
- Let be the number of observations (the sample size, or size of the dataset).
- The frequency of a value is how many times it occurs; it is often denoted .
The relative frequency compares a category’s frequency to the whole dataset:
Relative frequencies are especially useful when two datasets have different sizes, since percents put them on a common scale.
The cumulative frequency gives the count of observations less than or equal to a chosen value (or upper endpoint of a class). It is a running total as you move through ordered categories or ordered bins.
A frequency distribution lists possible values (or classes) of the variable together with their frequencies (and often relative or cumulative frequencies). Building that table is often the first step before drawing a histogram or cumulative relative frequency graph.
| Value or class | Frequency | Relative frequency | Cumulative frequency |
|---|---|---|---|
| Category/bin 1 | |||
| Category/bin 2 | |||
| Category/bin 3 |
| Display | Best use |
|---|---|
| Frequency table | exact counts by category or interval |
| Dotplot | small quantitative data sets |
| Histogram | distribution shape for many quantitative values |
| Stemplot | preserves individual values while showing shape |
| Boxplot | quick comparison of center, spread, and outliers |
Graphical Methods (Qualitative)
Section titled “Graphical Methods (Qualitative)”For categorical data, we want displays that compare category sizes.
// draw diagrams for each type of graphical method (qualitative and quantitative)
Bar charts
Section titled “Bar charts”In a bar chart, each category gets a bar and the length or height of the bar (depending on orientation) shows frequency (count) or relative frequency (percent). Categories on an axis are usually separated with a little space between bars, which signals that the order of categories is not necessarily numeric.
Pie charts
Section titled “Pie charts”A pie chart represents the whole as a circle and divides it into slices whose central angles (or areas) match relative frequencies. For example, a category with relative frequency 0.36 gets about 36% of the circle. Pie charts work best with a small number of categories and when you want to emphasize parts of a whole. Usually, the pies will be different colors to have better contrast. They become hard to read when there are many thin slices or when differences are subtle.
Graphical Methods (Quantitative)
Section titled “Graphical Methods (Quantitative)”For quantitative data, we care about center, spread, shape, and unusual values.
Dotplots
Section titled “Dotplots”A dotplot stacks a dot above a number line for each occurrence of a value (or stacks dots in equal-width bins if values are rounded). Dotplots are best with small-to-moderate datasets: you see every value, clusters, gaps, and outliers without losing detail. Dotplots can also illustrate the shape of a distribution.
Stemplots (stem-and-leaf displays)
Section titled “Stemplots (stem-and-leaf displays)”A stemplot splits each number into a stem (leading digit or digits) and a leaf (usually the last digit). Stems are listed in order; leaves are often ordered on each stem. The split between stem and leaf is a choice: you might split tens vs. ones, or group stems (e.g., 2*, 2•) when a plot is too sparse or too crowded. Stemplots preserve the actual values and work well for small datasets. The stems are listed on the left and the leaves are listed on the right.
Histograms
Section titled “Histograms”A histogram groups quantitative data into intervals (bins), then draws bars whose heights show frequency or relative frequency (or density, in more advanced courses). Bars touch to show that the horizontal axis is a continuous scale (even though data are binned). The shape of a histogram (symmetric, skewed, unimodal, bimodal) can tell you a lot about the data (talked about later).
// the vertical axis cuts off a bit and the vertical bars should not be intersecting with the vertical axis
Cumulative relative frequency graphs (ogives)
Section titled “Cumulative relative frequency graphs (ogives)”An ogive plots cumulative relative frequency (from 0 to 1, or 0% to 100%) against values or upper class boundaries. Place a point above each boundary at the cumulative percent up to that boundary, then connect points with line segments. The curve rises; its height at a value tells you what fraction of data falls at or below that point.
Boxplots
Section titled “Boxplots”A boxplot (box-and-whisker plot) summarizes a quantitative variable using quartiles and the median. Draw a box from the first quartile to the third quartile ; draw a line inside the box at the median. The interquartile range is . “Whiskers” typically extend to the most extreme values within 1.5 × IQR of the quartiles; points beyond that range are plotted individually as outliers. Boxplots are ideal for comparing several groups on the same scale.
// remove the overlapping lines on Q1, median, and Q3
Examining Graphs
Section titled “Examining Graphs”Whenever you look at a univariate graph, there are a few main traits that should always be described. When comparing two graphs, you should always describe the center, spread, and shape, as well as irregularities in the plot (like clusters, gaps, and outliers).
Center
Section titled “Center”The center is a typical or middle value—where much of the data sits. For many distributions, the mean and median lie near the visual center; for skewed data they can separate, which is an important aspect of the plot.
Spread
Section titled “Spread”Spread describes how far values wander from center. Informally, look at whether points are tightly packed or widely scattered. Later we attach numbers to spread: range, interquartile range, variance, and standard deviation.
Shape tells us where data pile up and whether the distribution is symmetric or skewed.
- Symmetric: the left and right sides are roughly mirror images (like a bell curve or a uniform histogram).
- Skewed: one tail stretches farther than the other. If the right tail is longer (extreme large values pull the tail), the distribution is right-skewed (positively skewed). If the left tail is longer, it is left-skewed (negatively skewed). Name the skew by the direction of the tail, not by where most of the data are.
Describe the modality too: one clear peak is unimodal, two peaks are bimodal, and so on. Multiple peaks can suggest that the data combine different subgroups.
Clusters and gaps
Section titled “Clusters and gaps”Clusters are groups of values separated from other groups; they can indicate the existence subpopulations or different regimes (for example, two manufacturing lines). Gaps are intervals with no (or very few) observations where you might have expected some; they invite questions about sampling, measurement, or real structure.
Outliers
Section titled “Outliers”An outlier is a value that stands apart from the overall pattern. On a boxplot, a common numerical rule flags outliers relative to the quartiles:
Always ask whether an outlier is a data entry error, a special case worth investigating, or simply natural variability in a heavy-tailed variable.
Summarizing Distributions: Population and Sample
Section titled “Summarizing Distributions: Population and Sample”We distinguish population and sample because notation and formulas track that distinction.
- The population is the entire group of individuals or instances we want to understand.
- A sample is the part of the population we actually measure.
We compute statistics from a sample to estimate unknown population quantities. Greek letters (for example , ) often denote population parameters; Roman letters (basically English letters) with bars or hats (for example , , ) denote sample statistics.
Numerical Methods for Continuous Variables
Section titled “Numerical Methods for Continuous Variables”Numerical summaries compress a distribution into a few interpretable numbers. Always pair a measure of center with a measure of spread.
Measures of Central Tendency
Section titled “Measures of Central Tendency”Mean (average) balances all values, but it is sensitive to outliers and skew.
For a population of size with values :
For a sample of size :
Median is the middle value when data are ordered: half the values lie at or below it and half at or above it.
- If there are ordered observations and is odd, the median is the value at position .
- If is even, the median is the average of the values at positions and .
The median is resistant (robust) to outliers, meaning extreme values barely move it, which makes it a measure of central tendency for skewed data or data with outliers.
Measures of variation
Section titled “Measures of variation”Range is the simplest spread measure: largest minus smallest. It uses only two numbers and is very sensitive to outliers.
Interquartile range (IQR) is the width of the middle half of the data:
It is resistant to extremes and matches the width of the box in a boxplot.
Standard deviation measures typical distance from the mean. For a population:
For a sample, we divide by (Bessel’s correction) so that is an unbiased estimator of population variance:
Larger standard deviation means more spread and zero standard deviation means no spread (all values equal).
Measures of position
Section titled “Measures of position”Percentiles generalize the median. The ****th percentile is a value such that about % of observations fall at or below it. A common position rule for the location of the th percentile in ordered data of size is:
If is not an integer, interpolate between adjacent ordered values. Calculator or software conventions may differ slightly, so be consistent and explain your method when needed.
Quartiles are special percentiles:
- : 25th percentile
- : 50th percentile (the median)
- : 75th percentile
Standardized scores (z-scores) compare a value to the distribution’s center and spread:
With a sample, use and in the same pattern. A z-score represents the amount of standard deviations above or below the mean a value is. Values with a large -score are unusual relative to that distribution. Note that for future chapters, z-score will apply heavily to a normal/Gaussian distribution.
Effects of Changing Units on Summary Measures
Section titled “Effects of Changing Units on Summary Measures”Linear changes to data produce predictable changes to summaries. Suppose we transform each observation .
Adding a constant (for example, converting Celsius to a shifted scale, or adding a bonus point to every score): .
- Mean, median and quartiles shift by .
- Spread measures that depend only on distances between values (range, IQR, standard deviation) are unchanged.
Multiplying by a constant (for example, feet to inches): .
- Mean, median, and quartiles multiply by .
- Range, IQR, and standard deviation multiply by
| Summary Measure | ||
|---|---|---|
| Mean | ||
| Median | ||
| Range | unchanged | |
| Standard Deviation | unchanged | |
| Quartiles | ||
| Interquartile Range | unchanged |
Investigative Questions and Data Collection
Section titled “Investigative Questions and Data Collection”Statistics starts with an investigative question: a question that can be answered with data and that anticipates variability. A weak question asks for one fixed fact. A stronger statistical question asks about a distribution, comparison, association, or effect.
Examples:
- Weak: “How many minutes did Alex study last night?”
- Statistical: “How do study times vary among students in this class?”
- Statistical comparison: “Do students in morning classes tend to study more than students in afternoon classes?”
Populations, Samples, and Frames
Section titled “Populations, Samples, and Frames”- The population is the full group you want to learn about.
- A sample is the smaller group actually measured.
- A sampling frame is the list or source used to choose the sample.
- A census measures every member of the population.
The population and frame do not always match. If the frame misses some groups, then even a random sample from that frame may underrepresent the population.
Random Sampling
Section titled “Random Sampling”A simple random sample gives every possible sample of the chosen size an equal chance of being selected. Random sampling is important because it reduces selection bias and supports generalizing from the sample to the population sampled from.
Other probability sampling designs:
- Stratified random sample: split the population into strata, then sample randomly within every stratum.
- Cluster sample: split the population into clusters, randomly choose clusters, then measure everyone in the chosen clusters.
- Systematic sample: choose a random starting point and then sample every th item.
In a proportional stratified sample, the number sampled from each stratum is proportional to the stratum’s size in the population. This helps the combined sample represent the population while still guaranteeing that every stratum appears in the data.
Systematic samples are quick to carry out, but they can be biased if the ordered list has a hidden pattern that lines up with the spacing . Cluster samples are often cheaper than simple random samples, but they can be more variable if people inside each selected cluster are very similar.
Potential Problems With Sampling
Section titled “Potential Problems With Sampling”Bias is systematic error, not just random variation. Common sources include:
- Undercoverage: part of the population is missing from the frame.
- Nonresponse bias: people who do not respond differ from those who do.
- Response bias: answers are inaccurate because of wording, pressure, memory, or other measurement problems.
- Voluntary response: people choose themselves into the sample, often because they have strong opinions.
- Convenience sampling: the sample is chosen because it is easy to reach.
- Wording bias: the question itself pushes people toward a particular answer.
Random sampling helps with selection bias, but it does not automatically fix bad wording, nonresponse, or measurement problems.
Experimental Design
Section titled “Experimental Design”An observational study measures variables without assigning treatments. It can show association, but confounding variables usually prevent a cause-and-effect conclusion.
An experiment deliberately imposes treatments on experimental units. Random assignment helps balance lurking variables across treatment groups and supports cause-and-effect conclusions.
Key ideas:
- Treatment: a condition applied to experimental units.
- Factor: an explanatory variable controlled by the experimenter.
- Levels: the values of a factor.
- Control group: a baseline group for comparison.
- Placebo: an inactive treatment that looks real.
- Blinding: subjects, evaluators, or both do not know which treatment was assigned.
- Replication: enough experimental units are assigned to each treatment.
- Blocking: group similar units first, then randomize within each block.
Common experiment layouts:
- Completely randomized design: all experimental units are randomly assigned among the treatments.
- Randomized block design: similar units are grouped into blocks first, then treatments are randomly assigned within each block.
- Matched-pairs design: each pair contains two similar units, or each unit receives both treatments in random order. This is a special block design for comparing two treatments.
If the same unit receives both treatments, think about order effects and carryover effects. Randomizing the order helps with order effects, but it cannot always fix carryover if the first treatment permanently changes the unit.