我正在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)
甚至開始=(1,4)或開始= 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)
什麼是'typeof運算(data.1 $ BMI)'? –
爲什麼使用日誌鏈接而不是logit? – AdmiralWen
typeof(數據,1 $ BMI)是雙倍的。 – Tina