>From the equation you write, I don't see why "lsfit" wouldn't work. 
To estimate the covariance matrix of e you could use the sample
covariance matrix of the residuals. If desired, use its cholesky
decomposition to transform to make the error approximately
uncorrelated, then refit (and back-transform the coefficient matrix).

Stacking the columns of Y and replicating X won't do what you write;
it forces each univariate regression to have the same coefficients.
To get what you wrote you would replicate X in blocks of a block-diagonal
matrix. 

I'm not sure I understand the role of W. If what you want is to fit
equations like

y(i) = a(w(i)) + xB(i) + e(i)

for each observation and each response y(1),...,y(p), then I guess you
could just fit each response separately, treating W as a factor. Then
estimate the covariance matrix of e via the residuals as before, etc. 

Reid Huntsinger

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 16, 2003 10:16 AM
To: [EMAIL PROTECTED]
Subject: [R] Multivariate regression in R


Hi Folks,

I want to do multivariate regression in R, i.e. basically
(but with a complication -- see below):

given an Nxp matrix Y of p-variate responses, and an Nxk
matrix X of covariates, to fit the model

  Y = X*B + e

with estimation of the kxp matrix of coefficients B
and estimation of the pxp matrix of covariances between
the p variates in Y.

I haven't managed to find a function/package in R which
seems to address this problem directly (maybe I'm overlooking
a way of using a standard one). One way, of course, could
be to stack the columns of Y on top of each other, replicate
X vertically accordingly, and try to introduce a suitably
structured covariance matrix; but I would like to think
that there's an easier way ... !

The complication: for each row of Y, each of the p variates
is associated with one level of a p-level factor W (on a
permuted basis, so that y1,...,yp are associated with levels
i1,...,ip of W where (i1,...,ip) is a permutation of levels
(1,...,p) of W).

I'm wondering, too, how to represent this in R. In the univariate
case, for instance, the matrix representation for a factor when
regressing y on r levels of a factor F represents the factor as
an Nxr matrix with zeros except for 1s in col j for rows where
y has the level j of F. In the multivariate case, each row of Y
would by analogy be associated with a matrix of factor levels,
one row for each variate in Y, so as to pick out the factor levels
by columns as in the univariate case for that variate.

Any help/advice would be much appreciated!

With thanks,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 167 1972
Date: 16-Jan-03                                       Time: 15:16:12
------------------------------ XFMail ------------------------------

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

------------------------------------------------------------------------------

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to