reisaw
February 12, 2020, 4:30am
1
Hi, I'm currently learning a multivariate class.
I know that the traditional multiple linear regression model is the univariate model with a single response variable. Thus, we would also have a correspondent residual.
Now here comes the Multivariate Linear Regression when we want to model with multiple response variables. Is there any method that I could fit the Multivariate Linear Regression, and obtain univariate residuals?
I would like to compare the residuals from the Univariate and Multivariate model.
Thanks!
Max
February 14, 2020, 8:51pm
2
They should be the same, at least for ordinary least squares:
mv_mod <- lm(cbind(mpg, wt) ~ ., data = mtcars)
mv_mod
#>
#> Call:
#> lm(formula = cbind(mpg, wt) ~ ., data = mtcars)
#>
#> Coefficients:
#> mpg wt
#> (Intercept) 15.570618 -0.879401
#> cyl 0.119824 -0.062246
#> disp -0.013609 0.007252
#> hp -0.011218 -0.002763
#> drat 1.327261 -0.145385
#> qsec 0.094279 0.195613
#> vs 0.667704 -0.094189
#> am 2.900740 -0.102418
#> gear 1.186497 -0.142945
#> carb -1.329123 0.304068
resid(mv_mod)
#> mpg wt
#> Mazda RX4 -0.9365932 -0.17842754
#> Mazda RX4 Wag -0.9893895 -0.03297082
#> Datsun 710 -4.5867058 0.30577894
#> Hornet 4 Drive 1.0366073 -0.23524638
#> Hornet Sportabout 2.3462788 -0.36059306
#> Valiant -2.4173780 0.03615826
#> Duster 360 1.4214066 -0.40579797
#> Merc 240D 1.5033583 0.10783233
#> Merc 230 -0.3854132 -0.33205269
#> Merc 280 -0.4543157 0.25712184
#> Merc 280C -1.9108831 0.13975403
#> Merc 450SE 0.3560112 0.50381523
#> Merc 450SL 1.2371554 0.12469263
#> Merc 450SLC -0.9005562 0.09644743
#> Cadillac Fleetwood -1.2332895 -0.10785763
#> Lincoln Continental -1.3622341 0.22226885
#> Chrysler Imperial 2.5663091 0.44143401
#> Fiat 128 3.9253258 0.18888586
#> Honda Civic 2.0179626 -0.40769248
#> Toyota Corolla 5.0843265 -0.18752048
#> Toyota Corona -1.5228350 -0.16694957
#> Dodge Challenger -1.1739576 -0.07242897
#> AMC Javelin -2.2226485 -0.08331296
#> Camaro Z28 -0.3643144 0.09643691
#> Pontiac Firebird 3.4806989 -0.26172229
#> Fiat X1-9 -1.1168526 0.03320965
#> Porsche 914-2 -1.0211667 0.23368553
#> Lotus Europa 3.4721306 -0.19067167
#> Ford Pantera L -3.4758598 0.10922903
#> Ferrari Dino 0.2223466 -0.05818496
#> Maserati Bora 2.0498031 -0.26671344
#> Volvo 142E -4.6453275 0.45139236
mpg_mod <- lm(mpg ~ . - wt, data = mtcars)
wt_mod <- lm(wt ~ . - mpg, data = mtcars)
all.equal(
resid(mv_mod)[, "mpg"],
resid(mpg_mod)
)
#> [1] TRUE
all.equal(
resid(mv_mod)[, "wt"],
resid(wt_mod)
)
#> [1] TRUE
Created on 2020-02-14 by the reprex package (v0.3.0)
system
Closed
March 6, 2020, 8:53pm
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.