Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #24 from andrie/master
Added some multi-model functions, e.g. rxPredictTransform()
- Loading branch information
Showing
28 changed files
with
294 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# RevoEnhancements/R/rxPredictTransform by Andrie de Vries | ||
# | ||
# Copyright 2013-2014 Revolution Analytics | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
#' Model formula for rxDTree. | ||
#' | ||
#' @param x \R object | ||
#' @param ... further arguments passed to or from other methods | ||
#' @method formula rxDTree | ||
#' @export | ||
formula.rxDTree <- function(x, ...){ | ||
as.formula(x$params$Formula) | ||
} | ||
|
||
|
||
#' Checks if dependent variable is log transformed. | ||
#' | ||
#' @param object An object, either a formula, or containing a formula that can be accessed with \code{formula(object)} | ||
#' @export | ||
isLogFormula <- function(object){ | ||
UseMethod("isLogFormula", object) | ||
} | ||
|
||
#' @export | ||
isLogFormula.default <- function(object){ | ||
frm <- formula(object) | ||
stopifnot(length(frm) >= 3L) | ||
grepl("^log[\\(\\.].*[\\)\\.]", frm[2]) | ||
} | ||
|
||
|
||
#' Applies a transformation on predicted values of model. | ||
#' | ||
#' The function automatically detects whether the formula in a fitted model was log transformed, and applies the inverse, i.e. \code{exp(pred)}. | ||
#' | ||
#' At the moment, always returns a vector, rather than a column in a data frame or XDF. | ||
#' | ||
#' @param modelObject object returned from a call to \code{rxLinMod}, \code{rxLogit}, or \code{rxGlm}. Objects with multiple dependent variables are not supported in rxPredict. | ||
#' @param data frame or XDF. New data to score. | ||
#' @param logModel Logical. If TRUE, applies exponential transformation, i.e. \code{exp(pred)} | ||
#' @param asVector Ignored | ||
#' @param ... Passed to \code{rxPredict} | ||
rxPredictTransform <- function(modelObject, data, logModel=isLogFormula(modelObject), asVector=TRUE, ...){ | ||
pred <- rxPredict(modelObject, data, predVarNames = "pred", ...)$pred | ||
if(logModel) pred <- exp(pred) | ||
pred | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
\name{formula.rxDTree} | ||
\alias{formula.rxDTree} | ||
\title{Model formula for rxDTree.} | ||
\usage{ | ||
\method{formula}{rxDTree}(x, ...) | ||
} | ||
\arguments{ | ||
\item{x}{\R object} | ||
|
||
\item{...}{further arguments passed to or from other | ||
methods} | ||
} | ||
\description{ | ||
Model formula for rxDTree. | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
\name{isLogFormula} | ||
\alias{isLogFormula} | ||
\title{Checks if dependent variable is log transformed.} | ||
\usage{ | ||
isLogFormula(object) | ||
} | ||
\arguments{ | ||
\item{object}{An object, either a formula, or containing | ||
a formula that can be accessed with | ||
\code{formula(object)}} | ||
} | ||
\description{ | ||
Checks if dependent variable is log transformed. | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.