Moodle - Statistics - Block III - Lesson 1

Table of contents

  1. Association and correlation
  2. Crosstabs
  3. Coefficients that can be obtained from crosstabs
  4. Covariance between two variables
  5. Correlation between numerical variables

1. Association and correlation

1.1 Association between variables

An association between variables exists when information about one variable provides insight into the other. This can occur with either categorical or quantitative variables 2.

  • Association: when knowing the value or category of one variable provides information about another.
  • Example: an association might exist between a tourist's country of origin and their chosen accommodation type (e.g., hotel, apartment, camping) 2.

1.2 Correlation between variables

Correlation is a specific type of association that applies to two quantitative variables, describing how they change together. Linear correlation quantifies the strength and direction of the linear relationship between these variables 3.

  • Correlation: a type of association between two quantitative variables that describes their joint variation.
  • Linear correlation: measures the strength and direction of the linear relationship between two quantitative variables.
  • Example: a positive correlation between tourists' income and their average travel spending suggests that higher-income tourists generally spend more 3.

1.3 Association does not imply causation

The presence of an association or linear correlation between two variables does not automatically mean that one causes the other. A causal relationship implies that changes in one variable directly produce changes in another 4.

  • Causation: a relationship where changes in one variable directly influence or produce changes in another.
  • Confounding variable: an association or correlation may be explained by a third, unmeasured variable that influences both observed variables.
  • Example: higher temperatures can increase both ice cream sales and swimming pool attendance, potentially leading to more pool accidents. In this case, temperature is a confounding variable 4.

A contingency table, also known as a crosstab, displays the joint distribution of two or more variables by organizing their categories into rows and columns.

A contingency table (crosstab) showing the joint distribution of two variables, with marginal distributions indicated.

A table displays tourist data with variables for Tourist, Variable X, and Variable Y, illustrating a bivariate analysis concept.

2. Crosstabs

2.1 Introduction to Crosstabulations

A crosstabulation, also known as a contingency table, is a statistical tool used to display the joint distribution of two or more categorical variables. It organizes the categories of these variables into rows and columns, with each cell representing the frequency of observations that fall into a specific combination of categories.

This method is fundamental for bivariate analysis, allowing for the examination of relationships between variables 6 7 8 13.

The structure of a crosstabulation involves:

  • Rows: Represent the categories of one variable.
  • Columns: Represent the categories of another variable.
  • Cells: Contain the absolute frequencies (counts) of observations for each combination of row and column categories 6 8 13.

For two categorical variables, X and Y, with rr categories for X and kk categories for Y, the table will have rr rows and kk columns. The total number of observations in the sample is denoted by nn 6.

The table can be represented as:

-: y1*, y2*,..., yj*,..., yk*, Row Total

  • X1*: n11, n12,..., n1j,..., n1k, n1.
  • X2*: n21, n22,..., n2j,..., n2k, n2. -...:...,...,...,...,...,...,...
  • Xi*: ni1, ni2,..., nij,..., nik, ni. -...:...,...,...,...,...,...,...
  • Xr*: nr1, nr2,..., nrj,..., nrk, nr.
  • Column Total: n.1, n.2,..., n.j,..., n.k, n 6 7 8 11 12 13.

2.2 Absolute Frequencies

Absolute frequencies in a crosstabulation represent the raw count of observations that fall into each specific cell, indicating how many times a particular combination of categories occurs in the sample. These counts are essential for understanding the raw distribution of data 6 8.

The notation nijn_{ij} denotes the absolute frequency for the cell at the intersection of row ii and column jj. The sum of all absolute frequencies across all cells equals the total number of observations, nn 6.

📝 For a cell at the intersection of row ii and column jj, the absolute frequency nijn_{ij} represents the raw count of observations that fall into that specific combination of categories 6.

2.3 Marginal Distributions

Marginal distributions are the frequency distributions of a single variable within a crosstabulation, calculated independently of the other variable. They are found in the margins of the table, either in the row totals or the column totals 7 8 13.

  • Row marginals (ni.n_{i.}): Represent the total frequency for each category of the variable displayed in the rows. They are calculated by summing the frequencies across each row.
  • Column marginals (n.jn_{.j}): Represent the total frequency for each category of the variable displayed in the columns. They are calculated by summing the frequencies down each column 7 8 12 13.

The sum of all row marginals equals the total number of observations (nn), as does the sum of all column marginals 7 8.

2.4 Relative Frequencies

Relative frequencies express the absolute frequencies as proportions or percentages of the total number of observations. They are calculated by dividing the absolute frequency of each cell by the total number of observations (nn) 11 12 13.

