Skip to contents

This function conducts a trend analysis by applying contrast tests to a given dataset.

Usage

trend_test(
  dat,
  order = 1:3,
  paired = FALSE,
  alternative = c("two.sided", "less", "greater"),
  conf.level = 0.95,
  verbose = TRUE
)

Arguments

dat

A data frame or matrix containing the data. Columns represent different levels of the independent variable.

order

An integer vector specifying the trend orders to test. Defaults to 1:3.

paired

Logical. If TRUE, a paired contrast test is performed. Defaults to FALSE.

alternative

A character string specifying the alternative hypothesis. One of "two.sided", "less", or "greater". Defaults to "two.sided".

conf.level

Confidence level for the test. Defaults to 0.95.

verbose

Logical. If TRUE, displays messages. Defaults to TRUE.

Value

A data frame containing the results of the contrast tests, with an additional column indicating the trend order.

Details

The function constructs contrast vectors for specified trend orders using polynomial contrasts (contr.poly). Then, contrast_test() is applied to test each contrast. For more details on the testing procedure, refer to the documentation of contrast_test().

See also

contrast_test() for details on the contrast testing procedure.

Examples

# Example dataset with 5 conditions
dat <- matrix(rnorm(50), nrow = 10, ncol = 5)

# Perform trend analysis for 1st and 2nd order trends
trend_test(dat, order = 1:2)
#>   order      weights   estimate     lower    upper          t          F
#> 1     1  -2,-1,0,1,2  0.2002632 -1.840372 2.240898  0.1976595 0.03906927
#> 2     2 2,-1,-2,-1,2 -1.2297319 -3.644244 1.184780 -1.0258004 1.05226647
#>   df_error SS_contrast SS_error SS_total SS_effect         p         eta2
#> 1       45  0.04010537 46.19337  47.9603  1.766928 0.8442017 0.0008362201
#> 2       45  1.08017188 46.19337  47.9603  1.766928 0.3104684 0.0225222092
#>         peta2   cohens_f n_total n_total_na
#> 1 0.000867453 0.02946534      50          0
#> 2 0.022849396 0.15291730      50          0