gpt4 book ai didi

r - 在 GLM 中,即使给出了数据,为什么有些系数是 NA?

转载 作者:行者123 更新时间:2023-12-04 07:38:22 27 4
gpt4 key购买 nike

在下面的例子中

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
输出是
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
为什么温度是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
这次有输出
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

最佳答案

我想是因为placetemperature 高度相关.
你会得到同样的 fitted(glm.fit)值(value)观,如果你这样做

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

另一个相关变量给出 NA 系数的例子。
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

关于r - 在 GLM 中,即使给出了数据,为什么有些系数是 NA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67628712/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com