5.3 Exercises

5.3.1 Estimating the parameters in a linear model

The data consist of a repeated measures experiment comparing two conditions which are labeled Type 1 and Type 2. The column Sub refers to subject id, and the column ID refers to item id. RT refers to reading time in seconds (we have converted it below to milliseconds); NA is missing data. You can ignore the other columns. This is a standard Latin square design.

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. Notice that there is missing data in this data-set; you have to deal with that complication somehow.

  • 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\) as on slide 33 of the matrix formulation lecture.
  • 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 Type 1 and 2 have no difference in reading time. Is the result of the likelihood ratio test any different from that in Question 1?
  • 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.

5.3.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?

5.3.3 Computing ANOVA by hand

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

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.

5.3.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.

##   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

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

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) (3): 1–12.