Week 4 Lab sheet

Yiling Huo

2024-05-28

All data in the exercises are simulated fake data.

Before the exercises: R operators and loops

If statement

There are two ways to write the if statement in R: the standard if statement, and the ifelse() function.

# If expression1 is true, statement1 will be executed. If expression1 is false but 2 is true, statement2 will be executed. Otherwise, statement3 will be executed. 
if (expression1) {
  statement1
} else if (expression2) {
  statement2
} else {
  statement3
}
# If expression is ture, statement1 will be executed, otherwise statement2 will be executed.
ifelse(expression, statement1, statement2)

While loops and for loops

In a while loop, test_expression is evaluated and the statement is executed if the result is TRUE. Then the expression is evaluated again. A while loop will run repeatedly until text_expression is no longer TRUE.

while (test_expression)
{
statement
}

In a for loop, value takes on each element in the vector sequence. statement is executed in each iteration.

for (value in sequence)
{
statement
}

Exercise 1: Language learning class

A teacher designed three sets of class materials (sets A, B, and C) for a language learning class. The teacher wants to know whether students’ learning outcome differ depending on the set of material used, and/or whether they receive a 10-min revision session after the class. 60 students participated in a round of trial classes: 10 students took part in the class with material set A, and received revision after class; 10 students also took part in the class with material set A, but did not receive revision; and so on.

This study is a 3 x 2 design with Material set (A vs. B vs. C) and Revision (revision vs. no revision).

  1. Download the data Here.
  2. Read the data into a data frame.
  3. Determine which statistical test to use to answer the teacher’s question.
    • How many factors are there in the study?
    • Are the factor(s) between- or within-subject?
    • How many levels does each factor have?
  4. Visualise the data using your preferred type of plot and get descriptive statistics.
  5. Check whether the data meet the assumptions and run the test.
  6. Find out the sizes of the effects.
  7. Report your findings in a short paragraph.

Exercise 2: Negation

Saying an affirmative sentence is true is easier than saying it’s false. For example, saying “A peguin is a bird” is true is easier (takes shorter time) than saying “A dolphin is a fish” is false. A researcher wants to know whether the same can be said about negative sentences.

10 participants took part in an experiment investigating negation processing. In each trial, the participant saw a visual display of a picture together with a sentence that is either congruent or incongruent with the visual display. Half of the sentences were affirmative, while the other half were negative. Participants were asked to jedge the truth value of each sentence. Their reaction time (seconds) was measured.1 Example adapted from Wang, S., Sun, C., Tian, Y., & Breheny, R. (2021). Verifying Negative Sentences. Journal of Psycholinguistic Research, 50(6), 1511-1534. Note that data used in this example is simulated and conclusions may differ from the real experiment.

This study has a 2 x 2 design with Polarity (affirmative vs. negative) and Truth value (true vs. false), resulting in four conditions. Each participant completed 15 trials in each condition.

A table representing the experiment design. (Adapted from Wang, Sun, Tian, & Breheny, 2021)
A table representing the experiment design. (Adapted from Wang, Sun, Tian, & Breheny, 2021)
  1. Download the data Here.
  2. Read the data into a data frame.
  3. Take a look at the data and determine which statistical test to use to anser the question: is reaction time affected by Polarity and/or Truth value?
    • How many factors are there in the study?
    • Are the factor(s) between- or within-subject?
    • How many levels does each factor have?
  4. Convert the independent variables to factors. Hint: data_frame$column_name <- as.factor(data_frame$column_name).
  5. Visualise the data using your preferred type of plot and get descriptive statistics.
  6. Remember we need by-participant (or by-item) means rather than raw data. Convert raw data to by-participant means. Hint: data_mean <- aggregate(DV ~ factor1+factor2+factor3..., data=data_frame, FUN=mean).
  7. Check whether the data meet the assumptions and run the test.
  8. Find out the sizes of the effects.2 ezANOVA automatically reports the generalised eta-squared (ges). This is slightly different from the partial eta-squared in terms of some assumptions, but for our purposes let’s report the generalised eta-squared
  9. Report your findings in a short paragraph.

Exercise 3: Scope and speaker
variability

Suppose there is a language A, where sentences such as “Every girl in this class read her favorite book” can have two different interpretations: either (A) for each girl (e.g. \(x_1\), \(x_2\), \(x_3\),…) in the class, there is a book that she likes (e.g. \(x_1\) likes \(book_1\), \(x_2\) likes \(book_2\), \(x_3\) likes \(book_3\), etc.), and each girl read their respective favorite book; or (B) there is some girl/woman \(x\), such that each girl in this class read \(x\)’s favorite book.

A speaker of language A will wither consistently prefer one or the other of the two readings for this type of sentences. A linguist wants to know whether this kind of speaker variability depends on the region that the speaker is from (south vs. north). 100 native speakers (50 from the south, 50 from the north) read the example sentence and gave their preferred interpretation (A or B).

  1. Download the data Here.
  2. Read the data into a data frame.
  3. Take a look at the data and determine which statistical test to use to answer the linguist’s question.
  4. Transform the data to a frequency table.
  5. Visualise the data using a suitable type of plot and get descriptive statistics.
  6. Run the statistical test.
  7. Report your findings in a short paragraph.