简体   繁体   中英

Is there a better way to conduct a 3 way ANOVA in R?

Right now I am working with my own dataset very similar to the example at https://www.datanovia.com/en/lessons/anova-in-r/ specifically the Three-Way ANOVA section. The code is well laid out, but when I get to the section for visualization using boxplots, I run into an unexpected error.

headache %>%
  group_by(gender, risk, treatment) %>%
  get_summary_stats(pain_score, type = "mean_sd")

In their code, they assign y as pain score, but for me, I get Error in:

FUN (x[[i]],...): object "pain_score" not found

As such, I can't get the plot they make or move farther into analysis.

  bxp <- ggboxplot(
  headache, x = "treatment", y = "pain_score", 
  color = "risk", palette = "jco", facet.by = "gender"
  )
bxp

All of the packages I have are up to date, I'm not seeing any errors in my code. I've tried other variables in my data set and the same issue, and when I change it to mean, I just get the line, not the box plot. If anyone has some input, it would be much appreciated!!

Its working perfectly alright, You also didn't mention the libraries in your code. Its hard to help if you don't provide all the complete information. In any case someone wants to reproduce this.

Please run the below, It should work at your end. The error you are getting suggests that you might have either mistakenly removed the column, or data is corrupt in your session.

Here is the complete working code:

library(tidyverse)
library(rstatix)
library(ggpubr)

data("headache", package = "datarium")

headache %>%
  group_by(gender, risk, treatment) %>%
  get_summary_stats(pain_score, type = "mean_sd")


bxp <- ggboxplot(
  headache, x = "treatment", y = "pain_score", 
  color = "risk", palette = "jco", facet.by = "gender"
)
bxp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM