Example R programs and commands 5. Box plots, confidence intervals # All lines preceded by the "#" character are my comments. # All other left-justified lines are my input. # Plot 3 data points specifying mean, confidence interval, and range x1 <- c( 1.0, 1.1, 1.5, 1.7, 1.9) x2 <- c( 2.0, 2.1, 2.5, 2.7, 2.9) x3 <- c( 3.0, 3.1, 3.5, 3.7, 3.9) boxplot(list(x1,x2,x3),range=0) # Compute the 95% confidence interval given the mean, standard deviation, # and number of samples: xbar<-3.3 # example mean value xsd<-0.44 # example standard deviation quantiles<-c(0.025,0.975) # 95% lies between 2.5% and 97.5% marks n <- 18 # Number of samples xdf <- n-1 # Degrees of freedom qt(quantiles,xdf) # t values for 95% confidence interval #OUTPUT: [1] -2.109816 2.109816 xbar+ (xsd/sqrt(n))*qt(quantiles,xdf) # confidence interval #OUTPUT: [1] 3.081193 3.518807 # Estimate the standard deviation of the mean from some samples: x<-c(1.1,1.2,1.1,1.4,1.5,1.3,1.2,1.0) # samples mean(x) # average of samples estimates the population mean #OUTPUT: [1] 1.225 sd(x) # sample standard deviation estimates population sd. #OUTPUT: [1] 0.1669046 sd(x)/sqrt(length(x)) # standard deviation of the sample mean #OUTPUT: [1] 0.05900968