Hands-on Teaching with webR

Brian Cervantes Alvarez

November 1, 2024

Traditional Teaching Methods

Teaching Statistics with RStudio

  • Many statistics courses incorporate R for data analysis and visualization.
  • Typically, lectures cover statistical concepts, and practical workshops focus on R programming.
  • Including R programming examples in lectures can be challenging due to window switching and limited student engagement.

Traditional Teaching Methods: Screenshots and Code

Static Screenshot in RStudio

Traditional Teaching Methods: Screenshots and Code

Static Screenshot in RStudio

Traditional Teaching Methods: Screenshots and Code

Static Code in RStudio (Better)

# Load necessary package
library(stats)

# Conduct a two-sample t-test
set.seed(123)
group_A <- rnorm(30, mean = 100, sd = 15)  # Sample data for group A
group_B <- rnorm(30, mean = 105, sd = 15)  # Sample data for group B

# Perform t-test
t.test(group_A, group_B)

Traditional Teaching Methods: Screenshots and Code

Static Code in RStudio (Better)

# Load necessary package
library(stats)

# Conduct a two-sample t-test
set.seed(123)
group_A <- rnorm(30, mean = 100, sd = 15)  # Sample data for group A
group_B <- rnorm(30, mean = 105, sd = 15)  # Sample data for group B

# Perform t-test
t.test(group_A, group_B)

    Welch Two Sample t-test

data:  group_A and group_B
t = -2.3755, df = 56.559, p-value = 0.02094
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -15.448139  -1.315124
sample estimates:
mean of x mean of y 
 99.29344 107.67508 

Traditional Teaching Methods: Screenshots and Code

Code and Output

  • Code is usually shown as static screenshots or pre-written blocks.
  • Students struggle to follow along without hands-on practice.

Traditional Teaching Methods: Live Coding

Pros

  • Shows the process of writing code
  • Teaches students how to debug code
  • Demonstrates good programming practices

Cons

  • Switching between windows
  • More pressure as a demonstrator
  • Hard for students to run the code themselves

This can be challenging for the instructor, as mistakes or technical issues during live coding can disrupt the lesson and hinder student understanding. If students are unfamiliar with programming languages like R, even small errors can cause confusion and negatively impact their learning experience.

Introducing webR

What is webR?

  • webR is a version of R that runs directly in a web browser.
  • It eliminates the need for local installation or server setup.
  • It just works (even on your phone).
  • Can be easily implemented using quarto.

Why webR is a Game Changer

  • webR transforms traditional lectures into dynamic and interactive sessions.
  • It helps maintain student interest and improves comprehension through hands-on practice.
  • Simplifies the teaching process, allowing instructors to focus on content delivery rather than technical setup.

Benefits of webR

  • Students can run code directly in the browser, fostering interactive learning.
  • No need for software installation, making it accessible to all students.
  • Ideal for live coding sessions, demonstrations, and exploratory data analysis.

webR Demo 1

Linear Regression

We’ll first start with the webR team’s demo example, the statistician’s way of saying, “Hello world!”—linear regression:

webR Demo 1

Linear Regression

You can continue your code from the previous slide! Just make sure you remember what variables you used!

webR Demo 2

Summarize Data

Glancing at data frames:

  • What would happen if you plot(mtcars)?
  • Find the overall average miles per gallon for all cars.
    • Hint: Use mean()

Advanced base R graphing:

ggplot2 Example

Create a box plot with ggplot2:

webR Demo 3

Mixing Active and Non-Active R Code

For if-else statements:

if (...) {
  # Statements for TRUE
} else {
  # Statements for FALSE
}
  • ... denotes a condition (either TRUE or FALSE).
  • If TRUE, the statements inside {} run.
  • Otherwise, the statements inside the else block run.

Let’s classify temperature to print “Hot!” or “Cold!”:

  • Change temperature to equal 80
  • Add a new logic if-statement that converts Fahrenheit to Celusis
    • Hint: the conversion formula is (32°F − 32) × 5/9 = 0°C

webR Browser

What Can You Currently Do With webR?

Use Cases

Current Limitations

  • Not all R packages are properly supported/implemented yet (e.g. plotly, leaflet).
  • May take a few minutes to download all required packages for specific lecture highlights (varies by internet speed).
  • Time to render revealjs documents are longer (more for older machines).

Summary

webR offers a powerful tool for teaching statistics and data visualization. By enabling interactive coding directly within presentations, it enhances student engagement and simplifies the instructional process.

References

Appendix

Downloading & Setting Up webR

webR Documentation

Explore how webR can be embedded in a Quarto document for teaching R in the following links.

RStudio Guide To Deploying webR