NiceHist.RdNiceHist is a tool to examine a metric variable in data inspection, cleaning and description. A histogram with density curve is produced. ScaleTransformations: ID, POWER_Z, LOG10, LOGIT are supported. Location and scale parameter as well as information on valid values can be displayed as legend. Outliers can be identified and filtered out using a +- factor* mad filter.
NiceHist(METRIC, NCLASS = 40, ADJ = 1, SCALE = "ID", MADFILTER = 0, MAIN = "Histogram with Density", XLAB = NULL, YLAB = "Density", XLIM = NULL, NPRETTY = 6, RUG = T, HISTCOL = 7, DENSCOL = 4, LEGEND = T, DIGITS = 3, CUTLINE = NULL, ...)
| METRIC | metric variable |
|---|---|
| NCLASS | = 40 defines the number of classes (=bins) in the histogram |
| ADJ | = 1controls the smoothing of the density curve relative to default=1 |
| SCALE | ="ID" chooses a ScaleTransformation ID, POWER_Z, LOG10, LOGIT for X: use optional parameter Z to specify the power to use with POWER_Z. use optional parameter PERCENT = T for percent instead of proportions on LOGIT scale. |
| MADFILTER | =0, if >0 (typically 3,4, or 5) filters out Outliers beyond +- MADFILTER* mad |
| MAIN | = "Histogram with Density" specifies the title of plot |
| XLAB | specifies the x-axis-Label, if NULL the variable name of x is extracted from the call using PruneVarName |
| YLAB | ="Density" specifies the y-axis-Label |
| XLIM | = NULL sets the x-axis range to be plotted manually - generally not necessary |
| NPRETTY | =6 influences approximate number of labels when using ID or POWER_Z (cf. base pretty) |
| RUG | =T logical whether to plot individual values above x-axis |
| HISTCOL | defines the colour of the histogram, default=7 (yellow) |
| DENSCOL | defines the colour of the density curve, default=4 (blue). DENSCOL=NA suppresses the density curve, |
| LEGEND | = T show legend, which is smartly placed on the side where there is most space. |
| DIGITS | controls the numbers of digits shown for location/scale parameters in the LEGEND |
| CUTLINE | =NULL Draws vertical lines from cut values to the density curve |
| ... | further parameters for scale transformations can be provided via ... Z specifies the power to use with POWER_Z when using POWER_Z PERCENT =F Use percent instead of proportions in LOGIT when using LOGIT |
data.frame Irregular with 4 variables: Rownr, and 2 logicals TransUndef and Outlier in order to identify irregular values.
if (FALSE) { Metric<-c(rnorm(200),rnorm(100,3,1)) NiceHist(Metric) NiceHist(Metric,RUG=F,ADJ=.7) NiceHist(Metric,LEGEND = F) # Demo LOG10 scale NiceHist(exp(Metric),LEGEND = T,SCALE="ID",NCLASS=100) NiceHist(exp(Metric),LEGEND = T,SCALE="ID",NCLASS=1000,XLIM=c(0,50)) NiceHist(exp(Metric),LEGEND = T,SCALE="LOG10") # Demo POWER_Z scale Metric<-rnorm(300,5,1)^3 NiceHist(Metric) NiceHist(Metric,SCALE="POWER_Z",Z=1/3,ADJ=.8) # Demo LOGIT scale Metric<-runif(300)^3 NiceHist(Metric) NiceHist(Metric,SCALE="LOGIT") NiceHist(Metric,SCALE="LOGIT",LEFT=T) NiceHist(100*Metric,SCALE="LOGIT",LEFT=T,PERCENT=T) NiceHist(100*Metric,SCALE="LOGIT",LEFT=T,PERCENT=T,XLAB="Percent values") # Dealing with outliers and missing values Metric<-c(rnorm(200),rnorm(100,3,1),runif(10,5,100),rep(NA,5)) NiceHist(Metric) Irregular<-NiceHist(Metric,MADFILTER=4) Metric[Irregular$Outlier] }