Skip to content

Commit

Permalink
Changed so it will predict with se.fit when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinErickson committed Oct 30, 2017
1 parent 0e43f90 commit e599b7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/mbc.R
Expand Up @@ -306,8 +306,10 @@ mbc <- function(..., times=5, input, inputi, evaluator, post, target, targetin,
} else {
targetinj <- targetin
}
po <- predict(po, targetinj)
po <- predict(po, targetinj, se.fit=any(c("t","mis90","sr27") %in% metric))
# }
} else {
targetinj <- NULL
}
# Run
if (!missing(target)) {
Expand All @@ -324,6 +326,7 @@ mbc <- function(..., times=5, input, inputi, evaluator, post, target, targetin,
if ("t" %in% metric) {
targetj <- if (is.function(target)) {target(j)}
else if (is.list(target)) {target[[j]]}
else if (is.character(target) && !is.character(po) && (target%in%names(targetinj))) {targetinj[[target]]}
else if (is.character(target) && !is.character(po)) {input[[target]]}
else {target}
po.mean <- if ("fit" %in% names(po)) po$fit else if ("mean" %in% names(po)) po$mean else {stop("Can't get fit/mean from post/out")}
Expand All @@ -336,6 +339,7 @@ mbc <- function(..., times=5, input, inputi, evaluator, post, target, targetin,
if ("mis90" %in% metric) {
targetj <- if (is.function(target)) {target(j)}
else if (is.list(target)) {target[[j]]}
else if (is.character(target) && !is.character(po) && (target%in%names(targetinj))) {targetinj[[target]]}
else if (is.character(target) && !is.character(po)) {input[[target]]}
else {target}
po.mean <- if ("fit" %in% names(po)) po$fit else if ("mean" %in% names(po)) po$mean else {stop("Can't get fit/mean from post/out")}
Expand All @@ -349,6 +353,7 @@ mbc <- function(..., times=5, input, inputi, evaluator, post, target, targetin,
if ("sr27" %in% metric) {
targetj <- if (is.function(target)) {target(j)}
else if (is.list(target)) {target[[j]]}
else if (is.character(target) && !is.character(po) && (target%in%names(targetinj))) {targetinj[[target]]}
else if (is.character(target) && !is.character(po)) {input[[target]]}
else {target}
po.mean <- if ("fit" %in% names(po)) po$fit else if ("mean" %in% names(po)) po$mean else {stop("Can't get fit/mean from post/out")}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_mbc.R
Expand Up @@ -100,6 +100,7 @@ test_that("test mbc metrics", {
expect_error(mbc(lm(y1 ~ x1), lm(y1 ~ x1 + x2), target=function(i) {ydf}, metric="mis90", post=function(mod){predict(mod, xdf,se=T)}), NA)
expect_error(mbc(lm(y1 ~ x1), lm(y1 ~ x1 + x2), target=lapply(1:5, function(i)ydf), metric="mis90", post=function(mod){predict(mod, xdf,se=T)}), NA)
expect_error(mbc(lm(y1 ~ x1), lm(y1 ~ x1 + x2), target="ydf", metric="mis90", input=list(ydf=ydf, x1=xdf$x1, x2=xdf$x2, y1=y1),post=function(mod){predict(mod, xdf,se=T)}), NA)
expect_error(mbc(lm(y1 ~ x1), lm(y1 ~ x1 + x2), targetin=data.frame(ydf=ydf, x1=xdf$x1, x2=xdf$x2, y1=y1), target="ydf", metric="mis90", input=list(ydf=ydf, x1=xdf$x1, x2=xdf$x2, y1=y1)), NA)

# t and mis90
m1 <- mbc(lm(y1 ~ x1), lm(y1 ~ x1 + x2), target=ydf, metric=c("t","mis90"), post=function(mod){predict(mod, xdf,se=T)})
Expand Down

0 comments on commit e599b7e

Please sign in to comment.