R 在GLM中,为什么即使给出了数据,一些系数也不适用?
在下面的示例中R 在GLM中,为什么即使给出了数据,一些系数也不适用?,r,glm,R,Glm,在下面的示例中 df <- data.frame(place = c("South","South","North"), temperature = c(30,30,20), outlookfine=c(TRUE,TRUE,FALSE) ) glm.fit <- glm(outlookfine ~ .,df, family=
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
为什么温度是NA
[更新]
我尝试了更多的数据
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
我认为这是因为
地点
与温度
高度相关
您将获得相同的fitted(glm.fit)
值
glm.fit <- glm(outlookfine ~ place,df, family=binomial)
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
glm.fit <- glm(outlookfine ~ place,df, family=binomial)
glm.fit <- glm(outlookfine ~ temperature, df, family=binomial)
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