r glm - 名称错误(coef)<- xnames 仅适用于数据中的 2 列

数据挖掘 r glm
2022-03-06 08:38:05

运行 glm() 的 R 代码时出现以下错误:

> fmla = 'status_id~ratings'
> logisticmodel <- glm(fmla, data = playdata, family=binomial(link="logit"))

你能纠正我哪里出错了吗,我在谷歌上搜索了很多,唯一的答案通常是命名约定,但是,这对我来说不是这样,因为我尝试通过将所有值都设置为 2 来更改数据工作 - 所以这不是变量的命名问题。

下面是数据说明:

> str(playdata)

'data.frame':   24160 obs. of  13 variables:
 $ idd         : int  57251659 63385939 51939145 64339389 33725679 47000250 62738883 33725679 53589441 36670488 ...
 $ status_id       : int  1 1 1 1 1 1 1 1 1 1 ...
 $ id              : int  22820543 22953283 22919397 22699949 22658030 22720403 22581860 22915483 22621108 22651736 ...
 $ group_id        : int  2 2 2 2 2 2 2 2 2 2 ...
 $ created_date    : POSIXct, format: "2017-03-31 12:45:10" "2017-04-04 10:50:11" "2017-04-03 16:40:04" "2017-03-28 14:40:48" ...
 $ question_id     : int  20073221 20219031 20185301 19948471 19906458 18651404 19816152 20175471 19865888 19897662 ...
 $ surftoanswertime: int  533 484 98 476 388 0 741 757 2222 381 ...
 $ skiprate        : num  0.981 0.95 0.993 0.875 0.966 ...
 $ ratings         :integer64 0 0 1 2 0 0 1 1 ... 
 $ pos             :integer64 0 0 1 2 0 0 1 0 ... 
 $ negratings      :integer64 0 0 0 0 0 0 0 1 ... 
 $ cf              : num  NA NA 1 1 NA NA 1 0 NA 1 ...
 $ cf1             : num  -1 -1 1 1 -1 -1 1 0 -1 1 ...

实际公式如下 - 只有评级和否定会引发上述错误。

fmla = 'status_id~skiprate+ratings+negratings+surftoanswertime+cf1'

您能否帮助我理解和纠正错误。

> logisticmodel <- glm(fmla, data = playdata, family=binomial(link="logit"))
Error in names(coef) <- xnames : names() applied to a non-vector
In addition: Warning messages:
1: In glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  :
  non-finite coefficients at iteration 1
2: glm.fit: algorithm did not converge 

如果我使用更多列,我会收到以下错误:

Error in `*tmp*`[fit$pivot] : object of type 'closure' is not subsettable
In addition: Warning messages:
1: In glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  :
  non-finite coefficients at iteration 1
2: glm.fit: algorithm did not converge 
1个回答

问题出在 datatypeinteger64上。我不知道为什么会出现这个问题,但将其更改为 type integer

ratings = as.integer(ratings)

通常,我没有看到任何人使用 integer64 数据类型。