Describing Distributions

(when the data is on hand)

Andrew Pua

2025-09-03

Plan for today

  • Recap

  • Jump into data-based activities

    • Descriptive statistics
    • Linear regressions
  • Handling a sensitive topic

  • Communicate results from a case study on executive compensation

  • Fast track into R

Descriptive statistics

  1. Statistics – “the art and science that has evolved for dealing with frequency distributions”
  2. Variables and their types, values and units, unit of analysis
  3. Descriptive statistics – a set of tools and visualizations used to summarize frequency distributions
  4. Why are they important?
  5. Which to focus on?

How much do executives earn?

  • We are going to study how much money CEOs in the US earn.

  • CEO compensation is a topic that attracts attention from almost everyone.

  • Many feel that all CEOs get paid high salaries, and perhaps their compensation levels are not entirely well justified.

  • Feel free to look into the debates and rich literature about executive compensation.

Origins of the data

  • I used data from a textbook.

    • Comes in xls format but I converted it into csv format.
    • Comes in two versions: one with sales information and the other with salary information.
  • Start to get used to the following:

    • Using non-Excel based formats
    • Merging different datasets
    • Choosing good variable names
dataset1 <- read.csv("sia1_ceo_comp.csv")
dataset2 <- read.csv("04_4m_exec_comp_2003.csv")
names(dataset1) <- c("Name", "Company", "Industry", "TotalCompMil", 
                     "NetSalesMil", "Log10TotalComp")
names(dataset2) <- c("SalaryThou", "Name", "Company", "Industry", 
                     "TotalCompMil")
execComp <- merge(dataset1, dataset2, 
                  by=c("Name","Company", "Industry", "TotalCompMil")) 
head(execComp)
             Name                      Company      Industry TotalCompMil
1       A. Bender         COOPER COMPANIES INC        Health     3.796108
2 A. Giannopoulos           MICROS SYSTEMS INC            IT     1.937943
3       A. Lafley          PROCTER & GAMBLE CO       Staples    19.086460
4    A. Mixon III                INVACARE CORP        Health     5.056142
5        A. Myers         WASTE MANAGEMENT INC    Industrial     5.695333
6    A. Perenchio UNIVISION COMMUNICATIONS INC Discretionary     0.000000
  NetSalesMil Log10TotalComp SalaryThou
1     411.790       6.579339      461.3
2     400.191       6.287341      690.0
3   43373.000       7.280725     1600.0
4    1247.176       6.703819      948.0
5   11574.000       6.755519     1000.0
6    1311.015             NA        0.0

Histogram and boxplot

hist(execComp$SalaryThou, breaks=20, ylim=c(0,500), 
     xlab="Salary (thousands of $)", 
     main="Salaries of 1501 US CEOs in 2003") 
boxplot(execComp$SalaryThou, add=TRUE, horizontal=TRUE, 
        at=475, boxwex=50, outcex=0.5)
par(cex=2)
hist(execComp$SalaryThou, breaks=20, ylim=c(0,500), 
     xlab="Salary (thousands of $)", 
     main="Salaries of 1501 US CEOs in 2003") 
boxplot(execComp$SalaryThou, add=TRUE, horizontal=TRUE, 
        at=475, boxwex=50, outcex=0.5)

Numerical summaries

  • Pay attention to the units and variable types.
summary(execComp)
     Name             Company            Industry          TotalCompMil   
 Length:1501        Length:1501        Length:1501        Min.   : 0.000  
 Class :character   Class :character   Class :character   1st Qu.: 1.257  
 Mode  :character   Mode  :character   Mode  :character   Median : 2.533  
                                                          Mean   : 4.628  
                                                          3rd Qu.: 5.477  
                                                          Max.   :74.750  
                                                          NA's   :6       
  NetSalesMil       Log10TotalComp    SalaryThou    
 Min.   :     0.0   Min.   :0.000   Min.   :   0.0  
 1st Qu.:   471.8   1st Qu.:6.100   1st Qu.: 450.0  
 Median :  1237.4   Median :6.404   Median : 650.0  
 Mean   :  5181.9   Mean   :6.411   Mean   : 696.8  
 3rd Qu.:  4044.8   3rd Qu.:6.739   3rd Qu.: 900.0  
 Max.   :257157.0   Max.   :7.874   Max.   :3993.0  
 NA's   :1          NA's   :7                       
  • In the numerical summaries, you have seen:

    • measures of central tendency: mean, median
    • measures of location: median, quartiles (more generally, quantiles)
  • Each of these have their meanings and quirks.

  • Next up is a measure of spread called the standard deviation. The name may seem mysterious but it will be clear later when we talk about transformations.

  • We can calculate the standard deviation of every column of the dataset, but you quickly run into problems.
