# R语言多元(多重)回归

y = a + b1x1 + b2x2 +...bnxn


• y - 是响应变量。
• a，b1，b2 … bn - 是系数。
• x1，x2，… xn - 是预测变量。

### lm()函数

lm()函数在多元回归中的基本语法是 -

lm(y ~ x1+x2+x3...,data)


• formula - 即：y ~ x1+x2+x3...是呈现响应变量和预测变量之间关系的符号。
• data - 是应用公式的向量。

### 示例

input <- mtcars[,c("mpg","disp","hp","wt")]


                   mpg disp  hp    wt
Mazda RX4         21.0  160 110 2.620
Mazda RX4 Wag     21.0  160 110 2.875
Datsun 710        22.8  108  93 2.320
Hornet 4 Drive    21.4  258 110 3.215
Hornet Sportabout 18.7  360 175 3.440
Valiant           18.1  225 105 3.460


input <- mtcars[,c("mpg","disp","hp","wt")]

# Create the relationship model.
model <- lm(mpg~disp+hp+wt, data = input)

# Show the model.
print(model)

# Get the Intercept and coefficients as vector elements.
cat("# # # # The Coefficient Values # # # ","\n")

a <- coef(model)[1]
print(a)

Xdisp <- coef(model)[2]
Xhp <- coef(model)[3]
Xwt <- coef(model)[4]

print(Xdisp)
print(Xhp)
print(Xwt)


Call:
lm(formula = mpg ~ disp + hp + wt, data = input)

Coefficients:
(Intercept)         disp           hp           wt
37.105505      -0.000937        -0.031157    -3.800891

# # # # The Coefficient Values # # #
(Intercept)
37.10551
disp
-0.0009370091
hp
-0.03115655
wt
-3.800891


Y = a+Xdisp.x1+Xhp.x2+Xwt.x3
## 或者
Y = 37.15+(-0.000937)*x1+(-0.0311)*x2+(-3.8008)*x3


Y = 37.15+(-0.000937)*221+(-0.0311)*102+(-3.8008)*2.91 = 22.7104


08-27 1万+

04-21 2万+

04-06 4891

05-23 4313

06-14 1万+

02-27 2万+

11-18 736

08-11 2617

08-11

06-13 5822

11-27 1万+

08-30

02-17

10-23

09-19 1188

02-23 1万+

07-03 3220

10-26

11-18 934

01-08 862

06-05 1万+

07-17

06-14 3万+

06-01 5857

11-08 1万+

04-08 7780

06-03 1万+

04-17 4339

02-16 227

06-08 297

04-19 687

01-31 1665

06-14 5271

06-17 2万+

01-30 77

06-05 1万+

09-29 7375

11-15 1万+

12-18 6834

11-17 2万+

11-07 47

06-02 198

02-24 1万+

01-21 3957

12-13 1万+

05-31 4万+

05-31 1607

08-24 577

04-09 1万+

11-27 5056

04-24 439

12-13 1万+

01-02 2万+

01-31 1109

02-24 1030

07-26

09-03 3万+

06-09 5万+

04-25 4959

02-11 1万+

02-15 6438

12-07 8657

04-18 1万+

01-31 553

07-28 5869

05-12 665

01-16 6327

06-05 1万+

03-26 3万+

08-10 1万+

11-13 4万+

11-24 438

02-21 1229

12-31 2万+

02-24 1万+

04-15 3万+

05-20 88

#### R语言-缺失值处理5

©️2019 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客