Exercises for 2.1: Descriptive statistics

Preliminaries

  • load the driving.Rdatafile.
  • type head( driving )to look at the first few observations
  • load the following packages: lsr, psych
load( "~/Work/Research/Rbook/workshop_dsto/datasets/driving.Rdata")
head( driving )
library(lsr)
library(psych)

Exercise 2.1.1: Central tendency

  • compute the mean age of the participants
  • compute the median age of the participants
  • compute the modal age of the participants (note what happens when there are multiple modal frequencies)

Exercise 2.1.2: Spread

  • compute the standard deviation age of the participants
  • compute the age range of the participants
  • compute the interquartile range on the age of the participants
  • compute the 10th, 25th, 75th and 90th percentiles for age

Exercise 2.1.3: Tabulation part 1

  • use table()to construct a tabulation of the distractorvarible
  • now use table()to cross-tabulate distractorby peak.hour

Exercise 2.1.4: Tabulation part 2

  • use xtabs()to cross-tabulate distractorby peak.hour

Exercise 2.1.5: Getting descriptives en masse

  • use describeto get descriptives for all variables in driving(this will produce some warnings!)
  • use summaryto get descriptives for all variables in driving

Exercise 2.1.6: Descriptives by group

  • use describeByto get descriptives separately depending on whether the tests were conducted in peak hour or not (this will produce some warnings!)
  • use aggregateto calculate the mean number of errors in the first test (i.e. errors_time1) broken down by peak.hourand distractor

Exercise 2.1.7: Correlations

  • calculate the correlation of the number of errors at time 1 with the number of errors at time 2 using cor()
  • calculate the Spearman correlation for the same variables, again using cor()
  • use correlate()to compute all pairwise correlations.