[R] Regress a matrix on another matrix column by column

Henrique Dallazuanna wwwhsd at gmail.com
Thu Mar 18 14:50:04 CET 2010


Try this:

mapply(function(y, x, z)lm(y ~ x + z), as.data.frame(y),
as.data.frame(x.a), as.data.frame(x.b), SIMPLIFY = FALSE)

On Thu, Mar 18, 2010 at 8:35 AM, Frederick Ho <crescal at gmail.com> wrote:
> Hi everyone,
>
> I have a response matrix (y) and two predictor matrices (x.a, x.b), how
> should i proceed if i want to regress y on x.a and x.b column by column?
>
> To be specific, what i want to do is:
>
> y[,1]~x.a[,1]+x.b[,1]
> y[,2]~x.a[,2]+x.b[,2]
> .
> .
> .
>
> I have tried lm(y~x1+x2) but it does not work as R treat that as:
>
> y[,1]~x.a[,1]+x.a[,2]+...+x.b[,1]+x.b[,2]+...
> .
> .
> .
>
> Thanks.
>
> Regards,
> Fred
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list