Upcoming SlideShare
×

Categorical data with R

4,206 views

Published on

Published in: Education
5 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
4,206
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
104
0
Likes
5
Embeds 0
No embeds

No notes for slide
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• \n
• Categorical data with R

1. 1. Tabulatingdata with 2012-10-22 @HSPHKazuki Yoshida, M.D. MPH-CLE student FREEDOM TO  KNOW
2. 2. Group Website is at:http://rpubs.com/kaz_yos/useR_at_HSPH
3. 3. Previously in this groupn Introductionn Reading Data into R (1)n Reading Data into R (2)n Descriptive statistics Group Website: http://rpubs.com/kaz_yos/useR_at_HSPH
4. 4. Menun Categorical datan How to tabulaten Get sums and proportions
5. 5. Ingredients Epi/Stat Programmingn Tables n data()n Cross tables n table(), summary()n Stratiﬁed tables n prop.table() n addmargins() n xtabs(), ftable() n gmodels::CrossTable() n epiR::epi.2by2() n Creating categorical variables
6. 6. country race gender ethnicity Categorical datacancer stage education level disease severity
7. 7. OpenR Studio
8. 8. Install and Load vcd epiR
9. 9. We will use “Arthritis” dataset in vcd packageLoad built-in dataset Named “Arthritis” data(Arthritis)
10. 10. Indexing: extraction of data from data frameExtract 1st to 17th rows Show all columns Arthritis[1:17 , ] Colon in between Don’t forget comma
11. 11. Treatment vector in Arthritis data frame Five vectors of same length tied together
12. 12. summary of whole dataset summary summary(Arthritis)
14. 14. Accessing a single variable in data set dataset name variable nameArthritis\$Treatment
15. 15. Arthritis\$Treatmentfactor levels (categories)
16. 16. Check factor levels of a vector levels levels(Arthritis\$Treatment)
18. 18. This is an ordered factor
19. 19. factor
20. 20. factor is categorical variable in R
21. 21. Create a singlevariable summary table table(Arthritis\$Improved)
23. 23. Convert tables to proportions prop.table table(table.object)
25. 25. Create cross tables xtabs xtabs(formula = ~ , data = Arthritis)
26. 26. Your turn adopted from Hadley Wickhamn xtabs(~ Treatment +Improved, Arthritis)n xtabs(~ Treatment +Improved +Sex, Arthritis)
27. 27. 2nd dimention 1stdimention 3rd dimention
30. 30. Create flat tables Good for ≥ 3 dimentional ftable ftable(..., exclude = c(NA, NaN), row.vars = NULL, col.vars = NULL)