# mixed model variance-covariance matrix| parameter estimation

I am fairly new to LMM's and I am trying to undestand how the parameter estimation happens; According to this:

Beta is obtained with equation 13.28. Beta is supposed to be the parameters for the fixed effects, X stands here for the design matrix for the fixed effects V is the variance-covariance matrix and y is the response value.

However, I don't understand how to obtain matrix V and the book I am using "linear mixed effect models using R by Galecki and Burzykowski is not really clear in it either).

I have tried obtaining the matrix V in R with the following command Cov(Y, X), This returns a vector of 1x7 (which makes sense I have 7 fixed variables; but with this I cannot calculate Beta since V is supposed to be a square matrix.

Any help would be appreciated

First, it helps to consider what dimension the matrix $$V_i^{-1}$$ needs to have so that the given matrix products are defined. You'll find that it needs to be a square matrix of dimension $$n_i \times n_i$$, where $$n_i$$ is the length of the vector $$y_i$$ (as well as the number of rows of $$X_i$$). In the book's nomenclature, $$y_i$$ is the vector of observations in some group $$i$$. Therefore, it becomes clear that $$V_i$$ has to be the VCV-matrix of responses in group $$i$$, $$y_i$$. (Side note: the estimator in (13.28) is of the form $$(X'W^{-1}X')^{-1}X'W^{-1}y$$, which would be the Generalized Least Squares (GLS) estimator for $$\beta$$, if the response $$y$$ were known to have the VCV-matrix $$W$$. It is not exactly the GLS estimator, because the VCV-matrix does actually depend on an unknown parameter $$\theta$$ which has to be estimated.)
Spoiler alert: from (13.25) and (13.26) of the book, you see that $$V_i = \sigma^2(Z_iDZ_i' + R_i),$$ where $$Z_i$$ is the matrix of regressors for the random effects of group $$i$$, $$D$$ is the VCV matrix of random effects, $$R_i$$ is the correlation matrix of the residuals in group $$i$$, and $$\sigma^2$$ is the residual variance. You'll obtain the whole matrix $$V$$ as a block diagonal matrix with the matrices $$V_i$$ on the diagonal.