I'm interested in how results may differ when means are compared by using a two sample t-test as opposed to a one sample t-test from the same data. Two assessments where "counts" are sampled randomly from across multiple populations ("Group_ID") using two different techniques ("source") are compared. A result of p>0.05 indicates that the means are not statistically different (i.e. both assessment techniques give similar results). Raw data for source=A is reliable and always available. Raw data for source=B may not be available but a mean will always be provided. Using a test data set I want to examine how the t.test outcomes differ by using the one sample t.test as opposed to the two sample t.test.
Using dplyr and broom functions I have determined how to do multiple two-sample t-tests across a number of cases ("Group_ID") where the two assessments were conducted. Data from two sources is merged to create a three column data frame containing raw counts ("count") identified by one of two sources ("source").
glimpse(Data)
Observations: 2,552
Variables: 3
$ Group_ID <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
$ count <dbl> 7, 8, 5, 5, 7, 3, 4, 2, 8, 11, 12, 1, 3, 5, 5, 12, 1, 5...
$ source <chr> "B", "B", "B", "B", "B", "B", "B", "B",...
The two-sample test compares the means from both sources and considers variation in both data sets using the following:
Data_Stats <- Data %>%
group_by(Group_ID) %>%
do(tidy(t.test(count ~ source, alt="two.sided", conf=0.95, var.eq=FALSE, paired=FALSE, data = .)))
Results in
Observations: 38
Variables: 11
Groups: Group_ID [38]
$ Group_ID <fct> 1, 1029, 1032, 1033, 1041, 1044, 1064, 1065, 1067, 1080, 1081, 1083, 1084, 117, 127, 180, 2...
$ estimate <dbl> -0.4250000, -6.5000000, -1.1944444, 0.3437500, -5.2250000, -1.4375000, -1.6250000, -1.48387...
$ estimate1 <dbl> 5.250000, 9.166667, 5.833333, 6.156250, 5.375000, 3.937500, 2.075000, 6.000000, 4.108108, 9...
$ estimate2 <dbl> 5.675000, 15.666667, 7.027778, 5.812500, 10.600000, 5.375000, 3.700000, 7.483871, 6.540541,...
$ statistic <dbl> -0.42469044, -3.42643903, -1.19922603, 0.32509809, -3.36599817, -1.94947775, -2.47005992, -...
$ p.value <dbl> 6.723526e-01, 1.480949e-03, 2.355386e-01, 7.463614e-01, 1.509467e-03, 5.649284e-02, 1.57612...
$ parameter <dbl> 70.66653, 38.05593, 55.46167, 54.07284, 47.94418, 53.45682, 75.67387, 44.38453, 49.87894, 6...
$ conf.low <dbl> -2.420560, -10.340117, -3.190125, -1.776090, -8.346179, -2.916196, -2.935370, -3.969856, -5...
$ conf.high <dbl> 1.570559944, -2.659882919, 0.801236360, 2.463590202, -2.103821060, 0.041195928, -0.31462953...
$ method <chr> "Welch Two Sample t-test", "Welch Two Sample t-test", "Welch Two Sample t-test", "Welch Two...
$ alternative <chr> "two.sided", "two.sided", "two.sided", "two.sided", "two.sided", "two.sided", "two.sided", ...
I know I can get means for each case using:
Data_means <- Data %>%
group_by(Group_ID) %>%
summarize(count_mean = mean(count))
I'm looking for a suggestion for how best to use the mean for each Group_ID from source=2 as the value for the "mu= " call in the t.test function to compare to the mean of source=1 using a one-sample t-test for each of 38 different Group_IDs?