Skip to content

by_2sd fails with model including interactions and non-standard contrasts #82

@bbolker

Description

@bbolker

when there are interactions in the model, by_2sd tries to find the relevant columns of the model frame by parsing the names of the components in the interaction. This fails when contrasts have been set and the names are no longer as naively expected ...

The example uses data from the glmmTMB package because it was what I was working with, but any model with an interaction (of two factors) should cause the same problem.

library(dotwhisker)
data(Owls,package="glmmTMB")
owls_lm1 <- lm(SiblingNegotiation~FoodTreatment*SexParent,
               contrasts=list(FoodTreatment="contr.sum",
                              SexParent="contr.sum"),
               Owls)
dwplot(list(owls_lm1))  ## failure
t1 <- broom::tidy(owls_lm1, conf.int = TRUE)
dotwhisker::by_2sd(t1,model.frame(owls_lm1))
##  Error in `[[<-.data.frame`(`*tmp*`, paste0(first, ":", second), value = integer(0)) : 
  replacement has 0 rows, data has 599

I may work on the fix, but in the meantime I wanted to document this.

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