R Screencasts
Introductory Material
Why R?
Installing R.
Using R as a Calculator.
The R Text Editor.
A Birds-Eye View of R Part 1
A Birds-Eye View of R Part 2
R Help
Saving your files
R packages: How to find, install find help and update packages from the command line.
All About R Objects
This screencast defines 5 R objects: vectors, matrices, arrays, lists and data frames, and describes why they are important for epidemiologists.
A continuation of the description of R objects of interest to epidemiologists and the fucntions used to create them.
A description of what object modes and classes are, the difference between atomic and recursive objects, and how R can change or coerce data.
Numeric vectors are the basic building block of R data structures. How to create and index them.
The difference between sorting and ordering R vectors, and how to use the order() function to arrange one vector according to the levels of another vector.
Logical are created using conditional operators. They are the key to indexing, and indexing is the key to manipulating data in R. This screencast introduces how logical are created, and can be used to index other vectors.
This screencast introduces the R matrix, which is essentially a 2-dimensional vector, and forms the basis for tabular epidemiologic analyses in epidemiology. It shows how to create matrices with the matrix() function for summary data and with the table() function for individual-level data, as well as how to index arrays.
R arrays are n-dimensional vectors that correspond to stratified tables in epidemiologic analysis. This screencast shows how to create arrays with the array() function for summary data, and with the tables() and xtab() functions for individual-level data. It also introduces how to index arrays.
A list can be made up of different kinds of R data types. Many functions return results as lists, and it is the basis for R data frames It can be created using the list() function.
Data frames are flexible in how they can be indexed and manipulated. The three main approaches consist of indexing by position, by name and by logical vector.
This screencast presents a short but non-trivial example of using logical indexing to manipulate an R data frame of hospital discharge data.
This screencast introduces the read.table() function and it’s read.csv() convenience wrapper version as the most effective means of reading data into an R data frame.
Stratified and Crosstabular Analyses
Using the base R apply() function on matrices and arrays to conduct marginal summary analyses like calculating row and column statistics.
Using lapply(), sapply() and mapply() to conduct marginal summary analyses on more complex R objects like lists.
Using the base R functions tapply(), by() and aggregate() to group observations and conduct stratified analyses.
Using the base R function table() to count frequencies and cross tabulate counts and proportions of categorical variables. Introduction to the CrossTable() function in the “gmodels” to return frequency and cross tabulations formatted like SAS PROC FREQ.
2x2 Table Analysis and Odds Ratios
An introduction to 2x2 table analysis in R using epitab() from Tomas Aragon’s “epitools” package.
The Mantel-Haenszel adjusted odds ratio using the cc() and mhor() from Virasakdi Chongsuvivatwong’s “epicalc” package.
Indexing and Data Manipulation
How to index vectors by position, logical expression and name. Using conditional expressions and logical indexes to identify and select one vector against another. Using logical indexing to categorize a variable into mutually exclusive groups.
How to index matrices and arrays by position, name and logical expression.
How to index lists by position using the double bracket notation, by logical expression, and by name. Using indexing to extract results from functions that return lists.
How to index data frame observations (rows) and variables (columns) by position, name and logical expressions to manipulate and recode or replace data elements.
Subsetting a data frame using indexing and logical expressions to restrict rows and variables. Introduction to the base R function subset() as an alternative to indexing.
Statistics and Modeling
An overview of a few of the many statistical functions that come with base R, including summary(), barplot(), t.test() and wilcox.test(), and how to extract information from the results of statistical function.
Linear Regression
A linear regression example using data from John Fox’s “car” package and the lm() function including simple residual analysis and how to update a model.
Logistic Regression
A brief review of odds, log odds and the logistic model followed by a logistic regression example using the glm() function.
Poisson
A review of the Poisson model, offset variables and the predictive interpretation of Poisson regression coefficients.
A Poisson regression example using traffic fatality data from Achim Zeileis’s “AER” package.
Approaches to assessing and adjusting for overdispersion in Poisson models.
Survival Analysis
An overview of the fundamental difference between disease risk and disease rates, and the implication of this difference for modeling time to event data.
A description of the assumptions underlying binomial models and exponential models of disease risk, and the role of Kaplan-Meier and the product limit estimator when those assumptions can not be reasonably met.
A description of the Kaplan-Meier method and illustration of how it can be implemented with basic R code.
An overview of how survival methods can be implemented in R using functions in the “survival” package.