预测一下明年的国家线

用R建立一个回归模型看一看明年学硕、教育学的国家线

建立数据框

gjx <- data.frame(
  year = c(2017,2018,2019,2020,2021,2022),
  grade = c(310,320,325,331,337,351)
)
gjx

拟合模型

fit1 <- lm(grade~year,data = gjx)
anova(fit1)
summary(fit1)

F=133.55, p=0.0003203, adjusted R-square=0.97
it seems our model works just fine

confint(fit1)

*the table below seems to be the 95% interval of the coefficient *

2.5 % 97.5 %
(Intercept) -18420.406517 -11156.393483
year 5.687247 9.284182

回归诊断

高斯-马尔科夫假设的诊断

par(mfrow=c(2,2))
plot(fit1)
i don't really know this G-M hypothesis shit

其他乱七八糟的诊断

just here for fun, stop doing such boring、 fun-killing、awkward、annoying、painful especially math-ish things plz
                                  -----wise man

回归方程可视化

library(ggplot2)

ggplot(gjx, 
       aes(x=year, y=grade,
           color="#5e616d"))+
  geom_point()+                                               #绘画散点图                        
  stat_smooth(method = lm,color="black")+                     #在散点图加回归拟合线 
  annotate( "text", 
           label = "R^2=0.97",
           parse=T,x=2019,y=300)+    #在图上添加R方
  annotate("text", 
           label = "y=-14790 + 7.486x",
           x=2019,y=305)            #在图上添加方程

ggplot2 is amazing

reference:铭记yu心, R语言|回归分析(一) ———R语言数据分析系列(一), CSDN

2017~2022年的预测值

predict(fit1,
        data.frame(year=2017:2022),
        interval = 'prediction',
        level = 0.95)

new <- data.frame(year=c(2023)) 
### 用于预测的数据名必须与回归中自变量名称相同

well... what could i say since the model nearly precisely predicted the grades of the limit

2023年预测值

predict(fit1,new,interval = 'prediction',level = 0.95)
fit lwr upr
2023 355.2 344.9209 365.4791

*it seems that the limit of first try of PEE would be at least 344, which is not going to happen. and the top of the limit would be, well, 365, then 365 it is *

画个图吧

x <- c(gjx$year,2023)
y <- c(gjx$grade,365)
plot(gjx$year,gjx$grade,
     cex=1,                  #  图形大小
      pch=18,                 # 点类型
     xlim=c(2017,2023),  # x轴范围
     ylim=c(310,370)      # y轴范围
      xlab='年份'         # x、y的坐标名称, lz太懒了没有加上
      ylab='分数')   

lines(x,y,lwd=1.5,col='gray') #画折线

points(2023,365,cex=2,pch=17,col='red') #添加2023年的新点
pic

looks like a exp regression is more suitable? someome who know how to realise it contact me

你可能感兴趣的:(预测一下明年的国家线)