R Programming for PH717
Contents
Page 1
Structure of a Data Set
Data Sets
Page 2
Installing R and R Studio
Install the base system for R
Install RStudio
Page 3
An Overview of R Studio
Using R as a Calculator - Simple Math Functions and Commands in R
Page 4
Importing Data Sets into R Studio
The Traditional Way (harder)
The Easy Way to Import Data
Viewing the Data Set
Problems Importing Data Sets
Importing Data from Excel Spreadsheets (.XLSX files) on a PC or Mac
Page 5
Creating and Saving a Script
Starting a New Script
Attaching and Detaching the Data Set
Page 6
Creating New Variables from Variables in the Data Set
Using a Calculation to Create a New Continuously Distributed Variable
Collapsing a Continuous Variable into Categories
Collapsing Categorical Variables
Page 7
Descriptive Statistics for Continuous Variables
Summary of a Continuous Variable
Mean
Standard Deviation
Median
Descriptive Statistics by Subsets
Page 8
Creating Tables for Dichotomous and Categorical variables
Counts
Proportions
Page 9
Z Scores and the Standard Normal Distribution
Computing Probabilities from the Standard Normal Distribution
pnorm(Z)
pnorm(X, μ, SD)
Computing Percentiles
Page 10
The T-Distribution
The probabilty for a t-statistic
Probability of a Sample Mean Less Than a Given Value
Page 11
Confidence Interval for a Mean
95% Confidence Interval from a Mean and Standard deviation
95% Confidence Interval for a Mean from a Raw Data Set
Confidence Intervals for a Mean by Group
Confidence Interval for a Proportion
Page 12
T-Tests
One Sample t-test
One-Tailed and Two-Tailed T-Tests
T-test to Compare Two Independent Sample Means (unpaired t-test)
t-Test for Comparing Two Matched or Paired Samples (paired t-test)
Page 13
Chi-Square Test of Independence
Chi-squared Test from a Raw Data Set in R
Creating a Contingency Table in R When You Don't Have the Raw Data Set
Computing the P-value from the Chi-squared Statistic and Degrees of Freedom
Page 14
Risk Ratios and Odds Ratios with 95% Confidence Interval
Installing the Epitools Package
Loading the Epitools Package When You Want to Use It
Computing a Risk Ratio and 95% Confidence Limits from a Data Set
Computing Risk Ratios and Odds Ratios using the epiR package
epi R for Case-Control Studies
Computing a Risk Ratio and 95% Confidence Limits When you DON'T Have a Data Set
Creating a contingency table that R can understand
Computing an Odds and 95% Confidence Limits When you DON'T Have a Data Set
Page 15
Stratified Analysis
Stratified Analysis of a Cohort Study
Stratified Analysis of a Case-Control Study
Calculating a Mantel-Haenszel Pooled Estimate of Odds Ratio with the epiDisplay package
Page 16
Correlation and Simple Linear Regression
Correlation Coefficient
Correlation Coefficient and Test of Significance
Simple Linear Regression
Page 17
Multiple Variable Regression
Multiple Linear Regression
Multiple Logistic Regression
Page 18
Creating Graphs
Plot Options
Histogram
Boxplot
Boxplots by group
Barplot
Side-by-Side Bar Plots
Scatterplot
Page 19
Learn more about R
return to top