Is it preferable to subset data to test specific hypotheses or specify a full model and run contrasts? Let's say I have a 2x2 design where participants are either in condition A or condition B and, within each condition, either get exposed to exposure C or exposure D.
First, I want to test whether exposure D > exposure C, within each condition. I can do one of two things.
First, I can subset the data to the appropriate condition and check the coefficient on a dummy variable set to 1 for exposure_d.
lm(outcome ~ exposure_d, data = subset(data, condition == "A")
lm(outcome ~ exposure_d, data = subset(data, condition == "B")

Or I can specify a full model and run a contrast
library(emmeans)
model <- lm(outcome ~ exposure_d * condition_a, data = data)
means = emmeans(model, ~ condition_a | exposure_d)
contrast_table = contrast(means, method = "pairwise")

Are these methods formally equivalent? I tested the two on simulated data and they seem to produce identical coefficients and standard errors, but I worry things might change when I start adding in more control variables (especially since the contrast() function throws the warning that the cell means and standard errors may not be accurate in the presence of interactions). Which of these methods is preferred?
 A: They are not equivalent, because when you leave everything together, you use all the data to estimate the error SD.
Another way to look at it is that the EMMs are based on the model you fitted, and when you fit a different model, you get different results. When you keep all the data together in the one model, the one you show has an underlying assumption that the variance is homogeneous. If you separate the data according to one factor, those two models together could be viewed as one model that allows separate error variances for the two levels of that factor. Yet another model would be one where the interaction is excluded. With these different models, you will get the same estimates (if the data are balanced), but the SEs will differ.
It is typically not a good idea to subset the data. You get more power (and/or lower SEs) by using more data to form estimates. The exception might be models that allow various types of heterogeneity. Such models have more parameters and may not perform better.
