My code:
#My test wrapper
SL.test <- function(Y.temp, X.temp, newX.temp, family, ...){
fit.test <- glm(Y.temp ~ state, data=X.temp, family=family)
out <- predict(fit.test, newdata=newX.temp, type="response")
fit <- list(object=fit.test)
foo <- list(out=out, fit=fit)
class(foo$fit) <- c("SL.glm")
return(foo)
}
#My library
SL.library <- list("SL.test")
fit <- SuperLearner(Y=data.samp$y, X=data.samp[, c(2:7, 9:11)], SL.library=SL.library,
family=binomial(), method="method.NNLS", verbose=TRUE)
The error:
Error in out[, s] <- testAlg$pred : number of items to replace is not a multiple of replacement length
If I instead fill the SL.library with ready-made wrappers, there are no problems. For example, there are no errors with the following:
SL.library <- list("SL.glm", "SL.mean")
Any ideas would be much appreciated. If helpful, my wrapper is essentially copied from Appendix B (p. 585) to M.J. van der Laan and S. Rose Targeted Learning: Causal Inference for Observational and Experimental Data.