@@ -211,8 +211,8 @@ test_that("tidy model type returns the expected column set", {
211211 expected_cols <- c(
212212 " Number of Rows" , " Mean" , " Std Deviation" , " Std Error" ,
213213 " Hypothesized Mean" , " Difference" , " t Value" , " DF" , " P Value" ,
214- " Conf Low" , " Conf High" , " Cohen's d " , " Power " ,
215- " Test Direction" , " Result"
214+ " Conf Low" , " Conf High" , " Diff Conf Low " , " Diff Conf High " ,
215+ " Cohen's d " , " Power " , " Test Direction" , " Result"
216216 )
217217 for (col in expected_cols ) {
218218 expect_true(col %in% names(tidied ), info = paste(" Missing column:" , col ))
@@ -237,6 +237,8 @@ test_that("tidy model values are numerically correct", {
237237 expect_equal(tidied $ `P Value` , expected $ p.value )
238238 expect_equal(tidied $ `Conf Low` , expected $ conf.int [1 ])
239239 expect_equal(tidied $ `Conf High` , expected $ conf.int [2 ])
240+ expect_equal(tidied $ `Diff Conf Low` , expected $ conf.int [1 ] - 4.5 )
241+ expect_equal(tidied $ `Diff Conf High` , expected $ conf.int [2 ] - 4.5 )
240242})
241243
242244test_that(" tidy model Test Direction maps correctly from alternative" , {
@@ -412,6 +414,58 @@ test_that("tidy prob_dist_mean no-ops (0-row tibble) when stderr is degenerate",
412414 expect_equal(nrow(pd ), 0 )
413415})
414416
417+ # --- tidy(type = "data_summary") ---
418+
419+ test_that(" tidy data_summary type returns summary statistics with confidence intervals" , {
420+ set.seed(42 )
421+ vec <- rnorm(50 , mean = 5 , sd = 2 )
422+ df <- data.frame (x = vec )
423+ model <- exp_one_sample_t_test(df , x , mu = 4.5 )$ model [[1 ]]
424+ result <- tidy(model , type = " data_summary" , conf_level = 0.95 )
425+
426+ expected_cols <- c(" Rows" , " Mean" , " Conf Low" , " Conf High" ,
427+ " Std Error of Mean" , " Std Deviation" , " Minimum" , " Maximum" )
428+ expect_true(all(expected_cols %in% names(result )))
429+ expect_equal(nrow(result ), 1 )
430+
431+ n <- length(vec )
432+ conf_threshold <- 1 - (1 - 0.95 ) / 2
433+ expected_se <- sd(vec ) / sqrt(n )
434+ expect_equal(result $ Rows , n )
435+ expect_equal(result $ Mean , mean(vec ))
436+ expect_equal(result $ `Std Deviation` , sd(vec ))
437+ expect_equal(result $ `Std Error of Mean` , expected_se )
438+ expect_equal(result $ `Conf Low` , mean(vec ) - expected_se * qt(p = conf_threshold , df = n - 1 ))
439+ expect_equal(result $ `Conf High` , mean(vec ) + expected_se * qt(p = conf_threshold , df = n - 1 ))
440+ expect_equal(result $ Minimum , min(vec ))
441+ expect_equal(result $ Maximum , max(vec ))
442+ })
443+
444+ test_that(" tidy data_summary conf_level parameter changes confidence intervals" , {
445+ set.seed(42 )
446+ vec <- rnorm(50 , mean = 5 , sd = 2 )
447+ df <- data.frame (x = vec )
448+ model <- exp_one_sample_t_test(df , x , mu = 4.5 )$ model [[1 ]]
449+
450+ result_95 <- tidy(model , type = " data_summary" , conf_level = 0.95 )
451+ result_90 <- tidy(model , type = " data_summary" , conf_level = 0.90 )
452+
453+ expect_true(result_95 $ `Conf Low` < result_90 $ `Conf Low` )
454+ expect_true(result_95 $ `Conf High` > result_90 $ `Conf High` )
455+ })
456+
457+ test_that(" tidy_rowwise with type=data_summary works for one sample t-test" , {
458+ set.seed(42 )
459+ vec <- rnorm(50 , mean = 5 , sd = 2 )
460+ df <- data.frame (x = vec )
461+ result <- exp_one_sample_t_test(df , x , mu = 4.5 ) %> %
462+ tidy_rowwise(model , type = " data_summary" , conf_level = 0.95 )
463+
464+ expect_true(" Rows" %in% names(result ))
465+ expect_true(" Mean" %in% names(result ))
466+ expect_equal(result $ Rows , 50 )
467+ })
468+
415469# --- tidy(type = "data") ---
416470
417471test_that(" tidy data type returns the raw data with the target column" , {
0 commit comments