[R] Interactions in regression

Rolf Turner ro||turner @end|ng |rom po@teo@net
Tue Feb 27 02:29:19 CET 2024

I have no real idea what you are trying to do, but if a table is
what you want, you can probably get it using the table() function.
Or, more likely, the xtabs() function.

Using your example from an earlier post (adjusted to make it
comprehensible to the human mind):

time      <- factor(rep(c("Pre","Post"),each=200))
treatment <- factor(rep(rep(c("Control","Treatment"),each=100),2))
mu        <- rep(rep(1:2,each=100),2)
response  <- rnorm(400,mean=mu)
xmpldata  <- data.frame(time=time,treatment=treatment,response)
mod       <- lm(response~time*treatment,data=xmpldata)
yhat      <- fitted(mod)
xtb       <- with(xmpldata,xtabs(yhat ~ time+treatment))


>       treatment
> time     Control Treatment
>   Post  94.10501 201.99112
>   Pre  101.63792 210.04248

Is that (something like) what you want?


Rolf Turner

P.S. You said:  "I usually use GUI software".  Now *there* lies your
problem.  A GUI is a black box that removes all control over what is
going on, from your hands.

R. T.

Honorary Research Fellow
Department of Statistics
University of Auckland
Stats. Dep't. (secretaries) phone:
         +64-9-373-7599 ext. 89622
Home phone: +64-9-480-4619

More information about the R-help mailing list