• BB852
  • 1 Preface
    • 1.1 How to use this book
    • 1.2 Data wrangling
    • 1.3 Data visualisation
    • 1.4 Statistics
    • 1.5 Data sources
    • 1.6 Your instructor
    • 1.7 Expectations
    • 1.8 Your feedback
    • 1.9 Assessment
    • 1.10 Acknowledgements
  • 2 Schedule
  • 3 Getting set up
    • 3.1 R and RStudio are two different things
    • 3.2 Installing R and RStudio
    • 3.3 A quick tour of RStudio
    • 3.4 Install the course packages
    • 3.5 Get the course data
    • 3.6 Key takeaways
    • 3.7 Common pitfalls recap
    • 3.8 Try this
  • 4 Paths and projects
    • 4.1 File paths in plain language
      • 4.1.1 Absolute paths (full address)
      • 4.1.2 Relative paths (recommended)
    • 4.2 Use an RStudio Project
      • 4.2.1 How to create a project
    • 4.3 Suggested folder structure
    • 4.4 Key takeaways
    • 4.5 Common pitfalls recap
    • 4.6 Try this
  • 5 An R refresher
    • 5.1 Getting started with RStudio
    • 5.2 Getting help
    • 5.3 R as a calculator
    • 5.4 Objects and vectors
    • 5.5 Manipulating vectors
    • 5.6 Missing values, infinity, and NaN
    • 5.7 Data frames
    • 5.8 Classes and factors
    • 5.9 Organising your work and importing data
    • 5.10 Inspecting the data
    • 5.11 Tables and summary statistics
    • 5.12 Basic plotting
    • 5.13 Exercise: Californian bird diversity
      • 5.13.1 The data
      • 5.13.2 Your tasks
    • 5.14 Key takeaways
    • 5.15 Common pitfalls recap
  • 6 Tips and tricks
    • 6.1 Appearance
    • 6.2 Shortcuts (top seven)
    • 6.3 Code style (keep it readable)
    • 6.4 The plots pane
    • 6.5 Tables
    • 6.6 Importing data: common problems
    • 6.7 Key takeaways
    • 6.8 Common pitfalls recap
  • 7 Additional recommended reading
    • 7.1 Books
    • 7.2 Papers and chapters
    • 7.3 Useful websites
  • I Data Wrangling
  • 8 Data wrangling with dplyr
    • 8.1 select
    • 8.2 filter
    • 8.3 arrange
    • 8.4 summarise and group_by
    • 8.5 Using pipes, saving data
    • 8.6 Exercise: Wrangling the Amniote Life History Database
  • 9 Combining data sets
    • 9.1 Using left_join
    • 9.2 Using pivot_longer
    • 9.3 Exercise: Temperature effects on egg laying dates
  • II Data visualisation
  • 10 Visualising data with ggplot2
    • 10.1 The data we will use
    • 10.2 Histograms
    • 10.3 Comparing groups in a histogram
    • 10.4 Facets (split across panels)
    • 10.5 Box plots
    • 10.6 Lines and points (trends over time)
    • 10.7 Scatter plots
    • 10.8 Bar plots (use with care)
    • 10.9 Key takeaways
    • 10.10 Common pitfalls recap
    • 10.11 Mini-project
  • 11 Distributions and summarising data
    • 11.1 Relationships in Data: Response and Explanatory Variables
    • 11.2 Populations, Samples, and Bias
    • 11.3 Probability, odds, and uncertainty
      • 11.3.1 Probability
      • 11.3.2 Odds
      • 11.3.3 Uncertainty and certainty
      • 11.3.4 Probability density
      • 11.3.5 Distributions
    • 11.4 Normal distribution
    • 11.5 How precise is a mean? The standard error
    • 11.6 Comparing normal distributions
    • 11.7 Poisson distribution
    • 11.8 Comparing normal and Poisson distributions
    • 11.9 The law of large numbers
      • 11.9.1 Coin flipping
    • 11.10 Exercise: Virtual dice
  • 12 Pimping your plots
    • 12.1 A basic plot
    • 12.2 Axis limits
    • 12.3 Transforming the axis (log scale)
    • 12.4 Changing the axis tick marks
    • 12.5 Axis labels
    • 12.6 Points hiding other points
    • 12.7 Colours
    • 12.8 Themes
    • 12.9 Moving the legend
    • 12.10 Combining multiple plots
    • 12.11 Saving your plot
    • 12.12 Final word on plots
  • III Statistics
  • 13 Randomisation Tests
    • 13.1 Randomisation test in R
      • 13.1.1 Calculate the observed difference
      • 13.1.2 Null distribution
      • 13.1.3 Testing significance
      • 13.1.4 Testing the hypothesis
      • 13.1.5 Writing it up
    • 13.2 Paired Randomisation Tests
      • 13.2.1 The randomisation test
      • 13.2.2 Null distribution
      • 13.2.3 The formal hypothesis test
    • 13.3 Exercise: Sexual selection in Hercules beetles
  • 14 t-tests: Comparing means
    • 14.1 Some theory
    • 14.2 One sample t-test
    • 14.3 Doing it “by hand” - where does the t-statistic come from?
    • 14.4 Paired t-test
    • 14.5 A paired t-test is a one-sample test
    • 14.6 Two sample t-test
    • 14.7 t-tests are linear models
    • 14.8 Exercise: Sex differences in fine motor skills
    • 14.9 Exercise: Therapy for anorexia
    • 14.10 Exercise: Compare t-tests with randomisation tests (optional)
  • 15 Assumptions in linear models
    • 15.1 The assumptions
    • 15.2 Also check for
    • 15.3 How to check the assumptions
  • 16 ANOVA: Linear models with a single categorical explanatory variable
    • 16.1 One-way ANOVA
    • 16.2 Fitting an ANOVA in R
      • 16.2.1 Where are the differences?
      • 16.2.2 Tukey’s Honestly Significant Difference (HSD)
    • 16.3 ANOVA calculation “by hand”.
    • 16.4 Exercise: Apple tree crop yield
  • 17 Linear regression: models with a single continuous explanatory variable
    • 17.1 Some theory
    • 17.2 Evaluating a hypothesis with a linear regression model
    • 17.3 Assumptions
    • 17.4 Worked example: height-hand length relationship
    • 17.5 Exercise: Chirping crickets
  • 18 ANCOVA: Linear models with categorical and continuous explanatory variables
    • 18.1 The height ~ hand length example.
    • 18.2 Summarising with anova
    • 18.3 The summary of coefficients (summary)
  • 19 n-way ANOVA: Linear models with >1 categorical explanatory variables
    • 19.1 Fitting a two-way ANOVA model
    • 19.2 Summarising the model (anova)
    • 19.3 Summarising the model (summary)
    • 19.4 Exercise: Fish behaviour
  • 20 Evaluating linear models
    • 20.1 R-squared value
    • 20.2 Akaike Information Criterion (AIC)
    • 20.3 Variance partitioning
    • 20.4 Conclusion
  • 21 Generalised linear models
    • 21.1 Count data with Poisson errors.
      • 21.1.1 Example: Number of offspring in foxes.
      • 21.1.2 Example: Cancer clusters
      • 21.1.3 Overdispersion: What It Is and Why It Matters
      • 21.1.4 Overdispersion in practice: elephant poaching
    • 21.2 Exercise: Maze runner
  • 22 Extending use cases of GLM
    • 22.1 Binomial response data
    • 22.2 Example: NFL field goals
      • 22.2.1 DHARMa
      • 22.2.2 Continuing the analysis
    • 22.3 Example: Sex ratio in turtles
    • 22.4 Example: Smoking
    • 22.5 Overdispersion in binomial models
    • 22.6 Exercise: Forensic footprints
  • 23 GLM families and use cases
    • 23.1 Summary Table of GLM Families
    • 23.2 Common GLM Families
    • 23.3 Quasi-family models
  • 24 Power analysis by simulation
    • 24.1 Type I and II errors and statistical power
    • 24.2 What determines statistical power?
    • 24.3 An example of calculating statistical power
      • 24.3.1 The simulation
      • 24.3.2 Some questions for you to address:
    • 24.4 Power for other models
      • 24.4.1 A binomial GLM
      • 24.4.2 A linear regression
    • 24.5 Extending the simulation (optional, advanced)
    • 24.6 Summary
    • 24.7 Exercise 1: Snails on the move
    • 24.8 Exercise 2: Mouse lemur strength
  • IV Appendix
  • 25 Examples of statistics reporting
    • 25.1 General rules
    • 25.2 t-test
    • 25.3 Simple linear regression model
    • 25.4 A generalised linear model (GLM)
    • 25.5 A model with two explanatory variables
  • 26 An example of a past written assignment (2020)
  • 27 Using AI chatbots for help with R
    • 27.1 Introduction
    • 27.2 How AI chatbots work
    • 27.3 Using AI in BB852: the rules
    • 27.4 Ways AI can help with R
      • 27.4.1 Finding errors
      • 27.4.2 Explaining code
      • 27.4.3 Interpreting output
      • 27.4.4 Choosing a model
      • 27.4.5 Improving code and adding comments
      • 27.4.6 Translating code
    • 27.5 When AI gets it wrong
      • 27.5.1 Will it admit that something does not exist?
      • 27.5.2 Do two tools agree?
    • 27.6 Verify, don’t trust
    • 27.7 Tips for good prompts
    • 27.8 Declaring your use of AI
      • 27.8.1 How much detail?
      • 27.8.2 Practice declaration
  • V Solutions
  • 28 Exercise Solutions
    • 28.1 Californian bird diversity
    • 28.2 Wrangling the Amniote Life History Database
    • 28.3 Temperature effects on egg laying dates
    • 28.4 Virtual dice
    • 28.5 Sexual selection in Hercules beetles
    • 28.6 Sex differences in fine motor skills
    • 28.7 Therapy for anorexia
    • 28.8 Compare t-tests with randomisation tests
    • 28.9 Apple tree crop yield
    • 28.10 Chirping crickets
    • 28.11 Fish behaviour
    • 28.12 Maze runner
    • 28.13 Forensic footprints
    • 28.14 Power analysis: questions in the chapter
    • 28.15 Snails on the move
    • 28.16 Mouse lemur strength
  • Published with bookdown

