Assumption checks for one-sample t-test
check_assumptions.RdCheck normality and outliers for a numeric sample, as typically required for a one-sample t-test on a population mean with unknown variance.
Value
A list of class "oneMeanTest_assumptions" with components:
- shapiro
List with W statistic, p-value,
alpha, and a logical flagnormalindicating if normality is acceptable (orNAif the test was not run).- outliers
Numeric vector of detected outliers (possibly empty).
- n
Sample size after removing NA values.
- normal
Logical flag indicating if normality is acceptable (
TRUE/FALSE), orFALSEif the Shapiro–Wilk test rejects at the chosenalpha.- message
Textual summary of the diagnostics.
Details
The function performs a Shapiro–Wilk normality test (when the sample size
is between 3 and 5000) and detects outliers using the 1.5*IQR rule. It is
used inside one_mean_test when check_assumptions = TRUE.
Examples
set.seed(123)
x <- rnorm(30, mean = 5, sd = 2)
# Verbose output
check_assumptions(x, alpha = 0.05, verbose = TRUE)
#> Normality appears acceptable based on the Shapiro-Wilk test. No outliers detected by the 1.5*IQR rule.
#> $shapiro
#> $shapiro$W
#> [1] 0.9789351
#>
#> $shapiro$p.value
#> [1] 0.7965839
#>
#> $shapiro$alpha
#> [1] 0.05
#>
#> $shapiro$normal
#> [1] TRUE
#>
#>
#> $outliers
#> numeric(0)
#>
#> $n
#> [1] 30
#>
#> $normal
#> [1] TRUE
#>
#> $message
#> [1] "Normality appears acceptable based on the Shapiro-Wilk test. No outliers detected by the 1.5*IQR rule."
#>
#> attr(,"class")
#> [1] "oneMeanTest_assumptions"
# Silent output (used internally by one_mean_test)
a_res <- check_assumptions(x, alpha = 0.05, verbose = FALSE)
a_res
#> $shapiro
#> $shapiro$W
#> [1] 0.9789351
#>
#> $shapiro$p.value
#> [1] 0.7965839
#>
#> $shapiro$alpha
#> [1] 0.05
#>
#> $shapiro$normal
#> [1] TRUE
#>
#>
#> $outliers
#> numeric(0)
#>
#> $n
#> [1] 30
#>
#> $normal
#> [1] TRUE
#>
#> $message
#> [1] "Normality appears acceptable based on the Shapiro-Wilk test. No outliers detected by the 1.5*IQR rule."
#>
#> attr(,"class")
#> [1] "oneMeanTest_assumptions"