# Linear regresson with four values as input and two values as output

I have the following problem for a personal project of mine: I am solving a system of two differential equations that has 4 changing parameters. The output are two vectors of numbers. Let's say I am only interested in the final entry of the two soluti0ons, so essentially I have 4 inputs and 2 outputs. What I mean by this is that every time I change the 4 coefficients I get different values in the two final entries of the two vectors of solution x and y.

I want to use linear regression to learn this relationship, by this I mean that I do not want to solve everytime the differential equations but I indeed want to use the linear model that I find by all the data that I have.

How would I formalize this? I am having trouble because my output is a vector so that suggests a multivariate regression model but my input are 4 integers, so I am not too sure on how to proceed.

Any suggestions?

• So you are trying to predict two quantities (dependent variables) given four inputs (independent variable)? This can be done with linear models, it's just a matter of syntax. – user2974951 Jan 11 at 7:47
• That's great! Do you mind elaborating on that a bit? – qcc101 Jan 11 at 17:11
• @user2974951 I mean, I guess what I am trying to do is multivariate multiple regression, is that right? – qcc101 Jan 12 at 13:20

## 1 Answer

This is multivariate multiple regression. In R you could do this with the base lm function, our DV's are mpg and disp, our IV's are cyl, hp and drat from the mtcars data set.

> summary(lm(cbind(mpg,disp)~cyl+hp+drat,data=mtcars))


Which results in the following output, note the two separate outputs, one for each DV.

Response mpg :

Call:
lm(formula = mpg ~ cyl + hp + drat, data = mtcars)

Residuals:
Min      1Q  Median      3Q     Max
-4.2103 -2.0384 -0.0944  1.2891  6.7107

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 22.51406    7.99354   2.817   0.0088 **
cyl         -1.36060    0.73493  -1.851   0.0747 .
hp          -0.02878    0.01530  -1.881   0.0704 .
drat         2.84090    1.52208   1.866   0.0725 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.045 on 28 degrees of freedom
Multiple R-squared:  0.7694,    Adjusted R-squared:  0.7447
F-statistic: 31.14 on 3 and 28 DF,  p-value: 4.616e-09

Response disp :

Call:
lm(formula = disp ~ cyl + hp + drat, data = mtcars)

Residuals:
Min      1Q  Median      3Q     Max
-88.625 -30.192  -5.832  32.559 113.487

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 105.8694   137.1689   0.772  0.44669
cyl          39.3327    12.6113   3.119  0.00418 **
hp            0.4039     0.2625   1.539  0.13514
drat        -49.4274    26.1188  -1.892  0.06882 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 52.26 on 28 degrees of freedom
Multiple R-squared:  0.8394,    Adjusted R-squared:  0.8222
F-statistic: 48.79 on 3 and 28 DF,  p-value: 3.027e-11