NOTE: This package is incomplete but under active development. Check back here for updates/new tutorials.
The discovr
package contains resources for my 2023 textbook
Discovering Statistics Using
and
.
There are tutorials written using
learnr. Once a tutorial is running
it’s a bit like reading a book but with places where you can practice
the code that you
have just been taught. The discovr
package is free and offered to
support tutors and students using my textbook who want to learn
.
discovr
To use discovr
you first need to install
and
and
familiarise yourself with
,
and good
workflow practice. You can do this using this interactive
tutorial. Once
you have installed
and you can
install discovr
. The package is in development so you have to install
it from github. To install the package execute (in
):
if(!require(remotes)){
install.packages('remotes')
}
remotes::install_github("profandyfield/discovr")
If you are trying to install on a networked computer the install might
fail (it’s to do install.packages not liking UNC paths, which I’m not
even going to pretend to understand). The solution is to specify the
location of your
library at the point of install. Most networks will map network
locations to a drive name (for example, at my own University, users
accounts are on the ‘N’ drive). Find the location of your
library (e.g.,
N:/Documents/R/win-library/3.5
), possibly executing .libPaths()
to
help you, and specify this location using the lib
argument:
remotes::install_github("profandyfield/discovr", lib = "N:/Documents/R/win-library/3.5")
I recommend working through this playlist of tutorials on how to install, set up and work within and before starting the interactive tutorials.
lavaan
.lm()
and the
afex
package. This tutorial builds on previous ones to show how
models can be fit with two categorical predictors to look at the
interaction between them. We look at fitting the models, setting
contrasts for the two categorical predictors, obtaining estimated
marginal means, interaction plots, simple effects analysis, diagnostic
plots, partial eta-squared and partial omega-squared, robust models
and Bayes factors.afex
package. This
tutorial builds on previous ones to show how models can be fit with
one or two categorical predictors when these variables have been
manipulated within the same entities. We look at fitting the models,
setting contrasts for the categorical predictors, obtaining estimated
marginal means, interaction plots, simple effects analysis, diagnostic
plots, robust models and Bayes factors.afex
package. This tutorial builds on previous ones to show how
models can be fit with one or two categorical predictors when at least
one of these variables has been manipulated within the same entities
and at least one other has been manipulated using different entities.
We look at fitting the models, setting contrasts for the categorical
predictors, obtaining estimated marginal means, interaction plots,
simple effects analysis, diagnostic plots, robust models and Bayes
factors.psych
package. This tutorial uses a fictitious
questionnaire (the
Anxiety Scale, RAQ) with 23 items to show how EFA can be used to
identify clusters of items that may, or may not, represent constructs
associated with anxiety about using
. We look at
inspecting the correlation matrix, obtaining the Bartlett test and KMO
statistics, using parallel analysis to determine the number of factors
to extract, extracting factors, rotating the solution nd
interpretation of the factors. We also learn to obtain Cronbach’s
alpha on each of the subscales.In Version 1.3 onwards there is a tutorial pane. Having executed
library(discovr)
A list of tutorials appears in this pane. Scroll through them and click on the button to run the tutorial:
Alternatively, to run a particular tutorial from the console execute:
library(discovr)
learnr::run_tutorial("name_of_tutorial", package = "discovr")
and replace “name of tutorial” with the name of the tutorial you want to run. For example, to run tutorial 2 execute:
learnr::run_tutorial("discovr_02", package = "discovr")
The name of each tutorial is in bold in the list above. Once the command to run the tutorial is executed it will spring to life in a web browser.
The tutorials are self-contained (you practice code in code boxes) so you don’t need to use at the same time. However, to get the most from them I would recommend that you create an project and within that open (and save) a new RMarkdown file each time to work through a tutorial. Within that Markdown file, replicate parts of the code from the tutorial (in code chunks) and use Markdown to write notes about what you have done, and to reflect on things that you have struggled with, or note useful tips to help you remember things. Basically, write a learning journal. This workflow has the advantage of not just teaching you the code that you need to do certain things, but also provides practice in using itself.
See this video explaining my suggested workflow:
Inspired by the rockthemes package and adapting code form that package I have come up with a bunch of colour themes based around the studio albums of my favourite band Iron Maiden. Full disclosure, I’m not a designer, so this largely involved uploading images of their sleeves to colorpalettefromimage.com and seeing what happened. If you have a better palette design send me the hex codes for the colours! If you’re wondering why some albums are missing, here’s the explanation: X Factor (would basically be 8 shades of gray), Fear of the Dark (shit album), The Book of Souls (would basically be 8 shades of black).
There is also a colourblind-friendly colour pallette from
The following palettes exist.
amolad_pal()
: Colour palette (8 colour) based on Iron Maiden’s A
Matter of Life and
Death
album sleeve. In ggplot2
use scale_color_amolad()
and
scale_fill_amolad()
.bnw_pal()
: Colour palette (8 colour) based on Iron Maiden’s Brave
New
World
album sleeve. In ggplot2
use scale_color_bnw()
and
scale_fill_bnw()
.dod_pal()
: Colour palette (8 colour) based on Iron Maiden’s Dance
of
Death
album sleeve. In ggplot2
use scale_color_dod()
and
scale_fill_dod()
.frontier_pal()
: Colour palette (8 colour) based on Iron Maiden’s
The Final
Frontier
album sleeve. In ggplot2
use scale_color_frontier()
and
scale_fill_frontier()
.im_pal()
: Colour palette (8 colour) based on Iron Maiden’s
eponymous
album sleeve. In ggplot2
use scale_color_im()
and
scale_fill_im()
.killers_pal()
: Colour palette (8 colour) based on Iron Maiden’s
Killers
album sleeve. In ggplot2
use scale_color_killers()
and
scale_fill_killers()
.nob_pal()
: Colour palette (8 colour) based on Iron Maiden’s The
Number of the
Beast
album sleeve. In ggplot2
use scale_color_nob()
and
scale_fill_nob()
.okabe_ito_pal
: Colourblind-friendly palette (8 colour) from Okabe
and Ito. In ggplot2
use
scale_color_oi()
and scale_fill_oi()
.pom_pal()
: Colour palette (8 colour) based on Iron Maiden’s Piece
of Mind
album sleeve. In ggplot2
use scale_color_pom()
and
scale_fill_pom()
.power_pal()
: Colour palette (8 colour) based on Iron Maiden’s
Powerslave
album sleeve. In ggplot2
use scale_color_power()
and
scale_fill_power()
.prayer_pal()
: Colour palette (8 colour) based on Iron Maiden’s No
Prayer for the
Dying
album sleeve. Use scale_color_prayer()
and scale_fill_prayer()
.senjutsu_pal()
: Colour palette (10 colour) based on the inner
gatefold image of Iron Maiden’s Senjutsu
album album
sleeve. In ggplot2
use scale_color_senjutsu()
and
scale_fill_senjutsu()
.sit_pal()
: Colour palette (8 colour) based on Iron Maiden’s
Somewhere in
Time
album sleeve. In ggplot2
use scale_color_sit()
and
scale_fill_sit()
.ssoass_pal()
: Colour palette (8 colour) based on Iron Maiden’s
Seventh Son of a Seventh
Son
album sleeve. In ggplot2
use scale_color_ssoass()
and
scale_fill_ssoass()
.virtual_pal()
: Colour palette (8 colour) based on Iron Maiden’s
Virtual
IX album
sleeve. In ggplot2
use scale_color_virtual()
and
scale_fill_virtual()
.To view the palette execute
scales::show_col(name_of_palette()(8))
Replacing name_of_palette()
with the name, for example
scales::show_col(pom_pal()(8))
To apply, for example, the Powerslave palette to the colours of a
ggplot2
plot add scale_color_power()
as a layer:
library(ggplot2)
# Get albums in the classic era from the discovr::eddiefy data.
# I'm not including fear of the dark because it's not in any way classic.
# No prayer for the dying was pushing its luck too if I'm honest.
classic_era <- subset(discovr::eddiefy, year < 1992)
#> Loading required package: lubridate
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
ggplot(classic_era, aes(x = energy, y = valence, color = album_name)) +
geom_point(size = 2) +
discovr::scale_color_power() +
theme_minimal()
Similarly to apply the Powerslave palette to the fill of objects in a
ggplot add scale_fill_power()
as a layer:
ggplot(classic_era, aes(x = album_name, y = valence, fill = album_name)) +
geom_violin() +
discovr::scale_fill_power() +
theme(axis.text.x = element_text(angle = 45)) +
theme_minimal()
See the book or data descriptions for more details. This is a list of available datasets within the package. Raw CSV files are available from the book’s website.
?acdc
.?album_sales
.?alien_scents
.?animal_bride
.?angry_pigs
.?angry_real
.?animal_dance
?beckham_1929
.?big_hairy_spider
.?biggest_liar
.?bronstein_2019
.?bronstein_miss_2019
.?catterplot
.?cat_dance
.?cat_reg
.?cetinkaya_2006
.?chamorro_premuzic
.?child_aggression
.?coldwell_2006
.?cosmetic
.?daniels_2012
.?dark_lord
.?davey_2003
.?download
.?df_beta
.?eel
.?elephooty
.?escape
.?essay_marks
.?exam_anxiety
.?field_2006
.?gallup_2003
.?gelman_2009
.?glastonbury
.?goggles
.?goggles_lighting
.?grades
.?hangover
?hiccups
.?hill_2007
.?honesty_lab
.?ice_bucket
.?invisibility_base
?invisibility_cloak
.?invisibility_rm
.?jiminy_cricket
.?johns_2012
.?lambert_2012
.?massar_2012
.?mcnulty_2008
.?men_dogs
.?metal
.?metal_health
.?metallica
.?miller_2007
.?mixed_attitude
.?murder
.?muris_2008
.?nichols_2004
.?notebook
.?ocd
.?ong_2011
.?ong_tidy
.?penalty
.?profile_pic
.?pubs
.?puppies
.?puppy_love
.?r_exam
.?reality_tv
.?raq
.?roaming_cats
.?rollercoaster
.?santas_log
.?self_help
.?self_help_dsur
.?sharman_2015
.?shopping_exercise
.?sniffer_dogs
.?social_anxiety
.?social_media
.?soya
.?speed_date
.?stalker
.?student
.?superhero
.?supermodel
.?switch
?tablets
.?tea_makes_you_brainy_15
.?tea_makes_you_brainy_716
.?teaching
.?teach_method
.?text_messages
.?tosser
.?tuk_2011
.?tumour
.?tutor_marks
.?van_bourg_2020
.?video_games
.?williams
?xbox
.?zhang_2013_subsample
.?zibarras_2008
.?zombie_growth
.?zombie_rehab
.Solutions for end of chapter tasks are available at www.discovr.rocks.
Solutions for the Labcoat Leni tasks are available at www.discovr.rocks.
Although I recommend working through the interactive solutions, each book Chapter has online code and a downloadable R Markdown file available from www.discovr.rocks.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.