R in the Classroom - Day II

Danny Kaplan
NIMBIOS Computing in the Cloud Workshop

Markdown and Editing

Markdown is a straightforward markup language for producing documents quickly.

  • Simple syntax (unlike \( \LaTeX \))
  • Compiles to HTML (or PDF or Word).
  • Can include straight HTML (e.g. iframes, video)

The `mosaic` package

Available on CRAN: Install in the usual way, e.g.

install.packages('mosaic')
  • Attempts to provide a coherent and unified set of commands, to make it easier for beginning students to use R.
  • Stays close to standard R whenever possible
  • Used for both statistics and calculus

Example:

mean( height ~ sex, data=Galton )

Created by DTK, Randall Pruim (Calvin College), Nick Horton (Amherst College)

The Principles in Brief

  • Keep it simple and consistent for your students.
  • Teach one thing at a time (or, at least, not everything at once).
  • Support collaboration.
  • Illustrate a professional workflow.
  • Don't code, Express!
  • Provide immediate gratification/confidence when starting out every day.
  • Give students a working scaffold/template.
  • Make the technology central to how and what you teach.
  • Build on what students already know.

Some Additional Principles

  • Do some things by hand.
  • Don't make the course about teaching the tool

Several people told me about students/colleagues using SPSS. They can do it, but they don't know what they are doing.

By Hand?

Often, the point of “by hand” is to develop an understanding of what a formula means:

  • mean: \( m = \frac{1}{n}\sum_{i=1}{n} x_i \)
  • correlation coefficient: \( r = \frac{\sum (x_i - m_x)(y_i - m_y)}{\sqrt{(\sum (x_i-m_x)^2)}\sqrt{(y-m_y)^2}} \)
  • standard error of the mean: \( s/\sqrt{n} \)

A critique:

When doing something by hand, you're really using technology:

  • Paper and pencil, Formulas, Tables

By Eye

To form intuition and understanding, it helps to have mastered a set of tasks that you can do at a glance:

Examples:

  • Standard deviation
    • From density
    • From dots
  • t-test Slides

Don't Teach Everything at Once

If you're teaching data cleaning or wrangling, give students the raw data and have them produce a new set of data.

If you're teaching statistics or the content of the data, give them clean data in an easy to use form.

You can always say later, “Here's where that simple dataset came from.”

Two things at once: Example

  • Data management and cleaning with nhanesOriginal
    • Everything is quantitative
    • Must constantly refer to the codebook
    • Have to convert some variables to categorical for even simple tasks.

Make the technology central to how and what you teach.

On Sunday:

To teach inference, implement sampling and randomization and repetition.

Today

Understanding ANOVA.

Template in 2014-04-07-notes HTML and Rmd

Give students a working scaffold/template.

Example: I often start with a graph-reading exercise. Partly, this is to get students to realize that even if they think they know, they often do not.

plot of chunk unnamed-chunk-4

Provide immediate confidence when starting out every day.

Not “R has a steep learning curve”

Your scaffolds can do this. Make them attractive.

Illustrate a professional workflow.

  • Document your work.
  • Write coherent explanations.
  • Don't alter your data, except when documented and reversible
  • Write and provide your own notes this way

This is where R/Markdown is fantastic.

Don't Code in Front of Students

Code examples:

  • loops
  • accumulators
  • conditionals
  • indexing brackets. Use subset(), transform(), …

Example: Bootstrapping

do() and resample() functions

Don't Code! (2)

Avoid distracting details:

  • Standard plots are generally good enough. You don't need to elaborate.
  • Don't force students to read code they won't understand.
  • If your project needs code, put it in a function and distribute the function via your course package.

mPlot()

We need to document, which implies code. But the code for graphics gets difficult, and it's hard for students to play with the possibilities.

Generates the code needed to recreate the plot. (mBar() to come.)

mPlot( Galton )

mScatter example

The deer infection data from yesterday's session with Wei-Chen Chen

deer <- read.csv('DeerInfections.csv')
Error in sample(NHANES, size = 500) : object 'NHANES' not found