[R] lm

Jorge Ivan Velez
2009-06-25T12:16:31Z

Dear Oscar,
Try this:

# Some data
set.seed(123)
a <- matrix(rnorm(100*200), ncol = 200)
b <- matrix(rnorm(100*200), ncol = 200)

# Auxiliar function to extract the coefficient
# after fitting models without intercept
mycoef <- function(x, y) coefficients( lm(y ~ x - 1) )

# Results
res <- sapply(1:200, function(i){
               y <- a[,i]
               x <- b[,i]
              mycoef(x,y)
               }
            )

plot(res)

HTH,

Jorge


On Thu, Jun 25, 2009 at 5:46 AM, Oscar Bayona <osbacan@gmail.com> wrote:

> Hi all,
>
> I want to make multiple least squares estimation on two matrix (without
> intercept)
>
> imagine matrix "a" and matrix "b", I want to
"regress" each colum on matrix
> "a" (dependent variable) on each column of matrix b, I mean,
regress first
> colum on a to first column on b. Second column on a to second column on b.
>
> Imagine "a" and "b" have 200 columns. So I will have
200 estimated
> coefficients.
>
> Why this doesn´´ t function?
>
>
> zza2<-function(){
>
> a<-read.table("a.txt")
> b<-read.table("b.txt")
>
> mrp <-lm(as.matrix(cbind(a)) ~ 0+as.matrix(cbind(b)))
> mr22p<-coefficients(mrp)
>
> plot(mr22p)
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@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.
>
>

	[[alternative HTML version deleted]]