码迷,mamicode.com
首页 > 编程语言 > 详细

数学建模算法(八):线性回归

时间:2016-01-21 23:49:41      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:

1.多元线性回归

 

pho<-c(
  0.69907424,    0.731751977,    0.82038317,    0.817860678,    0.793782346,    0.791145196 

)
waitt<-c(
  6.746842414,    7.033822049,    7.951127237,    7.92172466,    7.65163524,    7.623168881

)
pho<-log(pho)
waitt<-log(waitt)
m1<-30*c(10,25,14,14,0,0)  #for driver
m2<-30*c(10,150,100,100,100,100)   #for customers
data1<-data.frame(pho,m1,m2)
data2<-data.frame(waitt,m1,m2)
fit1<-lm(pho~m1+m2+m1*m2,data = data1)
summary(fit1)
fit2<-lm(waitt~m1+m2+m1*m2,data=data2)
summary(fit2)

library(car)
ncvTest(fit1)
ncvTest(fit2)
#计分检验不显著(P>0.05),说明满足方差不变假设

2.线性回归

data1<-c(
  2.6,1.1,1,1.8,1.9,3.9,8.1,8.1,8.1,8.3,7.2,6.6,8.3,6.2,8.7,6.6,5.3,5.5,8.5,3.5
  ,3.8,0.8,0.6,2.3,2.5,4,8.7,8.6,8.6,8.6,8.1,7.6,9.4,8,9.2,8,6.5,6.2,9.4,3.6
  ,2.3,1.1,1.4,1.8,2.1,4.9,8.4,8.6,8.7,8.8,8.6,8.3,9,8.7,9,8.1,8.3,8.2,8.8,3.5
  ,2.5,0.8,1,1.3,1.6,3,7.6,8.1,8.4,8.8,6.4,6.1,8.3,5.2,8.7,5.2,5.1,5,8.5,3
  ,3,1.2,0.9,2.1,2,5.2,8.4,8.4,8.4,8.5,6.9,5.9,6.6,5.4,8.8,5.4,4.7,5.5,8.2,3.8
  ,3,1,0.6,1.9,2.2,3.3,7.7,8.3,8.1,8.3,7,5.9,9.3,8,8.9,8,6.9,4.6,9.4,3.7
  ,3.9,0.8,1.2,2.3,2.6,5.2,8.7,8.5,8.6,8.6,8.5,8.5,9.2,8.3,9.4,8.3,6.5,7.1,9.2,3.1
  ,1.8,1.1,1.4,1.4,2,4.5,7,6.7,6,6.9,6.8,5.9,6.5,5.3,8.6,5.3,4.7,5.2,7.3,2.9
  ,3.8,1.4,1.1,2,1.8,4.2,8.4,8.5,8.6,8.8,8.1,7,8.8,6.9,8.9,6.9,6.1,6.9,9,5.4
  ,1.3,0.9,1.3,1.9,2.1,3.6,8,7.8,8.6,8.5,6.7,6.5,5.7,5.8,8.2,5.8,5.4,4.9,7.2,2
  ,0.5,1.1,1.1,1.2,2,5,5.6,7.2,7.8,8.1,5,4.1,3.4,3.3,7.6,3.3,2.9,3,6.7,1.5
  
)
value<-matrix(data1,nrow=20)
 data2<-c(
   34.2,42.2,49.9,39.9,38.3,31.4,24.8,24,24.2,23.2,25.2,26.4,23.2,26.1,21.5,26.1,27.7,27.7,22.4,31.9
   ,31,44.1,47,35.1,33.1,28,21.1,21.7,21.9,20.5,22.4,23.5,18.1,22.8,17.6,22.8,24.4,25.1,18.1,29.1
   ,34.3,44.1,46.8,38.3,37.2,30.9,24.2,22.9,23.5,22.6,22.4,24.2,21.7,23,20.2,23,23.9,24.6,21.2,31
   ,36.5,49.9,52.6,43.8,43.3,35.5,27.9,25.6,24.5,23.3,26.6,28.8,25.1,29.3,23.3,29.3,31.1,30,23,35.4
   ,32.5,36,54.7,42,39.8,30.8,24.9,24.2,24.5,23.6,26.4,27.6,27.7,30.8,23.6,30.8,31.9,29.1,25.4,33
   ,31,40.3,42.9,35.5,32.8,27.8,21.9,21.4,21.5,20.1,21.7,22.4,17.1,21,18,21,22.4,25.1,17.4,27.5
   ,30,44.1,47,33.9,31.7,26.6,21,21.3,21.4,20.6,21.1,22.4,19,22.6,16.3,22.6,24.5,23.7,18.9,28.9
   ,35.9,44.5,47.5,40,36.8,29.7,25.8,24.8,24.8,24,24.5,26.3,24.1,25.2,20.3,25.2,26.5,25.7,23.7,31.5
   ,29.8,39,51.1,41.1,39.7,32.1,23.7,23.3,23.5,22.5,25.2,25.9,22.7,26.5,22.5,26.5,27.8,27.9,21.3,29.2
   ,43.4,47.3,48.1,37.5,38.2,32,25,23.6,23.4,22.8,25.9,27.4,26.8,27.3,24.5,27.3,28.3,30.4,24.3,37.2
   ,43.7,48.6,51.8,43,40.8,29.5,26.4,25.3,26.1,24,28.7,27.8,30.4,32.2,23.1,32.2,32.7,26.6,26.7,39.1
   
 ) 
#vctor<-matrix(data2,nrow=20)

dataf<-data.frame(data1,data2)
fit<-lm(data2~data1,data=dataf)
summary(fit)

 

数学建模算法(八):线性回归

标签:

原文地址:http://www.cnblogs.com/pursuit1996/p/5149631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!