# [R] formula, how to express for transforming the whole model.matrix, data=Orthodont

Peng l12345p2000 at yahoo.com
Sat Mar 15 15:22:16 CET 2003

```Hi, R or S+ users,

I want to make a simple transformation for the model,
but for the whole design matrix.
The model is distance ~ age * Sex, where Sex is a
factor. So the design matrix may look like the
following:
(Intercept) age SexFemale age:SexFemale
1             1   8         0             0
2             1  10         0             0
3             1  12         0             0
4             1  14         0             0
5             1   8         0             0
6             1  10         0             0
7             1  12         0             0
8             1  14         0             0
...
101           1   8         1             8
102           1  10         1            10
103           1  12         1            12
104           1  14         1            14
105           1   8         1             8
106           1  10         1            10
107           1  12         1            12
108           1  14         1            14

I want to have the whole design matrix transformed by
a vector of multiplicator, say c(m1, m2, m3, ... ,
m26, m27 ), for each Subject. Then the design matrix
will look like this.
(Intercept)    age SexFemale age:SexFemale
1            m1    8m1         0             0
2            m1   10m1         0             0
3            m1   12m1         0             0
4            m1   14m1         0             0
5            m2    8m2         0             0
6            m2   10m2         0             0
7            m2   12m2         0             0
8            m2   14m2         0             0
...
101         m26   8m26       m26          8m26
102         m26  10m26       m26         10m26
103         m26  12m26       m26         12m26
104         m26  14m26       m26         14m26
105         m27   8m27       m27          8m27
106         m27  10m27       m27         10m27
107         m27  12m27       m27         12m27
108         m27  14m27       m27         14m27

I tried to add a new column in the data, say "m". But
the following formula expression does not work. Since
Sex is a factor.
y ~ m + I(m*age) + I(m*Sex) + I(m*age*Sex)
Moreover, in order to implement the EM from "Robust
Estimation in Linear Mixed-Effects Models
Using the Multivariate t-Distribution" by Dr.
Pinheiro, I also need to transform the response, y, in
the same way.
I did it by writing SAS liked codes (making a new
table, coding factors, finishing transformation,
making groupedData, call lme), but that is not
readable, and it will be complicated to realized that
for any other datasets.

I am wondering whether the formula has some sorts of
expression to realize transformation for the whole
design matrix, especially when having factors in the
formula.

Thanks a lot!

Peng

Peng Liu
------------------------------
Peng Liu                      |
Division of Statistics        |
Northern Illinois University  |
De Kalb, IL 60115, USA        |
E-mail: pliu at math.niu.edu     |
------------------------------

```