Bug? in summary( ) function base package

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug? in summary( ) function base package

R Saba
There seems to be an error in the summary() function when applied to "ts"
class objects. The results of a call to summary( ), on the R  "ts" data set
USAccDeaths , reports the wrong value for Max. The value reported by the
summary function is 11320. The max( ) function returns the correct value
11317, the July 1993 value. Coercing the data to a data.frame and calling
summary returns the correct max value. A search of R -help found a post in
2007 that mentioned a problem but attributed it to rounding errors. But this
is too large a difference to account for a simple rounding error.

Has anyone else encountered the problem? Is there a workaround?
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

R version 2.6.2 Patched (2008-02-08 r44394)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> data(USAccDeaths)
> summary(USAccDeaths)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   6892    8089    8728    8789    9323   11320
> max(USAccDeaths)
[1] 11317
> USAccDeaths
       Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
1973  9007  8106  8928  9137 10017 10826 11317 10744  9713  9938  9161  8927
1974  7750  6981  8038  8422  8714  9512 10120  9823  8743  9129  8710  8680
1975  8162  7306  8124  7870  9387  9556 10093  9620  8285  8466  8160  8034
1976  7717  7461  7767  7925  8623  8945 10078  9179  8037  8488  7874  8647
1977  7792  6957  7726  8106  8890  9299 10625  9302  8314  8850  8265  8796
1978  7836  6892  7791  8192  9115  9434 10484  9827  9110  9070  8633  9240

> dat1<-as.data.frame(USAccDeaths)
> summary(dat1)
       x        
 Min.   : 6892  
 1st Qu.: 8089  
 Median : 8728  
 Mean   : 8789  
 3rd Qu.: 9323  
 Max.   :11317  
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Thanks,
R Saba

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bug? in summary( ) function base package

hadley wickham
On Wed, Apr 30, 2008 at 1:06 PM, Richard Saba <[hidden email]> wrote:
> There seems to be an error in the summary() function when applied to "ts"
>  class objects. The results of a call to summary( ), on the R  "ts" data set
>  USAccDeaths , reports the wrong value for Max. The value reported by the
>  summary function is 11320. The max( ) function returns the correct value
>  11317, the July 1993 value. Coercing the data to a data.frame and calling
>  summary returns the correct max value. A search of R -help found a post in
>  2007 that mentioned a problem but attributed it to rounding errors. But this
>  is too large a difference to account for a simple rounding error.

Notice that all the numbers in :

>  > summary(USAccDeaths)
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>    6892    8089    8728    8789    9323   11320

have four significant digits and then carefully read the documentation
for the digits argument of summary.  That should suggest both the
cause and a solution.

Hadley


--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bug? in summary( ) function base package

Mike Prager
In reply to this post by R Saba
"Richard Saba" <[hidden email]> wrote:

> There seems to be an error in the summary() function when applied to "ts"
> class objects. The results of a call to summary( ), on the R  "ts" data set
> USAccDeaths , reports the wrong value for Max. The value reported by the
> summary function is 11320. The max( ) function returns the correct value
> 11317, the July 1993 value. Coercing the data to a data.frame and calling
> summary returns the correct max value. A search of R -help found a post in
> 2007 that mentioned a problem but attributed it to rounding errors. But this
> is too large a difference to account for a simple rounding error.
>
> Has anyone else encountered the problem? Is there a workaround?

A documented feature of summary() is that it rounds values. In
doing so, it may print meaningless digits and thus give the
appearance of more precision than is really represented.

--
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.