# exercise from last time
letters # returns a through z
letters[1:13] # a through m
letters[1:13*2] # even numbered letters
letters[1:13*2-1] # odd numbered letters
letters[-(1:13*2)] # odd numbered letters
letters[c(1,5,9,15,21)] # vowels
letters[-(c(1,5,9,15,21))] # consonants
vowels <- c(1,5,9,15,21)
letters[-vowels] # consonants again
letters[1:26%%2==1] # odd numbered letters using logical vector
1:26%%2==1 # display logical vector
# can you do anything with just vectors?
# not too chicken to try an example:
beans <- c(179,160,136,227,217,168,108,124,143,140 )
casein <- c(368,390,379,260,404,318,352,359,216,222,283,332)
boxplot(beans,casein)
t.test(beans,casein) # note the default doesn't assume equal variance
t.test(beans,casein,var.equal=T) # your traditional t test
#plot(beans,casein) # doesn't make sense and wont work - differing lengths
plot(c(beans,casein)) # will work, joins them together
# there is more than one dimension
a<-1:100
dim(a) # no dimensions yet
dim(a)<-c(10,10) # give it some (10*10=100)
dim(a) #
a[10,10] # 100
a[100] # 100
a[1,] # row 1
a[,1] # column 1
rn<-c('one','two','three','four','five','six','seven','eight','nine','ten')
rownames(a) <- rn
a['three',]
# lists allow any kind of data to be mixed
alist<-list(a,'cowboys and indians',42)
alist
# a special case of lists is the dataframe.
# a dataframe is a list of vectors all the same length
data(chickwts)
chickwts
str(chickwts)
plot(chickwts[,1]) # scatterplot of everything
plot(chickwts) # scatterplot of weight against feed
hist(chickwts[,1]) # distribution of weights
chickwts$feed # address columns by name
chickwts$weight
levels(chickwts$feed) # investigate propoerties of a factor
nlevels(chickwts$feed)
hist(chickwts$weight)
plot(density(chickwts$w)) #possibly superior view of density
hist(chickwts$w)
plot(weight ~ feed, data=chickwts) # introduce formula interface
windows() # open an additional plotting window
# some statistics
aov(weight ~ feed, data=chickwts) # returns a model fitting object
# (prints highlights)
chickova<-aov(weight ~ feed, data=chickwts) # save
chickova
summary(chickova) # prints traditional ANOVA table
plot(chickova) # plots a series of diagnostic plots
TukeyHSD(chickova) # post-hoc
plot(TukeyHSD(chickova))
##############
## exercise ##
##############
DNase
# data on an elisa assay for DNAse
# 1. try various plots of the DNase standard curve
# example to get started with:
plot(density ~ conc, data=DNase)
# 2. make a new data frame with only run 1 data
# # # the standard curve looks like a parabola. try plotting
# 3. make a plot of only the OD readings < 0.8 (linear region)
# 4. the sqrt() of conc
# 5. or the density ** 2