6 E
6.1 effect code
A coding scheme for categorical variables that contrasts each group mean with the mean of all the group means.
Also referred to as contrast coding.
6.2 effect size
The difference between the effect in your data and the null effect (usually a chance value)
6.3 effect
Some measure of your data, such as the mean value, or the number of standard deviations the mean differs from a chance value.
6.4 element
One item in a vector.
For example, the built-in vector LETTERS
contains 26 elements: the uppercase latin letters A through Z. You can select an element from a vector by putting its index in square brackets.
# get the tenth upppercase letter
LETTERS[10]
#> [1] "J"
6.5 element (html)
A unit of HTML, such as a header, paragraph, or image.
In HTML, an element is defined by start and end tags. Labelling parts of HTML content as elements defines how they should be visually displayed (controlled by CSS) and handled by screen readers.
6.6 ellipsis
Three dots (...) representing further unspecified arguments to a function.
When you look up the help for a function, you often see one of the arguments is ...
. This means that you can supply your own argument names and values here.
For example, the help page for dplyr::mutate()
shows a usage of mutate(.data, ...)
, which means that the first argument is called .data
and is the data table you want to mutate, and the second argument is ...
, which means that you can add as many new arguments as you want and each one will create a new column with the argument name and value.
# create a data frame with letters and numbers
df <- data.frame(
number = 1:5,
letter = LETTERS[1:5]
)
# the mutate function lets you add custom arguments
# like lower and plus_10
mutate(
.data = df,
lower = tolower(letter),
plus_10 = number + 10
)
number | letter | lower | plus_10 |
---|---|---|---|
1 | A | a | 11 |
2 | B | b | 12 |
3 | C | c | 13 |
4 | D | d | 14 |
5 | E | e | 15 |
6.7 environment
A data structure that contains R objects such as variables and functions
The Environment pane defaults to showing the contents of the Global Environment. This is where objects defined in the console or interactively running scripts are stored. You can also use the code ls()
to list all objects.
When you restart R, the global environment should clear. If it doesn't, go to Global Options...
under the Tools menu (⌘,), and uncheck the box that says Restore .RData into workspace at startup. If you keep things around in your workspace, things will get messy, and unexpected things will happen. You should always start with a clear workspace. This also means that you never want to save your workspace when you exit, so set this to Never. The only thing you want to save are your scripts.
You can also use the code rm(list = ls())
or click on the broom icon in the Environment pane to clear the global environment without restarting R.
When you knit an R markdown file, this happens in a new environment, so if any of your code relies on objects you created outside your script, that code will run interactively in R Studio, but will fail when you knit because the objects in the gloabl environment are not available in the knitting environment.
If you start writing your own functions, you need to understand a little about scope and how the environment inside a function is not the same as the global environment. The Environments chapter in Advanced R is a good resource for advanced understanding.
6.8 error term
The term in a model that represents the difference between the actual and predicted values
6.9 error
The statistical error in a linear model is how much an observation's value differs from the (typically unobserved) true value of a population parameter.
It is closely related to the notion of a residual, except that it reflects deflection from the (usually unknown) true value as opposed to an estimate of the true value. It is usually only possible to know an observation's error if one is dealing with simulated data.
6.10 escape
Include special characters like " inside of a string by prefacing them with a backslash.
When you need to use a character that has a special meaning in R or markdown, you can create the literal version by escaping it with a backslash.
str <- "This prints a \"quote\" and prevents twitter handles like \\@psyteachr from turning into references."
This prints a "quote" and prevents twitter handles like @psyteachr from turning into references.
6.11 extension
The end part of a file name that tells you what type of file it is (e.g., .R or .Rmd).
Common file types and their extensions
File type | extension |
---|---|
R script | .R |
R Markdown | .Rmd |
Comma-separated variable | .csv |
Plain text | .txt |
Web file | .html |
Word document | .doc, .docx |
6.12 extract operator
A symbol used to get values from a container object, such as [
, [[
, or $
You can extract values from a vector by index or name using [
and [[
.
my_vector <- c(A = "first", B = "second")
my_vector[1] # by index, retains name
#> A
#> "first"
my_vector[[1]] # by index, removes name
#> [1] "first"
my_vector["B"] # by name, retains name
#> B
#> "second"
my_vector[["B"]] # by name, removes name
#> [1] "second"
You can extract values from a list by index or name using [
and [[
and by name using $
.
my_list <- list(
A = "First item",
B = 2
)
my_list[1] # by index, returns a (named) list
#> $A
#> [1] "First item"
my_list[[1]] # by index, returns an (unnamed) vector
#> [1] "First item"
my_list["B"] # by name, returns a (named) list
#> $B
#> [1] 2
my_list[["B"]] # by name, returns an (unnamed) vector
#> [1] 2
my_list$A # by name, returns an (unnamed) vector
#> [1] "First item"