Learn R Programming

misty (version 0.4.5)

test.welch: Welch's Test

Description

This function performs Welch's two-sample t-test and Welch's ANOVA.

Usage

test.welch(formula, data, alternative = c("two.sided", "less", "greater"),
           conf.level = 0.95, hypo = TRUE, descript = TRUE, effsize = FALSE,
           weighted = FALSE, ref = NULL, correct = FALSE, digits = 2,
           p.digits = 4, as.na = NULL, check = TRUE, output = TRUE, ...)

Arguments

formula

a formula of the form y ~ group where y is a numeric variable giving the data values and group a numeric variable, character variable or factor with two or more than two values or factor levels giving the corresponding groups.

data

a matrix or data frame containing the variables in the formula formula.

alternative

a character string specifying the alternative hypothesis, must be one of code"two.sided" (default), "greater" or "less". Note that this argument is only used when conducting Welch's two-sample t-test.

conf.level

a numeric value between 0 and 1 indicating the confidence level of the interval for Cohen's d. Note that this argument is only used when conducting Welch's two-sample t-test.

hypo

logical: if TRUE, null and alternative hypothesis are shown on the console.

descript

logical: if TRUE, descriptive statistics are shown on the console.

effsize

logical: if TRUE, effect size measure Cohen's d for Welch's two-sample t-test (see cohens.d), \(\eta^2\) and \(\omega^2\) for Welch's ANOVA are shown on the console.

weighted

logical: if TRUE, the weighted pooled standard deviation is used to compute Cohen's d.

ref

a numeric value or character string indicating the reference group. The standard deviation of the reference group is used to standardized the mean difference to compute Cohen's d.

correct

logical: if TRUE, correction factor to remove positive bias in small samples is used.

digits

an integer value indicating the number of decimal places to be used for displaying descriptive statistics and confidence interval.

p.digits

an integer value indicating the number of decimal places to be used for displaying the p-value.

as.na

a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis.

check

logical: if TRUE, argument specification is checked.

output

logical: if TRUE, output is shown on the console.

...

further arguments to be passed to or from methods.

Value

Returns an object of class misty.object, which is a list with following entries: function call (call), type of analysis type, list with the input specified in x (data), specification of function arguments (args), and result table(s) (result).

Details

Note that by default Welch's two-sample t-test reports Cohen's d based on the unweighted standard deviation (i.e., weighted = FALSE) when requesting an effect size measure (i.e., effsize = TRUE) following the recommendation by Delacre et al. (2021).

References

Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.

Delacre, M., Lakens, D., Ley, C., Liu, L., & Leys, C. (2021). Why Hedges' g*s based on the non-pooled standard deviation should be reported with Welch's t-test. https://doi.org/10.31234/osf.io/tu6mp

See Also

test.t, test.z, test.levene, cohens.d, ci.mean.diff, ci.mean

Examples

Run this code
# NOT RUN {
dat1 <- data.frame(group1 = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
                   group2 = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3),
                   x = c(3, 1, 4, 2, 5, 3, 2, 3, 6, 6, 3, NA))

#--------------------------------------
# Two-Sample Design

# Two-sided two-sample Welch-test
test.welch(x ~ group1, data = dat1)

# One-sided two-sample Welch-test
test.welch(x ~ group1, data = dat1, alternative = "greater")

# Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD
test.welch(x ~ group1, data = dat1, effsize = TRUE)

# Two-sided two-sample Welch-test
# print Cohen's d with unweighted pooled SD
test.welch(x ~ group1, data = dat1, effsize = TRUE, weighted = FALSE)

# Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD and
# small sample correction factor
test.welch(x ~ group1, data = dat1, effsize = TRUE, correct = TRUE)

# Two-sided two-sample Welch-test
# print Cohen's d with SD of the reference group 1
test.welch(x ~ group1, data = dat1, effsize = TRUE,
           ref = 1)

# Two-sided two-sample Welch-test
# print Cohen's d with weighted pooled SD and
# small sample correction factor
test.welch(x ~ group1, data = dat1, effsize = TRUE,
           correct = TRUE)

# Two-sided two-sample Welch-test
# do not print hypotheses and descriptive statistics,
test.welch(x ~ group1, data = dat1, descript = FALSE, hypo = FALSE)

# Two-sided two-sample Welch-test
# print descriptive statistics with 3 digits and p-value with 5 digits
test.welch(x ~ group1, data = dat1, digits = 3, p.digits = 5)

#--------------------------------------
# Multiple-Sample Design

# Welch's ANOVA
test.welch(x ~ group2, data = dat1)

# Welch's ANOVA
# print eta-squared and omega-squared
test.welch(x ~ group2, data = dat1, effsize = TRUE)

# Welch's ANOVA
# do not print hypotheses and descriptive statistics,
test.welch(x ~ group2, data = dat1, descript = FALSE, hypo = FALSE)
# }

Run the code above in your browser using DataLab