Skip to content

Commit

Permalink
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
andrie committed May 19, 2014
2 parents 81d1ec0 + c8a3e8a commit 23a34fe
Show file tree
Hide file tree
Showing 28 changed files with 294 additions and 240 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -11,7 +11,7 @@ LazyData: true
LazyLoad: true
Description: This is a set of tools to enchance and expand RevoScaleR.
Version: 0.0-09
Date: 2014-05-16
Date: 2014-05-19
URL: https://github.com/RevoEnchancements/RevoEnhancements
VignetteBuilder: knitr
Roxygen: list(wrap = FALSE)
Expand Down
5 changes: 3 additions & 2 deletions NAMESPACE
@@ -1,8 +1,9 @@
# Generated by roxygen2 (4.0.0): do not edit by hand

S3method(formula,rxDTree)
S3method(isLogFormula,default)
S3method(plot,rxDTree)
S3method(rxKS,rxLorenz)
export(formulaExpand)
export(isLogFormula)
export(range2formula)
export(rxAIC)
export(rxBoxPlot)
Expand Down
13 changes: 13 additions & 0 deletions NEWS
@@ -1,3 +1,16 @@
RevoEnhancements 0.0-09 (Release date: 29/05/2014)
================

New functionality
* None

Bug fixes:
* Documentation improvements in rxAIC

General improvements:
* Updated documentation using roxygen2 version 4


RevoEnhancements 0.0-08 (Release date: 22/11/2013)
================

Expand Down
14 changes: 9 additions & 5 deletions R/rxAIC.R
@@ -1,7 +1,7 @@
#
# RevoEnhancements/R/rXAIC by Derek Norton
# RevoEnhancements/R/rxAIC by Derek Norton
#
# Copyright 2013 Revolution Analytics
# 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.
Expand All @@ -16,17 +16,21 @@
# limitations under the License.


#' Calculates Akaikes Information Criterium (AIC) from a model object.
#' Calculates Akaike's Information Criterium (AIC) from a model object.
#'
#' @param object Model object, the result of \code{\link[RevoScaleR]{rxLogit}}, \code{\link[RevoScaleR]{rxLinMod}} or \code{\link[RevoScaleR]{rxGlm}}
#' @param k Multiplier. Defaults to 2, the value for AIC
#' @param k numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC
#' @return Numeric
#' @export
#' @family Model summary statistics
#' @seealso \code{\link[stats]{AIC}}, \code{\link[stats]{BIC}}
#' @examples
#' library(RevoScaleR)
#' sampleDataDir <- rxGetOption("sampleDataDir")
#' working.file <- file.path(sampleDataDir, "AirlineDemoSmall.xdf")
#' airline <- file.path(sampleDataDir, "AirlineDemoSmall.xdf")
#' frm <- formulaExpand(ArrDelay ~ ., airline)
#' model <- rxLinMod(frm, airline)
#' rxAIC(model)
rxAIC <- function(object, k = 2) {
deviance(object) + k * object$df[1]
}
80 changes: 0 additions & 80 deletions R/rxNaiveBayes.R

This file was deleted.

61 changes: 61 additions & 0 deletions R/rxPredictTransform.R
@@ -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
}

1 change: 0 additions & 1 deletion man/RevoEnhancements-package.Rd
@@ -1,4 +1,3 @@
% Generated by roxygen2 (4.0.0): do not edit by hand
\docType{package}
\name{RevoEnhancements-package}
\alias{RevoEnhancements}
Expand Down
16 changes: 16 additions & 0 deletions man/formula.rxDTree.Rd
@@ -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.
}

6 changes: 3 additions & 3 deletions man/formulaExpand.Rd
@@ -1,14 +1,14 @@
% Generated by roxygen2 (4.0.0): do not edit by hand
\name{formulaExpand}
\alias{formulaExpand}
\title{Expand a . to represent all variables in an XDF (DF).}
\usage{
formulaExpand(formula, data)
}
\arguments{
\item{formula}{formula to be expanded}
\item{formula}{formula to be expanded}

\item{data}{XDF file or data.frame from which to create new formula}
\item{data}{XDF file or data.frame from which to create
new formula}
}
\description{
This function allows the use of . (dot) expansion in functions that would
Expand Down
15 changes: 15 additions & 0 deletions man/isLogFormula.Rd
@@ -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.
}

