在multocompView中使用multocompView函数时遇到了一个小问题。以下代码运行非常好:
set.seed(1000)
Data<-c(runif(20, min=0, max=0.4), runif(20, min=0.1, max=0.6), runif(20, min=0.2, max=1))
Names<-c(rep("Type.1", 20), rep("Type.2", 20), rep("Type.3", 20))
Data<-cbind.data.frame(Data, Names, stringsAsFactors=FALSE)
Data[,2]<-as.factor(Data[,2])
colnames(Data)<-c("Success", "Type")
boxplot(Success~Type, data=Data)
library(multcompView)
multcompBoxplot(Success~Type, data=Data)但是,这使用了compFn的默认设置,即"TukeyHSD“。我的p值将来自另一个函数。根据手册,compFn是
一种函数,其输出将作为“multcompTs”或“multcompLetters”的唯一非默认输入。默认的"TukeyHSD“实际上转换为‘TukeyHSD(公式,数据)’[1]。
因此,TukeyHSD(aov(formula, data))[[1]][, "p adj"]为每个可能的成对比较返回一个带有p值的向量。我从另一个源中格式化的p值,然后传递给multcompLetters和multcompTS,以便对这些函数进行相应的计算。如果我只是手工操作,一切都很好:
P.Adj<-TukeyHSD(aov(Success~Type, data=Data))[[1]][, "p adj"]
Species.Groups<-multcompLetters(P.Adj, threshold=0.05)
Species.T<-multcompTs(P.Adj, threshold=0.05)但是,一旦我试图在multcompBoxplot中提供完全相同的信息,我就会得到警告和一个不显示T和字母的坏输出:
multcompBoxplot(Success~Type, data=Data, compFn=P.Adj)
Error in do.call(Fn, list(formula = formula, data = data)) :
'what' must be a character string or a function
In addition: Warning messages:
1: In if (compFn == "TukeyHSD") { :
the condition has length > 1 and only the first element will be used
2: In if (compFn == "kruskalmc") { :
the condition has length > 1 and only the first element will be used正如我所理解的手册,这应该提供确切的数据,功能需要。那么,multcompBoxplot不只是提供结果而不是计算结果的函数,还是我做错了什么?
发布于 2015-04-23 13:50:39
在浏览了multcompBoxplot的源代码之后,我想出了答案。折叠式作品:
Test.Function<-function(formula, data){TukeyHSD(aov(formula, data))[[1]][, "p adj"]}
multcompBoxplot(Success~Type, data=Data, compFn="Test.Function")https://stackoverflow.com/questions/29820453
复制相似问题