[R] "Special" LS estimation problem

(Ted Harding) Ted.Harding at manchester.ac.uk
Fri Aug 21 19:48:34 CEST 2009


On 21-Aug-09 16:28:26, megh wrote:
> Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error
> 
> Here sampled data for Y, X1, X2 are like that :
> 
> Y <- replicate(10, matrix(rnorm(2),2), simplify = F)
> X1 <- replicate(10, matrix(rnorm(4),2), simplify = F)
> X2 <- replicate(10, matrix(rnorm(4),2), simplify = F)
> 
> My goal is to calculate LS estimates of vectors "a1" and "a2".
> Can anyone please guide me how to do that in R? Is there any
> special function to handle this kind of problem?
> 
> Thanks

In your example, a1 and a2 cannot be vectors, since Y, X1 and X2
are all 2x2 matrices. On the other hand, either or both of a1, a2
could be either a scalar or a 2x2 matrix, any of which would make
X1*a1 + X2*a2 (provided you interpret "*" as "%*%" in R) into a
2x2 matrix. But if (say) a1 is a vector it can only be a 2x1
vector (for multiplication conformity), and then X1*a1 (or X1%*%a1
in R) would be a 2x1 vector (in the linear algebra sense, i.e.
a 2x1 matrix in the R sense).

So what is it that you want in the model?

Next, if in fact a1 and a2 are scalars, then in effect you are
looking at

  Y1[1,1] = a1*X1[1,1] + a2*X2[1,1] + error[1,1]
  Y1[1,2] = a1*X1[1,2] + a2*X2[1,2] + error[1,2]
  Y1[2,1] = a1*X1[2,1] + a2*X2[2,1] + error[2,1]
  Y1[2,2] = a1*X1[2,2] + a2*X2[2,2] + error[2,2]

10 times over. The relevant question here is: Are you wanting
to include possible covariance between the 4 elements of 'error'?

One possibility in this case is to treat this as a multilevel
or longitudinal model, with 4 observations "per subject", and
correlated error within-subject.

But you really need to spell out more detail of the kind of
model you are seeking to fit. What you described is not enough!

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 21-Aug-09                                       Time: 18:48:31
------------------------------ XFMail ------------------------------




More information about the R-help mailing list