In GLM, why are some coeeficients NA even when the data is given?

Viewed 44

In the following example

df <- data.frame(place = c("South","South","North"),
                 temperature = c(30,30,20),
                 outlookfine=c(TRUE,TRUE,FALSE)
                 )
glm.fit <- glm(outlookfine ~ .,df, family=binomial)

glm.fit

The output is

Call:  glm(formula = outlookfine ~ ., family = binomial, data = df)

Coefficients:
(Intercept)   placeSouth  temperature  
     -23.57        47.13           NA  

Degrees of Freedom: 2 Total (i.e. Null);  1 Residual
Null Deviance:      3.819 
Residual Deviance: 3.496e-10    AIC: 4

Why is temperature NA?

[Update]

I experimented with more data

df <- data.frame(place = c("South","South","North","East","West"),
                 temperature = c(30,17,20,12,15),
                 outlookfine=c(TRUE,TRUE,FALSE,FALSE,TRUE)
                 )
glm.fit <- glm(outlookfine ~ .,df, family= binomial )
glm.fit

This time there was an output

Call:  glm(formula = outlookfine ~ ., family = binomial, data = df)

Coefficients:
(Intercept)   placeNorth   placeSouth    placeWest  temperature  
 -2.457e+01   -7.094e-07    4.913e+01    4.913e+01    8.868e-08  

Degrees of Freedom: 4 Total (i.e. Null);  0 Residual
Null Deviance:      6.73 
Residual Deviance: 2.143e-10    AIC: 10
1 Answers

I think it is because place is highly correlated with temperature.

You'll get the same fitted(glm.fit) values if you either do

glm.fit <- glm(outlookfine ~ place,df, family=binomial)

or

glm.fit <- glm(outlookfine ~ temperature, df, family=binomial)

Another example with correlated variables giving NA coefficients.

df <- iris
df$SL <- df$Sepal.Length * 2 + 1
glm(Sepal.Width ~ Sepal.Length + SL, data  = df)
Call:  glm(formula = Sepal.Width ~ Sepal.Length + SL, data = df)

Coefficients:
 (Intercept)  Sepal.Length            SL  
     3.41895      -0.06188            NA  

Degrees of Freedom: 149 Total (i.e. Null);  148 Residual
Null Deviance:        28.31 
Residual Deviance: 27.92  AIC: 179.5
Related