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)