# Extracting model matrices

### Description

This function extracts the fixed-effect design matrix, random-effect design matrix, or the list of variance-covariance matrices whose weighted sum being the variance-covariance matrix of the response variable.

### Usage

1 2 | ```
## S3 method for class 'varComp'
model.matrix(object, what = c("fixed", "random", "varcov", "X", "K", "Z"), ...)
``` |

### Arguments

`object` |
A |

`what` |
A character vector (only the first element will be used) specifying what kind of design matrix is requested. See details. |

`...` |
Not used. |

### Details

`"fixed"`

and `"X"`

are equivalent, requesting the fixed effect design matrix.

`"random"`

and `"Z"`

are equivalent, requesting the random effect design matrix. Note that this is an equivalent version of the design matrices such that the `tcrossprod`

will be the contribution to the marginal variance-covariance. This is not necessarily the one computed directly from the `random`

argument passed to `varComp`

. These are actually computed from `cholRoot`

of *K* matrices.

`"varcov"`

and `"K"`

are equivalent, requesting the contribution of each random effect to the marginal correlation matrix. These are not necessarily the same value passed to the `varcov`

argument of `varComp`

, because the input value will be treated as the "*G*" matrices when `random`

is not missing, but the result here will always be "*K*" matrices. See `varComp`

for notations.

### Value

If `what="fixed"`

or `"X"`

, a single numeric matrix of fixed-effect design matrix.

Otherwise, a list of requested matrices.

### Note

See details on possible confusions.

### Author(s)

Long Qu

### See Also

`varComp`

### Examples

1 2 3 4 5 6 | ```
library(nlme)
data(Oxide)
vcf = varComp(Thickness~Source, Oxide, ~Lot/Wafer)
model.matrix(vcf, 'fixed')
model.matrix(vcf, 'random')
model.matrix(vcf, 'varcov')
``` |

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.