1 / 22

Data Analysis Using R: 3. Graphical Analyses

Data Analysis Using R: 3. Graphical Analyses. Tuan V. Nguyen Garvan Institute of Medical Research, Sydney, Australia. Overview. Data Barchart Historgram Stripchart Boxplot Scatter plot. Data. Body composition data measured by dual energy X-ray absorptiometry

arnold
Télécharger la présentation

Data Analysis Using R: 3. Graphical Analyses

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Analysis Using R:3. Graphical Analyses Tuan V. Nguyen Garvan Institute of Medical Research, Sydney, Australia

  2. Overview • Data • Barchart • Historgram • Stripchart • Boxplot • Scatter plot

  3. Data • Body composition data measured by dual energy X-ray absorptiometry • 43 men and women, aged between 11 and 28 • Variable names: • id • age • sex • dur • weight • height • lm (lean mass) • pclm (percent lean mass) • fm (fat mass) • pcfm (percent fat mass) • bmc (bone mineral contents)

  4. Reading data into R setwd(“c:/works/stats”) bc <- read.table(“comp.txt”, header=T) attach(bc) names(bc) [1] "id" "age" "sex" "dur" "weight" "height" "lm" "pclm" [9] "fm" "pcfm" "bmc"

  5. View data bc id age sex dur weight height lm pclm fm pcfm bmc 1 1 15 M 5 39 148 32.96 84.50 4.86 12.5 1.33 2 2 16 M 8 45 162 38.16 84.80 4.15 9.2 1.89 3 3 11 M 4 23 132 18.51 80.50 2.99 13.0 0.74 4 4 19 M 9 46 159 35.92 78.10 6.73 14.6 1.59 5 5 19 M 6 56 166 46.63 83.00 5.61 10.2 2.56 6 6 22 M 12 50 152 42.13 84.00 3.93 8.1 2.12 7 7 16 M 8 53 170 45.23 85.00 5.15 9.8 2.21 8 8 12 M 5 35 151 25.26 72.20 9.02 25.6 0.95 9 9 21 M 8 46 166 39.44 85.70 4.64 10.1 2.00 10 10 15 M 6 45 165 38.47 85.50 3.92 8.9 1.70 11 11 13 M 5 32 142 25.50 79.70 4.26 13.9 0.99 12 12 20 M 6 40 153 32.70 82.00 4.66 12.0 1.38 ... 40 40 12 M 10 39 155 33.00 84.60 3.50 9.2 1.43 41 41 15 M 6 45 154 36.00 80.00 5.33 12.5 1.52 42 42 22 M 7 46 157 38.50 84.00 4.63 10.3 1.86 43 43 25 M 13 45 162 37.35 83.00 4.34 10.0 1.70

  6. Counting: barplot freq <- table(sex) barplot(freq) barplot(freq, horiz=T, main="Sex distribution")

  7. Counting by group : barplot agegroup <- cut(age, 3) agesex <- table(sex, agegroup) barplot(agesex)

  8. Counting by group : barplot agegroup <- cut(age, 3) agesex <- table(sex, agegroup) barplot(agesex, xlab="Age group") barplot(agesex, beside=T, xlab="Age group")

  9. Distribution of data: Histogram par(mfrow=c(2,2)) hist(age) hist(age, breaks=20) hist(age, breaks=40) hist(age, breaks=50)

  10. Distribution of data: Histogram par(mfrow=c(2,2)) hist(age) hist(weight) hist(lm) hist(fm)

  11. Distribution of data: plot(density) hist(lm, main="Distribution of lean mass") plot(density(lm), main="Distribution of lean mass")

  12. Normal distribution? qqnorm • qqnorm(lm)

  13. Contiunity of data: stripchart stripchart(lm, xlab=“Lean mass; kg") ?

  14. Summary of continuous data: boxplot boxplot(fm) boxplot(lm) LM Min. 1st Qu. Median Mean 3rd Qu. Max. 18.51 31.91 35.92 35.65 40.14 46.63 FM Min. 1st Qu. Median Mean 3rd Qu. Max. 2.990 4.250 5.270 6.500 8.795 12.800

  15. Summary of data by group: boxplot Fat mass by sex Lean mass by sex boxplot(fm ~ sex) boxplot(lm ~ sex)

  16. Analysis of association: scatter plot plot(lm ~ age) plot(lm ~ age, pch=16)

  17. Analysis of association: scatter plot line <- lm(lm ~ age) plot(lm ~ age, pch=16) abline(line)

  18. Analysis of association by group: scatter plot plot(lm ~ age, pch=ifelse(sex=="M", "M", "F"), xlab="Age", ylab="Kg")

  19. Analysis of multiple associations data <- data.frame(age, weight, lm, fm, bmc) pairs(data)

  20. Analysis of multiple associations – more fancy graph matrix.cor <- function(x, y, digits=2, prefix="", cex.cor){ usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r <- abs(cor(x, y)) txt <- format(c(r, 0.123456789), digits=digits)[1] txt <- paste(prefix, txt, sep="") if(missing(cex.cor)) cex <- 0.8/strwidth(txt) test <- cor.test(x,y) # borrowed from printCoefmat Signif <- symnum(test$p.value, corr = FALSE, na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " ")) text(0.5, 0.5, txt, cex = cex * r) text(.8, .8, Signif, cex=cex, col=2)} pairs(data,lower.panel=panel.smooth, upper.panel=matrix.cor)

  21. Results

  22. Summary • R is a very powerful package for graphical analysis • First step in data analysis: graphical analysis • Look for • Distributions • Differences • Associations

More Related