STAT5002 Chap.1 Graphical Summaries and Initial Data Analysis
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.
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
- +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.
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.
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.
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.
STAT5003 Computational Statistical Methods · DATA2002 Data Analytics: Learning from Data · QBUS5001 Foundation in Data Analytics for Business