Skip to content

emmeans() and mutate() in "visualizing_uncertainty.Rmd" (lines 398 ff.) #108

@napaxton

Description

@napaxton

Not sure this is actually an "issue."

Trying to replicate one of your graphs (16.5-Cocoa data v. CI), and I am running into a problem with emmeans and mutate. Here's the code in question:

cacao %>% 
  filter(location == "Canada") -> cacao_single

fit <- lm(rating ~ 1, data = cacao_single)

CI_df <- data.frame(type = c(0.8, 0.95, 0.99)) %>%
  mutate(df = map(type, ~tidy(emmeans(fit, ~ 1, options = list(level = .x))))) %>%
  unnest() %>%
  select(type, estimate, std.error, conf.low, conf.high) %>%
  mutate(type = paste0(signif(100*type, 2), "% confidence interval"))

When I run this code, I get the error Error: Can't subset columns that don't exist. x Column conf.low doesn't exist.

I've played around with the first mutate statement, and it seems that the emmeans estimation created there does not seem to iterate over creating the high and low CIs. While the emmeans statement used iteratively does produce the CIs as part of the output, within the mutate, the CIs don't get created.

At first I thought this was a mutate issue (as seen at https://stackoverflow.com/questions/64265476/problems-mutate-ing-and-select-ing-over-a-list-of-tibbles/), but it seems more to be emmeans.

Again, apologies if this isn't quite an issue, but wasn't sure where to turn on this, and the source seemed best.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions