简体   繁体   English

r 中的逻辑回归误差

[英]Logistic Regression Error in r

I'm creating a model with several thousand variables, all of which have a majority of values equal to NA.我正在创建一个包含数千个变量的模型,所有这些变量的大多数值都等于 NA。 I am able to successfully run logistic regression on some variables but not others.我能够成功地对某些变量而不是其他变量运行逻辑回归。

Here's my code to input the large amount of vars:这是我输入大量变量的代码:

model_vars <- names(dataset[100:4000])
vars<- paste("DP ~ ", paste(model_vars, collapse= " + "))  

This formats it with the dependant variable and each Independant variable having a "+" between.这将其格式化为因变量和每个独立变量之间有一个“+”。 I then run this through the glm function:然后我通过 glm 函数运行它:

glm(vars, data = training, family = binomial)

Here is the error I get when certain variables are included:这是包含某些变量时出现的错误:

Error in family$linkfun(mustart) : 
Argument mu must be a nonempty numeric vector

I cannot figure out why this is occuring and why the regression works for certain variables and not others.我无法弄清楚为什么会发生这种情况以及为什么回归适用于某些变量而不是其他变量。 I can't see any trend in the variables that cause the error.我看不到导致错误的变量的任何趋势。 Could someone clarify why this error shows up?有人可以澄清为什么会出现此错误吗?

For others with that cryptic error message.对于其他带有神秘错误消息的人。 Perhaps the data frame is empty?也许数据框是空的?

This reproduces the message:这再现了消息:

d=data.frame(x=c(NA),y=c(NA))
d=d[complete.cases(d),]
m=glm(y~.,d,family = 'binomial')

Error in family$linkfun(mustart) : Argument mu must be a nonempty numeric vector family$linkfun(mustart) 中的错误:参数 mu 必须是非空数字向量

I had the error:我有错误:

Error in family$linkfun(mustart) : 
  Argument mu must be a nonempty numeric vector

when using logistic regression with glm() , like:将逻辑回归与glm()一起使用时,例如:

glm(y~x,data=df, family='binomial')

after subsetting and standardizing data frames in a loop.在循环中对数据帧进行子集化标准化之后。

It turned out, that (some of) the subsetted and standardized data frames contained NA , which caused the error.事实证明,(一些)子集化和标准化的数据帧包含NA ,这导致了错误。

我也有这个错误,原因是 if_else 函数返回一个逻辑向量,而不是预期的数字变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM