build_contrast: Builds a contrast code from character vector

View source: R/build_contrast.R

build_contrastR Documentation

Builds a contrast code from character vector

Description

This function constructs a contrast code from a character variable. It is useful when one needs to recode a two-category character variable to a numeric one.

Usage

build_contrast(vector, cond_a, cond_b)

Arguments

vector

A character vector.

cond_a

A character string to be coded -0.5.

cond_b

A character string to be coded 0.5.

Details

The lm method supports factor and character variables by dummy coding them. Dummy coding can make the interpretation of regression coefficient difficult or at least more difficult than contrast coding. Contrast-coded-variable coefficients interpretation is particularly useful when conducting a joint-significance test.

Value

A numeric vector.

See Also

scale for centering continuous numeric variable.

Examples

  data(ho_et_al)

  ho_et_al$condition_contrast <- build_contrast(ho_et_al$condition,
                                                "Low discrimination",
                                                "High discrimination")

 head(ho_et_al)


cedricbatailler/JSmediation documentation built on March 4, 2024, 12:52 p.m.