作业一

a1 = c(25.6,22.2,28.0,29.8)
a2 = c(24.4,30.0,29.0,27.5)
a3 = c(25.0,27.7,23.0,32.2)
a4 = c(28.8,28.0,34.5,25.8)
a5 = c(20.6,21.2,22.0,21.2)
fivemethods = data.frame(result=c(a1,a2,a3,a4,a5),method=factor(c(rep("a1",4),rep("a2",4),rep("a3",4),rep("a4",4),rep("a5",4))))
                         
fit <- aov (result~method,data = fivemethods)
summary(fit)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## method       4  147.4   36.85   3.946 0.0221 *
## Residuals   15  140.1    9.34                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

说明:上述结果中,method为因子,自由度为4,平方和为147.4,均方和为36.85,F检验统计量的值为3.946,检验的p值为0.0221。因为p = 0.0221 < 0.05,故拒绝𝐻0,认为因子(除杂方法)显著,即五种除杂方法对除杂量有显著差别。

作业二

x = c(20,25,30,35,40,45,50,55,60,65)
y = c(13.2,15.1,16.4,17.1,17.9,18.7,19.6,21.2,22.5,24.3)
summary(lm(y~x))
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.67273 -0.33333 -0.07273  0.34545  0.68182 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.12121    0.47708   19.12  5.8e-08 ***
## x            0.22303    0.01063   20.97  2.8e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.483 on 8 degrees of freedom
## Multiple R-squared:  0.9821, Adjusted R-squared:  0.9799 
## F-statistic: 439.8 on 1 and 8 DF,  p-value: 2.805e-08
mylm <- summary(lm(y~x))
plot(x,y,xlab = "温度",ylab = "产量",xlim = c(15,70),ylim = c(13,25),abline(lm(y~x)))
#coefficients
text(x=60,y=18,labels=paste("y=",round(mylm$coefficients[1],3),"+",round(mylm$coefficients[2],3),"x",sep=""))
#R-squared
text(x=60,y=16,labels=paste("R2=",round(mylm$r.squared,3),sep = ""))
#p-value
text(x=60,y=14,labels=paste("p=",signif(mylm$coefficients[2,4],3),sep=""))

说明:回归系数的估计与检验:回归系数的估计为α= 9.12121,β=0.22303。相关分析:相关系数的平方为0.982,表明数据中98.2%可由此回归方程来描述。方程的检验:F分布的p值为2.8e-08,说明方程非常显著。

作业三

x1 = c(35,40,40,42,37,45,43,37,44,42)
x2 = c(60,74,64,71,72,68,78,66,70,65)
y = c(1600,2600,2100,2650,2400,2200,2750,1600,2750,2500)

r=cor(x1,y,use = 'pairwise.complete.obs');r
## [1] 0.6945435
cor.test(x1,y,alternative = c("two.sided"),method = c("pearson"))
## 
##  Pearson's product-moment correlation
## 
## data:  x1 and y
## t = 2.7305, df = 8, p-value = 0.02583
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.115368 0.921288
## sample estimates:
##       cor 
## 0.6945435
r=cor(x2,y,use = 'pairwise.complete.obs');r
## [1] 0.7616519
cor.test(x2,y,alternative = c("two.sided"),method = c("pearson"))
## 
##  Pearson's product-moment correlation
## 
## data:  x2 and y
## t = 3.3246, df = 8, p-value = 0.01047
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2536788 0.9403349
## sample estimates:
##       cor 
## 0.7616519
plot(x1,y,type="p",main="体重、胸围和肺活量的关系",xlab="体重(kg)",ylab="肺活量",xlim=c(35,45),ylim=c(1500,2800))

plot(x2,y,type="p",main="体重、胸围和肺活量的关系",xlab="胸围(cm)",ylab="肺活量",xlim=c(60,75),ylim=c(1500,2800))

说明:对于体重和肺活量,cor=0.695,p值=0.02583<0.05,可见体重和肺活量正相关。 对于胸围和肺活量,cor=0.762,p值=0.01047<0.05,可见胸围和肺活量也正相关。

作业四

探究内蒙古自治区12个盟市2021年GDP和各盟市人口是否存在相关性。如果存在,进行线性回归。2021年呼和浩特市GDP3121.4亿元,344.6万人。包头3293亿元,270.9万人。鄂尔多斯4715.7亿元,215.4万人。锡林郭勒盟1014.74亿元,110.7万人。乌海718.66亿元,55.7万人。通辽1411.44亿元,287.3万人。乌兰察布903.6亿元,170.6万人。兴安盟601.79亿元,141.7万人。赤峰1975.10亿元,403.6万人。呼伦贝尔1355.00亿元,224.3万人。巴彦淖尔983.00亿元,153.9万人。阿拉善盟364.00亿元,26.2万人。

预期结果:因为GDP是在人与人的交易中产生的,所以预测GDP和人口具有正相关关系。

gdp = c(3121.4,3293,4715.7,1014.74,718.66,1411.44,903.6,601.79,1975.10,1355.00,983,364)
pop = c(344.6,270.9,215.4,110.7,55.7,287.3,170.6,141.7,403.6,224.3,153.9,26.2)

r=cor(pop,gdp,use = 'pairwise.complete.obs');r
## [1] 0.5681066
cor.test(pop,gdp,alternative = c("two.sided"),method = c("pearson"))
## 
##  Pearson's product-moment correlation
## 
## data:  pop and gdp
## t = 2.183, df = 10, p-value = 0.05397
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.008598406  0.861218780
## sample estimates:
##       cor 
## 0.5681066
summary(lm(gdp~pop))
## 
## Call:
## lm(formula = gdp ~ pop)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1086.17  -629.41  -294.54    98.45  2910.83 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  366.878    696.909   0.526    0.610  
## pop            6.676      3.058   2.183    0.054 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1149 on 10 degrees of freedom
## Multiple R-squared:  0.3227, Adjusted R-squared:  0.255 
## F-statistic: 4.765 on 1 and 10 DF,  p-value: 0.05397

