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.

## load data:
dat<-read.csv("data/Type1Type2_data.csv",header=TRUE)
## convert RT to milliseconds:
dat$RT<-dat$RT*1000
## choose critical region:
word_n<-4
## subset critical data:
crit<-subset(dat,Position==word_n)

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 Generalized linear 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.

hindi10<-read.table("data/hindi10.txt",header=TRUE)
skip<-ifelse(hindi10$TFT==0,1,0)
hindi10$skip<-skip
## 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 word complexity and storage cost as predictors, and skipping probability (represented as 0,1 values) as dependent measure. Using anova, 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.