Learn R Programming

JSmediation (version 0.2.3)

build_contrast: 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)

Value

A numeric vector.

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.

See Also

scale for centering continuous numeric variable.

Examples

Run this code
  data(ho_et_al)

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

 head(ho_et_al)

Run the code above in your browser using DataLab