Calling and pasting testing statistics from two independent variables in R

19 Views Asked by At

I am looking to run a two-way ANOVA and paste the results for both independent variables in R. I am able to do this with tests using just one independent variable as the results only contain one test statistic and p-value (example t.test below)

Name1 <- t.test(dependent ~ group, data = NameOfData, var.equal = TRUE)
text = paste("2-Sample  t-Test:","\n",
             "t:", round(Name1$statistic, digits = 3) , ",",
             "p-value:", round(Name1$p.value, digits = 3))
ggplot() +
  annotate("text", x = 0.5, y = 0, size=4, label = text, hjust = 0.5) +
  theme_void()

The above code will then produce a visual that looks like: enter image description here

However, if I do the same with a test that produces multiple test statistics or p-values, the statistics are pasted overlapping each other ...

Name1 <- aov(dependent ~ Group1 + Group2, data = Chick)
Name2 <- anova(Name1)
text = paste("Two-Way ANOVA:","\n",
             "F:", round(Name2$`F value`, digits = 3) , ",",
             "p-value:", round(Name2$`Pr(>F)`, digits = 3))
ggplot() +
  annotate("text", x = 0.5, y = 0, size=4, label = text, hjust = 0.5) +
  theme_void()

enter image description here

Could someone please suggest how I might call both values and list the p-values and test statistics of both independent variables (so 'F value - Group 1:' and 'F value - Group 2', for example)?

Thanks very much.

0

There are 0 best solutions below