# Script for 2010-08-25 # Slight modifications were made # Create a sample of size 1e6 x <- round(rnorm(1e6, mean=1000, sd=1000),0) # Explore the mean-based functions mean(x) mean(x, trim=0.10) mean(x, trim=0.25) mean(x, trim=0.50) sd(x) var(x) # Explore the median-based finctions quantile(x) median(x) range(x) IQR(x) # Create a smaller dataset (n=10) to explain the geometric and harmonic means y <- runif(10)+1 # Recall: n is the sample size (N is the population size) n <- length(y) # (Arithmetic) mean mean(y) # Geometric mean geometricmean <- (prod(y))^(1/length(y)) geometricmean # Harmonic mean harmonicmean <- length(y) / sum(1/y) harmonicmean # # Graphing makes the data more understandable # Stem-and-Leaf plot stem(x) # Histogram hist(x) # Boxplot boxplot(y) # Add an outlier to the dataset v <- c(y,-1) # Show a boxplot of this new data boxplot(v) # Note that the outlier is signified by the circle