if(require(tree)) { library( SplitSoftening ) is.even <- function( n ) { return( 0L == n%%2L ) } # An alternative implementation of prediction with softsplits predictSoftsplitsAlt <- function(fit, newdata) { datalen <- nrow(newdata) tmp <- list() for (ri in nrow(fit):1) { # go over all nodes from last to first node <- fit[ri,] if (0L==node$ncat) { # the node is a leaf tmp[[ri]] <- matrix(node$yval, ncol=ncol(node$yval), nrow=datalen, byrow=TRUE) } if (is.even(ri)) { # compute values in the parent node pni <- which(fit$childref==ri)[1] # index of the parent node parent <- fit[pni,] # parent node record # get newdata values of the variable appropriate for the parent's split v <- newdata[[as.integer(factor(parent$var, levels=names(newdata)))]] lower.sub <- as.integer(parent$ncat==1L) lower <- ri+lower.sub upper <- ri+1-lower.sub if (parent$ncat<2L) { # compute probability values sval <- rep(NA, datalen) # init probability values sval[v<=parent$lb] <- 1 sval[v>=parent$ub] <- 0 mv <- v>parent$lb & v=parent$splits & v