14 changes: 8 additions & 6 deletions man/plot.rxDTree.Rd
@@ -1,4 +1,3 @@
% Generated by roxygen2 (4.0.0): do not edit by hand
\name{plot.rxDTree}
\alias{plot.rxDTree}
\title{Plots rxDTree object.}
Expand All @@ -7,15 +6,18 @@
...)
}
\arguments{
\item{x}{rxDTree object}
\item{x}{rxDTree object}

\item{text}{If TRUE, adds text labels}
\item{text}{If TRUE, adds text labels}

\item{plotArgs}{Named list, passed to \code{\link[rpart]{plot.rpart}}}
\item{plotArgs}{Named list, passed to
\code{\link[rpart]{plot.rpart}}}

\item{textArgs}{Names list, passed to \code{\link[rpart]{text.rpart}}}
\item{textArgs}{Names list, passed to
\code{\link[rpart]{text.rpart}}}

\item{...}{Not used. Required for consistency with other plot methods.}
\item{...}{Not used. Required for consistency with other
plot methods.}
}
\description{
Plots rxDTree object.
Expand Down
6 changes: 3 additions & 3 deletions man/range2formula.Rd
@@ -1,14 +1,14 @@
% Generated by roxygen2 (4.0.0): do not edit by hand
\name{range2formula}
\alias{range2formula}
\title{Create a formula from a range on an XDF (DF).}
\usage{
range2formula(range, data)
}
\arguments{
\item{range}{numeric range of values to use in formula}
\item{range}{numeric range of values to use in formula}

\item{data}{XDF file or data.frame from which to create new formula}
\item{data}{XDF file or data.frame from which to create
new formula}
}
\description{
This function allows the specification of a range of variable instead of a formula
Expand Down
20 changes: 14 additions & 6 deletions man/rxAIC.Rd
@@ -1,27 +1,35 @@
% Generated by roxygen2 (4.0.0): do not edit by hand
\name{rxAIC}
\alias{rxAIC}
\title{Calculates Akaikes Information Criterium (AIC) from a model object.}
\title{Calculates Akaike's Information Criterium (AIC) from a model object.}
\usage{
rxAIC(object, k = 2)
}
\arguments{
\item{object}{Model object, the result of \code{\link[RevoScaleR]{rxLogit}}, \code{\link[RevoScaleR]{rxLinMod}} or \code{\link[RevoScaleR]{rxGlm}}}
\item{object}{Model object, the result of
\code{\link[RevoScaleR]{rxLogit}},
\code{\link[RevoScaleR]{rxLinMod}} or
\code{\link[RevoScaleR]{rxGlm}}}
\item{k}{Multiplier. Defaults to 2, the value for AIC}
\item{k}{numeric, the penalty per parameter to be used;
the default k = 2 is the classical AIC}
}
\value{
Numeric
}
\description{
Calculates Akaikes Information Criterium (AIC) from a model object.
Calculates Akaike's Information Criterium (AIC) from a model object.
}
\examples{
library(RevoScaleR)
sampleDataDir <- rxGetOption("sampleDataDir")
working.file <- file.path(sampleDataDir, "AirlineDemoSmall.xdf")
airline <- file.path(sampleDataDir, "AirlineDemoSmall.xdf")
frm <- formulaExpand(ArrDelay ~ ., airline)
model <- rxLinMod(frm, airline)
rxAIC(model)
}
\seealso{
\code{\link[stats]{AIC}}, \code{\link[stats]{BIC}}

Other Model summary statistics: \code{\link{rxF1score}};
\code{\link{rxLinPredError}}
}
Expand Down

0 comments on commit 23a34fe

Please sign in to comment.