I am estimating many regressions iteratively and recording the coefficient summaries for each estimation. Sometimes, the data isn't good but I want to record the outcome none the less.
When the data is bad, and lm.fit kicks back NA's for some regressor, for some reason, it doesn't show up when calling coef()
on the summary()
When I make the following call (simplified for reproducability)
summary(lm(y ~., data=data.frame(y = 1:30, x1 = rep(0, 30), x2 = 1:30*2)))
As part of the output I get
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.595e-15 5.129e-16 -5.059e+00 2.36e-05 ***
x1 NA NA NA NA
x2 5.000e-01 1.445e-17 3.461e+16 < 2e-16 ***
However... when I make the call to get the coefficient matrix...
summary(lm(y ~., data=data.frame(y = 1:30, x1 = rep(0, 30), x2 = 1:30*2)))$coefficients
I obtain
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.594535e-15 5.128850e-16 -5.058707e+00 2.362068e-05
x2 5.000000e-01 1.444508e-17 3.461387e+16 0.000000e+00
The reality is that I want to have the coefficient with NA's in the output as I am constructing other objects and it's causing issues with not matching dimensions, and mis-alignments.
Obviously, this is a toy example to illustrate the problem. My actual problem is on a much larger scale with many more coefficients, and this issue occurs with different coefficients at different times.