Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R和GraphPad棱镜计算分位数_R_Boxplot_Outliers_Quantile - Fatal编程技术网

使用R和GraphPad棱镜计算分位数

使用R和GraphPad棱镜计算分位数,r,boxplot,outliers,quantile,R,Boxplot,Outliers,Quantile,我是R新手。在使用R之前,我使用了GraphPad Prism 7.0。现在我试着将两者作为数据处理器进行比较。我在分位数计算中发现了差异,所以有人知道为什么它们是不同的吗 在R我有 par(pty="s", cex.axis=1, las=1, cex.lab=1) a1=c(22.02, 23.83, 26.67, 25.38, 25.49, 23.50, 25.90, 24.89, 25) a2=c(21.49, 22.67, 24.62, 24.18, 22.78,

我是R新手。在使用R之前,我使用了GraphPad Prism 7.0。现在我试着将两者作为数据处理器进行比较。我在分位数计算中发现了差异,所以有人知道为什么它们是不同的吗

在R我有

par(pty="s", cex.axis=1, las=1, cex.lab=1)
a1=c(22.02, 23.83,  26.67,  25.38,  25.49,  23.50,  25.90,  24.89, 25)
a2=c(21.49, 22.67,  24.62,  24.18,  22.78,  22.56,  24.46,  23.79, 25)
a3=c(20.33, 21.67,  24.67,  22.45,  22.29,  21.95,  20.49,  21.81, 25)
boxplot(a1,a2,a3, names=c("a1","a2","a3"), ylab="Valor", ylim=c(20,28))

a3的分位数是

quantile(a3)
   0%   25%   50%   75%  100% 
20.33 21.67 21.95 22.45 25.00
在GraphPad Prism中绘制相同的数据:

图形族:列 盒子和胡须 情节:图基

我明白了

分位数是

为什么它们不同(特别是a3)

为什么R识别a3中的4个异常值而GraphPad不识别


建议???

回答如何在箱线图中使用不同分位数计算的问题:

使用ggplot2很容易

DF <- data.frame(a1, a2, a3)
DF <- stack(DF)

quants <- tapply(DF$values, list(DF$ind), quantile, type = 6)
quants <- as.data.frame(do.call(rbind, quants))
quants$g <- rownames(quants)

library(ggplot2)
ggplot(quants, aes(x = g, lower = `25%`, 
                   middle = `50%`, upper = `75%`,
                   ymin = `0%`, ymax = `100%`)) +
  geom_boxplot(stat = "identity")

DF正如@lmo所说,R有许多计算分位数的方法。默认情况下,R使用
type=7
。GraphPad使用的方法相当于R中的
type=6

par(pty="s", cex.axis=1, las=1, cex.lab=1)
a1=c(22.02, 23.83,  26.67,  25.38,  25.49,  23.50,  25.90,  24.89, 25)
a2=c(21.49, 22.67,  24.62,  24.18,  22.78,  22.56,  24.46,  23.79, 25)
a3=c(20.33, 21.67,  24.67,  22.45,  22.29,  21.95,  20.49,  21.81, 25)
boxplot(
  quantile(a1,type=6),
  quantile(a2,type=6),
  quantile(a3,type=6), 
  names=c("a1","a2","a3"), ylab="Valor", ylim=c(20,28))


与GraphPad相同,首先,您可以查看帮助文件中的类型部分(
?分位数
)。这表明有很多方法可以实现分位数算法,R提供了9种不同的方法。@lmo得到了它。graphpad中的分位数计算是使用R中的类型6进行的。但是如何在箱线图中使用此分位数计算类型?我不认为您可以调整根据箱线绘制的值。这些都是基于Tukey在
fivenum
中的五位数总结。您可以查看
?boxplot.stats
,并了解更多信息。您可以通过range参数调整胡须。例如,将此设置为0将把胡须连接到最小值和最大值。
> quantile(a1,type=6)
    0%    25%    50%    75%   100% 
22.020 23.665 25.000 25.695 26.670 
> quantile(a2,type=6)
    0%    25%    50%    75%   100% 
21.490 22.615 23.790 24.540 25.000 
> quantile(a3,type=6)
   0%   25%   50%   75%  100% 
20.33 21.08 21.95 23.56 25.00