R Programs
Printerfriendly version
Some Helpful Resources:
 R for Beginners, by Emmanuel Paradis (58 pages)
 New! R Package for Visualizing Categorical Data
 The vcd Package (documentation)
 Note: If you your current R version does NOT have the new {vcd} package, you can download it from the package page above.
 SPLUS (and R) Manual to Accompany Agresti’s Categorical Data Analysis (2002) 2nd edition (1.6 MB, 265 pages)
 Alan Agresti's Website for CATEGORICAL DATA ANALYSIS, 2nd edition.
 Penn State students can also access R Software video tutorials by logging into Lynda.psu.edu with their Penn State userid and password.
The Topic / Procedure  Page 
R code  text data file

Different chisquared distributions  chisqdistributions.R  
Binomial Likelihood  
Simple Binomial Calculations in R 
2.3.2  
Basic Poisson Calculations in R 
2.3.1  
GoodnessofFit Test: Cell Probabilities Functions of Unknown Parameters 
2.7  
Creates a table of oneway frequencies for observations of a die and then finds calculates a oneway chisquare test  2.5 

Binomial test of proportions 
2.3.2  
Poisson sampling and goodness of fit with oneway table Datafile: soccer2002.txt 
2.3.1  
Goodness of fit with X^{2} with G^{2} 
2.5  
Test of independence, and measures of associations for a 2 × 2 table  3.1.5  
Test of independence, and measures of associations for an I × J table  
Test of independence, and measures of associations for an I × J table; simple data visualization 
3.2.3  
Enters tea tasting data and performs onesided and twoside Fisher's exact test for count data.  3.3  
Enters the voters data and performs McNemar's test for 2 × 2 tables  4.2.3  
Cohen's kappa  4.2.5  
Takes the marginal counts specified for by each parameter and using these to estitmate the contents of a specific cell. This is used to test for mutual independence. Also for other independence models.  5.3  
Test for various independence models in a 3way table  5.4.1  
Tests for various independence models in a 3way table (Datafile: berkeley.txt) Loglinear models Simpson's paradox 
5.4.6  
Logistic Regression for 2way tables  6.2.2  
Logistic Regression for 3way tables  6.3.1  
Logistic Regression with continuous covariates  7.1.1  
ROC analysis, plot the ROC curve and a HosmerLemeshow test  7.1.1  ROCandHL.R 
CASE STUDY: The Water Level Study Water Level Study 2 (.doc) WaterStudyLogisticRegression.pdf Datafile: water_level.txt 
7.1.1 

Logistic regression  7.2.1  
Baselinecategory logit model  8.2.2  
Proportionalodds cumulative logit model  8.4.1  cheese.dat cheese.r 
Proportionalodds cumulative logit model Datafile: abortion.txt 
8.4.2  abortion.r 
Poisson Regression  9.2  
Poisson Regression with rates Datafile: creditcard.txt 
9.3  
CASE STUDY: The Ice Cream Study at Penn State 

CASE STUDY: Stress and Smoking Datafile: stress.txt 

Loglinear models for 2 × 2 tables  10.1.2  VitaminCLoglin.R VitaminCLoglin.out 
Loglinear model of independence for twoway table  10.1.3  vote.R 
Loglinear models 3way tables  10.2  berkeleyLoglin.R 
Loglinear models; model assessment and selection 
10.2.9  
Sparse data: Sampling & Structural Zeros  11.1.1  ZerosEx.R 
Sparse data: Incomplete table analysis  11.1.3  health.R health3.R 
Ordinal data: Linear by linear association model  11.2.1  HeartDiseaseLoglin.R 
Dependent data: loglinear models  11.3.2  movies.R 
Dependent data: quasiindependence loglinear model  11.3.5  monkey.R 