Re: [R] Problems on testing moderating effect (or interactive effect).

From: Jonathan Baron <>
Date: Tue 04 Jul 2006 - 21:09:06 EST

On 07/04/06 11:38, Guo Wei-Wei wrote:
> Hi everyone,
> I want to do test on moderating effect. I have three factors, A, B,
> and C. A has influence on B, and C moderating the influence. The
> relationship looks like this:
> A -----> B
> ^
> |
> C
> A, B, and C are all scale variables. I think I can test the moderating
> effect by adding a interactive variable between A and C. But I'm not
> sure how to do.
> Is there a default way to do it in package sem?
> I'm also thinking about create a interaction variable of A and C, but
> I don't know how to it. A has n (n = 27) items and p (p = 288) cases
> and C has m (m = 16) iterms and p (p = 288) cases.

Moderation is usually tested with an interaction. You would use lm() not sem. For example,

summary(lm(B ~ A*C))

which will report the main effects of A and C as well as their interaction. (Of course, main effects may be meaningless if there is an interaction.) See the help page for formula.

So far I'm assuming that you are interested in individual differences (cases). So A, B, and C would be the means of each case. If, for example, A is actually a matrix in which each row is a case, you would use something like rowMeans(A), etc., for each variable, so you could say

summary(lm(rowMeans(B) ~ rowMeans(A)*rowMeans(C)))

(or else compute each of these first).

However, you may be interested in moderation WITHIN cases, across items.

If you look up moderation on Google, you find

which cites

Judd, C. M., Kenny, D. A., & McClelland, G. H. (2001). Estimating and testing mediation and moderation in within-participant designs. Psychological Methods, 6, 115-134.

I have not read this article, but other articles by the same authors are both clear and well reasoned.

Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page:
Editor: Judgment and Decision Making (

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Tue Jul 04 21:13:54 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 04 Jul 2006 - 22:15:30 EST.

Mailing list information is available at Please read the posting guide before posting to the list.