Segmented and mosaic bar charts

分段条形图与马赛克图

How do segmented bar charts and mosaic plots work?

A segmented bar splits one bar per group; a mosaic uses width for group size and height for proportions.

SkillKP000939

Sign in to read the whole lesson, with 1 interactive aid, 4 exercises

Sign in / Sign up

Mastery goals

  • Can construct segmented bar charts or mosaic plots from a two-way table
  • Can use them to compare conditional distributions

Example 1 To compare the mathematics standard of students at two schools, A and B, students are chosen by simple random sampling. A test gives these data: of students from School A, have excellent mathematics results; of students from School B, have excellent mathematics results. Analyse whether the proportions of students with excellent mathematics results at the two schools differ.

Solution: Let be the set of all students at the two schools, and consider the classical probability model with sample space . For each student in , define categorical variables and as follows:

Organise the data into Table 8.3-2.

Table 8.3-2 (number of students)

SchoolNot excellent ()Excellent ()Total
School A ()
School B ()
Total

Table 8.3-2 is a contingency table of sample data on the categorical variables and : the first two numbers in the last row are the frequencies of the events and ; the first two numbers in the last column are the frequencies of the events and ; the numbers in the four middle cells are the frequencies of the events ; the number in the bottom right cell is the sample size. So among the students from School A, the relative frequencies of “not excellent” and “excellent” are

among the students from School B, the relative frequencies of “not excellent” and “excellent” are

These results can be shown visually by an equal-height stacked bar chart, as in Figure 8.3-1.

School ASchool B0.76740.23260.84440.1556
Figure 8.3-1 The two bars have the same height (). The left bar is School A and the right bar School B; in each bar, the height of the blank lower part is the relative frequency of “not excellent”, and the height of the shaded upper part is the relative frequency of “excellent”.

Bar charts can be drawn with statistical software: some spreadsheet programs can insert a chart and choose a bar chart among the chart types; in R the function barplot can be used.

In Figure 8.3-1, the heights of the blank part and the shaded part of the left bar are the relative frequencies of “not excellent” and “excellent” among the students from School A; those of the right bar are the relative frequencies of “not excellent” and “excellent” among the students from School B. Comparing them, we find that in the sample data the relative frequencies of excellent mathematics results at the two schools differ: School A's is clearly higher than School B's. By the principle that frequency settles down to probability, we can infer that . That is, if one student is chosen at random from each of School A and School B, the probability that the School A student has an excellent mathematics result is greater than the probability that the School B student does. So we may consider that the proportions of students with excellent mathematics results at the two schools differ, and that School A's proportion is higher than School B's.

In fact, the conclusion “the proportions of students with excellent mathematics results at the two schools differ” was inferred from a difference between two relative frequencies. This can happen: in this particular random sample the two relative frequencies really do differ, yet the proportions of students with excellent mathematics results at the two schools are actually the same. That is, the randomness of the sample produced a fairly large difference between the two relative frequencies. In that case, the conclusion we inferred is wrong. Later we shall discuss how large the probability of making this kind of mistake is.

Related points

All points in this topic

Cite this page: Segmented and mosaic bar charts · KnowledgeTree (知识树), https://www.knowledgetree.world/en/kp/KP000939