# # Exercise 2.3 # # Statistical Methods in Biology: Design and Analysis of Experiments and Regression # by S.J. Welham, S.A. Gezan, S.J. Clark & A. Mead (2014) # Chapman & Hall/CRC Press, Boca Raton, Florida. ISBN: 978-1-4398-0878-8 # Version 1, 16/09/2014 # Set working directory - use setwd() function or from Session menu in RStudio # e.g. setwd("d:/stats4biol/data) # Read data protein <- read.table("protein.dat",sep="",header=T) summary(protein) # Calculate change in proten protein$Change = protein$After - protein$Before # Do one-sample t-test directly t.test(protein$Change, mu=0) # Rest of file verifies t-test calculations # Get mean and variance of protein mean <- mean(protein$Change); mean var <- var(protein$Change); var # Verify these calculations N <- length(protein$Change) # Verify mean sum(protein$Change)/N # Verify variance Deviation <- protein$Change - mean sum(Deviation^2)/(N-1) # Calculate t statistic t <- mean/(sqrt(var/N)); t # Get critical value # = 97.5th quantile of t distribution with 11 df critical <- qt(0.975,N-1); critical # Get observed significance level # = proportion of t distribution with 11 df > abs(t) or < -abs(t) P <- 2*(1-pt(abs(t),N-1)); P # End of file