我正在尝试使用pls
库进行主成分回归,并且我尝试将摘要输出存储到变量c
中但没有成功。这是我的代码
library (pls)
b <- pcr(perm ~ area + peri + shape, data = rock, validation = "CV")
c <- summary(b)
c
NULL
我想要的是将pcr模型的摘要输出存储到变量中,以便稍后可以访问它。 提出这项工作的任何暗示都将是非常难以理解的
答案 0 :(得分:2)
我认为你需要capture.output()
。我记得有一段时间使用它从一个stackoverflow线程本身学习它:
library (pls)
b <- pcr(perm ~ area + peri + shape, data = rock, validation = "CV")
x<-(capture.output(summary(b)))
x
结果:
> x
[1] "Data: \tX dimension: 48 3 " "\tY dimension: 48 1"
[3] "Fit method: svdpc" "Number of components considered: 3"
[5] "" "VALIDATION: RMSEP"
[7] "Cross-validated using 10 random segments." " (Intercept) 1 comps 2 comps 3 comps"
[9] "CV 442.5 394.7 271.2 293.9" "adjCV 442.5 393.9 269.8 290.7"
[11] "" "TRAINING: % variance explained"
[13] " 1 comps 2 comps 3 comps" "X 94.07 100.00 100.00"
[15] "perm 23.01 68.33 70.44"