apply(execComp, 2, sd)
          Name        Company       Industry   TotalCompMil    NetSalesMil 
            NA             NA             NA             NA             NA 
Log10TotalComp     SalaryThou 
            NA       374.3382 
apply(execComp, 2, sd, na.rm=TRUE)
          Name        Company       Industry   TotalCompMil    NetSalesMil 
            NA             NA             NA   6.231619e+00   1.469691e+04 
Log10TotalComp     SalaryThou 
  5.006985e-01   3.743382e+02 
  • The name standard deviation has two components: standard and deviation.

    • The word “deviation” refers to the difference of each observation from a reference point.
    • For the standard deviation, the reference point is the mean.
    • The word “standard” refers to the ability to compare things on a common scale.
  • To illustrate where the word “standard” comes from, consider the data on salaries for CEOS. Recall the mean and standard deviation:
mean(execComp$SalaryThou, na.rm=TRUE) 
[1] 696.7979
sd(execComp$SalaryThou, na.rm=TRUE) 
[1] 374.3382
  • Next, let us look at some CEOs:
head(execComp[,c("Name", "SalaryThou")])
             Name SalaryThou
1       A. Bender      461.3
2 A. Giannopoulos      690.0
3       A. Lafley     1600.0
4    A. Mixon III      948.0
5        A. Myers     1000.0
6    A. Perenchio        0.0
  • From the extract, you can see that rows 1, 2, and 6 have CEOs whose salaries are below the mean.
  • But how far below the mean? We can express this distance in terms of the original units: thousand dollars.
  • Distances are affected by the units chosen! So, one approach is to express this distance as a unitless quantity.
  • For example, A. Bender is \(\left| \frac{461.3-696.7979}{374.3382} \right|\approx 0.63\) standard deviations below the mean. In other words, A. Bender’s salary is about 3/5 of a standard deviation below the mean.
  • What we have done is to construct a \(z\)-score. This plays a role in getting a sense of magnitudes of typical datasets.
  • It turns out that for many datasets, it is very unlikely to have observations in the data which are more than 3 standard deviations above or below the mean. This is called the empirical rule.
  • There are definitely exceptions to this rule. But the rule, along with visualizations and other summaries, can be useful to detect potential issues with data.
  • The empirical rule states that for “bell-shaped” histograms,

    • About 68% of the observations are within one standard deviation of the mean.
    • About 95% of the observations are within two standard deviations of the mean.
    • About 99% of the observations are within three standard deviations of the mean.
  • CEO salaries have a long right tail, and:
mSal <- mean(execComp$SalaryThou, na.rm=TRUE)
sdSal <- sd(execComp$SalaryThou, na.rm=TRUE) 
zSal <- (execComp$SalaryThou-mSal)/sdSal
hist(zSal, ylim = c(0, 700), xlab = "Standard Units", 
     main = "Standardized Salaries of 1501 US CEOs in 2003")
  • Let us get a rough sense of how well the empirical rule applies to CEO salaries.
mean(abs(zSal) > 1, na.rm=TRUE)
[1] 0.2098601
mean(abs(zSal) > 2, na.rm=TRUE)
[1] 0.0326449
mean(abs(zSal) > 3, na.rm=TRUE)
[1] 0.01399067
  • There are other numerical summaries:

    • measures of spread: interquartile range, mean absolute deviation
    • measures of symmetry: skewness
    • measures of tail information: kurtosis, outliers
  • Almost all of these are univariate in nature, or applied one variable at a time.

Data transformations

  • There is a ton of whitespace in the pictures earlier.
  • It may be a good idea to “show more data” by considering a transformation.
  • But transformations may or may not have effects of numerical summaries.
  • Transformations could either be linear or nonlinear.

Linear transformations

  • Translation: adding or subtracting a constant amount

  • Scaling: multiplying or dividing by a constant amount

    • Changing millions USD to USD
    • Changing USD to EUR
  • Combination of both

    • Changing Celsius to Fahrenheit
    • Standardizing variables

