2017-08-18 43 views
1

我有一个四栏的数据框显示几小时的日光。我需要制作boxplot来比较不同的群体,并且还需要进行anova测试来比较群体。这是我做的,但它不工作。如何为时间格式数据制作boxplot?

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) 
+0

将它们转换为秒数也许。这是我首先想到的。 – Masoud

回答

1

使用as.ITime将时间转换为小时。然后绘制箱形图并使用成对t检验来比较组。 R中的Anova将测试所有平均值,在这种情况下我不会假设:

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 
相关问题