0

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.

  • The code you have posted is missing a few variable definitions so we cannot run it. Please read [how to make a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for tips on improving your question. Always include all relevant `library()` calls. If we cannot run your code we are unlikely to be able to help you debug it. – MrFlick Jul 27 '14 at 21:44
  • Thanks. It's my first question, so forgive the sloppiness. I'll try to make the suggested fixes. – user1618622 Jul 28 '14 at 02:23

1 Answers1

0

The fix was simple. Changing

foo <- list(out=out, fit=fit)

to

foo <- list(pred=out, fit=fit)

did the trick. Apparently, SuperLearner now requires a wrapper to return a list of two objects: pred and fit.