control_for_map: Control for confounding variables via a function.

View source: R/control_for_map.R

control_for_mapR Documentation

Control for confounding variables via a function.

Description

Some variables (e.g. similarity measures) are hard to control for with control_for as they need to be recalculated for each word relative to each other, rather than there being a single value for each possible stimulus. The control_for_map function declares a function that the generate function should apply to each match_null within an iteration of stimulus generation. The function given as fun should be able to take the data in the column given in var as the first argument, and should be able to take the match_null's value in that column as the second argument.

Usage

control_for_map(x, fun, var, tol = NA, name = NA, standard_eval = FALSE, ...)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by(), control_for(), etc..

fun

The function to use to calculate the control varibale. Should be an object of class "function".

var

The column to provide the value which will be the first argument of the function.

tol

The tolerance of the control. For numeric variables, this should be in the form lower:upper (e.g. -0.1:0.1 will control within +/- 0.1). For categorical variables, this can be kept as NA.

name

What the output column should be named. If NA (default), will automatically assign as sprintf("control_fun_%i", nr), where nr is the number of the control function.

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R objects in var and tol. If TRUE, var should be a character vector referring to a column in df (e.g. "Zipf.SUBTLEX_UK"), and tol should be a vector of length 2, specifying the tolerance (e.g. c(-0.1, 0.5)). Default = FALSE.

...

Arguments to be passed to fun

Value

Returns df, with details on the variables to be controlled for added to the attributes. Run the generate function to then generate the actual stimuli.

Examples


# Create two levels of arousal, controlling for orthographic similarity
# (as optimal string alignment; default for `stringdist()`)
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, string, 0:4)

# Create two levels of arousal, controlling for orthographic Levenshtein distance
# (passed via `method` argument to `stringdist()`)
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, string, 0:4, method="lv")

# Create two levels of arousal, controlling for phonological Levenshtein distance
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, eSpeak.br_1letter, 0:2, method="lv")

# Bypass non-standard evaluation
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, "eSpeak.br_1letter", c(0, 2), standard_eval=TRUE, method="lv")


JackEdTaylor/LexOPS documentation built on July 10, 2024, 6:40 a.m.