nested fixed effects possible?

#1
Hi,

I investigate a problem via a regression model. Firtsly, I have two different ways to measure my outcome, which I incorporate as a two-level factor variable X. However, each of these methods is again influenced by a factor variable with two levels, but these factor variables differ for each method. Thus, for the level X_1 I have "nested" categorical predictor levels "A_x1 and B_x1" and for the level X_1, I have categorical predictor levels A_x2 and B_x2.

How do I formulate this within a regression model in R? Can I fuse the levels A_x1, B_x1, A_x2, B_x2 to just one factor variable with 4 levels, or does this produce problems, because these levels mutually exclude each other regarding the levels X_1 and X_2?

Thanks!
 

Jake

Cookie Scientist
#2
You can use the nesting operator "/".
Let the A vs. B factor be named "AB", and it consist of a column of A and B values. Then you could do:
lm(Y ~ X/AB)
 
#3
Hi,

thanks already. But what if the number of sublevels exclusively corresponding to level X1 differs from the number of sublevels exclusively corresponding to level X2? Is there any problem if I code just one factor variable (without using the nesting operator), and some of the levels of this variable appear exclusively ion only one level of X?

Thanks
 

Jake

Cookie Scientist
#4
I think that should work fine too, as long as the nested variable is "explicitly nested" in X (i.e., you use different labels within each level of X).
 
#5
Thank you, that was exactly what I wanted to know. I just worried, since such a design with "exclusive" sublevels seems to be extremely unbalanced at a first glance...