As interpreted by Joe Kunkel from a course in Project-Based Instruction [UMass EDUC 795A] given by Kathy Davis, Fall 2004.
R, a
free-software package and computational environment suitable for simple or complex calculations on most popular computer platforms and operating systems (i.e. PCs, Macs, Windows, Unix, Linux).Download DataSet.
The only quantitative data collected in this approach to the experiment was numbers of drops of fluid that fit on the surface of each coin face. All other data are defined as factors: coin type, coin face, detergent, group. We can use the library functions of the R computational environment to do the analysis of the data. Run the R software program on your computer. Change the working directory to that which houses the data set in the text file named 'CoinData.csv'. Cut and paste the following text into the R-console workspace:
# boxed set 1 of R commands:
# Text preceded by a pound sign is for comments and is not processed in R
dat<-data.frame(read.csv("CoinData.csv")) # Read the data.
saved<-par(mfrow=c(1,3)) # Set up to plot three plots per row in the graphics window.
attach(dat) # Make the data in the data frame callable by their names.
boxplot(drops ~ detergent) # Do a whisker plot of detergent effects on drops.
boxplot(drops ~ coin) # Do a whisker plot of coin effects on drops.
boxplot(drops ~ coin + detergent) # Do a whisker plot of detergent and coin effects on drops.
par(saved) # Reset the plotting environment
This latter boxed set of R commands reads the data file and plots it in three different ways. We can make the plots more readable by resizing the graph window to span the screen width and also by re-phrasing the plot commands to label the plots and make the axis labels more prominent, Fig 1.
# boxed set 2 of R commands:
boxplot(drops ~ coin + detergent, main="Effect of coin-type and detergent on drops held",
cex.main = 2) # Notice that commands can be completed on subsequent lines
Fig 1. Boxplot of coin-type and detergent on drops-per-coin, illustrating specifying the 'main'
title text and doubling the default font size using the 'cex.main' parameter.
While graphical output is intuitive and may prove ones point visually, scientists are devoted to testing hypotheses using statistical tests. We can do this with the R computing environment. We will ask several statistical questions using library functions in R. We do this using the same equation-like grammar that we used with boxplot. Now however we use the lm() function for doing linear regression.
# boxed set 3 of R commands: lm(formula = drops ~ coin + detergent) #Output: #Coefficients: # (Intercept) coin Nic coin Pen coin Qua detergent Yes # 47.771 30.750 7.083 42.083 -23.542
Further, the output of the lm() function can be used by the anova() function to produce an Analysis of Variance (ANOVA) Table (boxed set 4).
# boxed set 4 of R commands: anova(lm(drops ~ coin + detergent)) # Output: # Analysis of Variance Table # Response: drops # Df Sum Sq Mean Sq F value Pr(>F) # coin 3 14040.9 4680.3 12.594 4.829e-06 *** # detergent 1 6650.5 6650.5 17.896 0.0001199 *** # Residuals 43 15979.6 371.6 # --- # Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
This ANOVA Table presents the statistics (F-test) that conclude that there was a very highly significant (***) 'coin-type' effect on drops held by a coin. In addition there is a very highly significant 'detergent' effect on drops held by a coin.
Analysis of all the factors included in the data set can be done but its discussion would perhaps be laborious. Here are the results without comment.
lm(formula = drops ~ coin + detergent + group+ HT) #Output: #Call: #lm(formula = drops ~ coin + detergent + group + HT) #Coefficients: # (Intercept) coin Nic coin Pen coin Qua detergent Yes group C group D HT t # 43.896 30.750 7.083 42.083 -23.542 1.437 2.250 5.292 anova(lm(formula = drops ~ coin + detergent + group+ HT)) #Output #Analysis of Variance Table #Response: drops # Df Sum Sq Mean Sq F value Pr(>F) #coin 3 14040.9 4680.3 11.9992 9.66e-06 *** #detergent 1 6650.5 6650.5 17.0504 0.0001798 *** #group 2 41.5 20.8 0.0533 0.9482084 #HT 1 336.0 336.0 0.8615 0.3588917 #Residuals 40 15602.0 390.0 #--- #Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1