Page 1 of 1

can you generate R code for this one can generate data analysis for this one model.matrix(~ a:b) ; lm(z ~ a:b) model.mat

Posted: Mon Nov 15, 2021 9:54 am
by answerhappygod
can you generate R code for this one
can generate data analysis for this one
model.matrix(~ a:b) ; lm(z ~ a:b)
model.matrix(~ a * b) ; lm(z ~ a * b)
model.matrix(~ a:x) ; lm(z ~ a:x)
model.matrix(~ a * x) ; lm(z ~ a * x)
model.matrix(~ b * (x + y)) ; lm(z ~ b * (x + y))
R will reduce the set of design variables for an interaction term
between categorical variables if a main effect is present. but not
detect the singularity caused by the presence of the
intercept.
There’s no singularities in either of the two cases involving a
categorical and a continuous variable, but the first one has one
parameter less (common-intercept model).
The last example has a “coincidental” singularity (x and y are
proportional within each level of b) which R has no chance of
detecting.
You can easily see that the model matrix is singular since the sum
of the last two columns (b2:x and b2:y) is proportional to the
second (b2), and also the difference between the x and y columns is
a linear combination of b2 and b2:x.