14 M

14.1 marginal effects

The difference in the response variable for a given change in one predictor variable, with all other covariates held constant.

Also called partial effects.

You can calculate marginal effects as an average (AME) over the values of other covariates, at the mean (MEM), where all other covariates are set to their mean values, or marginal effects at representative values (MER), where the other covariates are set to specific values you are interested in.

14.2 markdown

A way to specify formatting, such as headers, paragraphs, lists, bolding, and links.

See R Markdown for more infomation on the R-specific version.

14.3 mask

When two packages have functions with the same name, the function from the package loaded last is used as the default unless the package name is also specified.

See conflict.

14.4 match operator

A binary operator (%in%) that returns a logical vector indicating if there is a match or not for its left operand.

# check if a single value is in a vector
"West Dakota" %in% state.name
#> [1] FALSE
# check if each item in the lefthand vector is in the righthand vector
c("A", "B", "1") %in% LETTERS
#> [1]  TRUE  TRUE FALSE
pangram <- "the quick brown fox jumps over the lazy dog"
pangram_chars <- strsplit(pangram, "")[[1]]
letters %in% pangram_chars
#>  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [18] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

14.5 matrix

A container data type consisting of numbers arranged into a fixed number of rows and columns

You can use the matrix() function to set up a vector of numbers as a matrix with a specified number of rows of columns.

# a 4x4 matrix
matrix(data = 1:16, nrow = 4)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    5    9   13
#> [2,]    2    6   10   14
#> [3,]    3    7   11   15
#> [4,]    4    8   12   16

Set byrow = TRUE to assign the vector across rows rather than down columns.

matrix(data = 1:16, nrow = 4, byrow = TRUE)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    2    3    4
#> [2,]    5    6    7    8
#> [3,]    9   10   11   12
#> [4,]   13   14   15   16

14.6 mean

A descriptive statistic that measures the average value of a set of numbers.

x <- c(3,5,8,9,11)
mean(x)
#> [1] 7.2

14.7 median

The middle number in a distribution where half of the values are larger and half are smaller.

values <- c(1, 1, 1, 2, 3, 5, 6, 9, 9)

# calculate the median of the values
median(values)
#> [1] 3

14.8 mixed design

An experimental design that has both within-subject and between-subject factors.

For example, imagine an experiment where you test half of subjects in a dark room with easy, medium, and hard tasks, and the other half in a light room with easy and hard tasks. This experiment has two factors: room darkness and task difficulty. The factor of room darkness is between subjects and has two levels: dark and light. The factor of task difficulty is within subjects has three levels: easy, medium, and hard. Because this experiment has both within- and between-subject factors, it is described as having a mixed design.

14.9 multilevel model

A type of regression model that involves estimating both fixed effects and random effects.

See linear mixed effects model.

14.10 multilevel

(or multi-level) Relating to datasets where there are multiple observations taken on the same variable on the same sampling units (usually subjects or stimuli).

A multilevel dataset is one where there are repeated measurements on the same subjects on the same variable. If you have multiple measurements on the same subjects but on different variables, with no more than one measurement per subject per variable, you have multivariate data, not multilevel data. It is called "multilevel" because different measurements might be taken at different levels. For example, in a simple reaction time study, you may measure how quickly someone presses a button in response to a flashing light. You can have measurements at the level of the individual trial (the intensity of the flash) as well as measurements at the level of the individual subject (the subject's age in years).

A multilevel model is one that can account for the variance introduced at the various levels.

See also repeated measures.

14.11 multivariate

Having multiple measurements on the same subjects but on different variables, with no more than one measurement per subject per variable.

Table 14.1: Multivariate data with 3 scores on different tasks per person
id stroop memory iat
S1 14 78 7
S2 12 72 5
S3 10 76 5
S4 10 76 4
S5 13 81 6

Contrast with univariate.

14.12 mutating joins

Joins that act like the dplyr::mutate() function in that they add new columns to one table based on values in another table.