扫帚::整理功能不适用于glm2对象?

时间:2020-08-27 00:40:48

标签: r broom

我试图在'glm2'对象上使用扫帚函数'tidy'来“整理”二进制回归(因此使用日志链接而不是logit链接->因此我无法获得RR估计值)。但是它给我一个错误的说法

> tidy(model, conf.int=TRUE, exponentiate=TRUE)
Error: no valid set of coefficients has been found: please supply starting values

以下是我的意思的可复制示例:


library(tidyverse)
library(glm2)
library(broom)

data(iris)
glimpse(iris)
table(iris$Species)

##create an outcome

df <-iris %>%
  mutate(outcome = case_when(Petal.Width>2 ~1, 
                             TRUE ~0))

#fit stardard glm 
glm(outcome ~ Sepal.Length+Sepal.Width, data=df, 
    family = binomial(link="log"))
# -> doesnt converge using a log link due to parameter space issues (common in fitting binary regression).
# go to glm2 to fit the model instead, but need starting values for this:
p0 <- sum(as.numeric(df$outcome))/length(as.numeric(df$outcome))
start.val <- c(log(p0),rep(0,2))

model<-glm2(outcome ~ Sepal.Length+Sepal.Width, data=df, 
    family = binomial(link="log"), 
    start = start.val)

##get warnings, but converges
model$converged

##now tidy up and display model
tidy(model, conf.int=TRUE, exponentiate=TRUE)

#error -> wants starting values again? also shows warnings from previous 
# (which are now saying model hasnt converged?)

tidy(model, conf.int=TRUE, exponentiate=TRUE, start=start.val)
# doesnt recognise starting values?

关于如何使tidy工作的任何想法,还是我只是手动进行?

0 个答案:

没有答案