2
$\begingroup$

In my dataset I have one independent variable (x) and am trying to determine if knowledge of X can be used to predict the value of any several thousand other dependent variables (Y1, Y2, ...., Y1000).

Is there a simple way to automatically perform single linear (or nonlinear) regression for all of the independent variables simultaneously?

Additionally, would it be possible to create a a table with summaries for the correlation coefficients, F and P values,AIC, etc..., instead of having to calculate the data for each comparison individual comparison (X vs Y1, X vs Y2, etc...)?

$\endgroup$
3
  • $\begingroup$ Besides what has been answered, you can add all your dependent variables in a list and use lapply. The output will be a list of models that can be passed into modelsummary() which will produce a nice table of all relevant statistics. $\endgroup$
    – Dayne
    Commented Mar 14, 2021 at 8:16
  • $\begingroup$ Additionally you may also like to see sur from systemfit package. Seemingly unrelated regression might also fit your requirement. $\endgroup$
    – Dayne
    Commented Mar 14, 2021 at 8:21
  • $\begingroup$ having just started with R, it is hard to know exactly how to use all of these commands, could you provide an example basic code so that i can try it? $\endgroup$ Commented Mar 14, 2021 at 9:29

1 Answer 1

0
$\begingroup$

The lm function does this. If you give it multiple variables on the left-hand side of the model formula it will use the same QR decomposition of the predictor variables on all of them. The time savings aren't huge unless you have lots of predictors.

$\endgroup$
3
  • $\begingroup$ So I would have to write something like lm(x~y1,y2,y3,etc)? Is there no way to make this easier and faster? $\endgroup$ Commented Mar 13, 2021 at 23:51
  • 1
    $\begingroup$ No, lm(y1+y2+y2~x) is what I suggested. Or you could do the matrix operations yourself qr() to get the qr() decomposition of x and then qr.coef() to get the coefficients $\endgroup$ Commented Mar 13, 2021 at 23:59
  • $\begingroup$ Sorry, my knowledge of R (and, it seems, mathematics) is rather limited, so I do not know what do to with the qr() decomposition. Could you give me a practical example, based on the data? $\endgroup$ Commented Mar 14, 2021 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.