I'm trying to be efficient in calculating multiple t-tests using summary statistics, but am failing miserably. My ultimate objective is to run DescTools::TtestA() on each row of a data frame, and then extract key values from the output (p value, confidence interval) to make a pretty table. Right now, I'm just stuck on actually getting DescTools::TtestA() to run with pipes for a single row.
library(tidyverse)
library(DescTools)
df <- data.frame(Subscale = c("A","B"),
mean_a = c(4,5),
sd_a = c(1,2),
n_a = c(40,50),
mean_b = c(7,2),
sd_b = c(.5,1),
n_b = c(90,60))
# Below works
subset.df <- df %>%
filter(Subscale == "A")
TTestA(mx = subset.df$mean_a,
sx = subset.df$sd_a,
nx = subset.df$n_a,
my = subset.df$mean_b,
sy = subset.df$sd_b,
ny = subset.df$n_b,
alternative = "two.sided",
mu = 0)
# Below does not work
df %>%
filter(Subscale == "A") %>%
TTestA(mx = .$mean_a,
sx = .$sd_a,
nx = .$n_a,
my = .$mean_b,
sy = .$sd_b,
ny = .$n_b,
alternative = "two.sided",
mu = 0)