13.7 Example

This example follows Analysis of depression data set section in PMA6 Section 14.5. This survey asks 20 questions on emotional states that relate to depression. The data is recorded as numeric, but are categorical in nature where 0 - “rarely or none of the time”, 1 - “some or a little of the time” and so forth.

These questions are typical of what is asked in survey research, and often are thought of, or treated as pseudo-continuous. They are ordinal categorical variables, but they are not truly interval measures since the “distance” between 0 and 1 (rarely and some of the time), would not be considered the same as the distance between 2 (moderately) and 3 (most or all of the time). And “moderately” wouldn’t be necessarily considered as “twice” the amount of “rarely”.

Our options to use these ordinal variables in a model come down to three options.

  • convert to a factor and include it as a categorical (series of indicators) variable.
    • This can be even more problematic when there are 20 categorical variables. You run out of degrees of freedom very fast with that many predictors.
  • leave it as numeric and treat it as pseudo-continuous ordinal measure. Where you can interpret as “as x increases y changes by…”, but
  • aggregate across multiple likert-type-ordinal variables and create a new calculated scale variable that can be treated as continuous.
    • This is what PCA does by creating new variables \(C_{1}\) that are linear combinations of the original \(x's\).

In this example I use PCA to reduce these 20 correlated variables down to a few uncorrelated variables that explain the most variance.

1. Read in the data and run princomp on the C1:C20 variables.

2. Pick a subset of PC’s to work with

In the cumulative percentage plot below, I drew a horizontal line at 80%. So the first 9 PC’s explain around 75% of the total variance, and the first 10 can explain around 80%.

3. Create a Scree plot by plotting the eigenvalue against the PC number.

  • Option 1: Take all eigenvalues > 1 (\(m=5\))
  • Option 2: Use a cutoff point where the lines joining consecutive points are steep to the left of the cutoff point and flat right of the cutoff point. Point where the two slopes meet is the elbow. (\(m=2\)).

4. Examine the loadings


  • \(X_{1}\) = “I felt that I could not shake…”
  • \(X_{2}\) = “I felt depressed…”

So the PC’s are calculated as

\[ C_{1} = 0.277x_{1} + 0.313x_{2} + \ldots \\ C_{2} = -0.1449x_{1} + 0.0271x_{2} + \ldots \]


The full question text for the depression data used here can be found on Table 14.2 in the PMA6 textbook.

5. Interpret the PC’s

  • Visualize the loadings using heatmap.2() in the gplots package.
    • I reversed the colors so that red was high positive correlation and yellow/white is low.
    • half the options I use below come from this SO post. I had no idea what they did, so I took what the solution showed, and played with it (added/changed some to see what they did), and reviewed ?heatmap.2 to see what options were available.

  • Loadings over 0.5 (red) help us interpret what these components could “mean”
    • Must know exact wording of component questions
  • \(C_{1}\): a weighted average of most items. High value indicates the respondent had many symptoms of depression. Note sign of loadings are all positive and all roughly the same color.
    • Recall
  • \(C_{2}\): lethargy (high energetic). High loading on c14, 16, 17, low on 4, 8, 20
  • \(C_{3}\): friendliness of others. Large negative loading on c19, c9