The formula for calculating the relative frequency (fijf_{ij}) for a cell at row ii and column jj is: fij=nijnf_{ij} = \frac{n_{ij}}{n} 11 12 13.

Relative frequencies are useful for comparing distributions across different sample sizes and for understanding the proportion of observations within each category combination 11 12 13.

Similar to absolute frequencies, relative frequencies can also be calculated for marginal distributions:

  • Row relative marginals (fi.f_{i.}): ni.n\frac{n_{i.}}{n}.
  • Column relative marginals (f.jf_{.j}): n.jn\frac{n_{.j}}{n} 12 13.

2.5 Exercise 3.1: Marital Status and Gender

This exercise requires constructing a crosstabulation from raw data on marital status and gender for 15 individuals. The goal is to organize these paired observations into a table showing the joint distribution of the two categorical variables 9.

2.6 Exercise 3.2: Marital Status and Gender (Different Sample)

Similar to Exercise 3.1, this problem involves creating a crosstabulation from a new set of 15 individuals' marital status and gender data. It reinforces the process of organizing paired categorical data 10.

2.7 Exercise 3.3: Marital Status and Gender with Relative Frequencies

This exercise builds upon the previous ones by asking for both the construction of a crosstabulation and the calculation of relative frequencies from the provided data on marital status and gender for 15 individuals 14.

2.8 Exercise 3.4: Tourist Spending and Stay Length

This exercise involves creating a crosstabulation from grouped data for 150 tourists. The variables are daily spending (grouped into intervals) and length of stay (grouped into intervals).

After constructing the table, the task is to calculate the relative frequencies for each cell 15.

📝 For 150 tourists, a crosstabulation of daily spending (grouped into intervals) and length of stay (grouped into intervals) is constructed, and then relative frequencies for each cell are calculated 15.

2.9 Exercise 3.5: Job Role and Work Arrangement

This exercise requires generating a crosstabulation from data on job roles (Sales, Administration, IT) and work arrangements (On-site, Remote, Hybrid) for 15 individuals. The task includes calculating the relative frequencies for the resulting table 16.

2.10 Exercise 3.6: Customer Spending and Shopping Time

This exercise involves creating a crosstabulation for 15 customers based on their total spending (grouped into intervals) and shopping time (grouped into intervals). The final step is to calculate the relative frequencies for the cells in the crosstab 17.

3. Coefficients that can be obtained from crosstabs

3.1 Pearson's chi-square coefficient (χ2\chi^2)

The Pearson's chi-square (χ2\chi^2) coefficient quantifies the discrepancy between observed frequencies in a contingency table and the frequencies expected if two categorical variables were statistically independent. It is calculated by summing the squared differences between observed and expected frequencies, divided by the expected frequencies, across all cells in the table.

The theoretical range for χ2\chi^2 is from 0 to n⋅tn \cdot t, where nn is the total number of observations and tt is the minimum of (r−1)(r-1) and (k−1)(k-1), with rr being the number of rows and kk being the number of columns.

  • Observed values: These are the actual counts recorded in the data for each category combination 19.
  • Expected values: These are the frequencies that would be observed if the two variables were independent. They are calculated using the formula feij=ni⋅njnf_{e_{ij}} = \frac{n_i \cdot n_j}{n}, where nin_i is the marginal total for row ii, njn_j is the marginal total for column jj, and nn is the grand total 20 21 22.
  • Residual values: These are the differences between the observed and expected frequencies (nij−feijn_{ij} - f_{e_{ij}}). They indicate the direction and magnitude of the deviation from independence for each cell 24 25.

This diagram displays two tables comparing observed and expected values for different transportation methods and time durations. 19.

The formula for calculating the chi-squared statistic, which measures the difference between observed and expected frequencies in a contingency table. 25.

  • Calculation of χ2\chi^2: The formula is χ2=∑i=1r∑j=1k(nij−feij)2feij\chi^2 = \sum_{i=1}^{r} \sum_{j=1}^{k} \frac{(n_{ij} - f_{e_{ij}})^2}{f_{e_{ij}}} 23 26 27.
  • Interpretation: A higher χ2\chi^2 value indicates a greater discrepancy between observed and expected frequencies, suggesting a stronger association between the variables. A χ2\chi^2 of 0 implies perfect independence 25 28.

3.2 Limitations of Pearson's χ2\chi^2

The theoretical range of the Pearson's χ2\chi^2 statistic depends on the sample size and the dimensions of the contingency table. This dependency means that χ2\chi^2 values from tables with different sizes or from samples of different sizes cannot be directly compared.

