predict
用参数object
和定义...
。我导出了一个类似 PCA 的模型,我称之为 pcaadd 并编写了一个predict.pcaadd
函数。到现在为止还挺好。现在我想添加一个 (S4) 方法,该方法适用于object
签名和(signature )"pcaadd"
中的特定类型的对象 。newdata
"hyperSpec"
(如何)如果泛型是用 object
且...
仅定义的,我可以这样做吗?
这是我目前所做的:检查类newdata
并进行适当的处理,但这似乎不是一个干净的解决方案:
predict.pcaadd <- function (object, newdata, ...){
## deal with class "hyperSpec"
if (is (newdata, "hyperSpec")){
validObject (newdata)
## extract the matrix that is used for the prediction
newdata <- newdata [[]]
}
## default part of prediction
tmp <- predict (object$pca, newdata)
tcrossprod (tmp [, - object$refcomps], object$pca$rotation [, -object$refcomps])
}