score_by: Score stereotypes by moderator

View source: R/stereotypes.R

score_byR Documentation

Score stereotypes by moderator

Description

Score stereotypes by moderator

Usage

score_by(
  x,
  moderator,
  extrapolate_to = "minmax",
  method = lm,
  drop_unused_levels = T,
  long_format = F
)

Arguments

x

Data to score (numerical)

moderator

A moderator variable (vector input, same length as x rows)

extrapolate_to

Values to extrapolate to if using a numerical moderator. Default is minimum and maximum values of observed moderator values.

method

Which method to use for numerical extrapolation. Default is a linear model, but could be e.g. loess.

drop_unused_levels

Whether to drop unused factor levels if categorical moderator (default is to drop them)

long_format

Transposes the data so that each column has a set of estimates instead of each row.

Value

A dataframe with expected value by moderator levels or values sought.

Examples

test_data = tibble(
a = c(1:4),
b = c(5:8)
)

#chr moderator
score_by(test_data, moderator = c("m", "m", "f", "f"))
#specified levels and thus order
score_by(test_data, moderator = c("m", "m", "f", "f") %>% factor(levels = c("m", "f")))
#numerical moderator
score_by(test_data, moderator = seq(0, 1, length.out = 4))
#long format
score_by(test_data, moderator = c("m", "m", "f", "f"), long_format = T)
score_by(test_data, moderator = seq(0, 1, length.out = 4), long_format = T)

Deleetdk/kirkegaard documentation built on May 8, 2024, 12:27 a.m.