score_by | R Documentation |
Score stereotypes by moderator
score_by(
x,
moderator,
extrapolate_to = "minmax",
method = lm,
drop_unused_levels = T,
long_format = F
)
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. |
A dataframe with expected value by moderator levels or values sought.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.