'emmip error from emmeans package - unevaluated constants

Only today I learned about the emmeans package for R. I'm making a model similar to to the rdocumentation for the emmip() function, but I seem to get an error of some sort when I run my own data through it. The primary difference I spot between my data and the example model in the documentation is I'm using cbind() for my binomial model. Perhaps that's the primary culprit?

I'm unsure of what the error means, and I haven't currently found any other mentions of these errors out there, nor do I see clarification in the help section/manual. Is there any advice as to what's wrong with my data, or maybe what the error means?

#dput of data
test<-structure(list(Mean = c(33, 91.5, 7, 68, 25.75, 101, 2, 47.75, 
                              26, 125, 6.75, 51.5), Factor1 = structure(c(2L, 2L, 1L, 1L, 2L, 
                                                                          2L, 1L, 1L, 2L, 2L, 1L, 1L), .Label = c("1400", "800"), class = "factor"), 
                     Factor2 = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
                                           2L, 1L, 2L), .Label = c("25", "31"), class = "factor")), row.names = c(NA, 
                                                                                                                  -12L), class = "data.frame")

#Creating a binomial generalized linear model of the above data
Mod_test<-glm(cbind(Mean*4, (800-(Mean*4)))  ~
                Factor1 * #Interactive effect of the factors
                Factor2,
              family = "binomial",
              data = test)

anova(Mod_test, test = "Chisq") #Confirming the factors are significant in their interaction

library(emmeans)
# On link scale: # This does create a plot, but produces an error
emmip(Mod_test, Factor1 ~ Factor2)

# On response scale: #This does not produce a plot, produces an additional error. 
emmip(Mod_test, Factor1 ~ Factor2, type = "response")


Solution 1:[1]

The first command does not produce an error, but a warning: "There are unevaluated constants in the response formula. Auto-detection of the response transformation may be incorrect." This is referring to this part of your model:

cbind(Mean*4, (800-(Mean*4)))

emmeans is not built to deal with this on the fly calculation of parameters. Just do the calculations beforehand:

test2 <- test
test2$Mean <- test2$Mean * 4
test2$Mean2 <- 800 - test2$Mean
Mod_test2 <- glm(
  cbind(Mean, Mean2) ~ Factor1 * Factor2,
  family = "binomial",
  data = test2
)

anova(Mod_test2, test = "Chisq")
emmip(Mod_test2, Factor1 ~ Factor2)
emmip(Mod_test2, Factor1 ~ Factor2, type = "response")

Now it all works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Axeman