2

I stumbeled upon the stats::model.matrix function in R. In the description it sais that it would create a design matrix. It gives me a weired number of rows, which does not correspend to neither the number of observations in my data, nor the number of parameters in my model.

What is a design matrix / model matrix?

Here is how i used it:

M03b <- glmer(APMs ~ PrePost + Gf + eyeFRF + (1|content) + (eyeFRF|ID),    data=mlmData, family=binomial("logit"))
X <- model.matrix(M03b)

it gives me a 2895x4 Matrix. ID has 105 levels and content 28, so the number of rows does not make much sense to me. Maybe missing values are an issue?

vanao veneri
  • 970
  • 2
  • 12
  • 31

1 Answers1

5

In a regression model, written in matrix-vector form as

Y = X * B + e,

the matrix X is the design matrix, while Y is the vector of observations on the dependent variable, B is a vector of response coefficients (one for each explanatory variable) and e is a vector containing the values of the model's error term for the various observations. In the design matrix, each column is a vector of observations on one of the explanatory variables.

Thus, the size of X must be such that it is a n X m matrix and B is a m x p matrix, allowing that the product XB is defined only if the number of columns in X is equal to the number of rows in B, in this case m.

Given your 2895x4 dim for X, you should be able to confirm that your B, M03b, has 4 response coefficients.

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
  • Thanks. I actually just figured out that there are 45 missings on one of the predictor variables thus I get 105x28-45 = 2895 rows in that design matrix. – vanao veneri Nov 01 '15 at 19:43