Nonlinear transformations

  • One useful transformation is the logarithmic transformation. Logarithmic transformations are related to growth rates. We will see more of this later.
  • Here we use base 10. This may make sense for monetary amounts.
execComp$log10TotalComp <- log10(execComp$TotalCompMil*10^6)
execComp$log10Sal <- log10(execComp$SalaryThou*10^3)
summary(execComp$log10Sal)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   -Inf   5.653   5.813    -Inf   5.954   6.601 
summary(execComp$log10TotalComp)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
   -Inf   6.099   6.404    -Inf   6.739   7.874       6 
  • Another base to use is \(e \approx 2.718\). This is used more frequently in economics.
execComp$logTotalComp <- log(execComp$TotalCompMil*10^6)
execComp$logSal <- log(execComp$SalaryThou*10^3)
summary(execComp$logSal)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   -Inf   13.02   13.38    -Inf   13.71   15.20 
summary(execComp$logTotalComp)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
   -Inf   14.04   14.74    -Inf   15.52   18.13       6 
  • Other types of transformations such as squaring a variable could be useful, but there numerical summaries might not be meaningful.
par(cex=2)
hist(execComp$log10Sal[execComp$log10Sal > 0], breaks = 20, 
     ylim = c(0, 700), xlab = "Log Salary", 
     main = "Log Salaries of 1501 US CEOs in 2003") 
boxplot(execComp$log10Sal[execComp$log10Sal > 0], add = TRUE, 
        horizontal = TRUE, at = 700, boxwex = 50, outcex = 0.5)

Visualizing variables together

par(cex=2)
plot(execComp$NetSalesMil, execComp$TotalCompMil, xlim=c(0,280000), ylim=c(0,90), 
     xlab = "Net Sales in Millions", ylab = "Total Compensation in Millions")
par(cex=2)
execComp$log10NetSales <- log10(execComp$NetSalesMil*10^6)
plot(execComp$log10NetSales, execComp$log10TotalComp, xlim = c(4, 12), 
     ylim = c(0, 9), xlab = "Log Net Sales", ylab = "Log Total Compensation")
boxplot(execComp$log10TotalComp, add = TRUE, horizontal = FALSE, 
        at = 12, outcex = 0.25)
boxplot(execComp$log10NetSales, add = TRUE, horizontal = TRUE, 
        at = 9, outcex = 0.25)

Linear regression analysis

  • We can look at one possible numerical summary of the previous plots.
  • Here I report the results for the full dataset.
lm(TotalCompMil ~ NetSalesMil, data=execComp)

Call:
lm(formula = TotalCompMil ~ NetSalesMil, data = execComp)

Coefficients:
(Intercept)  NetSalesMil  
  3.7602330    0.0001674  
  • TotalCompMil is called the regressand or outcome variable and NetSalesMil is called the regressor or predictor.
  • Next, I report the results when I drop firms with no sales and whose CEO has no reported compensation.
eCsub <- subset(execComp, (TotalCompMil>0 & NetSalesMil>0))
lm(TotalCompMil ~ NetSalesMil, data=eCsub)

Call:
lm(formula = TotalCompMil ~ NetSalesMil, data = eCsub)

Coefficients:
(Intercept)  NetSalesMil  
  3.7670804    0.0001673  
  • Dropping zero net sales and zero compensation did not change the reported values too much.
  • Think of these numerical summaries as averages or comparisons of averages.

    • Intercept: The average compensation of CEOs with net sales of zero is about 3.77 million dollars.
    • Slope: When we compare firms whose net sales differ by 1 million dollars, the average compensation of their CEOs differ by about 0.00017 million dollars or better yet, 170 dollars.
    • Even better: When we compare firms whose net sales differ by 1 trillion dollars, the average compensation of their CEOs differ by about 170000 dollars.
  • Take note that you are NOT comparing the same CEO! We are comparing different CEOs.
  • In the current context, would zero net sales be plausible?
  • Note that for communication purposes, it is really good practice to reduce the number of digits reported (more digits NOT the same as more accurate!) considering the context.

Regression with only an intercept

  • What happens when you apply lm() without NetSalesMil?
lm(TotalCompMil ~ 1, data=eCsub)

