我的任务是:
使用leaps包中的regsubsets功能执行详尽的搜索
获得最佳子集回归模型。然后比较为每个
选择的调整r^2
子集大小。根据这个标准,哪种型号最好?你必须
查看summary.regsubsets的组件。在那里你可以找到相关的。
每种尺寸选择的最佳模型的不同最优标准的值。
我有一个数据集cigs,我打电话给
q=regsubsets(Sales~Age+HS+Income+Black+Female+Price, data=cigs, method="exhaustive")
所有这些都是正确的变量
summary(q)
返回
Subset selection object
Call: regsubsets.formula(Sales ~ Age + HS + Income + Black + Female +
Price, data = cigs, method = "exhaustive")
6 Variables (and intercept)
Forced in Forced out
Age FALSE FALSE
HS FALSE FALSE
Income FALSE FALSE
Black FALSE FALSE
Female FALSE FALSE
Price FALSE FALSE
1 subsets of each size up to 6
Selection Algorithm: exhaustive
Age HS Income Black Female Price
1 ( 1 ) " " " " "*" " " " " " "
2 ( 1 ) " " " " "*" " " " " "*"
3 ( 1 ) "*" " " "*" " " " " "*"
4 ( 1 ) "*" " " "*" "*" " " "*"
5 ( 1 ) "*" " " "*" "*" "*" "*"
6 ( 1 ) "*" "*" "*" "*" "*" "*"
知道为什么这不会给我任何关于r^2
的信息?
答案 0 :(得分:1)
您看到的只是regsubsets
对象的打印摘要。如果您输入?regsubsets
,则会看到summary.regsubsets
返回的组件多于打印的组件。要访问例如r^2
,只需输入:
summary_of_q <- summary(q)
summary_of_q$rsq