# How to model "amount of correlation between two metric items along a third metric item"?

I'm trying to understand the best way for analysis whether the tightness of the correlation between to items correlates with a third variable; a toy example might be the question:

"does the connection between "money-at-hand"(MO) and "happiness"(HA) change with the growing "age"(AGE) ?

---------- where the hypothese might be that with growing age this relation weakens.

[update] Well, thinking a bit deeper says that even that "toy example" has its trickeries... Reading over this, one could think it means that both items (together) reduce its importance in older age. But when we look precisely we find that the model measures in a way that in higher age either both are seen positive or both are seen negative (but not complementary) and that in the youth it is more likely that the two aspects are seen as complementary: either much MO AND little HA or little MO and much HA and perhaps one could find a more smooth example for such type of a model... But I'll leave the initial example just as it is [/update]

If age were taken in two or a couple of groups I could think of comparing the correlation MO x HA for the young and for the old people in terms of the Pearson's r 's . But now the third variable is metric and not a nominal "factor".
I've often thought that a possibility were to go back to the case-level and determine the case-specific contribution to the correlation MO x HA. Let MO,HA and AGE be already centered, then to introduce a new variable $CMH_i = MO_i \cdot HA_i$ . Then CMH has

• high positive values when MO and HA have either both high positive or both high negative values
• high negative values when MO and HA have high values with opposite sign
• small values if both MO and HA have small absolute values.

I thought that this one can then be correlated with age. Some experiments with toy data show that it is - although the idea looks simple and convincing to me- not trivial to configure the setting (for instance center CMH ?), but possibly one can overcome this after deeper analysis, for instance doing this in a small program I come to expressions like $x_i \cdot y_i \cdot z_i$ thus crossproductswith three multiplicative factors instead of two as we are used to apply for covariance-computation.
However, before trying to step more into this there might be a "canonical" solution for this? So my question is:

Q How would I model the measure of correlation between two metric items as dependend on a third metric variable?

You may want to look into interaction analysis. The syntax is simple in r:

lm.obj <- lm(response ~ predictor*modifier)


Though a little more difficult to understand with continuous variables, it is useful to see the concept working in logistic. When you add the *modifier, R creates an interaction term, which is basically saying "does this factor being 0 or 1 modify the relationship between my response and predictor". The P value has the null that there is no difference between these two groups. It might be useful to do some reading on continuous interaction. If it were me, for a quick check I would divide my ages into two categories, seeing if this dichotomy would show significantly different relationships. All the best.

If you are looking for a deep canonical answer, whuber had previously cited chapter 10-13 of Tukey's EDA for interaction analysis.

• Thanks Chris! I just found that in principle a similar thing is done in AnoVa/AnCova; I'm implementing that ANOVA procedure using splitting of the factors into dummy-variables and doing regression with them. The interaction-terms are handled just in the way as I described it in my question. However, these are based on dummy-variables, so it is not exactly the same as what I asked for. Thanks also for the links, I'll look at them later. Oct 10 '14 at 14:18

It sounds like your problem involves moderation when both the moderator and the predictor are continuous. You may want to take a look at "Multiple Regression: Testing and Interpreting Interactions" by Leona Aiken (1992). Let me explain using mtcars dataset in R. Both wt and hp are mean centered:

library(dplyr)
library(ggplot2)

mtcars <- mtcars %>%
mutate(wt_c = wt - mean(wt),
hp_c = hp - mean(hp),
wt_f = cut(wt, breaks=quantile(wt, c(0, 1/3, 2/3, 1)), include.lowest=TRUE))
## wt_f is created for visual exploration.

summary(lm(mpg ~ wt*hp, data=mtcars))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 18.898400   0.495703  38.124  < 2e-16 ***
hp_c        -0.030508   0.007503  -4.066 0.000352 ***
wt_c        -4.131649   0.529558  -7.802 1.69e-08 ***
hp_c:wt_c    0.027848   0.007420   3.753 0.000811 ***


Here, hpis negatively associated with mpg at the mean wt and hp while holding wt constant. Yet, each increase in wt by 1 unit increases the mpg~hp slope by 0.03. That is, the negative association between mpg and hp is weaker for heavier cars (i.e., less negative) than for lighter cars. A plot really helps interpret this result.

ggplot(mtcars, aes(hp, mpg, colour=wt_f)) + geom_point(size=5) +
stat_smooth(method="lm", size=2, se=FALSE)


It appears that, for heavier cars (the blue line), their mpg is already much lower than lighter cars, so adding more horsepower does not penalize the cars' mpg as steeply as for the lighter cars.

I suppose something like this may happen for your dataset: older people tend to have more money at hand, so they may not gain as much happiness from having more money as do younger people, who tend to have less money especially nowadays. This pattern, if true, should result in weaker slope/correlations among older people than among the younger counterparts.

• Well, it seems to reflect the idea which I'm after, while the change of the mean through the groups were an additional effect which I didn't consider so far. But if we want to generalize to more groups and finally to a continuous variable $wt_f$ instead of a discrete one I think we need something like the three-items-productterms as I suspected/mentioned them in my other comment. "Interaction-analysis" seems to be the most likely generic term for this, I'll see. Oct 10 '14 at 17:43