Section 36 Three-way Relationships

Relationship between three or more variables - a combination of a set of continuous and categorical variables.

36.1 Tabulation

We can still produce summary statistics to capture relationship between continuous and a set of categorical variables.

weather <- read.csv('weather.csv')

with(data=weather, 
     tapply(X = humidity, 
            INDEX = list(rain, winddir), 
            FUN = median))
    Calm East North South West
Dry   95 88.0  73.5    74   82
Wet   91 95.5  89.0    90   89
with(data=weather, 
     tapply(X = temp, 
            INDEX = list(rain, winddir), 
            FUN = mean))
           Calm     East    North South     West
Dry -0.08461538 3.057143 5.338889   7.3 3.729870
Wet  2.70000000 3.583333 5.240000   3.6 3.841176
with(data=weather, table(windsp, winddir, rain))
, , rain = Dry

      winddir
windsp Calm East North South West
    0    13    0     0     0    0
    2     0    0     0     2    0
    3     0    0     0     0    0
    4     0    0     1     1    0
    5     0    2     1     1    3
    6     0    2     2     3    0
    7     0    0     0     4    4
    8     0    1     2     2    2
    9     0    1     1     2   10
    10    0    2     0     0    8
    11    0    1     1     0    9
    12    0    1     1     0   11
    13    0    1     1     0    4
    14    0    1     3     0    4
    15    0    0     2     0    5
    16    0    1     1     0    3
    17    0    0     1     0    0
    18    0    0     1     0    2
    19    0    1     0     0    2
    20    0    0     0     0    5
    21    0    0     0     0    1
    22    0    0     0     0    2
    23    0    0     0     0    1
    24    0    0     0     0    0
    25    0    0     0     0    1

, , rain = Wet

      winddir
windsp Calm East North South West
    0     1    0     0     0    0
    2     0    0     0     0    0
    3     0    0     0     0    1
    4     0    0     0     0    0
    5     0    0     0     1    0
    6     0    0     0     0    1
    7     0    0     0     1    0
    8     0    0     0     0    1
    9     0    0     0     0    2
    10    0    0     0     0    0
    11    0    1     0     0    0
    12    0    0     0     0    2
    13    0    0     0     0    2
    14    0    0     1     0    0
    15    0    2     0     0    0
    16    0    0     3     0    2
    17    0    0     0     0    0
    18    0    0     0     0    0
    19    0    0     1     0    2
    20    0    1     0     0    0
    21    0    0     0     0    0
    22    0    0     0     0    2
    23    0    0     0     0    2
    24    0    2     0     0    0
    25    0    0     0     0    0

36.2 Plot

Plot of continuous variables identifying levels of categorical variables.

  • Scatter plot
  • Box plot
  • Histogram
  • A combination of these plots
  • Presentation of plots in panels