Plotting profile likelihood curves in R

后端 未结 2 1484
春和景丽
春和景丽 2021-02-09 16:19

I am trying to figure out how to plot the profile likelihood curve of a GLM parameter with 95% pLCI\'s on the same plot. The example I have been trying with is below. The plot

2条回答
  •  执念已碎
    2021-02-09 17:22

    FYI, for fun, I took the above and whipped it together into a single function using purrr::imap_dfr as I couldn't find a package that implements the above.

    get_profile_glm <- function(aglm){
      prof <- MASS:::profile.glm(aglm)
      disp <- attr(prof,"summary")$dispersion
    
      purrr::imap_dfr(prof, .f = ~data.frame(par = .y,
                                    deviance=.x$z^2*disp+aglm$deviance, 
                                    values = as.data.frame(.x$par.vals)[[.y]],
                                    stringsAsFactors = FALSE))
    
    }
    

    Works great!

    counts <- c(18,17,15,20,10,20,25,13,12)
    outcome <- gl(3,1,9)
    treatment <- gl(3,3)
    print(d.AD <- data.frame(treatment, outcome, counts))
    glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
    
    ggplot(get_profile_glm(aglm), aes(x = values, y = deviance)) +
      geom_point() +
      geom_line() +
      facet_wrap(~par, scale = "free_x")
    

提交回复
热议问题