multi_t_test | R Documentation |
This function performs t-tests comparing multiple groups against a reference group using summary statistics. It offers flexibility in the method for calculating degrees of freedom, can estimate sample sizes if they are not provided, and can adjust p-values for multiple comparisons.
multi_t_test(
means,
ses,
reference_index,
n = NULL,
alpha = 0.05,
df_method = "estimated",
alternative = "two.sided",
adjust_method = NULL
)
means |
Numeric vector of group means. |
ses |
Numeric vector of standard errors for each group. |
reference_index |
Integer indicating the index of the reference group. |
n |
Optional numeric vector of sample sizes for each group. |
alpha |
Numeric value for significance level (default is |
df_method |
String specifying the method for calculating degrees of freedom. Options are:
Default is |
alternative |
String specifying the alternative hypothesis: |
adjust_method |
String specifying the method of adjustment for multiple
comparisons: |
This function conducts t-tests to compare multiple groups against a reference group.
The estimated
degrees of freedom method (Welch's t-test) is generally
preferred and is set as the default. However, when sample sizes (n
) are
less than 30, results can be unreliable. When n
is not specified and
df_method = "estimated"
, the function estimates sample sizes based partly
on the distribution of mean values. The quality of these estimates depends on
the number of groups (length of the means argument). While the function can
estimate sample sizes if not provided, it's always preferable to use actual
sample sizes when available to ensure more accurate results.
A data.table containing comparison results with the following columns:
comparison |
String describing the comparison |
diff_means |
Numeric difference in means |
ci_lower |
Numeric lower bound of the confidence interval |
ci_upper |
Numeric upper bound of the confidence interval |
p.value |
Numeric p-value |
significant |
Logical indicating if the result is significant (TRUE if p-value < alpha, FALSE otherwise) |
t.statistic |
Numeric t-statistic |
df |
Numeric degrees of freedom |
df_method |
String indicating the method used for calculating degrees of freedom |
adjust_method |
String indicating the method used for multiple
comparisons p.value adjustment (when |
This function assumes unequal variances, which is typically more appropriate
for comparisons across demographic groups in vital statistics, survey data, and
other population-based studies. Equal variances are rarely encountered in such
contexts due to inherent differences between subpopulations. If you have the
underlying raw data (not just the means and standard errors) and want to
perform calculations assuming equal variances or a paired t-test, please
refer to t.test
in the stats
package.
# Example 1: Comparing birthweights across different maternal age groups
age_groups <- c("18-24", "25-29", "30-34", "35-39", "40+")
birthweight_means <- c(3150, 3450, 3400, 3250, 3100) # in grams
birthweight_ses <- c(50, 45, 40, 55, 60)
sample_sizes <- c(500, 800, 750, 400, 200)
reference_group <- 3 # comparing all groups to the 30-34 age group
birthweight_comparison <- multi_t_test(
means = birthweight_means,
ses = birthweight_ses,
reference_index = reference_group,
n = sample_sizes,
df_method = "estimated"
)
# Add age group labels to the results
birthweight_comparison[, Age_Group := age_groups]
print(birthweight_comparison)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.