BB852 - Data handling, visualisation and statistics

Chapter 7 Additional recommended reading

Why this section exists

These readings and websites give helpful background, examples, and visual inspiration. None are required, but all are useful if you want to go deeper.

7.1 Books

  • Beckerman, A. P., Childs, D. Z., & Petchey, O. L. (2017). Getting Started with R: An Introduction for Biologists (2nd ed.). Oxford University Press. The course textbook: the Schedule lists the relevant chapter for each session.
  • Wickham, H., Çetinkaya-Rundel, M., & Grolemund, G. (2023). R for Data Science (2nd ed.). O’Reilly. Free online at https://r4ds.hadley.nz. Uses the same dplyr and ggplot2 tools as the data wrangling and data visualisation parts of this book (it writes pipes as |>, which works the same as %>%; see Tips and tricks).
  • Childs, D. Z., et al. APS 240: Data Analysis and Statistics with R. University of Sheffield. Free online at https://dzchilds.github.io/stats-for-bio/. A course book that inspired parts of this one, with more detail on the statistics.

7.2 Papers and chapters

  • Broman, K. W., & Woo, K. H. (2018). Data organization in spreadsheets. The American Statistician, 72(1), 2–10. https://doi.org/10.1080/00031305.2017.1375989. Practical rules for entering and storing data so that it is easy to analyse later (goes with the Data management lecture).
  • Gotelli, N. J., & Ellison, A. M. (2013). Chapter 4, Framing and Testing Hypotheses, in A Primer of Ecological Statistics (2nd ed.). Sinauer. Background for the Hypotheses and questions lecture.
  • Petchey, O., Beckerman, A., & Childs, D. (2009). Shock and awe by statistical software — why R? Bulletin of the British Ecological Society, 40(4), 55–58. Why biologists use R rather than point-and-click software (goes with the Overview and philosophy lecture).
  • Weissgerber, T. L., Milic, N. M., Winham, S. J., & Garovic, V. D. (2015). Beyond bar and line graphs: time for a new data presentation paradigm. PLoS Biology, 13(4), e1002128. https://doi.org/10.1371/journal.pbio.1002128. Why you should show the data, not just bars of means (goes with Visualising data with ggplot2 and Distributions and summarising data).
  • Wickham, H. (2014). Tidy data. Journal of Statistical Software, 59(10), 1–23. https://doi.org/10.18637/jss.v059.i10. The idea behind the data layout used throughout this book (goes with Data wrangling with dplyr and Combining data sets).

7.3 Useful websites

  • The R Graph Gallery: https://www.r-graph-gallery.com/
  • Datanovia ggplot2 tutorials: https://www.datanovia.com/learn/data-visualization/ggplot2/
  • Datanovia R foundations: https://www.datanovia.com/learn/programming/r-foundations/

Tip: Pick one reading and one website and spend 30 minutes exploring. A little browsing goes a long way.