[R] loop issues (r.squared)

andy1983 andy1983 at excite.com
Thu Feb 8 23:45:16 CET 2007


That was a neat trick. However, it created a new problem.

Before, it took way too long for a 10,000 columns to finish.

Now, I test the memory limit. With 10,000 columns, I use up about 1.5 GBs.

Assuming memory is not the issue, I still end up with a huge matrix that is
difficult to export. Is there a way to convert it to 3 columns (1 for row, 1
for column, 1 for value)?

Thanks.



Greg Snow wrote:
> 
> The most straight forward way that I can think of is just:
> 
>> cor(my.mat)^2 # assuming my.mat is the matrix with your data in the
> columns
> 
> That will give you all the R^2 values for regressing 1 column on 1
> column (it is called R-squared for a reason).
> 
> 
>> I would like to compare every column in my matrix with every 
>> other column and get the r-squared. I have been using the 
>> following formula and loops:
>> summary(lm(matrix[,x]~matrix[,y]))$r.squared
>> where x and y are the looping column numbers
>> 
>> If I have 100 columns (10,000 iterations), the loops give me 
>> results in a reasonable time.
>> If I try 10,000 columns, the loops take forever even if there 
>> is no formula inside. I am guessing I can vectorize my code 
>> so that I could eliminate one or both loops. Unfortunately, I 
>> can't figure out how to.
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A--R--loop-issues-%28r.squared%29-tf3196163.html#a8875897
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list