CRAN status R build status codecov


CourseKata Statistics and Data Science, is an innovative interactive online textbook for teaching introductory statistics and data science in colleges, universities, and high schools. Part of CourseKata’s Better Book Project, we are leveraging research and student data to guide continuous improvement of online learning resources. The coursekata package is designed to make it easy to install and load the packages, functions, and data used in the book and supplementary materials.

Learn more about CourseKata and its free services and materials at

This package makes it easy to install and load all packages and functions used in CourseKata courses. It additionally provides a handful of helper functions and augments some generic functions to provide cohesion between the network of packages. This package was inspired by the tidyverse meta-package.


This package is not available on CRAN, it is only available on GitHub. You can install it using any package manager that supports GitHub installations, such as remotes or pak.

# install.packages("remotes")

# install.packages("pak")

After installing the core packages, you might want to install the supplementary data packages used in the course. These are not required for the package to work, but they are used in the course materials. You can install them with the following command:


If you don’t install these packages, you will be prompted to install them when you load the package. If you want to disable that message, you can set options(coursekata.quickstart = TRUE).

Loading Packages Used in CourseKata Courses

library(coursekata) will load the following core packages in addition to the functions and theme included in the coursekata package:

#> ── CourseKata packages ──────────────────────────────────── coursekata 0.16.1 ──
#> ✔ dslabs              0.8.0       ✔ Metrics             0.1.4
#> ✔ Lock5withR          1.2.2       ✔ lsr                 0.5.2
#> ✔ fivethirtyeightdata 0.1.0       ✔ mosaic              1.9.1
#> ✔ fivethirtyeight     0.6.2       ✔ supernova           3.0.0

In addition to useful functions, a great deal of data sets are used by instructors who teach the course. This package installs these:

Startup options

Functions and Theme

This package also comes with a variety of functions useful for teaching statistics and data science, and it has an automatically set ggplot2 theme complete with colorblind-friendly palettes and other improvements to aid perception and clarity of plots.

Estimate Extraction (and Bootstrapping)

Extracting an estimate is as easy as passing a fitted linear model to one of the extraction functions:

fit <- lm(mpg ~ hp, data = mtcars)

# the estimate for β₀, the intercept
#> [1] 30.09886

# the estimate for β₁, the slope
#> [1] -0.06822828

# all the estimates
#> $b_0
#> [1] 30.09886
#> $b_hp
#> [1] -0.06822828

# the proportional reduction in error
#> [1] 0.6024373

# Fisher's F value
#> [1] 45.4598

# the p-value for the F test
#> [1] 1.787835e-07

The estimate extraction functions help to simplify the ability to create bootstrapped sampling distributions of those estimates. Here is an example of bootstrapping the slope:

# use mosaic package to repetitively resample to bootstrap a distribution
samp_dist_of_b1 <- do(1000) * b1(lm(mpg ~ hp, data = resample(mtcars)))

# plot the bootstrapped estimates
gf_histogram(~ samp_dist_of_b1$b1)

Other estimates and terms can be bootstrapped using the same technique, but you will need to calculate the values yourself. Here’s an example of doing that for a term that doesn’t have a dedicated extraction function:

samp_dist_of_hp <- do(1000) * {
  # create a new model from the resampled data
  model <- lm(mpg ~ disp * hp, data = resample(mtcars))

  # extract the desired estimate, here the coefficient for hp

# plot the bootstrapped estimates
gf_histogram(~ samp_dist_of_hp$result)

Sectioning a Distribution

When teaching about hypothesis testing, F, and p-value, it is useful to mark different portions of a distribution as inside or outside the critical zone. middle(), upper(), and lower() each take a distribution of values and return whether the value was in, e.g. the middle 95% of the distribution. Use this with a plotting function to shade in those areas:

# shade in the middle 80% of the Thumb distribution
gf_histogram(~Thumb, data = Fingers, fill = ~ middle(Thumb, .80))

Toggling the Theme

The ggplot2 theme is loaded by default but can be toggled on and off via coursekata_load_theme() and coursekata_unload_theme(). The actual plot theme and scale components are also provided for advanced users as theme_coursekata() and scale_discrete_coursekata() (viridis is used for continuous color scales).


If you see an issue, problem, or improvement that you think we should know about, or you think would fit with this package, please let us know on our issues page. Alternatively, if you are up for a little coding of your own, submit a pull request:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D