Construct a sum-to-zero contrast between two logical expressions. This function is particularly useful for comparing specific conditions or combinations of conditions.
Arguments
- A
A formula representing the first logical expression in the contrast.
- B
A formula representing the second logical expression in the contrast.
- name
A character string specifying the name of the contrast (mandatory).
- where
An optional formula specifying the subset over which the contrast is computed.
Value
A pair_contrast_spec object containing:
- A
First logical expression
- B
Second logical expression
- where
Subsetting formula (if provided)
- name
Contrast name
Details
The contrast is constructed as (A - B), where A and B are logical expressions that evaluate to TRUE/FALSE for each observation. The resulting contrast weights sum to zero.
See also
pairwise_contrasts
for all pairwise comparisons,
contrast_set
for creating sets of contrasts
Examples
# Compare faces vs scenes
pair_contrast(~ category == "face", ~ category == "scene", name = "face_vs_scene")
#> contrast: face_vs_scene
#> A: ~category == "face"
#> B: ~category == "scene"
# Compare with subsetting
pair_contrast(~ category == "face", ~ category == "scene",
name = "face_vs_scene_block1",
where = ~ block == 1)
#> contrast: face_vs_scene_block1
#> A: ~category == "face"
#> B: ~category == "scene"
#> where: ~block == 1
# Complex logical expressions
pair_contrast(~ stimulus == "face" & emotion == "happy",
~ stimulus == "face" & emotion == "sad",
name = "happy_vs_sad_faces")
#> contrast: happy_vs_sad_faces
#> A: ~stimulus == "face" & emotion == "happy"
#> B: ~stimulus == "face" & emotion == "sad"