Title: | Statistics: Data Analysis and Modelling |
---|---|
Description: | Data sets and functions to support the books "Statistics: Data analysis and modelling" by Speekenbrink, M. (2021) <https://mspeekenbrink.github.io/sdam-book/> and "An R companion to Statistics: data analysis and modelling" by Speekenbrink, M. (2021) <https://mspeekenbrink.github.io/sdam-r-companion/>. All datasets analysed in these books are provided in this package. In addition, the package provides functions to compute sample statistics (variance, standard deviation, mode), create raincloud and enhanced Q-Q plots, and expand Anova results into omnibus tests and tests of individual contrasts. |
Authors: | Maarten Speekenbrink [aut, cre]
|
Maintainer: | Maarten Speekenbrink <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2025-03-13 06:18:15 UTC |
Source: | https://github.com/mspeekenbrink/sdam-r |
Numerical judgments of the height of the Mount Everest after a low or high anchor. This dataset comes from the ManyLabs 1 study
anchoring
anchoring
A data frame with 4632 rows and 5 variables:
Unique identifier for participants
Sex of participant (f = female, m = male)
Age of participant in years
Country code of citizenship
Location of data collection. Site abbreviations used here can be matched up to the full site name in the online supplement https://osf.io/wx7ck/
Was the study conducted on a US sample or international sample?
Was the study conducted online or in-lab?
anchor, whether high or low
judged height of Mount Everest in feet. Converted from meters if given in meters.
judged height of Mount Everest in meters. Only contains values when judgment was actually given in meters.
https://osf.io/pqf9r/. See also Klein, R. A., Ratliff, K. A., Vianello, M., Adams, R. B., Jr., Bahník, S., Bernstein, M. J., . . ., Nosek, B. A. (2014). Investigating variation in replicability: A "many labs" replication project. Social Psychology, 45(3), 142-152. doi:10.1027/1864-9335/a000178
center
computes mean-centered values. It is a convenience wrapper to scale
, equal to scale(x, scale=FALSE)
center(x)
center(x)
x |
Numeric vector |
A numeric vector with mean-centered values
data(anchoring) center(anchoring$everest_feet)
data(anchoring) center(anchoring$everest_feet)
\@format A data frame with 320 observations of 16 variables:
(factor) Participant ID
(numeric) Participant age in years
(factor) Participant sex (Male or Female)
(factor) Identical-Distractors, or Self-Distractors.
Measure of average response deviation from the visual analogue scale; scores > +/- 2.00 constitute exclusion.
(numeric) Indicator whether participant was excluded from main analysis (0 = no, 1 = yes)
(character) explanation for exclusion
(factor) Item description
Attractiveness rating for the target face on a visual analogue scale ranging from “Very Unattractive” (0) to “Very Attractive” (100)
cheerleader
cheerleader
An object of class data.frame
with 192 rows and 9 columns.
https://osf.io/je5u7/. Carragher, D.J., Thomas, N.A., Gwinn, O.S. et al. (2019) Limited evidence of hierarchical encoding in the cheerleader effect. Scientific Reports, 9, 9329 doi:10.1038/s41598-019-45789-6.
expand_Anova
is an experimental function to add more detailed results to those returned by car::Anova
. In particular, expand_Anova
aims to provide test results for all individual contrasts assigned to the factors in a linear model, in addition to the omnibus tests returned by car::Anova
.
expand_Anova(mod, type = c("III", "II", 3, 2), ...)
expand_Anova(mod, type = c("III", "II", 3, 2), ...)
mod |
A model of class lm (see ?stats::lm) |
type |
SS Type (see ?car::Anova) |
... |
Further arguments passed to Anova |
This is an experimental function
Object of class anova returned by car::Anova
car::Anova()
for more information about the Anova tables, and stats::lm()
for information about how to specify the model
data("tetris2015") mod <- lm(Days_One_to_Seven_Number_of_Intrusions ~ Condition, data=tetris2015) car::Anova(mod,type=3) # default type III Anova table expand_Anova(mod,type=3)
data("tetris2015") mod <- lm(Days_One_to_Seven_Number_of_Intrusions ~ Condition, data=tetris2015) car::Anova(mod,type=3) # default type III Anova table expand_Anova(mod,type=3)
\@format A data frame with 400 observations of 16 variables:
Participant ID
Experimenter Number
Participant age in years
Participant self-reported gender
Year in University
Self-reported ethnicity
Self-reported English fluency (1=beginner; 7=native language)
Experimenter Belief (H: High or L: Low)
Actual Prime Condition (HPP: High-power prime or LPP: low-power prime)
Self-reported power BEFORE the manipulation
Self-reported power AFTER the manipulation
Approach advantage (Avoid RT - Approach RT; see manuscript)
Rating of experimenter ATTRACTIVENESS
Rating of experimenter COMPETENCE
Rating of experimenter FRIENDLINESS
Rating of experimenter TRUSTWORTHINESS
expBelief
expBelief
An object of class data.frame
with 400 rows and 16 columns.
https://osf.io/un4h6/. See also Gilder, T. S. E., & Heerey, E. A. (2018). The Role of Experimenter Belief in Social Priming. Psychological Science, 29(3), 403–417. doi:10.1177/0956797617737128.
A dataset containing the predictions and outcomes of matches in the 2010 FIFA European Cup.
fifa2010
fifa2010
A data frame with 8 rows and 4 variables:
countries playing
country predicted to win
score at the end of the match
whether Paul was correct or incorrect
https://en.wikipedia.org/wiki/Paul_the_Octopus
Statistics for all teams playing in the 2010 FIFA world cup.
fifa2010teams
fifa2010teams
A data frame with 11 variables and 32 rows
Unique numeric identifier for each team
Name of the team (i.e. country)
Number of matches played
Total goals counted against their opponents
Total goals scored against their opponents
Goals counted against the team
Number of penalty goals scored
Number of own goals
Number of yellow cards
Number of indirect red cards
Number of direct red cards
FIFA website. https://www.fifa.com/worldcup/archive/southafrica2010/statistics/teams/goal-scored and https://www.fifa.com/worldcup/archive/southafrica2010/statistics/teams/disciplinary
Half violin plot
geom_flat_violin( mapping = NULL, data = NULL, stat = "ydensity", position = "dodge", trim = TRUE, scale = "area", show.legend = NA, inherit.aes = TRUE, ... )
geom_flat_violin( mapping = NULL, data = NULL, stat = "ydensity", position = "dodge", trim = TRUE, scale = "area", show.legend = NA, inherit.aes = TRUE, ... )
mapping |
The mapping |
data |
data.frame |
stat |
statistic (don't change) |
position |
position dodge |
trim |
Logical |
scale |
Scale (don't change) |
show.legend |
Logical |
inherit.aes |
Logical |
... |
other arguments |
A layer for a ggplot2::ggplot
object, similar to e.g. ggplot2::geom_violin
.
urlhttps://gist.github.com/dgrtwo/eb7750e74997891d7c20
ggplot2::geom_violin()
, which provided the basis of this function.
library(ggplot2) data(diamonds) ggplot(diamonds, aes(cut, carat)) + geom_flat_violin() + coord_flip()
library(ggplot2) data(diamonds) ggplot(diamonds, aes(cut, carat)) + geom_flat_violin() + coord_flip()
\@format A data frame with 54 observations of 6 variables:
(factor) Participant ID
(factor) Whether talking to a friend or professor
(numeric) Duration of the interaction
(factor) Language spoken: Catalan or Korean
(factor) Participant gender (M = male, F = female)
(numeric) number of gestures in the interaction.
gestures
gestures
An object of class data.frame
with 54 rows and 6 columns.
Legacy motives and pro-environmental behaviour
legacy2015
legacy2015
A data frame with 245 rows and 9 variables:
(numeric) ID variable relating to the original dataset
(character) biological sex of participant (male or female)
(numeric) age in years
(numeric) Sverage of 8 items reflecting legacy motivation, on a scale from 1 (Not at all) to 6 (A great amount)
(numeric) average of 5 items reflecting belief in climate change, on a scale from 1 (Strongly Disagree) to 7 (Strongly Agree)
(numeric) average of 8 items reflecting intention to act in a pro-environmental way, on a scale from 1 (Never) to 6 (All the time)
(numeric) Level of education, 1 = 8th grade or less, 2 = Some high school, 3 = Graduated high school, 4 = Some college or technical school, 5 = Graduated college or technical school, 6 = Post-graduate
(numeric) Approximate household income, 1 = less than $20K, 2 = $20K-$35K, 3 = $35K-$50K 4 = $50K-$75K, 5 = $75K-100K, 6 = more than 100K
(numeric) Donation of possible bonus payment, between $0 and $10
Harvard DataVerse https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/27740&version=1.0
## Not run: # this dataset was processed from the raw data as follows: tdat <- read.csv("legacy study - pilot_data.csv") ## End(Not run)
## Not run: # this dataset was processed from the raw data as follows: tdat <- read.csv("legacy study - pilot_data.csv") ## End(Not run)
\@format A data frame with 7560 observations of 10 variables:
(factor) Participant ID
(numeric) Participant age in years
(factor) Participant sex (male or female)
(numeric) number of the test block (from 1 to 9). Practice block is excluded.
(numeric) number of trial (between 1 and 42) within a block.
(numeric) whether grating is horizontal (0) or vertical (90)
(numeric) contrast of grating shown
(numeric) Whether identified title was correct (1) or not (0)
(numeric) Rated visibility of the stimulus, on a scale between 0 () and 100 ()
(numeric) Rated confidence in tilt identification, on a scale between 0 () and 100 ()
metacognition
metacognition
An object of class data.frame
with 7560 rows and 10 columns.
https://osf.io/vk6fe/. Rausch, M. & Zehetleitner, M. (2016) Visibility is not equivalent to confidence in a low contrast orientation discrimination task. Frontiers in Psychology, 7, p. 591 doi:10.3389/fpsyg.2016.00591.
\@format A data frame with 90 observations of 3 variables:
(factor) Reported newspaper read most often
(factor) Which party voted on (including "did not vote")
(numeric) Number of people in the survey who responded with that combination of newspaper and vote
papervotes
papervotes
An object of class data.frame
with 90 rows and 3 columns.
plot_qq_marginals
creates an enhanced Q-Q plot with the observed and theoretical distributions shown in the margins of the plot.
plot_qq_marginals( x, breaks = "Sturges", newpage = TRUE, xlab = "Observed Quantiles", ylab = "Theoretical quantiles", xlim = grDevices::extendrange(c(min(x), max(x))), ylim = NULL, main = NULL, sub = NULL, axes = TRUE, border = TRUE, ... )
plot_qq_marginals( x, breaks = "Sturges", newpage = TRUE, xlab = "Observed Quantiles", ylab = "Theoretical quantiles", xlim = grDevices::extendrange(c(min(x), max(x))), ylim = NULL, main = NULL, sub = NULL, axes = TRUE, border = TRUE, ... )
x |
A numeric vector |
breaks |
How to compute breakpoints for the histogram. See ?hist |
newpage |
(logical) Should the plot be plotted on a new page? |
xlab |
Label for x-axis |
ylab |
Label for y-axis |
xlim |
Range of x values shown |
ylim |
Range of y values shown |
main |
Main title |
sub |
Subtitle |
axes |
(logical) Draw axes? |
border |
(logical) Draw a border? |
... |
Further arguments |
No return value. The function adds a plot to the active graphics window.
data(anchoring) plot_qq_marginals(anchoring$everest_feet)
data(anchoring) plot_qq_marginals(anchoring$everest_feet)
plot_raincloud
creates a raincloud plot to display the distribution of data by a combination of a a boxplot, a kernel density plot, and a scatterplot. The boxplot includes the median (displayed as a horizontal line) and the mean (displayed as a point). It does not indicate potential outliers, as these can be seen in the scatter plot. The kernel density plot provides a nonparametric estimate of the distribution. The scatterplot depicts all values in y
with random jittering on the x-axis. The data can be grouped by supplying a grouping factor in the groups
argument, in which case multiple raincloud plots are shown side by side. As plot_raincloud
provides a ggplot2::ggplot
object, it can be combined with further layers and functionality from the ggplot2
package.
plot_raincloud(data, y, horizontal = FALSE, groups, point_size = 0.5, ...)
plot_raincloud(data, y, horizontal = FALSE, groups, point_size = 0.5, ...)
data |
Data.frame (or tibble) |
y |
The unquoted name of the variable in data for which to create the raincloud plot |
horizontal |
(logical) change the orientation of the plot |
groups |
An unquoted name of grouping variable in data (ideally a factor) |
point_size |
Size of the jittered points |
... |
Other arguments, passed to ggplot(aes(...)) |
An object of class gg
, i.e. a ggplot
object from the ggplot2
package
Allen M, Poggiali D, Whitaker K et al. Raincloud plots: a multi-platform tool for robust data visualization. Wellcome Open Res 2019, 4:63 (doi:10.12688/wellcomeopenres.15191.1)
ggplot2::ggplot()
for information about ggplot objects, ggplot2::theme()
for information about changing various aspects of the plot, and ggplot2::facet_wrap()
and ggplot2::facet_grid()
for creating multiple raincloud plots for different levels of grouping factors beyond those specified in groups
.
data(anchoring) plot_raincloud(anchoring,y=everest_feet) plot_raincloud(anchoring,y=everest_feet,groups=anchor) plot_raincloud(anchoring,y=everest_feet,groups=anchor) + ggplot2::facet_wrap(~us_or_international) + ggplot2::ylab("How high is Mount Everest (in feet)?")
data(anchoring) plot_raincloud(anchoring,y=everest_feet) plot_raincloud(anchoring,y=everest_feet,groups=anchor) plot_raincloud(anchoring,y=everest_feet,groups=anchor) + ggplot2::facet_wrap(~us_or_international) + ggplot2::ylab("How high is Mount Everest (in feet)?")
Simultaneously nudge and jitter
position_jitternudge( jitter.width = NULL, jitter.height = 0, nudge.x = 0, nudge.y = 0, seed = NA )
position_jitternudge( jitter.width = NULL, jitter.height = 0, nudge.x = 0, nudge.y = 0, seed = NA )
jitter.width |
degree of jitter in x direction. Defaults to 40% of the resolution of the data. |
jitter.height |
degree of jitter in y direction. Defaults to 0. |
nudge.x |
the amount to nudge in the x direction. |
nudge.y |
the amount to nudge in the y direction. |
seed |
Optional seed for the random jitter |
Positions for data in a ggplot2::ggplot
object, similar to e.g. ggplot2::position_jitter
ggplot2::position_jitter()
, which is the basis of this function.
library(ggplot2) dsub <- diamonds[ sample(nrow(diamonds), 1000), ] ggplot(dsub, aes(x = cut, y = carat, fill = clarity)) + geom_boxplot(outlier.size = 0) + geom_point(pch = 21, position = position_jitterdodge())
library(ggplot2) dsub <- diamonds[ sample(nrow(diamonds), 1000), ] ggplot(dsub, aes(x = cut, y = carat, fill = clarity)) + geom_boxplot(outlier.size = 0) + geom_point(pch = 21, position = position_jitterdodge())
It is generally found that wealthy people tend to be more opposed to policies to reduce wealth inequalities. This may be unsurprising from a classical economic standpoint, because the material burden of the redistribution of wealth will fall on wealthier people. Wealthier people are also more likely than poorer people to adopt political ideologies that oppose redistribution policies. Dawtry, Sutton, and Sibley (2015) investigated whether, in addition to such factors, “social-sampling processes” lead wealthier people to oppose redistribution policies. Social sampling is the idea that people (partly) base inferences on their social surroundings. Wealthier people tend to live in more affluent areas and move in wealthier social circles. This may bias their view of the world, where wealthier people estimate the general population to be wealthier (with less of a gap between the wealthy and the poor) than it really is.
redist2015
redist2015
A data frame with 305 rows and 12 variables:
unique ID number for each participant
only "male" or "female" could be answered by the looks of it
participant age in years
yearly household income (in units of $1,000)
political leaning from 1="Extremely Liberal" to 9="Extremely Conservative"
estimate average household income in the general US population
GINI index computed for a subjective distribution of wealth in the general US population. The GINI index is a measure of wealth inequality; higher numbers mean more inequality
Answer to the question "To what extent do you feel that household incomes are fairly–unfairly distributed across the US population?" on a scale from 1="Extremely Fair" to 9 = "Extremely Unfair".
Answer to the question "How satisfied–dissatisfied are you with the way in which household incomes are distributed across the US population?" on a scale from 1="Extremely satisfied" to 9="Extremely dissatisfied".
estimate average household income in the participant's social circles
(subjective) inequality in the participant's social circles
support for wealth redistribution policies (average of four items, higher scores indicate stronger support).
In Experiment 1a of Dawtry, Sutton, and Sibley (2015), they assessed income and opinions for n=305 online U.S. participants recruited via Amazon’s Mechanical Turk.
https://osf.io/3mftr/. See also Dawtry, Rael J., Robbie M. Sutton, and Chris G. Sibley. 2015. “Why Wealthier People Think People Are Wealthier, and Why It Matters: From Social Sampling to Attitudes to Redistribution.” Psychological Science 26 (9): 1389–1400. doi:10.1177/0956797615586560.
\@format A data frame with 2600 observations of 6 variables:
(factor) Participant ID
(factor) Strategy adopted by AI player
(numeric) Round number (between 1 and 50)
(factor) Action taken by human (rock, paper, or scissors)
(factor) Action taken by AI (rock, paper, or scissors)
(numeric) Outcome for human player, where 1 indicates a win, -1 a loss, and 0 a tie
rps
rps
An object of class data.frame
with 2600 rows and 6 columns.
Guennouni, I., Speekenbrink, M. (2022). Transfer of learned opponent models in repeated games. Computational Brain and Behaviour, 5, 326–342. doi:10.1007/s42113-022-00133-6
sample_mode
computes the sample mode, i.e. the value in x
with the highest frequency of occurrence. If there are multiple modes, the mode that occurs first in x
is returned, with a warning that lists the other modes found.
sample_mode(x)
sample_mode(x)
x |
Numeric vector |
A single numeric value equal to the sample mode
data(anchoring) sample_mode(anchoring$everest_feet) # Multiple modes give a warning: sample_mode(c(3,3,3,1,1,1,2,2,2))
data(anchoring) sample_mode(anchoring$everest_feet) # Multiple modes give a warning: sample_mode(c(3,3,3,1,1,1,2,2,2))
sample_sd
computes the sample standard deviation, i.e. the square root of the sum of squared deviations of x
from the mean divided by the total number of observations. This is in contrast to sd
, which computes an unbiased estimate of the standard deviation (i.e. it divides the sum of squared deviations by n - 1).
sample_sd(x, na.rm = FALSE)
sample_sd(x, na.rm = FALSE)
x |
Numeric vector |
na.rm |
(logical) Should missing values be removed? |
A single numeric value equal to the sample variance
data(anchoring) sample_sd(anchoring$everest_feet)
data(anchoring) sample_sd(anchoring$everest_feet)
sample_var
computes the sample variance, i.e. the sum of squared deviations of x
from the mean divided by the total number of observations. This is in contrast to var
, which computes an unbiased estimate of the variance (i.e. it divides the sum of squared deviations by n - 1).
sample_var(x, na.rm = FALSE)
sample_var(x, na.rm = FALSE)
x |
Numeric vector |
na.rm |
(logical) Should missing values be removed? |
A single numeric value equal to the sample variance
data(anchoring) sample_var(anchoring$everest_feet)
data(anchoring) sample_var(anchoring$everest_feet)
A subset of cases (wave 6-9) and variables (see below) from an experiment on speed dating. by Columbia Business School professors Ray Fisman and Sheena Iyengar for their paper Gender Differences in Mate Selection: Evidence From a Speed Dating Experiment.
speeddate
speeddate
A data frame with 1562 rows and 32 variables:
(numeric) unique ID variable of participant
(numeric) unique ID variable of date partner
(character) gender of participant (male or female)
(numeric) age in years
(numeric) how much they like their date partner in general (between 1 and 10)
(numeric) how much their date partner likes them (between 1 and 10)
do they want to go on another date with their date partner? (1 = yes, 0 = no)
does their date partner want to go on another date with them? (1 = yes, 0 = no)
do they both want to go on another date with each other? (1 = yes, 0 = no)
how attractive do they think they are? (between 1 and 10)
how sincere do they think they are? (between 1 and 10)
how intelligent do they think they are? (between 1 and 10)
how much fun do they think they are? (between 1 and 10)
how ambitious do they think they are? (between 1 and 10)
how attractive etc does their date partner think they are? (between 1 and 10)
how much does their date partner think they share hobbies and interests? (between 1 and 10)
how do they rate their date partner's attractiveness etc? (between 1 and 10)
how important do they find attractiveness etc in a partner? (between 1 and 10)
how important does their date partner find attractiveness etc? (between 1 and 10)
Kaggle https://www.kaggle.com/annavictoria/speed-dating-experiment
Tetris and intrusive memories
tetris2015
tetris2015
A data frame with 72 rows and 28 variables:
(factor) Condition: Control, Tetris_Reactivation, Tetris, or Reactivation
Time of day participant commenced experiment, either "morning” or “afternoon”
Beck Depression Inventory-II (BDI-II): Total score
Spielberger State-Trait Anxiety Trait scale (STAI): Total score
Self-rated level of Sadness: Pre-film VAS mood. VAS = visual analogue scale. All VAS mood scales anchored from “not at all” to “extremely” in response to the question “Right at this very moment I am feeling”. Composite for pre-film mood calculated by summing the six pre-film VAS mood ratings
Self-rated level of Hopelessness: Pre-film VAS mood
Self-rated level of Depressed: Pre-film VAS mood
Self-rated level of Fear: Pre-film VAS mood
Self-rated level of Horror: Pre-film VAS mood
Self-rated level of Anxiousness: Pre-film VAS mood
Self-rated level of Sadness: Post-film VAS mood. Composite for post-film mood calculated by summing the six post-film VAS mood ratings
Self-rated level of Hopelessness: Post-film VAS mood
Self-rated level of Depressed: Post-film VAS mood
Self-rated level of Fear: Post-film VAS mood
Self-rated level of Horror: Post-film VAS mood
Self-rated level of Anxious: Post-film VAS mood
Attention paid to the film rating: How much attention did you pay to the film from 0-not at all to 10-extremely
Post film distress rating: How distressing did you find the film from 0-not at all to 10-extremely
Day 0: Number of image-based intrusive memories in the Intrusion Diary (pre-intervention)
Days 1-7: Number of image-based intrusive memories in the Intrusion Diary (post-intervention)
Visual recognition memory test score: Number of correct responses (out of 22)
Verbal recognition memory test score: Number of correct responses (out of 32)
Intrusion Provocation Task (IPT): Number of image-based intrusive memories during 2min laboratory task on Day 7
Diary compliance rating - indicate how accurate you think your diary is from 1 - not at all accurate to 10 extremely
Impact of Event Scale-Revised (IES-R): Intrusion Subscale
Tetris game play computer score total - cumulative (sum of all games). Only participants who played Tetris have data relating to Tetris_Total_Score
Self-rated Tetris performance: How difficult or easy did you find the game you just played. Only participants who played Tetris have data relating to Self_Rated_Tetris_Performance.
Demand rating: How much did you think Tetris after a distressing film would increase or decrease intrusive memories of the film: -10: extremely decrease, to +10: extremely increase
https://osf.io/ideta/. See also James et al., 'Computer Game Play Reduces Intrusive Memories of Experimental Trauma via Reconsolidation-Update Mechanisms'.
Trump votes in 2016 for 50 US states and the District of Columbia
trump2016
trump2016
A data frame with 4632 rows and 5 variables:
Name of the state
Number of hate groups in the state in 2016 as reported by the Southern Poverty Law Center (https://www.splcenter.org/hate-map)
Number of citizens in the state in 2016
Number of hate groups per million citizens
Percentage of citizens with a bachelor's degree of higher
Percentage of citizens below the poverty threshold
Percentage of votes for Trump in the 2016 elections
CSI Without Dead Bodies "Hate Groups and Trump's Vote%: Predictive effect present when education and poverty are considered" https://web.archive.org/web/20210414051437/https://www.csiwithoutdeadbodies.com/2017/02/hate-groups-and-trumps-vote-predictive.html
A dataset containing the predictions and outcomes of matches in the 2008 UEFA European Cup.
uefa2008
uefa2008
A data frame with 6 rows and 4 variables:
countries playing
country predicted to win
score at the end of the match
whether Paul was correct or incorrect
https://en.wikipedia.org/wiki/Paul_the_Octopus