说明:对于内蒙古各个盟市2021年的GDP和各盟市的人口,cor=0.568,p值=0.05397>0.05,因此不能说两者之间存在显著的相关关系。

mylm <- summary(lm(gdp~pop))
plot(pop,gdp,main="人口-GDP关系",xlab = "人口",ylab = "GDP",xlim = c(25,410),ylim = c(350,5000),abline(lm(gdp~pop)))
#coefficients
text(x=150,y=4000,labels=paste("y=",round(mylm$coefficients[1],3),"+",round(mylm$coefficients[2],3),"x",sep=""))
#R-squared
text(x=150,y=3000,labels=paste("R2=",round(mylm$r.squared,3),sep = ""))
#p-value
text(x=150,y=2000,labels=paste("p=",signif(mylm$coefficients[2,4],3),sep=""))

回归系数的估计与检验:回归系数的估计为α= 366.878,β=6.676。相关分析:相关系数的平方为0.323,表明数据中32.3%可由此回归方程来描述。方程的检验:p值为0.054>0.05,说明方程并不显著。

看图发现,鄂尔多斯距离回归线非常远,虽然人口较少,但是GDP极高。众所周知,鄂尔多斯这个城市有房地产泡沫,不属于正常的城市发展模式,因此我们尝试把鄂尔多斯去掉,再对GDP与人口进行相关性检验和回归分析。

gdp1 = c(3121.4,3293,1014.74,718.66,1411.44,903.6,601.79,1975.10,1355.00,983,364)
pop1 = c(344.6,270.9,110.7,55.7,287.3,170.6,141.7,403.6,224.3,153.9,26.2)

r=cor(pop1,gdp1,use = 'pairwise.complete.obs');r
## [1] 0.7676035
cor.test(pop1,gdp1,alternative = c("two.sided"),method = c("pearson"))
## 
##  Pearson's product-moment correlation
## 
## data:  pop1 and gdp1
## t = 3.5929, df = 9, p-value = 0.005812
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3108767 0.9363302
## sample estimates:
##       cor 
## 0.7676035
summary(lm(gdp1~pop1))
## 
## Call:
## lm(formula = gdp1 ~ pop1)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -752.5 -406.5 -161.9  169.9 1406.5 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  169.469    403.953   0.420  0.68467   
## pop1           6.338      1.764   3.593  0.00581 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 662.4 on 9 degrees of freedom
## Multiple R-squared:  0.5892, Adjusted R-squared:  0.5436 
## F-statistic: 12.91 on 1 and 9 DF,  p-value: 0.005812

说明:去掉鄂尔多斯以后,cor=0.768,p值=0.005812<0.05,可见去掉鄂尔多斯以后,GDP和人口呈现比较显著的正相关关系。

mylm <- summary(lm(gdp1~pop1))
plot(pop1,gdp1,main="去掉鄂尔多斯以后的人口-GDP关系",xlab = "人口",ylab = "GDP",xlim = c(25,410),ylim = c(350,5000),abline(lm(gdp~pop)))
#coefficients
text(x=150,y=4000,labels=paste("y=",round(mylm$coefficients[1],3),"+",round(mylm$coefficients[2],3),"x",sep=""))
#R-squared
text(x=150,y=3000,labels=paste("R2=",round(mylm$r.squared,3),sep = ""))
#p-value
text(x=150,y=2000,labels=paste("p=",signif(mylm$coefficients[2,4],3),sep=""))

回归系数的估计与检验:回归系数的估计为α= 169.469,β=6.338。相关分析:相关系数的平方为0.589,表明数据中58.9%可由此回归方程来描述。方程的检验:p值为0.00581<0.05,说明方程比较显著。

分析:GDP是在人与人交易的过程中产生的。所以,按预计,应该和人口具有正相关关系。

我们发现,鄂尔多斯以外的内蒙其他11个盟市,p值为0.00581,可以说和理论上的预期符合的很好。然而,鄂尔多斯成为了离弦之音,大大破坏了回归方程的可信度。由此可以推测,一般来说,GDP和人口呈正相关的结论是没有太大问题的,只是鄂尔多斯具有特殊性。

我们可以回顾一下鄂尔多斯崛起的历史:2001年开始,大量煤炭企业入驻鄂尔多斯,开始乱暴地采掘鄂尔多斯地区丰富的煤矿资源。这促成了鄂尔多斯资源型经济的大发展,很快形成”羊煤土气”(羊绒、煤矿、高岭土、天然气)的局面。在资源型经济急速扩张的大拆大建过程中,大量热钱涌入市民的口袋。随着鄂尔多斯地价飙升,鄂尔多斯房地产行业急速生长。紧接着,自然而然地,市民手中的热钱被吸引至房地产市场。市民买房,放高利贷,一时成为热潮。这导致鄂尔多斯产生了巨大的房地产泡沫。在广袤无人的大草原上急速扩张的昂贵楼盘,甚至在这片成吉思汗安眠之地塑造了”鬼城”的神奇景观。可以说,鄂尔多斯的经济奇迹是不正常的。

由此,我们可以认为,鄂尔多斯发展的历史,印证了这个数据点具有特殊性的观点。因此,我们把这个不正常的数据点去掉,用剩下的数据点得出GDP和人口具有正相关关系的结论,是具有合理性的。