Significant differences for Means

Hi,
I am trying to find something which is very common in other statistical packages like SPSS.
I trying to highlight all means scores in one subgroup which are significantly different to another subgroup.
I have this simple df:

source <- data.frame(
  stringsAsFactors = FALSE,
                     URN = c("bbb","ccc","hhh",
                             "aaa","ddd","eee","fff","ggg","iii"),
                    QF16 = c("No","No","No",
                             "No","Yes","Yes","Yes","Yes","Yes"),
         QF70_Top2 = c(50, 50, 0, 100, 0, 100, 100, 100, 100),
          Q12_Top2 = c(0, 0, 0, NA, 100, 100, 0, 100, NA),
          QF2_Top2 = c(0, 0, 0, 100, 100, 0, 100, 100, 100),
               QF4 = c(100, 100, 0, 100, 100, 100, 100, 100, 100)
      )

source

and I need output similar to this:
image
image

In the above you have a table with means of all questions including (Top2).
The second table in empty but if Average of QF70_Top2 for QF16=Yes was significantly higher than Average of QF70_Top2 for QF16=No that I would see A in the first row of the second column like this example based on a different data:
image
image

In the example above, value 1 (B) in question QG1 is significantly higher than value 0 (A) and value 2 (C).

Is it possible to do something like this in R (for variables containing Top2 in their name)?

suppressPackageStartupMessages({
  library(magrittr)
})

iris1 <- iris %>% filter(Species != "virginica")
iris2 <- iris %>% filter(Species != "versicolor")
iris3 <- iris %>% filter(Species != "setosa")

s_ver <- t.test(Sepal.Width ~ Species, paired = TRUE, data = iris1)
s_vir <- t.test(Sepal.Width ~ Species, paired = TRUE, data = iris2)
ver_vir <- t.test(Sepal.Width ~ Species, paired = TRUE, data = iris3)

s_ver
#> 
#>  Paired t-test
#> 
#> data:  Sepal.Width by Species
#> t = 8.8506, df = 49, p-value = 9.857e-12
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  0.508597 0.807403
#> sample estimates:
#> mean of the differences 
#>                   0.658

s_vir
#> 
#>  Paired t-test
#> 
#> data:  Sepal.Width by Species
#> t = 6.4698, df = 49, p-value = 4.399e-08
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  0.3129833 0.5950167
#> sample estimates:
#> mean of the differences 
#>                   0.454

ver_vir
#> 
#>  Paired t-test
#> 
#> data:  Sepal.Width by Species
#> t = -3.0755, df = 49, p-value = 0.003432
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  -0.33729519 -0.07070481
#> sample estimates:
#> mean of the differences 
#>                  -0.204

Hi,
Thank you but I have many variables to be tested at the same time so I'm wondering if a tabular (rather than descriptive) solution is possible.
As you can see above, SPSS (and I think other solutions) offer this simple table where you can calculate means and check the differences at the same time in a simple form.
I don't think we can do it in R but I still believe in its power and flexibility!

I misapprehended the question as related to calculation, rather than presentation. All the pieces are there—some assembly required. For that there's {infer} for plotting two-way t.tests and {broom} for tables.

Thank you.
I think this is too complicated and perhaps this is a good place for a new Package!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.