I have a regression with many qualitative interactions and some of the combinations don't have any observations. How do I exclude the interaction coefficients with no observations from the summary.lm() output?
            Asked
            
        
        
            Active
            
        
            Viewed 1,594 times
        
    0
            
            
         
    
    
        Sandipan Dey
        
- 21,482
- 2
- 51
- 63
 
    
    
        Robert Kubrick
        
- 8,413
- 13
- 59
- 91
- 
                    1Please read: [How to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – C8H10N4O2 Feb 09 '17 at 20:22
1 Answers
2
            It would be hard (impossible?) to do without hacking the summary.lm() method, but if you are willing to look just at the coefficient table you can just use na.omit(coef(summary(...)))).
Example:
set.seed(101)
d <- data.frame(y=rnorm(100),x1=rnorm(100))
## add redundant variables
d$x2 <- d$x3 <- d$x1
m1 <- lm(y~.,data=d)  ## fit y to all other vars
summary(m1)
na.omit(coef(summary(m1)))
##               Estimate Std. Error    t value Pr(>|t|)
## (Intercept) -0.0329789 0.09341769 -0.3530263 0.724827
## x1           0.1002849 0.09341569  1.0735337 0.285668
 
    
    
        Ben Bolker
        
- 211,554
- 25
- 370
- 453