Graphics in S-Plus Jagdish S. Gangolly School of Business State University of New York at Albany 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Trellis Graphics I A matrix of graphs Example: >par(mfrow=c(2,2)) # 2 X 2 matrix of figures >x <- 1:100/100:1 >plot(x) # plot cell (1,1) >plot(x, type=“l”) # plot cell (1,2) line >hist(x) # plot cell (2,1) histogram >boxplot(x) # plot cell (2,2) boxplot 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Trellis Graphics II Syntax: Dependent variable ~ explanatory variable |conditioning variable, Data set 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Trellis Graphics III Example: histogram(~height | voice.part, data=singer) No dependent variable for histogram 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Trellis Graphics IV: Singer Data Height is explanatory variable Data set is singer 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Trellis Graphics V: Barley data 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Trellis Graphics VI: Sunspots v. Time 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Trellis Graphics VI: CO2 levels 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Trellis Graphics VII: Scatterplots 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Graphics I: Summary > summary(barley) yield variety year site Min.:14.43333 Svansota,No.462:24 1932:60 Grand Rapids:20 1st Qu.:26.87500 Manchuria:12 1931:60 Duluth:20 Median:32.86667 No. 475:12 University Farm:20 Mean:34.42056 Velvet,Peatland:24 Morris:20 3rd Qu.:41.40000 Glabron:12 Crookston:20 Max.:65.76670 No. 457:12 Waseca:20 Wisconsin No. 38,Trebi:24 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics II: Stem and Leaf Display attach(barley) > stem(yield) N = 120 Median = 32.86667 Quartiles = 26.85, 41.46666 Decimal point is 1 place to the right of the colon 1 : 4 1 : 579 2 : 0011122223333 2 : 555666666667777777889999999 3 : 0000001112222223333344444 3 : 5555667777888899 4 : 000112223334444 4 : 567777779999 5 : 00 5 : 5889 6 : 4 6 : 6 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics III: Quantiles > quantile(yield, seq(0.1, 0.9, by=0.1)) 10% 20% 30% 40% 50% 60% 70% 80% 90% 22.49667 26.08 28.09 29.94667 32.86667 35.13333 38.97333 43.32 47.45666 > > quantile(yield, c(0.25, 0.5, 0.75)) 25% 50% 75% 26.875 32.86667 41.4 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Graphics IV: tapply > tapply(yield, list(site, year), mean) 1932 1931 Grand Rapids 20.81000 29.05334 Duluth 25.70000 30.29333 University Farm 29.50667 35.82667 Morris 41.51333 29.28667 Crookston 31.18000 43.66000 Waseca 41.87000 54.34667 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Graphics V: by by(barley, year, summary) year:1932 yield variety year site Min.:14.43333 Svansota,No. 462:12 1932:60 Grand Rapids:10 1st Qu.:25.48334 Manchuria: 6 1931: 0 Duluth:10 Median:30.98334 No. 475: 6 University Farm:10 Mean:31.76333 Velvet,Peatland:12 Morris:10 3rd Qu.:37.80000 Glabron: 6 Crookston:10 Max.:58.16667 No. 457: 6 Waseca:10 Wisconsin No. 38,Trebi:12 ------------------------------------------------------------------------------------------------- year:1931 yield variety year site Min.:19.70000 Svansota,No. 462:12 1932: 0 Grand Rapids:10 1st Qu.:29.09166 Manchuria: 6 1931:60 Duluth:10 Median:34.20000 No. 475: 6 University Farm:10 Mean:37.07778 Velvet,Peatland:12 Morris:10 3rd Qu.:43.85000 Glabron: 6 Crookston:10 Max.:65.76670 No. 457: 6 Waseca:10 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics VI: histogram > histogram(~yield) 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics VII: histogram in trellis > histogram(~yield | site) 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics VIII: Box-and-Whiskers Plot The boxplot is interpreted as follows: The box itself contains the middle 50% of the data. The upper edge (hinge) of the box indicates the 75th percentile of the data set, and the lower hinge indicates the 25th percentile. The range of the middle two quartiles is known as the inter-quartile range. The line in the box indicates the median value of the data. If the median line within the box is not equidistant from the hinges, then the data is skewed. The ends of the vertical lines or "whiskers" indicate the minimum and maximum data values, unless outliers are present in which case the whiskers extend to a maximum of 1.5 times the inter-quartile range. The points outside the ends of the whiskers are outliers or suspected outliers. 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics IX: Box-and-Whiskers Plot bwplot(site~yield | year, data=barley) 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Graphics X: Box-and-Whiskers Plot in Trellis Graphs bwplot(year~yield | site, data=barley) 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)
Acc 522 Statistical Methods for Business Decisions (J Gangolly) Graphics X: Persp > attach(geyser) > persp(hist2d(waiting, duration)) 12/4/2018 Acc 522 Statistical Methods for Business Decisions (J Gangolly)