This diagram illustrates the comparison of two samples, Sample A and Sample B, with different variables and categories, showing that their respective Pearson chi-squared coefficients (χ²) and contingency coefficients (C) cannot be directly compared due to variations in sample size and table dimensions. 32 33 36.

📝 For a 2x2 table, the phi coefficient is calculated as ϕ=χ2n\phi = \sqrt{\frac{\chi^2}{n}}. If χ2=7.4\chi^2 = 7.4 and n=20n = 20, then ϕ=7.420=0.6124\phi = \sqrt{\frac{7.4}{20}} = 0.6124 31.

3.3 Phi coefficient (ϕ\phi)

The phi coefficient (ϕ\phi) is a measure of association specifically designed for two dichotomous (2x2) categorical variables. It is derived from Pearson's chi-square statistic and is calculated as the square root of χ2\chi^2 divided by the total sample size (nn).

  • Formula: ϕ=χ2n\phi = \sqrt{\frac{\chi^2}{n}} 29 31.
  • Interpretation: The strength of association indicated by the phi coefficient is typically interpreted as follows:
  • 0 - 0.1: Negligible association
  • 0.1 - 0.3: Weak association
  • 0.3 - 0.5: Moderate association
  • 0.5 - 1.0: Strong association 30.

This diagram illustrates the calculation of the Phi coefficient, a measure of association between two binary variables. 31.

📝 The contingency coefficient is calculated as C=χ2χ2+nC = \sqrt{\frac{\chi^2}{\chi^2 + n}}. For a table with χ2=13.9662\chi^2 = 13.9662 and n=60n = 60, C=13.966213.9662+60=0.4345C = \sqrt{\frac{13.9662}{13.9662 + 60}} = 0.4345 35.

3.4 Contingency coefficient (C)

The contingency coefficient (C) measures the strength of association between two categorical variables and is derived from Pearson's chi-square statistic, adjusting for sample size. Its maximum possible value, however, still depends on the dimensions of the contingency table, meaning that C values obtained from tables of different sizes cannot be directly compared.

  • Formula: C=χ2χ2+nC = \sqrt{\frac{\chi^2}{\chi^2 + n}}.
  • Maximum value: The maximum value of C (CmaxC_{max}) is related to the table dimensions (t=min⁡{(r−1),(k−1)}t = \min\{(r-1), (k-1)\}) by the formula Cmax=tt+1C_{max} = \sqrt{\frac{t}{t+1}}.
  • Interpretation: The value of C ranges from 0 to a maximum value (CmaxC_{max}) that depends on the dimensions of the contingency table. The strength of association is typically interpreted as follows:
  • Values closer to 0 indicate a weak association.
  • Values closer to CmaxC_{max} indicate a strong association 34 35.

The contingency coefficient (C) formula is presented, showing its relationship with chi-square and sample size. 34.

3.5 Limitations of the Contingency Coefficient

Similar to Pearson's χ2\chi^2, the contingency coefficient's theoretical range is dependent on the dimensions of the contingency table. Consequently, C values calculated from tables of different sizes cannot be directly compared.

33 36.

3.6 Cramer's V coefficient

Cramer's V is an improved and more robust measure of association than the contingency coefficient, offering a standardized value that ranges between 0 and 1, regardless of the table's size. This standardization allows for the comparison of associations between variables with different numbers of categories.

  • Formula: V=χ2n⋅tV = \sqrt{\frac{\chi^2}{n \cdot t}}, where t=min⁡{(r−1),(k−1)}t = \min\{(r-1), (k-1)\}39.
  • Consistency with Phi: For 2x2 tables, Cramer's V is equal to the absolute value of the phi coefficient (V=∣ϕ∣V = |\phi|), ensuring consistency between the measures.
  • Interpretation: The strength of association is typically interpreted as follows:
  • ≥0.1\geq 0.1: Weak association
  • ≥0.3\geq 0.3: Moderate association
  • ≥0.5\geq 0.5: Strong association 38.

This diagram illustrates the calculation of Cramer's V coefficient, a measure of association between two categorical variables. 39.

3.7 Comparability of Cramer's V

Cramer's V provides a fixed theoretical range making it suitable for comparing the strength of association across contingency tables of different dimensions. This allows for direct comparison of association strengths between variables with varying numbers of categories 1.

37.

3.8 Exercise 3.7: Association between educational attainment and employment category

This exercise investigates the association between employees' educational attainment and their employment category within The Williams Corporation. It requires constructing a contingency table, calculating expected frequencies, and then computing Pearson's chi-square (χ2\chi^2), the Contingency coefficient (C), and Cramer's V 40.

3.9 Exercise 3.8: Association between sex and ulcer status

