0

I am trying to perform t-tests between two states called n and t. These populations are measured through times 1 to 4. Each time point then belongs to two further groups above them. So for example:

Group-->Sub-group-->Time points-->State-->Var_measured

 Var_measured<-sample(248)

 State<-rep(c("t","n"), 124)

 Time<-as.factor(sample(1:4, 62,replace = TRUE))

 Sub_group<-sample(c("Met","Tet","Pep","Cep"),62, replace = TRUE)

 Group<-sample(c("AA","Gly"),62, replace = TRUE)

 df<-data.frame(Var_measured,State,Time,Sub_group,Group)

So from this data frame I would need a list of p-values from a t-test between each Sub_group at each Time point for State n and t. This is best visualised with an example:

p<-ggplot(df, aes(x= Time, y= Var_measured, fill= State))+
    geom_boxplot()+
    # coord_cartesian(ylim = c(0, 150000))+
    theme(axis.text.x=element_text(angle=90)) +
    facet_grid(Group ~ Sub_group, scales = "free_y")
p

I would ultimately like be able to show significance markers on the boxplots (as shown by this 'impeccable' paint job below). Any help would be appreciated.

Best, M

Example t-test of boxplots

MRF
  • 377
  • 1
  • 4
  • 15
  • 1
    You should look into `?TukeyHSD`, and the [plots you can create from it](https://www.r-graph-gallery.com/84-tukey-test/). – LAP Jan 24 '18 at 10:33
  • see [this question](https://stackoverflow.com/questions/17084566/put-stars-on-ggplot-barplots-and-boxplots-to-indicate-the-level-of-significanc) for how to add significance stars – Jan Boyer Jan 24 '18 at 16:11
  • Adding p values and stars might be best handled through a library like [ggpubr](http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots) but it appears to me that statistically you're on very shakey ground treating this simply as a very large number of t-tests. Also not clear whether this is a repeated measure design (same subject all 4 times) in which case your example data frame is incorrect. – Chuck P Jan 24 '18 at 19:10
  • No its not a repeated measure. In the 'real' data they are individual measurements of a population. – MRF Jan 25 '18 at 13:53

0 Answers0