错误:请提供起始值 [英] Error: please supply starting values

查看:258
本文介绍了错误:请提供起始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中进行对数二项式回归。我想控制模型中的协变量(年龄和BMI-两个连续变量),而因变量是结果(是或否),自变量是组(1或2)。

  fit< -glm(Outcome〜Group,data = data.1,family = binomial(link =log)) 

,它的工作正常。



我试着把年龄放在模型中,它仍然可以正常工作。
但是,当我将BMI放在模型中时,它给了我以下内容:

 错误:没有有效的系数已被发现:请提供起始值

我已经尝试过不同组合的起始值,如:



fit< -glm(Outcome〜Group + Age + BMI,data = data.1,family = binomial(link =log ,start = c(0,0,0,0)甚至start =(1,4)或start = 4,但仍然给我错误。



它还说:

  glm.fit中的错误(x = c(1,1,1, 1,1,1,1,1,1,1,1,1,1,1,:
'start'的长度应等于4,并对应于c的初始系数),group1,age,bmi)

b
$ b

对此的任何帮助将不胜感激!



已编辑:添加可重现的示例。

  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 = binary(link =log coefini)


解决方案

经过一些尝试和错误,使用 set.seed(123)

  coefini = coef(glm(Outcome〜 group + Age,data = data.1,family = binomial(link =log))
fit2< -glm(Outcome〜Group + Age + BMI,data = data.1,family = binary =log),start = c(coefini,0))

摘要(fit2)

调用:
glm(formula = Outcome〜Group + Age + BMI,family = binomial(link =log),
data = data.1,start = c(coefini,0))

偏差余数:
最小1Q中位数3Q最高
-1.2457 -0.9699 -0.7725 1 .2737 1.6799

系数:
估计标准错误z值Pr(> | z |)
(截取)-1.5816964 1.0616813 -1.490 0.136
Group1 0.4987848 0.3958399 1.260 0.208
年龄0.0091428 0.0138985 0.658 0.511
BMI -0.0005498 0.0331120 -0.017 0.987

(二项式族的分散参数取为1)

空值:65.342在49自由度
剩余偏差:63.456在46度的自由
AIC:71.456

费舍尔计分迭代次数:3


I am conducting a log binomial regression in R. I want to control for covariates in the model (age and BMI- both continuous variables) whereas the dependent variable is Outcome(Yes or No) and independent variable is Group (1 or 2).

fit<-glm(Outcome~Group, data=data.1, family=binomial(link="log"))

and it works fine.

When I try putting age in the model, it still works fine. However, when I put BMI in the model, it gives me the following:

Error: no valid set of coefficients has been found: please supply starting values

I have been tried different combination of starting values such as:

fit<-glm(Outcome~Group+Age+BMI, data=data.1, family=binomial(link="log"), start=c(0,0,0,0) or even start=(1,4) or start =4 but it still gives me the error.

It also says:

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")

.

Any help on this will be much appreciated!

Edited: adding reproducible example.

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)

解决方案

After some trial and error, using set.seed(123):

coefini=coef(glm(Outcome~Group+Age, data=data.1,family =binomial(link = "log") ))
fit2<-glm(Outcome~Group+Age+BMI, data=data.1, family=binomial(link="log"),start=c(coefini,0))

summary(fit2)

Call:
glm(formula = Outcome ~ Group + Age + BMI, family = binomial(link = "log"), 
    data = data.1, start = c(coefini, 0))

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.2457  -0.9699  -0.7725   1.2737   1.6799  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.5816964  1.0616813  -1.490    0.136
Group1       0.4987848  0.3958399   1.260    0.208
Age          0.0091428  0.0138985   0.658    0.511
BMI         -0.0005498  0.0331120  -0.017    0.987

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 65.342  on 49  degrees of freedom
Residual deviance: 63.456  on 46  degrees of freedom
AIC: 71.456

Number of Fisher Scoring iterations: 3

这篇关于错误:请提供起始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