forked from coursekata/coursekata-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
165 lines (111 loc) · 7.58 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(coursekata.quiet = TRUE)
```
# coursekata <img src='man/figures/logo.png' align="right" height="138.5" />
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/coursekata)](https://CRAN.R-project.org/package=coursekata)
[![R build status](https://github.com/coursekata/coursekata-r/workflows/R-CMD-check/badge.svg)](https://github.com/coursekata/coursekata-r/actions)
[![codecov](https://codecov.io/gh/coursekata/coursekata-r/branch/main/graph/badge.svg?token=HEenoYyHcn)](https://app.codecov.io/gh/coursekata/coursekata-r)
<!-- badges: end -->
## Overview
*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 [CourseKata.org](https://coursekata.org/).
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](https://tidyverse.tidyverse.org) meta-package.
## Installation
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`](https://cran.r-project.org/package=remotes) or [`pak`](https://cran.r-project.org/package=pak).
```{r eval = FALSE}
# install.packages("remotes")
remotes::install_github("coursekata/coursekata-r")
# install.packages("pak")
pak::pak("coursekata/coursekata-r")
```
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:
```{r eval = FALSE}
coursekata::coursekata_install()
```
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](#functions-and-theme) included in the `coursekata` package:
```{r}
library(coursekata)
```
* [supernova](https://cran.r-project.org/package=supernova), for
- creating ANOVA tables.
- tools for extracting information from fitted models (`b0()`, `b1()`, `PRE()`, `fVal()`)
- an augmented `print.lm()` which prints the fitted equation as well
- … and more!
* [mosaic](https://cran.r-project.org/package=mosaic), for a unified interface to most statistical tools.
* [ggformula](https://cran.r-project.org/package=ggformula), for a formula interface to ggplot2.
* [dplyr](https://cran.r-project.org/package=dplyr), for data manipulation.
* [Metrics](https://cran.r-project.org/package=Metrics), for model
evaluation.
In addition to useful functions, a great deal of data sets are used by instructors who teach the course. This package installs these:
* [fivethirtyeight](https://cran.r-project.org/package=fivethirtyeight)
* [fivethirtyeightdata](https://fivethirtyeightdata.github.io/fivethirtyeightdata/index.html)
* [Lock5withR](https://cran.r-project.org/package=Lock5withR)
* [dslabs](https://cran.r-project.org/package=dslabs)
### Startup options
- `coursekata.quickstart`: Each time the package is loaded (e.g. via `library(coursekata)`) a check is run to ensure that all the dependencies are installed and reasonably up-to-date. If they are not, you will be prompted to install missing packages. This can be disabled by setting `options(coursekata.quickstart = TRUE)`.
- `coursekata.quiet`: By default, the package will show all startup messages from the dependent packages. To quiet these (like in the output above), you can set `options(coursekata.quiet = TRUE)`
## 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:
```{r single_estimate}
fit <- lm(mpg ~ hp, data = mtcars)
# the estimate for β₀, the intercept
b0(fit)
# the estimate for β₁, the slope
b1(fit)
# all the estimates
b(fit)
# the proportional reduction in error
pre(fit)
# Fisher's F value
f(fit)
# the p-value for the F test
p(fit)
```
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:
```{r samp_dist_of_b1}
# 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:
```{r samp_dist_of_hp}
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
coef(model)[["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:
```{r shaded_middle}
# 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).
# Contributing
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](https://github.com/coursekata/coursekata-r/issues). 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](https://github.com/coursekata/coursekata-r/pulls) :D