rm(list=ls())
load("more/bdims.RData")
mdims <- subset(bdims, sex == 1)
fdims <- subset(bdims, sex == 0)Height is normally distributed and clustered somewhat. Mean height for males is 177.7 cm or 5 ft, 10 in. Mean height for females is 164.9 cm or 5 ft, 5 in.
require(ggplot2)
p1<-ggplot(mdims,aes(x=hgt))+geom_histogram(binwidth=1,color="darkblue", fill="lightblue")+theme_bw()+ylim(c(0,30))
p2<-ggplot(fdims,aes(x=hgt))+geom_histogram(binwidth=1,color="darkred", fill="lightpink")+theme_bw()+ylim(c(0,30))
require(gridExtra)
grid.arrange(p1,p2,nrow=1)mdims_sd <- sd(mdims$hgt)*sqrt((length(mdims$hgt)-1)/(length(mdims$hgt)))
mdims_mean <- mean(mdims$hgt)
fdims_sd <- sd(fdims$hgt)*sqrt((length(fdims$hgt)-1)/(length(fdims$hgt)))
fdims_mean <- mean(fdims$hgt)
Z_stat<-(mdims_mean-fdims_mean)/sqrt(mdims_sd^2 + fdims_sd^2)The Z-statistic 1.33 < 1.96 which implies the distribution of height among females and males in this sample are very similar.
fhgtmean <- mean(fdims$hgt)
fhgtsd <- sd(fdims$hgt)
hist(fdims$hgt, probability = TRUE,ylim = c(0, 0.06))
x <- 140:190
y <- dnorm(x = x, mean = fhgtmean, sd = fhgtsd)
lines(x = x, y = y, col = "blue")Yes, the data follow a nearly normal distribution.
qqnorm(fdims$hgt)
qqline(fdims$hgt)sim_norm <- rnorm(n = length(fdims$hgt), mean = fhgtmean, sd = fhgtsd)sim_norm. Do all of the points fall on the line? How does this plot compare to the probability plot for the real data?
Most points fall on the line, though many do not; the plots are almost identical. The points are distributed in astep-like fashion.
qqnorm(sim_norm)
qqline(sim_norm)Even better than comparing the original plot to a single plot generated from a normal distribution is to compare it to many more plots using the following function. It may be helpful to click the zoom button in the plot window.
qqnormsim(fdims$hgt)fdims$hgt look similar to the plots created for the simulated data? That is, do plots provide evidence that the female heights are nearly normal?
The normal probability plot looks very similar; this provides evidence that the female heights are nearly normal.
Female weights are not normally distributed; the tails diverge from the line and two data points stray from the normal distribution.
qqnormsim(fdims$wgt)theory1<-round(pnorm(q = 168, mean = fhgtmean, sd = fhgtsd)*100,1)
empirical1<-round((sum(fdims$hgt < 168) / length(fdims$hgt))*100,1)The theoretical probability that a female randomly chosen from our sample would be shorter than 168 cm (or 5.5 ft) is 68.4%; the empirical probability is 68.5%.
fwgtmean <- mean(fdims$wgt)
fwgtsd <- sd(fdims$wgt)
theory2<-round(pnorm(q = 55, mean = fwgtmean, sd = fwgtsd),1)
empirical2<-round((sum(fdims$wgt < 55) / length(fdims$wgt))*100,1)Now let’s consider some of the other variables in the body dimensions data set. Using the figures at the end of the exercises, match the histogram to its normal probability plot. All of the variables have been standardized (first subtract the mean, then divide by the standard deviation), so the units won’t be of any help. If you are uncertain based on these figures, generate the plots in R to check.
a. The histogram for female biiliac (pelvic) diameter (bii.di) belongs to normal probability plot letter B.
b. The histogram for female elbow diameter (elb.di) belongs to normal probability plot letter C.
c. The histogram for general age (age) belongs to normal probability plot letter D.
d. The histogram for female chest depth (che.de) belongs to normal probability plot letter A.
kne.di). Based on this normal probability plot, is this variable left skewed, symmetric, or right skewed? Use a histogram to confirm your findings.qqnorm(fdims$kne.di)
qqline(fdims$kne.di)
fkne.dimean <- mean(fdims$kne.di)
fkne.disd <- sd(fdims$kne.di)
hist(fdims$kne.di, breaks=100)