0
votes
df <- data.frame(
  num =
    c(5, 7, 3,
      4, 2, 6,
      5, 3, 6,
      5, 6, 0,
      7, 4, 0,
      7, 7, 0,
      6, 6, 0,
      4, 6, 1,
      6, 4, 0,
      7, 7, 0,
      2, 4, 0,
      5, 7, 4,
      7, 5, 0,
      4, 5, 0,
      6, 6, 3
    ),
  x1 = factor(rep(c("xx", "pp", "tru"), 15)),
  x2 = factor(rep(c("A", "B", "C"), 15)),
  x3 = factor(rep(1:15, rep(3, 15))))

I would like to calculate significance for:

x1
x2
x3
interaction x1/x2
interaction x1/x3
interaction x2/x3
interaction x1/x2/x3

I think I have to do a linear model lm so I have tried

lm(df[,"num"] ~ df[,"x1"] * df[,"x2"] * df[,"x3"])

I am not sure if this is correct.

1

1 Answers

1
votes

The rule of thumb is to fit a linear model then perform an ANOVA:

fit <- lm(num ~ x1 * x2 * x3, data = df)
anova(fit)

However, your provided toy example is really a bad one, so nothing interesting will be seen.

  1. You have x1 and x2 identical (so they have perfect nesting). In this regard, you will get lots of NA coefficients;
  2. You have no replication. For each factor combination you only have one observation, so you will end up with an exact fit with zero residuals.