我已定义此功能:
fresults <- function(svrFit,testSet,var) {
library(caret)
if(substr(deparse(substitute(svrFit)), 1, 3)!="svr") {
options(digits=3)
tiff(filename = paste("Predicted vs. Residuals (Train)", "_", deparse(substitute(svrFit)), ".tiff", sep=""),
res = 300, height = 2480, width = 3508, compression = "lzw")
print(xyplot(resid(svrFit) ~ predict(svrFit),
type = c("p", "g"),
xlab=list(label = "Predicted",cex = 2), ylab = list(label = "Residuals",cex = 2),
cex = 1.5, scales = list(cex = 1.5, tick.number = 8)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline( h=0, lty = 1, col = "gray60", lwd=5)
})
dev.off()
}
}
但是当它也应该绘制一条水平线时,它会返回此错误:
Error in printFunction(x, ...) :
argument 2 matches multiple formal arguments
回溯()
5: printFunction(x, ...)
4: print.trellis(xyplot(resid(svrFit) ~ predict(svrFit), type = c("p",
"g"), xlab = list(label = "Predicted", cex = 2), ylab = list(label = "Residuals",
cex = 2), cex = 1.5, scales = list(cex = 1.5, tick.number = 8)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline(h = 0, lty = 1, col = "gray60",
lwd = 5)
})
3: print(xyplot(resid(svrFit) ~ predict(svrFit), type = c("p", "g"),
xlab = list(label = "Predicted", cex = 2), ylab = list(label = "Residuals",
cex = 2), cex = 1.5, scales = list(cex = 1.5, tick.number = 8)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline(h = 0, lty = 1, col = "gray60",
lwd = 5)
})
2: print(xyplot(resid(svrFit) ~ predict(svrFit), type = c("p", "g"),
xlab = list(label = "Predicted", cex = 2), ylab = list(label = "Residuals",
cex = 2), cex = 1.5, scales = list(cex = 1.5, tick.number = 8)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline(h = 0, lty = 1, col = "gray60",
lwd = 5)
}) at Surrogate.R#67
1: fresults(gbmFitRy, testSetRy, "Ry")
我确定解决方案是微不足道的,但我找不到它。谢谢你的帮助。
答案 0 :(得分:2)
plot.trellis
函数(当你使用print
时最终被调用的内容)接受一些panel.*
参数,所以当你传递一个名为panel
的参数时,它不能猜猜你要使用哪一个。并抱怨。只要确保使用完整的参数名称,你应该很高兴。请参阅?plot.trellis
。
编辑:相反,将panel
传递给print.trellis
而不是xyplot
的事实是语法问题的标志,是对括号的错误使用。正确的语法应该是:
print(xyplot(resid(svrFit) ~ predict(svrFit),
type = c("p", "g"),
xlab =list(label = "Predicted",cex = 2),
ylab = list(label = "Residuals",cex = 2),
cex = 1.5, scales = list(cex = 1.5, tick.number = 8),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.abline( h=0, lty = 1, col = "gray60", lwd=5)
}))