[Distr-commits] r333 - in pkg/distrEx: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 13 12:51:51 CET 2008
Author: stamats
Date: 2008-11-13 12:51:50 +0100 (Thu, 13 Nov 2008)
New Revision: 333
Modified:
pkg/distrEx/DESCRIPTION
pkg/distrEx/R/AllMaskedMethods.R
pkg/distrEx/man/Var.Rd
Log:
corrected small bug in mad, added new implementation for skewness and kurtosis for signature "ANY".
Modified: pkg/distrEx/DESCRIPTION
===================================================================
--- pkg/distrEx/DESCRIPTION 2008-11-13 08:06:35 UTC (rev 332)
+++ pkg/distrEx/DESCRIPTION 2008-11-13 11:51:50 UTC (rev 333)
@@ -1,6 +1,6 @@
Package: distrEx
-Version: 2.0.2
-Date: 2008-11-06
+Version: 2.0.3
+Date: 2008-11-13
Title: Extensions of package distr
Description: Extensions of package distr and some additional
functionality
Modified: pkg/distrEx/R/AllMaskedMethods.R
===================================================================
--- pkg/distrEx/R/AllMaskedMethods.R 2008-11-13 08:06:35 UTC (rev 332)
+++ pkg/distrEx/R/AllMaskedMethods.R 2008-11-13 11:51:50 UTC (rev 333)
@@ -42,44 +42,49 @@
setMethod("mad","ANY",function(x , ...)
{dots <- list(...)
- na.rm <- ifelse(hasArg(na.rm), dots$"na.rm", FALSE)
- low <- ifelse(hasArg(low), dots$"low", FALSE)
- high <- ifelse(hasArg(high), dots$"high", FALSE)
- center <- ifelse(hasArg(center), dots$"center", median(x))
- constant <- ifelse(hasArg(constant), dots$"constant", 1.4826)
- stats::mad(x = x, center = center, constant = constant ,
- na.rm = na.rm, low = low, high = high)})
+ na.rm <- ifelse(hasArg(na.rm), dots$"na.rm", FALSE)
+ low <- ifelse(hasArg(low), dots$"low", FALSE)
+ high <- ifelse(hasArg(high), dots$"high", FALSE)
+ center <- ifelse(hasArg(center), dots$"center", median(x, na.rm = na.rm))
+ constant <- ifelse(hasArg(constant), dots$"constant", 1.4826)
+ stats::mad(x = x, center = center, constant = constant, na.rm = na.rm, low = low, high = high)}
+)
############################################################################
-### ------------------------------------------------
-### In this comment substitute 'xxx' by
-### 'kurtosis', 'skewness', respectively
-### ------------------------------------------------
-### We intentionally /copy/ function 'xxx' from e1071 in order to avoid
-### the necessity to add e1071 to the 'Depends' tag in the DESCRIPTION
-### file of this package.
-### functionality of 'e1071::xxx' is completely retained, however
-###
### acknowledgement:
### methods 'skewness' and 'kurtosis' for particular methods
### have been provided by G. Jay Kerns, gkerns at ysu.edu
+###
+### replaced e1071 version by sample and bias free (under normal distribution)
+### version for skewness and kurtosis (MK, 13 Nov. 2008)
############################################################################
setMethod("skewness","ANY",function(x , ...)
{dots <- list(...)
- na.rm <- ifelse(hasArg(na.rm), dots$"na.rm", FALSE)
- ### definition taken from package e1071
- if (na.rm)
- x <- x[!is.na(x)]
- sum((x - mean(x))^3)/(length(x) * sd(x)^3)
+ na.rm <- ifelse(hasArg(na.rm), dots$"na.rm", FALSE)
+ sample.version <- ifelse(hasArg(sample.version), dots$"sample.version", FALSE)
+ if (na.rm) x <- x[!is.na(x)]
+ M <- mean(x)
+ m3 <- mean((x-M)^3)
+ m2 <- mean((x-M)^2)
+ bias.cor <- ifelse(sample.version, 1, sqrt(n*(n-1))/(n-2))
+ bias.cor*m3/m2^(3/2)
})
setMethod("kurtosis","ANY",function(x , ...)
{dots <- list(...)
na.rm <- ifelse(hasArg(na.rm), dots$"na.rm", FALSE)
- ### definition taken from package e1071
- if (na.rm)
- x <- x[!is.na(x)]
- sum((x - mean(x))^4)/(length(x) * var(x)^2) - 3
- })
+ sample.version <- ifelse(hasArg(sample.version), dots$"sample.version", FALSE)
+ if (na.rm) x <- x[!is.na(x)]
+ M <- mean(x)
+ m4 <- mean((x-M)^4)
+ m2 <- mean((x-M)^2)
+ n <- length(x)
+ g2 <- m4/m2^2 - 3
+ if(sample.version){
+ return(g2)
+ }else{
+ ## bias free for normal distributed samples
+ return((n-1)/((n-2)*(n-3))*((n+1)*g2 + 6))
+ }})
Modified: pkg/distrEx/man/Var.Rd
===================================================================
--- pkg/distrEx/man/Var.Rd 2008-11-13 08:06:35 UTC (rev 332)
+++ pkg/distrEx/man/Var.Rd 2008-11-13 11:51:50 UTC (rev 333)
@@ -330,7 +330,8 @@
\item{\code{mad}, \code{signature(x = "AffLinDistribution")}:}{\code{abs(x at a) * mad(x at X0)}}
\item{\code{skewness}, \code{signature(x = "Any")}:}{
- interface to the \pkg{e1071}-function \code{skewness} --- see \code{\link[e1071]{skewness}}.}
+ bias free estimation of skewness under normal distribution (default) as
+ well as sample version (by argument \code{sample.version = TRUE}).}
\item{\code{skewness}, \code{signature(x = "UnivariateDistribution")}:}{
skewness of univariate distributions using corresponding \code{E()}-method.}
\item{\code{skewness}, \code{signature(x = "AffLinDistribution")}:}{
@@ -338,7 +339,8 @@
else uses method for \code{signature(x = "UnivariateDistribution")}}
\item{\code{kurtosis}, \code{signature(x = "Any")}:}{
- interface to the \pkg{e1071}-function \code{kurtosis} --- see \code{\link[e1071]{kurtosis}}.}
+ bias free estimation of kurtosis under normal distribution (default) as
+ well as sample version (by argument \code{sample.version = TRUE}).}
\item{\code{kurtosis}, \code{signature(x = "UnivariateDistribution")}:}{
kurtosis of univariate distributions using corresponding \code{E()}-method.}
\item{\code{kurtosis}, \code{signature(x = "AffLinDistribution")}:}{
@@ -570,8 +572,7 @@
\seealso{\code{\link{distrExIntegrate}}, \code{\link{m1df}}, \code{\link{m2df}},
\code{\link[distr]{Distribution-class}},\cr
\code{\link[stats]{sd}}, \code{\link[stats]{var}}, \code{\link[stats]{IQR}},\cr
- \code{\link[stats]{median}}, \code{\link[stats]{mad}}, \code{\link[distr]{sd}},\cr
-\code{\link[e1071]{skewness}}, \code{\link[e1071]{kurtosis}} }
+ \code{\link[stats]{median}}, \code{\link[stats]{mad}}, \code{\link[distr]{sd}} }
\concept{functional}
\concept{var}
\concept{sd}
More information about the Distr-commits
mailing list