我想从主成分回归中提取最低的MSEP。在下面的例子中,我想添加一行代码来说明" [x]的最佳MSE是用[y]组件产生的,"其中[x]是MSEP_object中的最小CV MSE(未调整的CV),[y]是产生该MSE的组件数。
library(MASS)
library(pls)
PCR_fit <- pcr(crim~., data=Boston, scale=TRUE, validation="CV")
MSEP_object <- MSEP(PCR_fit)
答案 0 :(得分:1)
看了之后:
str(MSEP_object)
#------
List of 5
$ val : num [1:2, 1, 1:14] 74.1 74.1 51.8 51.8 51.8 ...
..- attr(*, "dimnames")=List of 3
.. ..$ estimate: chr [1:2] "CV" "adjCV"
.. ..$ response: chr "crim"
.. ..$ model : chr [1:14] "(Intercept)" "1 comps" "2 comps" "3 comps" ...
$ type : chr "MSEP"
$ comps : num [1:14] 0 1 2 3 4 5 6 7 8 9 ...
$ cumulative: logi TRUE
$ call : language MSEP.mvr(object = PCR_fit)
- attr(*, "class")= chr "mvrVal"
很容易看出“CV”-row是MSEP_object$val
访问的数组的第一个维度。
> MSEP_object$val[1,1, ]
(Intercept) 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps
74.13309 51.81121 51.77481 45.79611 45.60764 45.84421 46.42630
7 comps 8 comps 9 comps 10 comps 11 comps 12 comps 13 comps
46.32160 44.53877 44.83946 45.02798 44.91884 44.49455 43.51062
> which.min(MSEP_object$val[1,1, ] )
13 comps
14
我不会称之为“最佳”,因为这意味着某种统计判断,但宁可暗示:
paste( "Minimum MSE of ",
MSEP_object$val[1,1, ][ which.min(MSEP_object$val[1,1, ] )],
" was produced with ",
sub(" comps","", names(which.min(MSEP_object$val[1,1, ] ))),
" components")
#[1] "Minimum MSE of 43.51061955445 was produced with 13 components"