Call:
lm(formula = TotalCompMil ~ 1, data = eCsub)

Coefficients:
(Intercept)  
      4.626  
mean(eCsub$TotalCompMil)
[1] 4.626229
  • You will note that the intercept matches the mean of TotalCompMil. This pattern holds in general.
  • You can also think of the intercept as the slope of a regressor which takes on the value 1 for all observations.
  • Note that as soon as you include NetSalesMil, the meaning of the intercept will change.

Regression lines, fitted values, and residuals

  • In the compensation-sales relationship, the regression line is \[\widehat{\mathtt{TotalCompMil}}_t=3.7670804+0.0001673*\mathtt{NetSalesMil}_t\]
  • The regression line where I did not include NetSalesMil is \[\widehat{\mathtt{TotalCompMil}}_t=4.626\]
  • Both these lines could be used to produce fitted values. Just plug-in values for NetSalesMil from the data.
    • This plugging-in matters for the first line.
    • It does not matter for the second line.
  • It is possible to use these lines to make predictions outside of the data used for linear regression analysis. This also produces fitted values, which are more accurately termed as predicted values.
  • The regression line always passes through the point of averages or “the center”.

  • For the regression line \[\widehat{\mathtt{TotalCompMil}}_t=3.7670804+0.0001673*\mathtt{NetSalesMil}_t\] observe that

mean(eCsub$TotalCompMil)
[1] 4.626229
mean(eCsub$NetSalesMil)
[1] 5135.554
mean(fitted(lm(TotalCompMil ~ NetSalesMil, data=eCsub)))
[1] 4.626229
  • The difference between the TotalCompMil from the data and the fitted value produces the residuals: \[\mathtt{TotalCompMil}_t-\widehat{\mathtt{TotalCompMil}}_t\]

  • Provided that there is an intercept, the residuals are guaranteed to sum up to zero. So, the mean of the residuals is always equal to zero.

  • You can verify easily for the case where our regression line is just \[\widehat{\mathtt{TotalCompMil}}_t=4.626\]

  • For the regression line \[\widehat{\mathtt{TotalCompMil}}_t=3.7670804+0.0001673*\mathtt{NetSalesMil}_t\] observe that
mean(eCsub$TotalCompMil - fitted(lm(TotalCompMil ~ NetSalesMil, data=eCsub)))
[1] -8.645476e-17
mean(residuals(lm(TotalCompMil ~ NetSalesMil, data=eCsub)))
[1] -8.105251e-17

Regression with a dummy variable

  • Communicating the results from the compensation-sales relationship are about comparing subgroups which may unlikely be observable.
  • Finding firms whose net sales differ by exactly 1 million dollars (or 1 trillion dollars or differ by 1 percent) would be extremely rare.
  • But the language is still appropriate.
  • What happens if these subgroups are actually observable and are labeled correctly in the data?
table(eCsub$Industry)

Discretionary        Energy     Financial        Health    Industrial 
          277            78           201           149           229 
           IT     Materials       Staples       Telecom       Utility 
          278           108            69            22            80 
tapply(eCsub$TotalComp, eCsub$Industry=="Energy", mean)
   FALSE     TRUE 
4.601004 5.083188 
lm(TotalCompMil ~ as.factor(eCsub$Industry=="Energy"), data=eCsub)

Call:
lm(formula = TotalCompMil ~ as.factor(eCsub$Industry == "Energy"), 
    data = eCsub)

Coefficients:
                              (Intercept)  
                                   4.6010  
as.factor(eCsub$Industry == "Energy")TRUE  
                                   0.4822  
  • The previous analysis is essentially reproducing the average of the energy industry and the average of all other industries.
  • The presentation is just slightly different but carry exactly the same information.
  • Putting in as.factor(eCsub$Industry=="Energy") creates a dummy variable.
  • Dummy variables are indicator variables which take on only two values 0 (when the condition is false) and 1 (when the condition is true).

The regression slope

  • The regression slope actually depends on another numerical summary for relationships between two variables.
  • It can be shown that the means and the standard deviations of each variable enter into the calculation.
  • But there is one more number that ties them all together.
  • This is best seen by looking at the incorrect intuition most people have about the regression line being the “best-fitting” line.
