1 year ago

#314174

test-img

Abhishek Pant

How do I create a loop for multiple iteration of linear regression of OLS with dynamic LHS and RHS?

I have a dataset with multiple columns with variables that I want to check for correlations. My identifier is country code and the remaining are all variables that are to be studied. The goal is to find the top 5/10 linear regressions among all combinations using r square value as comparison attribute. My data looks like:

Country_code | A1 | A2 | A3 |...... | A193

I want to run a simulation that can run lm in loop and have summaries of all combination of attributes in a list so that I can compare their r square value and publish/plot the top 5/10 correlations. It should run like For A1: lm(A1~A2) then lm(A1~A3)..... Next: lm(A2~A3)....

I know I need to put two loops but either the results are not saved because the summary have too many attributes to be pushed into a list, etc.

r

loops

linear-regression

least-squares

0 Answers

Your Answer

Accepted video resources