r语言多元线性回归_R语言手把手 数理统计5多元线性回归

多元线性回归

new.eg1.csv
677
·
百度网盘
new.eg2.csv
540
·
百度网盘
new.eg3.csv
603
·
百度网盘
new.eg5.csv
490
·
百度网盘

multiple linear regression

##例1:new.eg1
rm(list=ls())
setwd("/Users/sifan/R/datasets")
dat <- read.csv("new.eg1.csv",header=T)
dat

## x1 x2 x3 x4 y
## 1 5.68 1.90 4.53 8.2 11.2
## 2 3.79 1.64 7.32 6.9 8.8
## 3 6.02 3.56 6.95 10.8 12.3
## 4 4.85 1.07 5.88 8.3 11.6
## 5 4.60 2.32 4.05 7.5 13.4
## 6 6.05 0.64 1.42 13.6 18.3
## 7 4.90 8.50 12.60 8.5 11.1
## 8 7.08 3.00 6.75 11.5 12.1
## 9 3.85 2.11 16.28 7.9 9.6
## 10 4.65 0.63 6.59 7.1 8.4
## 11 4.59 1.97 3.61 8.7 9.3
## 12 4.29 1.97 6.61 7.8 10.6
## 13 7.97 1.93 7.57 9.9 8.4
## 14 6.19 1.18 1.42 6.9 9.6
## 15 6.13 2.06 10.35 10.5 10.9
## 16 5.71 1.78 8.53 8.0 10.1
## 17 6.40 2.40 4.53 10.3 14.8
## 18 6.06 3.67 12.79 7.1 9.1
## 19 5.09 1.03 2.53 8.9 10.8
## 20 6.13 1.71 5.28 9.9 10.2
## 21 5.78 3.36 2.96 8.0 13.6
## 22 5.43 1.13 4.31 11.3 14.9
## 23 6.50 6.21 3.47 12.3 16.0
## 24 7.98 7.92 3.37 9.8 13.2
## 25 11.54 10.89 1.20 10.5 20.0
## 26 5.84 0.92 8.61 6.4 13.3
## 27 3.84 1.20 6.45 9.6 10.4

attach(dat)
fit <- lm(y ~ ., data=dat)
fit

##
## Call:
## lm(formula = y ~ ., data = dat)
##
## Coefficients:
## (Intercept) x1 x2 x3 x4
## 5.9433 0.1424 0.3515 -0.2706 0.6382

summary(fit)

##
## Call:
## lm(formula = y ~ ., data = dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.6268 -1.2004 -0.2276 1.5389 4.4467
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.9433 2.8286 2.101 0.0473 *
## x1 0.1424 0.3657 0.390 0.7006
## x2 0.3515 0.2042 1.721 0.0993 .
## x3 -0.2706 0.1214 -2.229 0.0363 *
## x4 0.6382 0.2433 2.623 0.0155 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.01 on 22 degrees of freedom
## Multiple R-squared: 0.6008, Adjusted R-squared: 0.5282
## F-statistic: 8.278 on 4 and 22 DF, p-value: 0.0003121

anova(fit)

## Analysis of Variance Table

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值