- Plot histograms of each length and (separately) of weight by
year and species.
require(lattice)
histogram(~length|factor(year)*species, rubyFish)
- Use tapply or by to obtain mean and SD for length and for
weight at each year/species combination.
round(with(rubyFish, tapply(length, list(species, year), mean)),0)
- What changes in data collection occurred
over the course of the study? Fix them so the data are all
comparable. (Hint: use ifelse so you don't have to split the
data into "OK" and "not OK")
- Redo the plots and summaries and comment on distributions across
years and species.
- Plot weight as a function of length separately for each
species. Lattice xyplot would do this nicely, but then we
wouldn't be able to identify unusual fish, so do it in two
separate plots and click on each outlying point to see which row
of data it comes from. Click the middle mouse button when you're
done.
par(mfrow=c(1,2))
plot(weight ~ length , data =rubyFish, subset=species=="Brn")
oddballBrns <- with(subset(rubyFish, species=="Brn"), identify(x=length,
y = weight))
subset(rubyFish, species=="Brn")[oddballBrns, ]
Repeat the last three lines for the rainbows.
- What do you think we should do with the unusual fish you
identified? Discuss plusses and minuses of at least 2
options. Can you tell that some are recorded wrong? If so
fix the probable error, if not remove them.
- Use an ftable command to see how many fish were captured at
each site/species/year combination.
with(rubyFish, ftable(year,species,site))