我正在尝试对虚拟变量执行logit回归。
变量y是一个chr,我已使用以下代码将其转换为数字。
myData$y <- as.numeric(as.character(myData$y))
myData$x19 <- as.numeric(as.character(myData$x19))
结果如下:
> str(myData)
'data.frame': 2089 obs. of 21 variables:
$ cod: chr "DEFEB97411" "ESA87020566" "LT112021238" "ESA70302039" ...
$ x1 : chr "10.368400000000001" "18.104500000000002" "53.338142857142849" "18.096999999999998" ...
$ x2 : chr "81.251592378494607" "24.169624052591214" "20.258977190130423" "13.834562559615202" ...
$ x3 : chr "N/A" "N/A" "18.122857142857143" "15.467500000000001" ...
$ x4 : chr "92.257276111020005" "80.742324540987497" "53.251824749595997" "78.217022461160269" ...
$ x5 : chr "N/A" "N/A" "1.8639827074905999" "11.306989139206143" ...
$ x6 : chr "N/A" "N/A" "3.8017284097507149" "6.2387112552580009" ...
$ x7 : chr "N/A" "N/A" "-18.776333013159142" "63.587694201206432" ...
$ x8 : chr "N/A" "N/A" "N/A" "N/A" ...
$ x9 : chr "423.45434977976021" "11.683217643759502" "12.353727918269428" "7.4528876298177149" ...
$ x10: chr "188.66242539565681" "11.282744548351999" "11.902544271951285" "6.8315087254777138" ...
$ x11: chr "34.814814814814667" "0.71972866025899995" "1.4488644105372859" "1.128749296162143" ...
$ x12: chr "29.512676056338002" "11.225379651791" "10.349080357197428" "-48.646148547886426" ...
$ x13: chr "0.31797384757359998" "70.477571651141247" "81.34607558631528" "65.442536245008867" ...
$ x14: chr "347.83320016228879" "33.855519321625252" "27.042740986499286" "6.5450441963748585" ...
$ x15: chr "64.731000000000009" "10.11375" "10.614714285714285" "6.2912857142857135" ...
$ x16: chr "2.5469999999999997" "5.9179427965575062" "11.861177222645995" "5.9179427965575062" ...
$ x17: chr "5" "5.8" "6.2" "5.8" ...
$ x18: chr "5.2" "6.6943242163984618" "10.173227449851671" "6.6943242163984618" ...
$ x19: num "72.317277605096791" "68.303293784830231" "72.485515585867958" "68.303293784830231" ...
$ y : num 0 0 0 1 0 0 0 0 0 0 ...
然后,我正在尝试进行概率回归:
m1=glm(y~x19,
family=binomial(link="logit"))
但是我仍然收到错误消息:
> m1=glm(y~x19,
+ family=binomial(link="logit"))
Error in weights * y : non-numeric argument to binary operator
您能帮我解决这个问题吗?
谢谢
答案 0 :(得分:0)
以下是将myData
直接传递给glm
的方法:
m1=glm(y~x19, family=binomial(link="logit"), data=myData)
答案 1 :(得分:-1)
请在this other thread中查看我的帖子
glm()
仅接受numeric
或factor
类型的变量。