我正在 R 中进行对数二项式回归。我想控制模型中的协变量(年龄和 BMI - 都是连续变量),而因变量是结果(是或否),自变量是组(1 或 2)。
fit<-glm(Outcome~Group, data=data.1, family=binomial(link="log"))
而且效果很好。
当我尝试在模型中加入年龄时,它仍然工作得很好。
然而,当我将 BMI 放入模型中时,它会给出以下结果:
Error: no valid set of coefficients has been found: please supply starting values
我尝试过不同的起始值组合,例如:
fit<-glm(Outcome~Group+Age+BMI, data=data.1, family=binomial(link="log"), start=c(0,0,0,0)
甚至 start=(1,4) 或 start =4 但它仍然给我错误。
它还说:
Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
length of 'start' should equal 4 and correspond to initial coefs for c("(Intercept)", "group1", "age", "bmi")
.
对此的任何帮助将不胜感激!
编辑:添加可重现的示例。
N=50
data.1=data.frame(Outcome=sample(c(0,0,1),N, rep=T),Age=runif(N,8,58),BMI=rnorm(N,25,6),
Group=rep(c(0,1),length.out=N))
data.1$Group<-as.factor(data.1$Group)
fit<-glm(Outcome~Group, data=data.1, family=binomial(link="log"))
coefini=coef(glm(Outcome~Group+Age+BMI, data=data.1,family =binomial(link = "logit") ))
fit<-glm(Outcome~Group+Age+BMI, data=data.1, family=binomial(link="log"),start=coefini)