【问题标题】:glm logistic regression in RR中的glm逻辑回归
【发布时间】:2014-06-20 15:32:50
【问题描述】:

我正在我拥有的数据集上尝试逻辑回归

model <- glm(feature1 ~ feature2, data=df, family="binomial")

但是glm 做了一些意想不到的事情。它将“feature2”的所有值作为变量,并在模型的logit参数中为其分配系数。

总结(模型)的输出:

> summary(model)

Call:

glm(formula = feature1 ~ price, family = binomial(logit), data = df)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.22931  -0.00008   0.00008   0.82033   1.97277  

Coefficients:
               Estimate Std. Error z value Pr(>|z|)
(Intercept)   6.931e-01  1.225e+00   0.566    0.571
price0.06     1.887e+01  1.075e+04   0.002    0.999
price0.1     -6.931e-01  1.871e+00  -0.371    0.711
price0.11     1.887e+01  1.075e+04   0.002    0.999
price0.2      1.887e+01  1.075e+04   0.002    0.999
price0.9      1.887e+01  1.075e+04   0.002    0.999
price0.99     1.092e-01  1.269e+00   0.086    0.931
price1        1.253e+00  1.626e+00   0.771    0.441
price1.01     1.887e+01  1.075e+04   0.002    0.999
price1.02     1.887e+01  1.075e+04   0.002    0.999
price1.04     1.887e+01  1.075e+04   0.002    0.999

> typeof(nonNPpriceDf$price)
[1] "integer"

我希望价格只是一个预测变量。我无法理解为什么所有价格都被附加并被视为变量。

【问题讨论】:

  • 你能提供dput(df)和summary(model)吗?
  • 我猜是变量(它是变量,而不是特性 :P)feature2 是一个因素?
  • 这对于分类变量(R 中的因子)是正常的。你期待什么行为?
  • 如果我执行 typeof,它会为 feature2 返回“整数”。它在数据集中有数值。
  • 因子是整数,整数值代表的级别带有字符标签。

标签: r logistic-regression


【解决方案1】:

这是 typeof 和类方法之间的混淆。因子 2 的类型是整数,但类是因子。我将 factor2 转换为数字,它按预期工作得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2020-08-06
    • 2012-02-25
    • 2015-04-26
    • 2018-08-11
    相关资源
    最近更新 更多