University of Sydney · FACULTY OF STATISTICS

STAT5002 Chap.1 Graphical Summaries and Initial Data Analysis

- one subject, every graph, every model, every mark
12 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 1 of 12 · STAT5002

Graphical Summaries and Initial Data Analysis

Before any formal analysis, a statistician takes a first broad look over the data, called initial data analysis. It asks whether the data can answer the research question at all: where the data came from and how clean it is, what was recorded, what wrangling is needed, and which graphical and numerical summaries will show its main features. Here the focus is the structure and graphical side of that first look.

You learn to classify every variable as qualitative (categories, either ordered as ordinal or unordered as nominal) or quantitative (numbers that are counted, so discrete, or measured, so continuous), and to see that context can move a variable between types, as when an age is recorded in bands. You then make R agree with that classification by checking str() output and converting columns with as.factor() and as.numeric().

The plot follows from the type: a barplot built from table() for one qualitative variable, stacked or side by side bars for two, a histogram or boxplot for one quantitative variable, a scatter plot for two quantitative variables and a comparative boxplot for a quantitative variable split by groups. Most of the computational weight sits on the density scale histogram.

With unequal class intervals, the area of a block is the proportion of subjects in it and the height is that proportion divided by the interval length, so the tallest block need not hold the most subjects. You also set interval edges with right = F, choose a sensible number of intervals, and replace missing value codes with NA.

The chapter closes with logical operators in R: comparisons that act elementwise, the difference between = and ==, combining conditions with &, | and !, counting with sum() because TRUE counts as one, and filtering rows of a data frame.

In this chapter

What this chapter covers

  • 01

    Four parts of a first look: background, structure, wrangling and summaries

  • 02

    Variables, subjects and the dimension of a data frame

  • 03

    Qualitative variables: ordinal versus nominal categories

  • 04

    Quantitative variables: discrete counts versus continuous measurements

  • 05

    Checking storage with str() and converting with as.factor() and as.numeric()

  • 06

    Barplots from table(), and stacked or side by side bars for two variables

  • 07

    Histograms on the density scale: area is proportion, height is crowding

  • 08

    Left closed, right open intervals and the right = F argument

  • 09

    Choosing the number of class intervals

  • 10

    Scatter plots, boxplots and comparative boxplots

  • 11

    Logical operators, elementwise comparisons and counting with sum()

  • 12

    Filtering rows of a data frame with combined conditions

Worked example · free

Parcel weights on the density scale

Q [5 marks]. A courier weighs 200 parcels and groups the weights (kg) into the class intervals [0,1), [1,2), [2,5), [5,15) with counts 40, 50, 80, 30. Find the area and height of each block of a density scale histogram, say which interval is most crowded and which holds the most parcels, and find the proportion of parcels weighing at least 2 kg. (5 marks. The mark allocation is ours, not the University's.)
Our 80 commute times on the density scale.Our 80 commute times on the density scale. The block over [10,20) is the tallest, yet [20,40) holds more students: its block is lower but 2 times as wide, so its area is larger.12 studentsarea 15.0%28 studentsarea 35.0%30 studentsarea 37.5%10 studentsarea 12.5%0102040900.000.010.020.030.04commute time (minutes), intervals closed on the leftdensity (proportion per minute)
Our 80 commute times on the density scale. The block over [10,20) is the tallest, yet [20,40) holds more students: its block is lower but 2 times as wide, so its area is larger.
  • +1Areas are proportions: [0,1): 40/200 = 0.2; [1,2): 50/200 = 0.25; [2,5): 80/200 = 0.4; [5,15): 30/200 = 0.15. They add to 1.
  • +1Heights are proportion divided by interval length: [0,1): 0.2/1 = 0.2; [1,2): 0.25/1 = 0.25 per kg.
  • +1[2,5): 0.4/3 = 0.1333; [5,15): 0.15/10 = 0.015 per kg, so the two wide intervals get much lower blocks.
  • +1The most crowded interval is [1,2) at 0.25 per kg, but the largest area is [2,5), which holds 0.4 of the parcels.
  • +1At least 2 kg means the last two blocks: 0.4 + 0.15 = 0.55.
Heights are 0.2, 0.25, 0.1333, 0.015 per kg; [1,2) is the most crowded interval, [2,5) holds the most parcels, and 0.55 of parcels weigh at least 2 kg.
Sia tip — Before answering any question that asks which interval holds the most subjects, multiply each height by its interval width; comparing heights alone answers a different question about crowding.
Glossary

Key terms

Initial data analysis
The first general look at a data set, covering its background, structure, wrangling and summaries, done before formally answering the research question.
Qualitative variable
A qualitative variable is one whose values are categories rather than amounts; it is ordinal when the categories have an order and nominal when they do not.
Quantitative variable
A quantitative variable is one whose values are numbers that measure an amount, either discrete (counted) or continuous (measured on a scale).
Density scale
The density scale is a vertical axis for a histogram on which each block's area equals the proportion of subjects in its class interval, so the total area is one.
Class interval
A class interval is one bin of a histogram; R's right = F makes each interval include its left edge and exclude its right edge.
Logical operator
A logical operator is an R symbol such as ==, !=, &, | or ! that returns TRUE or FALSE, elementwise when applied to a vector.
FAQ

Graphical Summaries and Initial Data Analysis FAQ

Why is the tallest bar of a histogram not always the interval with the most data?

Height on the density scale is the proportion divided by the interval width. A narrow interval with a moderate share can stand taller than a wide interval holding more subjects, so the count lives in the area, not the height.

Is a postcode or student ID a quantitative variable?

No. Although the values are digits and R may store them as integers, they label categories and averaging them is meaningless. Treat them as qualitative and convert the column with as.factor() before summarising.

What does right = F do in hist() and cut()?

It makes each class interval left closed and right open, so a value sitting exactly on a boundary is counted in the interval that starts at that value rather than the one that ends there.

How do I count values meeting a condition in R?

Write the condition as a logical comparison such as x > 5 & x <= 10, which returns TRUE or FALSE for every element, then wrap it in sum(). Each TRUE counts as one, so the sum is the number of matching values.

Study strategy

Exam move

Take any data set you have met in the unit and, before plotting, write each column's type (ordinal, nominal, discrete or continuous) beside the R type that str() reports; fix every mismatch with as.factor() or as.numeric().

Next, practise the density histogram by hand: invent four unequal intervals with counts, build the table of proportions and heights, and then reverse it by recovering counts from heights times widths times the total. Draw the blocks to scale on grid paper so the tallest block and the largest area visibly disagree.

For the R side, type small vectors and predict the output of sum() with combined & and | conditions before running them, and practise one filter of a data frame by rows. Finally, for each plot type, write one sentence naming the variables it needs, so choosing the plot becomes automatic under time pressure.

Working through Graphical Summaries and Initial Data Analysis in STAT5002? Sia is AskSia’s AI Statistics tutor — ask any STAT5002 Graphical Summaries and Initial Data Analysis question and get a clear, step-by-step explanation grounded in how STAT5002 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 196 of your University of Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your STAT5002 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works