0

I'm not familiar with R at all but have to run this code for uni, not able to make it work. I want to do pairwise comparison for my ANOVA test, any help on how to resolve this would be greatly appreciated.

This is my code:

comp <- emmeans(anova_A, specs=pairwise ~ mydata$`Which group of people influences your decisions about sustainable food options the most?`, model="univariate")

And it shows this error message:

Error in str2lang(x) : :1:21: unexpected symbol 1: pairwise~mydata.Av1.Which group of people influences your decisions about sustainable food options the most?

Peter
  • 11,500
  • 5
  • 21
  • 31
Joep
  • 1
  • 1
  • Does this answer your question? [When using sapply,I get Error in str2lang(x) : :1:31: unexpected symbol 1 ^](https://stackoverflow.com/questions/70313780/when-using-sapply-i-get-error-in-str2langx-text131-unexpected-symbol-1) – NelsonGon Dec 12 '21 at 20:31
  • Try my [answerr](https://stackoverflow.com/a/70315310/10323798) from yesterday :) I think you've also got the formula syntax wrong. It seems unusual to specify a formula using `$`. – NelsonGon Dec 12 '21 at 20:32
  • 2
    you will find it much easier going forward if you convert all of your variable names to be syntactically valid e.g. running `names(yourData) <- make.names(names(yourData))` is one way – user20650 Dec 12 '21 at 20:49

1 Answers1

3

If you really have a variable by that name in your model, then the following should work:

EMM <- emmeans(anova_A, "Which group of people influences your decisions about sustainable food options the most?")
pairs(EMM)

In any case, you specify names of predictors used in the model, because emmeans() summarizes the model, not the data set.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Russ Lenth
  • 5,922
  • 2
  • 13
  • 21