This exercise examines the relationship between sex and ulcer status using data from a healthcare center. It involves constructing a contingency table, calculating Pearson's chi-square (χ2\chi^2), and assessing the strength of association by calculating and interpreting Cramer's V 41.

3.10 Exercise 3.9: Association between previous visits and recommendation

This exercise assesses the strength of association between tourists who have visited a destination before and their willingness to recommend it. It specifically requires the calculation of the Phi coefficient (ϕ\phi) for the given 2x2 contingency table 42.

3.11 Exercise 3.10: Association between exhibition preference and museum visit frequency

This exercise explores the relationship between visitors' preferred exhibition type and their museum visit frequency. Given a Pearson's chi-square statistic (χ2=24.6\chi^2 = 24.6), the task is to calculate Cramer's V and interpret its value to conclude on the strength of the association 43.

4. Covariance between two variables

4.1 Covariance definition

Covariance is a statistical measure used in bivariate analysis to quantify how two quantitative variables change together. It indicates the direction of their linear association 44.

  • Positive covariance: suggests that both variables tend to increase or decrease simultaneously.
  • Negative covariance: indicates that as one variable increases, the other tends to decrease.
  • Zero covariance: implies no linear relationship between the variables 44.

4.2 Covariance formulas

Covariance can be calculated using different formulas, depending on the available data. The formulas provide a way to numerically assess the relationship between two variables 44.

Formula NameFormula
Covariance (using deviations from mean)Sxy=1n∑i=1n(xi−xˉ)(yi−yˉ)S_{xy} = \frac{1}{n} \sum_{i=1}^{n} (x_i - \bar{x}) (y_i - \bar{y})
Covariance (using raw data)Sxy=1n∑i=1nxiyi−xˉyˉS_{xy} = \frac{1}{n} \sum_{i=1}^{n} x_i y_i - \bar{x} \bar{y}
Covariance (alternative raw data form)Sxy=1n∑i=1jnijxiyi−xˉyˉS_{xy} = \frac{1}{n} \sum_{i=1}^{j} n_{ij} x_i y_i - \bar{x} \bar{y}

5. Correlation between numerical variables

5.1 Pearson's correlation coefficient

Pearson's correlation coefficient, denoted as rxyr_{xy}, quantifies the strength and direction of the linear relationship between two quantitative variables. It is important to note that correlation does not imply causation; the relationship may be causal or non-causal.

The absolute value of the coefficient indicates the strength of the linear association, while its sign reveals the direction of the relationship (positive or negative). The coefficient ranges from -1 to 1 45.

The formula for Pearson's correlation coefficient is: rxy=SxySxSyr_{xy} = \frac{S_{xy}}{S_x S_y} where SxyS_{xy} is the covariance between variables x and y, SxS_x is the standard deviation of variable x, and SyS_y is the standard deviation of variable y 45.

5.2 Interpretation of Pearson's correlation coefficient

The interpretation of Pearson's correlation coefficient (rxyr_{xy}) is based on its value, indicating the strength and direction of the linear relationship between two variables. A value close to 1 indicates a strong positive linear relationship, while a value close to -1 indicates a strong negative linear relationship.

A value close to 0 suggests a very weak or no linear relationship 45 48.

Range ofrxy—Strength of Linear Relationship
0 < rxy ≤ 0.2Very Low——
0.2 ≤rxy≤ 0.4Low
0.4 ≤rxy≤ 0.7Medium
0.7 ≤ rxy ≤ 0.9High——
0.9 ≤ rxy ≤ 1Very High——

5.3 Scatter plots and correlation

Scatter plots are graphical representations used to visualize the relationship between two numerical variables. The pattern of points on a scatter plot can provide a visual indication of the strength and direction of the linear association, which can then be quantified by Pearson's correlation coefficient 46 47.

  • Positive correlation: Points tend to rise from left to right, indicating that as one variable increases, the other tends to increase.
  • Negative correlation: Points tend to fall from left to right, indicating that as one variable increases, the other tends to decrease.
  • No linear correlation: Points are scattered randomly with no discernible pattern, suggesting no linear relationship between the variables 46 47.

5.4 Exercise 3.11: Tourist stay and expenditure

This exercise involves calculating Pearson's correlation coefficient (rxyr_{xy}) to assess the linear relationship between the average length of stay for tourists and their average daily expenditure. The data provided includes monthly figures for both variables 49.

5.5 Exercise 3.12: Advertising expenditure and sales revenue

This exercise requires calculating Pearson's correlation coefficient (rxyr_{xy}) to examine the linear relationship between advertising expenditure and sales revenue for a furniture company. Data for four months, expressed in millions of euros, are provided 50.

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also