1

I have a data frame with four columns showing the daylight in hours. I need to make boxplot to compare different groups and also to take anova test for comparing the groups. here is what i did but it is not working.

   A            B            C       D
15:15:08    15:29:08    15:32:50    15:34:12
15:02:32    15:23:43    15:21:06    15:34:50
14:40:34    14:58:30    15:21:06    15:32:50
15:15:08    15:29:08    15:21:06    15:34:50
15:10:03    14:58:30    15:30:01    15:34:12
15:23:43    15:19:42    15:30:01    15:34:00
14:56:24    15:29:08    15:21:06    15:34:50
15:15:08    14:58:30    15:24:56    15:34:50
15:15:08    14:58:30    15:32:50    15:34:12
14:56:24    14:42:57    15:32:50    15:34:50
14:56:24    14:47:35    15:21:06    15:30:01
14:56:24    15:23:43    15:24:56    15:34:12
15:15:08    14:49:51    15:30:01    15:34:12
15:02:32    15:32:50    15:30:01    15:27:10
15:10:03    15:29:08    15:34:12    15:34:12

DF<-as.POSIXct(DF$A, format = "%H:%M:%S")
DF<-as.POSIXct(DF$B, format = "%H:%M:%S")
DF<-as.POSIXct(DF$C, format = "%H:%M:%S")
DF<-as.POSIXct(DF$D, format = "%H:%M:%S")


boxplot(DF)
Df.anova <- c(DF$A, DF$B, DF$C, DF$D)
groups = factor(rep(letters[1:4], each = 15))

fit = lm(formula = Df.anova~ groups)
anova (fit)
LyzandeR
  • 37,047
  • 12
  • 77
  • 87
Mori
  • 241
  • 1
  • 2
  • 10
  • Convert them to number of seconds maybe. That's the first thing comes to my mind. – M-- Aug 18 '17 at 15:34

1 Answers1

1

Convert the times to hours using as.ITime. Then plot the boxplots and use pairwise t-tests to compare the groups. Anova in R will test for all the means being the equal, which would not be what you need on this occasion I assume:

library(data.table)
#convert to hours
DF[] <- lapply(DF, function(x) as.numeric(as.ITime(x)) / 3600)

#boxplots
boxplot(DF)

#melt the data.frame and calculate pairwise t.tests
meltedDF <- melt(DF)
pairwise.t.test(meltedDF$value, meltedDF$variable)

#Pairwise comparisons using t tests with pooled SD 

#data:  meltedDF$value and meltedDF$variable 
#
#  A       B       C      
#B 0.24228 -       -      
#C 9.9e-06 0.00073 -      
#D 4.1e-08 5.0e-06 0.24228

#P value adjustment method: holm 
LyzandeR
  • 37,047
  • 12
  • 77
  • 87