I have a panel data set and want to create a matrix similar to a correlation matrix but only with the differences of the t-test estimates as well as the t-statistic.
Using the toothgrowth data, I first subgroup supp ids according to their dose values and I want to calculate the t-statistics for all possible combination between the sub groups.
I want my t-test matrix to look as follows
VC_all VC_0.5 VC_1 VC_all VC_0.5 VC_1 OJ_all OJ_0.5 OJ_1
VC_all -4 ( -1.92 )
VC_0.5
VC_1
VC_all
VC_0.5
VC_1
OJ_all
OJ_0.5
OJ_1
as an example I filled one value with the following formula
t_test <- t.test(x = filter(ToothGrowth, supp== "VC")$len,
y = filter(ToothGrowth, supp== "OJ")$len, var.equal = TRUE)
Is there a faster way to this but calculate all t-stats for every single grouping?
df["VC_all","OJ_all"] <- paste(round(t_test$estimate[1] - t_test$estimate[2]),
"(", round(t_test$statistic,2), ")")