Error: provide initial values

I am doing binomial regression in R. I want to control the covariates in the model (age and BMI are continuous variables), whereas the dependent variable is the result (yes or no) and the independent variable is the group (1 or 2).

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

      

and it works great.

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

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

      

I was offered another combination of initial 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 an 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 would be much appreciated!

Edited: Add a 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)

      

+3


source to share


1 answer


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

      

+4


source







All Articles