Skip to content

Commit

Permalink
Updates for issue #560
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Kuhn authored and Max Kuhn committed Dec 27, 2016
1 parent 4b5f580 commit 7fa8aed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 7 additions & 8 deletions models/files/gamboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ modelInfo <- list(label = "Boosted Generalized Additive Model",
fit = function(x, y, wts, param, lev, last, classProbs, ...) {
##check for control list and over-write mstop
theDots <- list(...)
if(any(names(theDots) == "control"))
{
if(any(names(theDots) == "control")) {
theDots$control$mstop <- param$mstop
ctl <- theDots$control
theDots$control <- NULL
Expand All @@ -40,7 +39,8 @@ modelInfo <- list(label = "Boosted Generalized Additive Model",

dat <- if(is.data.frame(x)) x else as.data.frame(x)
dat$.outcome <- y
modelArgs <- c(list(formula = as.formula(".outcome ~ ."), data = dat, control = ctl),
modelArgs <- c(list(formula = as.formula(".outcome ~ ."),
data = dat, control = ctl),
theDots)

out <- do.call("gamboost", modelArgs)
Expand Down Expand Up @@ -95,8 +95,8 @@ modelInfo <- list(label = "Boosted Generalized Additive Model",
},
prob = function(modelFit, newdata, submodels = NULL) {
if(!is.data.frame(newdata)) newdata <- as.data.frame(newdata)
lp <- predict(modelFit, newdata)
out <- cbind( binomial()$linkinv(-lp), 1 - binomial()$linkinv(-lp))
probs <- predict(modelFit, newdata, type = "response")
out <- cbind(1 - probs, probs)
colnames(out) <- modelFit$obsLevels
if(!is.null(submodels)) {
tmp <- vector(mode = "list", length = nrow(submodels) + 1)
Expand All @@ -106,9 +106,8 @@ modelInfo <- list(label = "Boosted Generalized Additive Model",
submodels$mstop[j] > modelFit$.org.mstop)
modelFit$.org.mstop else submodels$mstop[j]

tmpProb <- predict(modelFit[this_mstop], newdata)
tmpProb <- cbind(binomial()$linkinv(-tmpProb),
1 - binomial()$linkinv(-tmpProb))
tmpProb <- predict(modelFit[this_mstop], newdata, type = "response")
tmpProb <- cbind(1 - tmpProb, tmpProb)
colnames(tmpProb) <- modelFit$obsLevels
tmp[[j+1]] <- as.data.frame(tmpProb[, modelFit$obsLevels,drop = FALSE])
}
Expand Down
15 changes: 7 additions & 8 deletions models/files/glmboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ modelInfo <- list(label = "Boosted Generalized Linear Model",
fit = function(x, y, wts, param, lev, last, classProbs, ...) {
##check for control list and over-write mstop
theDots <- list(...)
if(any(names(theDots) == "control"))
{
if(any(names(theDots) == "control")) {
theDots$control$mstop <- param$mstop
ctl <- theDots$control
theDots$control <- NULL
Expand All @@ -40,7 +39,8 @@ modelInfo <- list(label = "Boosted Generalized Linear Model",

dat <- if(is.data.frame(x)) x else as.data.frame(x)
dat$.outcome <- y
modelArgs <- c(list(formula = as.formula(".outcome ~ ."), data = dat, control = ctl),
modelArgs <- c(list(formula = as.formula(".outcome ~ ."),
data = dat, control = ctl),
theDots)
out <- do.call(mboost:::glmboost.formula, modelArgs)

Expand Down Expand Up @@ -95,8 +95,8 @@ modelInfo <- list(label = "Boosted Generalized Linear Model",
},
prob = function(modelFit, newdata, submodels = NULL) {
if(!is.data.frame(newdata)) newdata <- as.data.frame(newdata)
lp <- predict(modelFit, newdata)
out <- cbind( binomial()$linkinv(-lp), 1 - binomial()$linkinv(-lp))
probs <- predict(modelFit, newdata, type = "response")
out <- cbind(1 - probs, probs)
colnames(out) <- modelFit$obsLevels
if(!is.null(submodels)) {
tmp <- vector(mode = "list", length = nrow(submodels) + 1)
Expand All @@ -106,9 +106,8 @@ modelInfo <- list(label = "Boosted Generalized Linear Model",
submodels$mstop[j] > modelFit$.org.mstop)
modelFit$.org.mstop else submodels$mstop[j]

tmpProb <- predict(modelFit[this_mstop], newdata)
tmpProb <- cbind(binomial()$linkinv(-tmpProb),
1 - binomial()$linkinv(-tmpProb))
tmpProb <- predict(modelFit[this_mstop], newdata, type = "response")
tmpProb <- cbind(1 - tmpProb, tmpProb)
colnames(tmpProb) <- modelFit$obsLevels
tmp[[j+1]] <- as.data.frame(tmpProb[, modelFit$obsLevels,drop = FALSE])
}
Expand Down

0 comments on commit 7fa8aed

Please sign in to comment.