1 Aims of this exercise

In this tutorial you will further sharpen your skills in

  • data wrangling
  • formulating the null and alternative hypothesis of t-tests
  • critically evaluating the assumptions of t-tests,
  • in selecting the appropriate test for answering the research question, and
  • in formulating your conclusion in terms of the research question.

2 Cuckoo dataset

The common cuckoo does not build its own nest: it prefers to lay its eggs in another birds’ nest. It is known, since 1892, that the type of cuckoo bird eggs are different between different locations. In a study from 1940, it was shown that cuckoos return to the same nesting area each year, and that they always pick the same bird species to be a “foster parent” for their eggs.

Over the years, this has lead to the development of geographically determined subspecies of cuckoos. These subspecies have evolved in such a way that their eggs look as similar as possible as those of their foster parents.

The cuckoo dataset contains information on 120 Cuckoo eggs, obtained from randomly selected “foster” nests. For these eggs, researchers have measured the length (in mm) and established the type (species) of foster parent. The type column is coded as follows:

  • type=1: Meadow pipit
  • type=2: Tree pipit
  • type=3: Dunnock
  • type=4: European robin
  • type=5: White wagtail
  • type=6: Eurasian wren

3 Goal

The researchers want to test if the type of foster parent has an effect on the average length of the cuckoo eggs.

In theory, they want to study this for all six species. However, a t-test can only be used to study mean differences between two groups. If we want to analyze multiple groups, there are two options.

  1. We perform t-tests on all pairwise combinations of types. This mean we need to perform n*(n-1)/2 = 15 t-tests.

  2. We perform an ANOVA analysis.

The second strategy is much more efficient and has a higher statistical power. We will learn about ANOVA in chapter 7.

In the current tutorial, we will assess a single pairwise comparison, between the European robin and the European wren. In later tutorials, we revisit this dataset and analyse all data.

4 Import data

First, load the required libraries

...

Data path:

https://raw.githubusercontent.com/statOmics/PSLSData/main/Cuckoo.txt

Import the data, make sure to use the appropriate function for the delimiter used in this file!

...

5 Tidy data

For this exercise, we only care about the European robin and the Eurasian wren. Therefore, we can remove the observations of the other types. In addition, it seems that the tpye column rather than a factor. Let’s fix this:

Cuckoo <- Cuckoo %>%
  filter(type %in% c("4", "6")) %>%
  mutate(type = as.factor(type))

6 Data exploration

How many birds do we have for each type?

Cuckoo %>%
  count(...)

# in base R, you could use the table() function

Visualize the data using a suitable strategy

  1. What do you observe?

  2. How will you model the data?

  3. Translate the research question in a null and alternative hypothesis

  4. Which test will you use to assess the research hypothesis?

  5. Formulate the assumptions of the test and assess the assumptions using diagnostic plots.

  6. If all assumptions to perform the test, complete the analysis and formulate a proper conclusion.

LS0tCnRpdGxlOiAiRXhlcmNpc2UgNS4zOiBIeXBvdGhlc2lzIHRlc3Rpbmcgb24gdGhlIGN1Y2tvbyBkYXRhc2V0IgphdXRob3I6ICJMaWV2ZW4gQ2xlbWVudCwgSmVyb2VuIEdpbGlzIGFuZCBNaWxhbiBNYWxmYWl0IgpkYXRlOiAic3RhdE9taWNzLCBHaGVudCBVbml2ZXJzaXR5IChodHRwczovL3N0YXRvbWljcy5naXRodWIuaW8pIgotLS0KCiMgQWltcyBvZiB0aGlzIGV4ZXJjaXNlCgpJbiB0aGlzIHR1dG9yaWFsIHlvdSB3aWxsIGZ1cnRoZXIgc2hhcnBlbiB5b3VyIHNraWxscyBpbgoKLSBkYXRhIHdyYW5nbGluZwotIGZvcm11bGF0aW5nIHRoZSBudWxsIGFuZCBhbHRlcm5hdGl2ZSBoeXBvdGhlc2lzIG9mIHQtdGVzdHMKLSBjcml0aWNhbGx5IGV2YWx1YXRpbmcgdGhlIGFzc3VtcHRpb25zIG9mIHQtdGVzdHMsCi0gaW4gc2VsZWN0aW5nIHRoZSBhcHByb3ByaWF0ZSB0ZXN0IGZvciBhbnN3ZXJpbmcgdGhlIHJlc2VhcmNoIHF1ZXN0aW9uLCBhbmQKLSBpbiBmb3JtdWxhdGluZyB5b3VyIGNvbmNsdXNpb24gaW4gdGVybXMgb2YgdGhlIHJlc2VhcmNoIHF1ZXN0aW9uLgoKCgojIEN1Y2tvbyBkYXRhc2V0CgpUaGUgY29tbW9uIGN1Y2tvbyBkb2VzIG5vdCBidWlsZCBpdHMgb3duIG5lc3Q6IGl0IHByZWZlcnMKdG8gbGF5IGl0cyBlZ2dzIGluIGFub3RoZXIgYmlyZHMnIG5lc3QuIEl0IGlzIGtub3duLCBzaW5jZ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