diff --git a/NAMESPACE b/NAMESPACE index 6b47469..f595949 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(buildModelCI) export(buildModelCI.default) export(coefplot) +export(coefplot.data.frame) export(coefplot.default) export(coefplot.glm) export(coefplot.lm) @@ -11,6 +12,7 @@ export(coefplot.rxLinMod) export(coefplot.rxLogit) export(collidev) export(extract.coef) +export(extract.coef.maxLik) export(multiplot) export(plotcoef) export(pos_dodgev) diff --git a/R/coefplot.r b/R/coefplot.r index d080728..9fa9858 100644 --- a/R/coefplot.r +++ b/R/coefplot.r @@ -147,7 +147,7 @@ coefplot.default <- function(model, title="Coefficient Plot", xlab="Value", ylab return(modelCI) } - p <- buildPlotting.default(modelCI=modelCI, + p <- coefplot.data.frame(model=modelCI, #modelMeltInner=modelMeltInner, modelMeltOuter=modelMeltOuter, title=title, xlab=xlab, ylab=ylab, lwdInner=lwdInner, lwdOuter=lwdOuter, pointSize=pointSize, color=color, cex=cex, textAngle=textAngle, @@ -159,6 +159,74 @@ coefplot.default <- function(model, title="Coefficient Plot", xlab="Value", ylab return(p) # return the ggplot object } +#' @title coefplot.data.frame +#' @description Dotplot for coefficients +#' @details A graphical display of the coefficients and standard errors from a fitted model, this function uses a data.frame as the input. +#' @aliases coefplot.data.frame +#' @author Jared P. Lander +#' @export coefplot.data.frame +#' @param model A data.frame like that built from coefplot(..., plot=FALSE) +#' @param title The name of the plot, if NULL then no name is given +#' @param xlab The x label +#' @param ylab The y label +#' @param innerCI How wide the inner confidence interval should be, normally 1 standard deviation. If 0, then there will be no inner confidence interval. +#' @param outerCI How wide the outer confidence interval should be, normally 2 standard deviations. If 0, then there will be no outer confidence interval. +#' @param multi logical; If this is for \code{\link{multiplot}} then leave the colors as determined by the legend, if FALSE then make all colors the same +#' @param lwdInner The thickness of the inner confidence interval +#' @param lwdOuter The thickness of the outer confidence interval +#' @param pointSize Size of coefficient point +#' @param color The color of the points and lines +#' @param shape The shape of the points +#' @param linetype The linetype of the error bars +#' @param cex The text size multiplier, currently not used +#' @param textAngle The angle for the coefficient labels, 0 is horizontal +#' @param numberAngle The angle for the value labels, 0 is horizontal +#' @param zeroColor The color of the line indicating 0 +#' @param zeroLWD The thickness of the 0 line +#' @param zeroType The type of 0 line, 0 will mean no line +#' @param facet logical; If the coefficients should be faceted by the variables, numeric coefficients (including the intercept) will be one facet +#' @param scales The way the axes should be treated in a faceted plot. Can be c("fixed", "free", "free_x", "free_y") +#' @param numeric logical; If true and factors has exactly one value, then it is displayed in a horizontal graph with constinuous confidence bounds. +#' @param fillColor The color of the confidence bounds for a numeric factor +#' @param alpha The transparency level of the numeric factor's confidence bound +#' @param horizontal logical; If the plot should be displayed horizontally +#' @param value Name of variable for value metric +#' @param coefficient Name of variable for coefficient names +#' @param errorHeight Height of error bars +#' @param dodgeHeight Amount of vertical dodging +#' @param \dots Further Arguments +#' @return a ggplot graph object +#' @examples +#' data(diamonds) +#' head(diamonds) +#' model1 <- lm(price ~ carat + cut*color, data=diamonds) +#' model2 <- lm(price ~ carat*color, data=diamonds) +#' df1 <- coefplot(model1, plot=FALSE) +#' df2 <- coefplot(model2, plot=FALSE) +#' coefplot(df1) +#' coefplot(df2) +#' +coefplot.data.frame <- function(model, title="Coefficient Plot", + xlab="Value", ylab="Coefficient", lwdInner=1, lwdOuter=0, + pointSize=3, color="blue", cex=.8, textAngle=0, numberAngle=0, + shape=16, linetype=1, + outerCI=2, innerCI=1, multi=FALSE, + zeroColor="grey", zeroLWD=1, zeroType=2, + numeric=FALSE, fillColor="grey", alpha=1/2, + horizontal=FALSE, facet=FALSE, scales="free", + value="Value", coefficient="Coefficient", + errorHeight=0, dodgeHeight=1, + ...) +{ + buildPlotting.default(modelCI=model, + #modelMeltInner=modelMeltInner, modelMeltOuter=modelMeltOuter, + title=title, xlab=xlab, ylab=ylab, + lwdInner=lwdInner, lwdOuter=lwdOuter, pointSize=pointSize, color=color, cex=cex, textAngle=textAngle, + numberAngle=numberAngle, zeroColor=zeroColor, zeroLWD=zeroLWD, outerCI=outerCI, innerCI=innerCI, multi=FALSE, + zeroType=zeroType, numeric=numeric, fillColor=fillColor, alpha=alpha, + horizontal=horizontal, facet=facet, scales=scales) +} + #' coefplot.lm #' #' Dotplot for lm coefficients diff --git a/R/extractCoef.r b/R/extractCoef.r index 0739497..67f04c2 100644 --- a/R/extractCoef.r +++ b/R/extractCoef.r @@ -271,6 +271,7 @@ extract.coef.cv.glmnet <- function(model, lambda="lambda.min", ...) #' @details Gets the coefficient values and variable names from a model. #' @author Jared P. Lander #' @method extract.coef maxLik +#' @export extract.coef.maxLik #' @aliases extract.coef.maxLik #' @param model Model object from which to extract information. #' @param \dots Further arguments @@ -301,5 +302,5 @@ extract.coef.maxLik <- function(model, ...) coefNames <- seq(along=theCoef) } - data.frame(Value=theCoef, SE=stdEr(model), Coefficient=coefNames) + data.frame(Value=theCoef, SE=summary(model)$estimate[, 'Std. error'], Coefficient=coefNames) } \ No newline at end of file diff --git a/man/buildModelCI.default.Rd b/man/buildModelCI.default.Rd index 64e9857..322bc19 100644 --- a/man/buildModelCI.default.Rd +++ b/man/buildModelCI.default.Rd @@ -49,7 +49,7 @@ Construct Confidence Interval Values Takes a model and builds a data.frame holding the coefficient value and the confidence interval values. } \examples{ -data(diamonds) +data(diamonds, package='ggplot2') model1 <- lm(price ~ carat + cut, data=diamonds) coefplot:::buildModelCI(model1) coefplot(model1) diff --git a/man/coefplot.data.frame.Rd b/man/coefplot.data.frame.Rd new file mode 100644 index 0000000..3d6744a --- /dev/null +++ b/man/coefplot.data.frame.Rd @@ -0,0 +1,99 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/coefplot.r +\name{coefplot.data.frame} +\alias{coefplot.data.frame} +\title{coefplot.data.frame} +\usage{ +\method{coefplot}{data.frame}(model, title = "Coefficient Plot", + xlab = "Value", ylab = "Coefficient", lwdInner = 1, lwdOuter = 0, + pointSize = 3, color = "blue", cex = 0.8, textAngle = 0, + numberAngle = 0, shape = 16, linetype = 1, outerCI = 2, innerCI = 1, + multi = FALSE, zeroColor = "grey", zeroLWD = 1, zeroType = 2, + numeric = FALSE, fillColor = "grey", alpha = 1/2, horizontal = FALSE, + facet = FALSE, scales = "free", value = "Value", + coefficient = "Coefficient", errorHeight = 0, dodgeHeight = 1, ...) +} +\arguments{ +\item{model}{A data.frame like that built from coefplot(..., plot=FALSE)} + +\item{title}{The name of the plot, if NULL then no name is given} + +\item{xlab}{The x label} + +\item{ylab}{The y label} + +\item{lwdInner}{The thickness of the inner confidence interval} + +\item{lwdOuter}{The thickness of the outer confidence interval} + +\item{pointSize}{Size of coefficient point} + +\item{color}{The color of the points and lines} + +\item{cex}{The text size multiplier, currently not used} + +\item{textAngle}{The angle for the coefficient labels, 0 is horizontal} + +\item{numberAngle}{The angle for the value labels, 0 is horizontal} + +\item{shape}{The shape of the points} + +\item{linetype}{The linetype of the error bars} + +\item{outerCI}{How wide the outer confidence interval should be, normally 2 standard deviations. If 0, then there will be no outer confidence interval.} + +\item{innerCI}{How wide the inner confidence interval should be, normally 1 standard deviation. If 0, then there will be no inner confidence interval.} + +\item{multi}{logical; If this is for \code{\link{multiplot}} then leave the colors as determined by the legend, if FALSE then make all colors the same} + +\item{zeroColor}{The color of the line indicating 0} + +\item{zeroLWD}{The thickness of the 0 line} + +\item{zeroType}{The type of 0 line, 0 will mean no line} + +\item{numeric}{logical; If true and factors has exactly one value, then it is displayed in a horizontal graph with constinuous confidence bounds.} + +\item{fillColor}{The color of the confidence bounds for a numeric factor} + +\item{alpha}{The transparency level of the numeric factor's confidence bound} + +\item{horizontal}{logical; If the plot should be displayed horizontally} + +\item{facet}{logical; If the coefficients should be faceted by the variables, numeric coefficients (including the intercept) will be one facet} + +\item{scales}{The way the axes should be treated in a faceted plot. Can be c("fixed", "free", "free_x", "free_y")} + +\item{value}{Name of variable for value metric} + +\item{coefficient}{Name of variable for coefficient names} + +\item{errorHeight}{Height of error bars} + +\item{dodgeHeight}{Amount of vertical dodging} + +\item{\dots}{Further Arguments} +} +\value{ +a ggplot graph object +} +\description{ +Dotplot for coefficients +} +\details{ +A graphical display of the coefficients and standard errors from a fitted model, this function uses a data.frame as the input. +} +\examples{ +data(diamonds) +head(diamonds) +model1 <- lm(price ~ carat + cut*color, data=diamonds) +model2 <- lm(price ~ carat*color, data=diamonds) +df1 <- coefplot(model1, plot=FALSE) +df2 <- coefplot(model2, plot=FALSE) +coefplot(df1) +coefplot(df2) +} +\author{ +Jared P. Lander +} +