par(cex=2)
plot(eCsub$NetSalesMil, eCsub$TotalCompMil, xlim=c(0,280000), ylim=c(0,90), 
     xlab = "Net Sales in Millions", ylab = "Total Compensation in Millions")
abline(a= mean(eCsub$TotalCompMil)-sd(eCsub$TotalCompMil)/sd(eCsub$NetSalesMil)*mean(eCsub$NetSalesMil), 
       b=sd(eCsub$TotalCompMil)/sd(eCsub$NetSalesMil), col="red")
abline(a=coef(lm(TotalCompMil ~ NetSalesMil, data=eCsub))[[1]], 
       b=coef(lm(TotalCompMil ~ NetSalesMil, data=eCsub))[[2]])
  • The black line is the regression line obtained from lm().
  • Compared to the red line, the black line has a smaller slope in absolute value.
  • It turns out that there is a factor that produces the smaller absolute slope relative to the red line.
  • This factor is called the correlation coefficient.

Impact of logarithmic transformation

lm(log10TotalComp ~ log10NetSales, data=eCsub)

Call:
lm(formula = log10TotalComp ~ log10NetSales, data = eCsub)

Coefficients:
  (Intercept)  log10NetSales  
       2.7543         0.4002  
  • What happens when you use a different base for the logarithmic transformation?
  • How do you interpret these numbers?
eCsub$logNetSales <- log(eCsub$NetSalesMil*10^6)
eCsub$logTotalComp <- log(eCsub$TotalCompMil*10^6)
lm(logTotalComp ~ logNetSales, data=eCsub)

Call:
lm(formula = logTotalComp ~ logNetSales, data = eCsub)

Coefficients:
(Intercept)  logNetSales  
     6.3421       0.4002  
  • Notice that the computed slopes are the same, but the intercepts are different.

  • Intercept if you used base 10: The average log compensation of CEOs with log net sales of zero is about 2.75. What about the units? Is it million dollars? Hard to communicate.

  • Slope: When we compare firms whose log net sales differ by 1, the average log compensation of their CEOs differ by about 0.4.
  • Even better: When we compare firms whose net sales differ by 1 percent, the average compensation of their CEOs differ by about 0.4 percent.
  • Where did the relative changes come from? Note that \(\log_b x_2 - \log_b x_1 = \log_b\left(\dfrac{x_2}{x_1}\right) \\ =\log_b\left[1+\left(\dfrac{x_2}{x_1}-1\right)\right] \approx \dfrac{1}{\log_e b}\left(\dfrac{x_2-x_1}{x_1}\right)\)
par(cex=2)
execComp$log10NetSales <- log10(execComp$NetSalesMil*10^6)
plot(execComp$log10NetSales, execComp$log10TotalComp, xlim = c(4, 12), 
     ylim = c(0, 9), xlab = "Log Net Sales", ylab = "Log Total Compensation")
boxplot(execComp$log10TotalComp, add = TRUE, horizontal = FALSE, 
        at = 12, outcex = 0.25)
boxplot(execComp$log10NetSales, add = TRUE, horizontal = TRUE, 
        at = 9, outcex = 0.25)
abline(a= mean(eCsub$log10TotalComp)-sd(eCsub$log10TotalComp)/sd(eCsub$log10NetSales)*mean(eCsub$log10NetSales), 
       b=sd(eCsub$log10TotalComp)/sd(eCsub$log10NetSales), col="red")
abline(a=coef(lm(log10TotalComp ~ log10NetSales, data=eCsub))[[1]], 
       b=coef(lm(log10TotalComp ~ log10NetSales, data=eCsub))[[2]])

Operations on data

  • You have seen visualizations and numerical summaries of data.

    • Behind every visualization and numerical summary, there is a set of operations on data.
    • Typical data operations involve: summing up, scaling, transforming, subsetting or filtering, arranging in some order, standardizing, comparing
  • Everything we have done is based on the data we have on hand.
  • We also saw many linear regressions. All of them are about comparisons involving averages.
  • What we are going to do next is to think hard about summaries and linear regressions before doing any computations.

More things to think about

  • Smoothing the histogram to capture broad features

  • Time series data and other types of data

    • Does it make sense to apply summary statistics directly?
    • How to visualize? Can we use histograms?
  • Effect of transformations on summaries

  • Subgroups formed when regressors are not discrete

  • Designing visualizations / graphics