rmatrixmodellmmultivariate-testing

Interpretation of a multivariate linear model


I have a question about the model matrix and parameter matrix of the linear multivariate model fit to the iris data set in R. This is the code (function lm) I am using and the outputs:

> (fm = lm(cbind(iris[,1],iris[,2],iris[,3],iris[,4])~(iris[,5])))

Call:
lm(formula = cbind(iris[, 1], iris[, 2], iris[, 3], iris[, 4]) ~ 
    (iris[, 5]))

Coefficients:
                     [,1]    [,2]    [,3]    [,4]  
(Intercept)           5.006   3.428   1.462   0.246
iris[, 5]versicolor   0.930  -0.658   2.798   1.080
iris[, 5]virginica    1.582  -0.454   4.090   1.780

My objective is to get the decomposition of the model in matrices:

The model matrix A and the 4 by 4 parameter matrix β for the multivariate model X = Aβ + E

From my knowledge the matrix β is the Coefficient matrix just obtained above:

                    [,1]    [,2]    [,3]    [,4]  
(Intercept)           5.006   3.428   1.462   0.246
iris[, 5]versicolor   0.930  -0.658   2.798   1.080
iris[, 5]virginica    1.582  -0.454   4.090   1.780

Therefore, is not the matrix β a 3 by 4 matrix (3 rows and 4 columns) instead of a 4 x 4 matrix?


Solution

  • You can query how R codes the Species predictor:

    contrasts( iris$Species )
    
    ## and verify how this applies to your model matrix:
    
    model.matrix( fm )
    

    In short - you don't need an intercept and 4 parameters. In this case setosa is the intercept. Thus a 3x4. Is this what you were asking for?