5.5 Exercises

Exercise 5.1 Estimating the parameters in a linear model

The data consist of a repeated measures self-paced reading experiment comparing two conditions, subject and object relatives, in Chinese. The data are from Gibson and Wu (2013).

## load data:
data("df_gibsonwu")
dat <- df_gibsonwu
head(dat)
##     subj item     type   rt
## 94     1   13  obj-ext 1561
## 221    1    6 subj-ext  959
## 341    1    5  obj-ext  582
## 461    1    9  obj-ext  294
## 621    1   14 subj-ext  438
## 753    1    4 subj-ext  286

Using 0,1 contrast coding (treatment contrast coding), fit a simple linear model (not a linear mixed model!) to rt, with type as a predictor. This model is incorrect for the data but we ignore this detail for now.

  • Extract the model/design matrix X from the fitted model.
  • Extract sigma estimate \(\hat\sigma\).
  • Compute \(\hat\sigma (X^TX)^{-1}\).
  • Use the X matrix and the \(y\) vector to estimate the \(\hat\beta\) vector.
  • Compute the variance covariance matrix of \(\hat\beta\).
  • Display the bivariate distribution of the sampling distribution of the intercept \(\hat \beta_0\) and slope \(\hat\beta_1\).
  • What is the correlation between \(\hat \beta_0\) and \(\hat\beta_1\)?

Next, using \(\pm 1\) contrast coding (sum contrast coding), fit a simple linear model (not a linear mixed model!) to rt, with type as a predictor. This model is incorrect for the data but we ignore this detail for now.

  • Extract the model/design matrix X from the fitted model.
  • Extract sigma estimate \(\hat\sigma\).
  • Compute \(\hat\sigma (X^TX)^{-1}\).
  • Use the X matrix and the y vector to estimate the \(\hat\beta\) vector.
  • Compute the variance covariance matrix of \(\hat\beta\).
  • Display the bivariate distribution of the sampling distribution of the intercept \(\hat \beta_0\) and slope \(\hat\beta_1\).
  • What is the correlation between \(\hat \beta_0\) and \(\hat\beta_1\)?
  • Use the likelihood ratio test (use the anova() function in R), find out if we can reject the null hypothesis that the relative clause types have no difference in reading time. Is the result of the likelihood ratio test any different if you carry out a likelihood ratio test for the model with 0,1 contrast coding?
  • Speculate on why there a difference between the correlations of the \(\hat\beta_0\) and \(\hat\beta_1\) in the treatment vs. sum contrast coding you carried out above.

Exercise 5.2 Using ANOVA to carry out hypothesis testing

Using the above data, with the sum contrast coding you defined above, carry out a null hypothesis significance test using the anova() function with an appropriate linear mixed model. What null hypothesis are you testing here, and what is your conclusion?

Exercise 5.3 Computing ANOVA by hand

In this chapter, we saw how the ANOVA is computed in R:

m1 <- lm(y ~ x_c)
m0 <- lm(y ~ 1)
anova(m0, m1)

We also saw how an ANOVA is standardly summarized using matrix notation:

Reproduce this table for the analysis shown above as R code, and show that the results of anova() function (the F-value) above are identical to those produced through this table.

Exercise 5.4 Generalized linear (mixed) model

In the chapter, we saw the following code in connection with the logistic regression model. This is Hindi eyetracking data excerpted from Husain, Vasishth, and Srinivasan (2015). The code below evaluates the effect of various predictors of sentence processing difficulty, such as word complexity and storage cost (SC), on skipping probability.

## display relevant columns:
head(hindi10[, c(1, 2, 3, 24, 33, 34)])
##   subj expt item word_complex SC skip
## 1   10 hnd1    6          0.0  1    1
## 2   10 hnd1    6          0.0  1    1
## 3   10 hnd1    6          0.0  2    0
## 4   10 hnd1    6          1.5  1    1
## 5   10 hnd1    6          0.0  1    1
## 6   10 hnd1    6          0.5  1    0
# fm_skip<-glm(skip ~ word_complex+SC,family=binomial(),hindi10)

Fit a linear mixed model using the function glmer and the link function family=binomial(), with varying intercepts for subject and item, as well as varying slopes if possible, with centered word complexity and storage cost as predictors, and skipping probability (represented as 0,1 values) as dependent measure. Using the anova function, find out whether there is evidence for (a) word complexity, and (b) storage cost affecting skipping probability. Display the effects of these two variables on skipping probability on the probability scale by back-transforming the mean and 95% confidence interval of each effect from the log odds scale to the probability scale.

References

Gibson, Edward, and H-H Iris Wu. 2013. “Processing Chinese Relative Clauses in Context.” Language and Cognitive Processes 28 (1-2): 125–55.
Husain, Samar, Shravan Vasishth, and Narayanan Srinivasan. 2015. “Integration and Prediction Difficulty in Hindi Sentence Comprehension: Evidence from an Eye-Tracking Corpus.” Journal of Eye Movement Research 8(2): 1–12.