######################################################################################## ## This code is for distribution shape ## [EMS] Chapter 3 on page 20-21 ## created on Jan. 05, 2007 by Leena Choi ## modified on Jan. 13, 2007 by Leena Choi ######################################################################################## ######################################################################################## ## Distribution Shape on page 20-21 ######################################################################################## ## Symmetrical and Bell-shaped set.seed(191) n <- 636 age <- rnorm(636, 9, 0.7) yes <- c(rep(1, 145), rep(0, 491)) y <- rnorm(636, 0, 1) dd <- density(y, adjust = 1.5,) hist(y, probability = T, nclass=20, axes=F, ylab=" ", xlab="", main="Symmetrical\n Bell-shaped") lines(dd\$x, dd\$y, col=2, lwd=2) abline(v=0, lty=1, col=4, lwd=2) text(2, 0.3, "Density curve", col=2) ## Positively Skewed or Skewed to the right set.seed(191) n <- 1000 age <- rnorm(n, 9, 0.7) y <- 0.6+ 0.1*age + rlnorm(n, meanlog = 0, sdlog = 0.5) dd <- density(y, adjust = 1.5,) hist(y, probability = T, axes=F, nclass=20, ylab=" ", xlab="", main="Positively Skewed\n Skewed to the right") lines(dd\$x, dd\$y, col=2, lwd=2) abline(v=2.27, lty=1, col=4, lwd=2) ## Negatively skewed or Skewed to the left set.seed(191) n <- 1000 age <- rnorm(n, 9, 0.7) y <- 0.6+ 0.1*age - rlnorm(n, meanlog = 0, sdlog = 0.35) dd <- density(y, adjust = 1.5) hist(y, probability = T, axes=F, nclass=20, ylab=" ", xlab="", main="Negatively skewed\n Skewed to the left") lines(dd\$x, dd\$y, col=2, lwd=2) abline(v=0.62, lty=1, col=4, lwd=2) ## Bimodal set.seed(191) n <- 1000 y <- c(rnorm(0.8*n, 20, 6), rnorm(0.2*n, 80, 10)) dd <- density(y, adjust = 1.8,) hist(y, probability = T, axes=F, nclass=20, ylab=" ", xlab="", main="Bimodal", ylim=c(0, 0.05)) lines(dd\$x, dd\$y, col=2, lwd=2)