?s 16:30 de 12/11/2025, Brian Smith escreveu:> Hi,
>
> I have below code
>
> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
> group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
> group1 <- head(gl(2, 10, 22, labels =
c("Ctl1","Trt1")), 20)
> weight <- c(ctl, trt)
> dat = as.data.frame(cbind(weight, group, group1))
> lm.D9 <- lm(weight ~ group * group1 - 1 - group1, dat)
>
> I want to incorporate interaction between 2 variables group and
> group1, however do not want to incorporate level-0 for group1 not the
> intercept.
>
> Therefore I used (-1 - group1) in the formula.
>
> I would like to know if above is a valid syntax for the stated model.
>
> Thanks and regards,
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Hello,
Yes, that syntax is valid. But isn't
lm.D9b <- lm(weight ~ 0 + group + group:group1, dat)
more readable?
You can check that the two models are the same with
summary(lm.D9)
summary(lm.D9b)
This will tell where the objects returned by those two calls to lm() are
different, giving further arguments to prefer model lm.D9b.
all.equal(lm.D9, lm.D9b, check.attributes = FALSE)
Hope this helps,
Rui Barradas