前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AIC准则选三个变量的r语言代码

AIC准则选三个变量的r语言代码

作者头像
全栈程序员站长
发布2022-08-31 20:25:46
6080
发布2022-08-31 20:25:46
举报

大家好,又见面了,我是你们的朋友全栈君。

setwd(“C:/Users/IBM/Desktop/研一课程/2.2回归分析/回归作业”) #设定当前的工作目录

shuju=read.table(“shuju.txt”,header=T)

shuju #读取数据

#采用AIC原则自动选择模型-前进法

library(MASS)

stepAIC(lm(y~.,data=shuju[,-1])) #146.11

stepAIC(lm(y~,data=shuju[,-1])) #181.53

stepAIC(lm(y~x3,data=shuju[,-1])) #204.33

stepAIC(lm(y~x4,data=shuju[,-1])) #172.52min

stepAIC(lm(y~x5,data=shuju[,-1])) #182.18

stepAIC(lm(y~x6,data=shuju[,-1])) #172.76

stepAIC(lm(y~x7,data=shuju[,-1])) #204.22

stepAIC(lm(y~x4+x1,data=shuju[,-1])) #155.75min

stepAIC(lm(y~x4+x2,data=shuju[,-1])) #174.14

stepAIC(lm(y~x4+x3,data=shuju[,-1])) #172.9

stepAIC(lm(y~x4+x5,data=shuju[,-1])) #173.71

stepAIC(lm(y~x4+x6,data=shuju[,-1])) #168.67

stepAIC(lm(y~x4+x7,data=shuju[,-1])) #174.35

stepAIC(lm(y~x4+x1+x2,data=shuju[,-1])) #157.21

stepAIC(lm(y~x4+x1+x3,data=shuju[,-1])) #157.5

stepAIC(lm(y~x4+x1+x5,data=shuju[,-1])) #157.65

stepAIC(lm(y~x4+x1+x6,data=shuju[,-1])) #148.55min

stepAIC(lm(y~x4+x1+x7,data=shuju[,-1])) #155.63

setwd(“C:/Users/IBM/Desktop/研一课程/2.2回归分析/回归作业”) #设定当前的工作目录

shuju=read.table(“shuju.txt”,header=T)

shuju #读取数据

#采用AIC原则自动选择模型-后退法

library(MASS)

stepAIC(lm(y~x1+x2+x3+x4+x5+x6,data=shuju[,-1])) #146.11min

stepAIC(lm(y~x1+x2+x3+x4+x5+x7,data=shuju[,-1])) #159.96

stepAIC(lm(y~x1+x2+x3+x6+x5+x7,data=shuju[,-1])) #153.58

stepAIC(lm(y~x1+x2+x6+x4+x5+x7,data=shuju[,-1])) #149.11

stepAIC(lm(y~x1+x6+x3+x4+x5+x7,data=shuju[,-1])) #148.08

stepAIC(lm(y~x6+x2+x3+x4+x5+x7,data=shuju[,-1])) #165.79

stepAIC(lm(y~x1+x2+x3+x4+x5,data=shuju[,-1])) #161.14

stepAIC(lm(y~x1+x2+x3+x4+x6,data=shuju[,-1])) #151.88min

stepAIC(lm(y~x1+x2+x3+x5+x6,data=shuju[,-1])) #153.83

stepAIC(lm(y~x1+x3+x4+x5+x6,data=shuju[,-1])) #150.08

stepAIC(lm(y~x2+x3+x4+x5+x6,data=shuju[,-1])) #163.79

stepAIC(lm(y~x1+x2+x3+x4,data=shuju[,-1])) #159.17

stepAIC(lm(y~x1+x2+x3+x6,data=shuju[,-1])) #152.87

stepAIC(lm(y~x1+x2+x4+x6,data=shuju[,-1])) #150.49

stepAIC(lm(y~x1+x3+x4+x6,data=shuju[,-1])) #150.2min

stepAIC(lm(y~x1+x3+x4,data=shuju[,-1])) #AIC=157.5

stepAIC(lm(y~x1+x3+x6,data=shuju[,-1])) #AIC=155.12

stepAIC(lm(y~x1+x4+x6,data=shuju[,-1])) #AIC=148.55min

years y x1 x2 x3 x4 x5 x6 x7

1974 172.9 11246 681 105.9 10183 4110 11242 9

1975 352.94 10335 791 107.4 10414 3996 12693 6.5

1976 447.67 13156 607 114.4 13134 4689 16681 6

1977 404.02 6127 714 110.8 15033 6876 22131 4.75

1978 409.51 27419 911 99.4 17389 8636 31353 4.75

1979 619.71 25633 1231 91.4 21715 12339 43528 9.5

1980 1121.17 95684 2760 90.8 27075 16623 70752 10

1981 1506.94 105987 2651 86.3 31827 19937 125989 16

1982 1105.79 46230 2105 125.3 35393 24787 99468 10.5

1983 933.03 37165 3030 107.4 38823 25112 82478 10.5

1984 1008.54 48787 2810 106.6 46079 24414 54936 8.5

1985 1567.56 75808 2649 115.7 47871 22970 87135 6

1986 1960.06 123128 3031 110.1 54372 24403 129884 6.5

1987 2884.88 371406 3644 105.8 65602 30531 153044 5

1988 2556.72 198569 3690 101.6 74917 37861 215033 5.25

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/142279.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年5月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档