I'm new to R and I'm not a Statistician I'm an Accountant, but I'm finding it an excellent tool for the business analysis work I do. I need to run LM() where both response and predictor are held in matrices. The model follows the form:- regression1 = matrix1.col1 <-> matrix2.col1 regression2 = matrix1.col2<->matrix2.col2 and so on...... I have no problem with the multivariate response but I can't get the function to recognise a tabular predictor. Is this possible without using a loop ? -- View this message in context: http://r.789695.n4.nabble.com/Linear-regression-using-matrices-tp4260945p4260945.html Sent from the R help mailing list archive at Nabble.com.
I've done a lot of research on this very topic and found a few solutions. But all the ways I've discovered involve loops. Applying it to what you want, the best way I've found is to do (stolen from an experienced R user, of course): y<-array(rnorm(100),dim=c(10,10)) x<-array(rnorm(100),dim=c(10,10)) regg<-list() for(i in 1:ncol(y)) { regg[[i]]<-lm(y[,i]~x[,i]) } Now the reason I've stuck onto the list() method is because the output is still in lm() format. So you can write neat functions to extract every statistic you want off summary(regg[[N]]). ----- ---- Isaac Research Assistant Quantitative Finance Faculty, UTS -- View this message in context: http://r.789695.n4.nabble.com/Linear-regression-using-matrices-tp4260945p4260988.html Sent from the R help mailing list archive at Nabble.com.
OK thanks. In my case I think it might be possible to work around this by reshaping my data and then using lmlist() to run separate regressions for each data group. lmlist() is new to me but it looks like it will do the job. -- View this message in context: http://r.789695.n4.nabble.com/Linear-regression-using-matrices-tp4260945p4261368.html Sent from the R help mailing list archive at Nabble.com.
Apparently Analagous Threads
- rownames cannot allocate vector of size
- How do I retrieve column and row names after comparing two matrices?
- Problem with lsa package (data.frame) on Windows XP
- Read data from .csv file as a matrix and compare the different between two matrix
- reordering materix presentation in heatmap.2 in the 'gplots' library