Making expression containing t-test results

expr_t_parametric(
  data,
  x,
  y,
  subject.id = NULL,
  paired = FALSE,
  k = 2L,
  conf.level = 0.95,
  effsize.type = "g",
  var.equal = FALSE,
  output = "expression",
  ...
)

Arguments

data

A dataframe (or a tibble) from which variables specified are to be taken. A matrix or tables will not be accepted.

x

The grouping variable from the dataframe data.

y

The response (a.k.a. outcome or dependent) variable from the dataframe data.

subject.id

In case of repeated measures design (paired = TRUE, i.e.), this argument specifies the subject or repeated measures id. Note that if this argument is NULL (which is the default), the function assumes that the data has already been sorted by such an id by the user and creates an internal identifier. So if your data is not sorted and you leave this argument unspecified, the results can be inaccurate.

paired

Logical that decides whether the experimental design is repeated measures/within-subjects or between-subjects. The default is FALSE.

k

Number of digits after decimal point (should be an integer) (Default: k = 2L).

conf.level

Scalar between 0 and 1. If unspecified, the defaults return 95% lower and upper confidence intervals (0.95).

effsize.type

Type of effect size needed for parametric tests. The argument can be "d" (for Cohen's d) or "g" (for Hedge's g).

var.equal

a logical variable indicating whether to treat the variances in the samples as equal. If TRUE, then a simple F test for the equality of means in a one-way analysis of variance is performed. If FALSE, an approximate method of Welch (1951) is used, which generalizes the commonly known 2-sample Welch test to the case of arbitrarily many samples.

output

If "expression", will return expression with statistical details, while "dataframe" will return a dataframe containing the results.

...

Additional arguments (currently ignored).

Value

Expression containing details from results of a two-sample test and effect size plus confidence intervals.

Details

Cohen's d is calculated in the traditional fashion as the difference between means or mean minus mu divided by the estimated standardized deviation. By default Hedge's correction is applied (N-3)/(N-2.25) to produce g. For independent samples t-test, there are two possibilities implemented. If the t-test did not make a homogeneity of variance assumption, (the Welch test), the variance term will mirror the Welch test, otherwise a pooled and weighted estimate is used. If a paired samples t-test was requested, then effect size desired is based on the standard deviation of the differences.

The computation of the confidence intervals defaults to a use of non-central Student-t distributions.

When computing confidence intervals the variance of the effect size d or g is computed using the conversion formula reported in Cooper et al. (2009)

References

For more details, see- https://indrajeetpatil.github.io/statsExpressions/articles/stats_details.html

Examples

# for reproducibility set.seed(123) library(statsExpressions) # creating a smaller dataset msleep_short <- dplyr::filter(ggplot2::msleep, vore %in% c("carni", "herbi")) # with defaults expr_t_parametric( data = msleep_short, x = vore, y = sleep_rem )
#> paste(italic("t")["Welch"], "(", "10.89", ") = ", "1.49", ", ", #> italic("p"), " = ", "0.164", ", ", widehat(italic("g"))["Hedge"], #> " = ", "0.61", ", CI"["95%"], " [", "-0.19", ", ", "1.28", #> "]", ", ", italic("n")["obs"], " = ", 34L)
# changing defaults (getting expression as output) expr_t_parametric( data = msleep_short, x = vore, y = sleep_rem, var.equal = TRUE, effsize.type = "d" )
#> paste(italic("t")["Student"], "(", "32", ") = ", "1.95", ", ", #> italic("p"), " = ", "0.060", ", ", widehat(italic("d"))["Cohen"], #> " = ", "0.73", ", CI"["95%"], " [", "-0.03", ", ", "1.49", #> "]", ", ", italic("n")["obs"], " = ", 34L)