poly_contrast: Polynomial Contrast

View source: R/contrast.R

poly_contrastR Documentation

Polynomial Contrast

Description

Create polynomial contrasts for testing trends across ordered factor levels. This is particularly useful for analyzing factors with a natural ordering (e.g., time, dose).

Usage

poly_contrast(A, name, where = NULL, degree = 1, value_map = NULL)

Arguments

A

A formula specifying the ordered factor.

name

A character string identifying the contrast.

where

An optional formula for subsetting the data.

degree

An integer specifying the degree of the polynomial (default: 1).

value_map

An optional list mapping factor levels to numeric values.

Details

The function creates orthogonal polynomial contrasts up to the specified degree. These contrasts can test for linear, quadratic, cubic, and higher-order trends in the data. The value_map parameter allows for non-uniform spacing between levels.

Value

A poly_contrast_spec object containing the specification for generating polynomial contrast weights.

See Also

oneway_contrast for categorical contrasts, interaction_contrast for interaction effects

Examples

# Linear trend across time points
pcon <- poly_contrast(~ time, name = "linear_time", degree = 1)

# Cubic trend with custom spacing
pcon <- poly_contrast(~ dose, name = "dose_cubic",
                     degree = 3,
                     value_map = list("low" = 0, "med" = 2, "high" = 5))


bbuchsbaum/fmrireg documentation built on March 1, 2025, 11:20 a.m.