简体   繁体   English

如何为 R 中的这些最小显着差异 (LSD) 结果创建字母摘要?

[英]How can I create a letter summary for these Least Significant Difference (LSD) results in R?

I am trying to compare the tensile strength of different material weights of material in R. The tensile data is as follows:我试图比较R中不同材料重量的材料的拉伸强度。拉伸数据如下:

tensile <- read.table(text="   Weight Strength Replicate
1      15        7         1
2      15        7         2
3      15       15         3
4      15       11         4
5      15        9         5
6      20       12         1
7      20       17         2
8      20       12         3
9      20       18         4
10     20       18         5
11     25       14         1
12     25       18         2
13     25       18         3
14     25       19         4
15     25       19         5
16     30       19         1
17     30       25         2
18     30       22         3
19     30       19         4
20     30       23         5
21     35        7         1
22     35       10         2
23     35       11         3
24     35       15         4
25     35       11         5", header=TRUE)

The variable Weight should be regarded as a factor (explanatory/independent variable) for the purpose of this analysis:出于此分析的目的,变量Weight应被视为一个因素(解释性/自变量):

tensile$Weight <- factor(tensile$Weight)

I first fitted a one-way ANOVA model to my data:我首先为我的数据拟合了一个单向方差分析模型:

tensile.aov <- aov(Strength ~ Weight, data = tensile)

According to the ANOVA, there appears to be a difference in the different weights with respect to the response (strength).根据方差分析,不同权重在响应(强度)方面似乎存在差异。 So I then decided to do pairwise comparisons using the LSD (Least Significant Difference):因此,我决定使用 LSD(最小显着差异)进行成对比较:

LSD.aov(tensile.aov)

However, this LSD function was provided through a separate file, so I'm unfortunately unable to share the code here.然而,这个 LSD 函数是通过一个单独的文件提供的,所以很遗憾我无法在这里分享代码。

I calculated the LSD for my data and got the following table:我计算了我的数据的 LSD 并得到下表:

在此处输入图片说明

Note that, according to the raw p-values, the pairwise comparisons between the 35 and 15 and 25 and 20 weights are the only ones that are not significantly different from each other at the alpha = 0.05 significance level;请注意,根据原始 p 值,35 和 15 以及 25 和 20 权重之间的成对比较是唯一在 alpha = 0.05 显着性水平上彼此没有显着差异的比较; the other pairwise comparisons are significantly different.其他成对比较有显着差异。 I want to create a letter summary to illustrate this, where groups only have the same letter if they are not significantly different from each other, and groups which do not have the same letter are significantly different from each other:我想创建一个字母摘要来说明这一点,如果组之间没有显着差异,则组只有相同的字母,没有相同字母的组彼此之间有显着差异:

在此处输入图片说明

How can I go about creating such a table in R?我怎样才能在 R 中创建这样的表?

I'm also totally open to a 'manual' solution.我也完全接受“手动”解决方案。 By this, I mean manually creating a table using vectors and such.我的意思是使用向量等手动创建表格。 I'm new to R, so I don't have a good grasp on even the most basic aspects.我是 R 的新手,所以即使是最基本的方面我也没有很好的掌握。

The multcompView package can turn p-values into letters, but in this case, the emmeans package can do both the comparison and the letters. multcompView包可以将 p 值转换为字母,但在这种情况下, emmeans包可以同时进行比较和字母。

library(emmeans)
em <- emmeans(tensile.aov, ~Weight)

summary(pairs(em, adjust="none"), infer=TRUE)
#>  contrast estimate      SE df    lower.CL   upper.CL t.ratio p.value
#>  15 - 20      -5.6 1.79555 20  -9.3454518 -1.8545482  -3.119  0.0054
#>  15 - 25      -7.8 1.79555 20 -11.5454518 -4.0545482  -4.344  0.0003
#>  15 - 30     -11.8 1.79555 20 -15.5454518 -8.0545482  -6.572  <.0001
#>  15 - 35      -1.0 1.79555 20  -4.7454518  2.7454518  -0.557  0.5838
#>  20 - 25      -2.2 1.79555 20  -5.9454518  1.5454518  -1.225  0.2347
#>  20 - 30      -6.2 1.79555 20  -9.9454518 -2.4545482  -3.453  0.0025
#>  20 - 35       4.6 1.79555 20   0.8545482  8.3454518   2.562  0.0186
#>  25 - 30      -4.0 1.79555 20  -7.7454518 -0.2545482  -2.228  0.0375
#>  25 - 35       6.8 1.79555 20   3.0545482 10.5454518   3.787  0.0012
#>  30 - 35      10.8 1.79555 20   7.0545482 14.5454518   6.015  <.0001
#>
#> Confidence level used: 0.95

cld(em, adjust="none")
#>  Weight emmean       SE df  lower.CL upper.CL .group
#>  15        9.8 1.269646 20  7.151566 12.44843  1    
#>  35       10.8 1.269646 20  8.151566 13.44843  1    
#>  20       15.4 1.269646 20 12.751566 18.04843   2   
#>  25       17.6 1.269646 20 14.951566 20.24843   2   
#>  30       21.6 1.269646 20 18.951566 24.24843    3  
#> 
#> Confidence level used: 0.95 
#> significance level used: alpha = 0.05

I managed to do it as follows:我设法做到了如下:

Weight = c(15, 20, 25, 30, 35)
mean = c(9.8, 15.4, 17.6, 21.6, 10.8)
letters = c("a", "b", "b", "", "a")
LSDletterSummary <- data.frame(Weight, mean, letters)
LSDletterSummary

If anyone has a better way to go about it, feel free to share.如果有人有更好的方法来解决它,请随时分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM