poly_contrast | R Documentation |
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).
poly_contrast(A, name, where = NULL, degree = 1, value_map = NULL)
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. |
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.
A poly_contrast_spec object containing the specification for generating polynomial contrast weights.
oneway_contrast
for categorical contrasts,
interaction_contrast
for interaction effects
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.