Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Un-paired t-test using data within one column

$
0
0

I want to do an unpaired t-test to examine if values differ between sites in each type category.

So my question is, within types (AB or CD), do values (valueA or valueB) differ between sites (A or B)?

Here is an example of my data:

dat <- data.frame(
  "site" = c("A","B","B","A","A","B","B","A"), 
  "type" = c("AB","CD"), 
  "valueA" = c(13,-10,-5,18,-14,12,-17,19), 
  "valueB" = c(-3,20,15,-16,12,15,-11,14)
)
dat

site type valueA valueB
A   AB     13     -3
B   CD    -10     20
B   AB     -5     15
A   CD     18    -16
A   AB    -14     12
B   CD     12     15
B   AB    -17    -11
A   CD     19     14

I am trying to do four unpaired t-tests to examine:

  1. If valueA Type AB, differs between site A vs. site B
  2. If valueB Type AB, differs between site A vs. site B
  3. If valueA Type CD, differs between site A vs. site B
  4. If valueB Type CD, differs between site A vs. site B

In order to run the unpaired t-test, I believe I need to re-arrange my data so that type AB and type CB and site A and site B are each a column (instead of being within the type or site column).

EDIT:

Using the suggested code in the comments:

library(dplyr)
d %>% 
  group_by(site, type) %>% 
  summarise(pval = t.test(valueA, valueB)$p.value)

The output is this:

site  type   pval
A     AB    0.784
A     CD    0.417
B     AB    0.492
B     CD    0.365

To my understanding, this p-value here is giving me the difference between valueA and valueB.

I am looking for, for example: The difference between site A and site B of valueA in type CD.

So if I am thinking correctly, the output of the t-test should have a column for type, value A and value B. Then the p-values are for the differences between sites.

Similar to this:

type  valueA  valueB
AB     0.365   0.784
CD     0.492   0.417

Does this make sense?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>