{
    "content": [
        {
            "type": "text",
            "text": "# Statistics::Descriptive::Sparse (perldoc)\n\n## NAME\n\nStatistics::Descriptive - Module of basic descriptive statistical functions.\n\n## SYNOPSIS\n\nuse Statistics::Descriptive;\nmy $stat = Statistics::Descriptive::Full->new();\n$stat->adddata(1,2,3,4);\nmy $mean = $stat->mean();\nmy $var = $stat->variance();\nmy $tm = $stat->trimmedmean(.25);\n$Statistics::Descriptive::Tolerance = 1e-10;\n\n## DESCRIPTION\n\nThis module provides basic functions used in descriptive statistics. It has an object oriented\ndesign and supports two different types of data storage and calculation objects: sparse and\nfull. With the sparse method, none of the data is stored and only a few statistical measures are\navailable. Using the full method, the entire data set is retained and additional functions are\navailable.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS** (2 subsections)\n- **REPORTING ERRORS**\n- **AUTHOR**\n- **CONTRIBUTORS**\n- **REFERENCES**\n- **COPYRIGHT**\n- **LICENSE**\n- **SUPPORT** (2 subsections)\n- **BUGS**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Statistics::Descriptive::Sparse",
        "section": "",
        "mode": "perldoc",
        "summary": "Statistics::Descriptive - Module of basic descriptive statistical functions.",
        "synopsis": "use Statistics::Descriptive;\nmy $stat = Statistics::Descriptive::Full->new();\n$stat->adddata(1,2,3,4);\nmy $mean = $stat->mean();\nmy $var = $stat->variance();\nmy $tm = $stat->trimmedmean(.25);\n$Statistics::Descriptive::Tolerance = 1e-10;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Sparse Methods",
                        "lines": 46
                    },
                    {
                        "name": "Full Methods",
                        "lines": 275
                    }
                ]
            },
            {
                "name": "REPORTING ERRORS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CONTRIBUTORS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "REFERENCES",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Websites",
                        "lines": 49
                    },
                    {
                        "name": "Source Code",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "BUGS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Statistics::Descriptive - Module of basic descriptive statistical functions.\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 3.0800\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Statistics::Descriptive;\nmy $stat = Statistics::Descriptive::Full->new();\n$stat->adddata(1,2,3,4);\nmy $mean = $stat->mean();\nmy $var = $stat->variance();\nmy $tm = $stat->trimmedmean(.25);\n$Statistics::Descriptive::Tolerance = 1e-10;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module provides basic functions used in descriptive statistics. It has an object oriented\ndesign and supports two different types of data storage and calculation objects: sparse and\nfull. With the sparse method, none of the data is stored and only a few statistical measures are\navailable. Using the full method, the entire data set is retained and additional functions are\navailable.\n\nWhenever a division by zero may occur, the denominator is checked to be greater than the value\n$Statistics::Descriptive::Tolerance, which defaults to 0.0. You may want to change this value to\nsome small positive value such as 1e-24 in order to obtain error messages in case of very small\ndenominators.\n\nMany of the methods (both Sparse and Full) cache values so that subsequent calls with the same\narguments are faster.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Sparse Methods",
                        "content": "$stat = Statistics::Descriptive::Sparse->new();\nCreate a new sparse statistics object.\n\n$stat->clear();\nEffectively the same as\n\nmy $class = ref($stat);\nundef $stat;\n$stat = new $class;\n\nexcept more efficient.\n\n$stat->adddata(1,2,3);\nAdds data to the statistics variable. The cached statistical values are updated\nautomatically.\n\n$stat->count();\nReturns the number of data items.\n\n$stat->mean();\nReturns the mean of the data.\n\n$stat->sum();\nReturns the sum of the data.\n\n$stat->variance();\nReturns the variance of the data. Division by n-1 is used.\n\n$stat->standarddeviation();\nReturns the standard deviation of the data. Division by n-1 is used.\n\n$stat->min();\nReturns the minimum value of the data set.\n\n$stat->mindex();\nReturns the index of the minimum value of the data set.\n\n$stat->max();\nReturns the maximum value of the data set.\n\n$stat->maxdex();\nReturns the index of the maximum value of the data set.\n\n$stat->samplerange();\nReturns the sample range (max - min) of the data set.\n"
                    },
                    {
                        "name": "Full Methods",
                        "content": "Similar to the Sparse Methods above, any Full Method that is called caches the current result so\nthat it doesn't have to be recalculated. In some cases, several values can be cached at the same\ntime.\n\n$stat = Statistics::Descriptive::Full->new();\nCreate a new statistics object that inherits from Statistics::Descriptive::Sparse so that\nit contains all the methods described above.\n\n$stat->adddata(1,2,4,5);\nAdds data to the statistics variable. All of the sparse statistical values are updated and\ncached. Cached values from Full methods are deleted since they are no longer valid.\n\n*Note: Calling adddata with an empty array will delete all of your Full method cached\nvalues! Cached values for the sparse methods are not changed*\n\n$stat->adddatawithsamples([{1 => 10}, {2 => 20}, {3 => 30},]);\nAdd data to the statistics variable and set the number of samples each value has been built\nwith. The data is the key of each element of the input array ref, while the value is the\nnumber of samples: [{data1 => smaples1}, {data2 => samples2}, ...].\n\nNOTE: The number of samples is only used by the smoothing function and is ignored\notherwise. It is not equivalent to repeat count. In order to repeat a certain datum more\nthan one time call adddata() like this:\n\nmy $value = 5;\nmy $repeatcount = 10;\n$stat->adddata(\n[ ($value) x $repeatcount ]\n);\n\n$stat->getdata();\nReturns a copy of the data array.\n\n$stat->getdatawithoutoutliers();\nReturns a copy of the data array without outliers. The number minimum of samples to apply\nthe outlier filtering is $Statistics::Descriptive::Minsamplesnumber, 4 by default.\n\nA function to detect outliers need to be defined (see \"setoutlierfilter\"), otherwise the\nfunction will return an undef value.\n\nThe filtering will act only on the most extreme value of the data set (i.e.: value with the\nhighest absolute standard deviation from the mean).\n\nIf there is the need to remove more than one outlier, the filtering need to be re-run for\nthe next most extreme value with the initial outlier removed.\n\nThis is not always needed since the test (for example Grubb's test) usually can only detect\nthe most exreme value. If there is more than one extreme case in a set, then the standard\ndeviation will be high enough to make neither case an outlier.\n\n$stat->setoutlierfilter($coderef);\nSet the function to filter out the outlier.\n\n$coderef is the reference to the subroutine implementing the filtering function.\n\nReturns \"undef\" for invalid values of $coderef (i.e.: not defined or not a code\nreference), 1 otherwise.\n\n*   Example #1: Undefined code reference\n\nmy $stat = Statistics::Descriptive::Full->new();\n$stat->adddata(1, 2, 3, 4, 5);\n\nprint $stat->setoutlierfilter(); # => undef\n\n*   Example #2: Valid code reference\n\nsub outlierfilter { return $[1] > 1; }\n\nmy $stat = Statistics::Descriptive::Full->new();\n$stat->adddata( 1, 1, 1, 100, 1, );\n\nprint $stat->setoutlierfilter( \\&outlierfilter ); # => 1\nmy @filtereddata = $stat->getdatawithoutoutliers();\n# @filtereddata is (1, 1, 1, 1)\n\nIn this example the series is really simple and the outlier filter function as well.\nFor more complex series the outlier filter function might be more complex (see Grubbs'\ntest for outliers).\n\nThe outlier filter function will receive as first parameter the\nStatistics::Descriptive::Full object, as second the value of the candidate outlier.\nHaving the object in the function might be useful for complex filters where statistics\nproperty are needed (again see Grubbs' test for outlier).\n\n$stat->setsmoother({ method => 'exponential', coeff => 0, });\nSet the method used to smooth the data and the smoothing coefficient. See\n\"Statistics::Smoother\" for more details.\n\n$stat->getsmootheddata();\nReturns a copy of the smoothed data array.\n\nThe smoothing method and coefficient need to be defined (see \"setsmoother\"), otherwise the\nfunction will return an undef value.\n\n$stat->sortdata();\nSort the stored data and update the mindex and maxdex methods. This method uses perl's\ninternal sort.\n\n$stat->presorted(1);\n$stat->presorted();\nIf called with a non-zero argument, this method sets a flag that says the data is already\nsorted and need not be sorted again. Since some of the methods in this class require sorted\ndata, this saves some time. If you supply sorted data to the object, call this method to\nprevent the data from being sorted again. The flag is cleared whenever adddata is called.\nCalling the method without an argument returns the value of the flag.\n\n$stat->skewness();\nReturns the skewness of the data. A value of zero is no skew, negative is a left skewed\ntail, positive is a right skewed tail. This is consistent with Excel.\n\n$stat->kurtosis();\nReturns the kurtosis of the data. Positive is peaked, negative is flattened.\n\n$x = $stat->percentile(25);\n($x, $index) = $stat->percentile(25);\nSorts the data and returns the value that corresponds to the percentile as defined in\nRFC2330:\n\n*   For example, given the 6 measurements:\n\n-2, 7, 7, 4, 18, -5\n\nThen F(-8) = 0, F(-5) = 1/6, F(-5.0001) = 0, F(-4.999) = 1/6, F(7) = 5/6, F(18) = 1,\nF(239) = 1.\n\nNote that we can recover the different measured values and how many times each occurred\nfrom F(x) -- no information regarding the range in values is lost. Summarizing\nmeasurements using histograms, on the other hand, in general loses information about\nthe different values observed, so the EDF is preferred.\n\nUsing either the EDF or a histogram, however, we do lose information regarding the\norder in which the values were observed. Whether this loss is potentially significant\nwill depend on the metric being measured.\n\nWe will use the term \"percentile\" to refer to the smallest value of x for which F(x) >=\na given percentage. So the 50th percentile of the example above is 4, since F(4) = 3/6\n= 50%; the 25th percentile is -2, since F(-5) = 1/6 < 25%, and F(-2) = 2/6 >= 25%; the\n100th percentile is 18; and the 0th percentile is -infinity, as is the 15th percentile,\nwhich for ease of handling and backward compatibility is returned as undef() by the\nfunction.\n\nCare must be taken when using percentiles to summarize a sample, because they can lend\nan unwarranted appearance of more precision than is really available. Any such summary\nmust include the sample size N, because any percentile difference finer than 1/N is\nbelow the resolution of the sample.\n\n(Taken from: *RFC2330 - Framework for IP Performance Metrics*, Section 11.3. Defining\nStatistical Distributions. RFC2330 is available from: <http://www.ietf.org/rfc/rfc2330.txt>\n.)\n\nIf the percentile method is called in a list context then it will also return the index of\nthe percentile.\n\n$x = $stat->quantile($Type);\nSorts the data and returns estimates of underlying distribution quantiles based on one or\ntwo order statistics from the supplied elements.\n\nThis method use the same algorithm as Excel and R language (quantile type 7).\n\nThe generic function quantile produces sample quantiles corresponding to the given\nprobabilities.\n\n$Type is an integer value between 0 to 4 :\n\n0 => zero quartile (Q0) : minimal value\n1 => first quartile (Q1) : lower quartile = lowest cut off (25%) of data = 25th percentile\n2 => second quartile (Q2) : median = it cuts data set in half = 50th percentile\n3 => third quartile (Q3) : upper quartile = highest cut off (25%) of data, or lowest 75% = 75th percentile\n4 => fourth quartile (Q4) : maximal value\n\nExample :\n\nmy @data = (1..10);\nmy $stat = Statistics::Descriptive::Full->new();\n$stat->adddata(@data);\nprint $stat->quantile(0); # => 1\nprint $stat->quantile(1); # => 3.25\nprint $stat->quantile(2); # => 5.5\nprint $stat->quantile(3); # => 7.75\nprint $stat->quantile(4); # => 10\n\n$stat->median();\nSorts the data and returns the median value of the data.\n\n$stat->harmonicmean();\nReturns the harmonic mean of the data. Since the mean is undefined if any of the data are\nzero or if the sum of the reciprocals is zero, it will return undef for both of those\ncases.\n\n$stat->geometricmean();\nReturns the geometric mean of the data.\n\nmy $mode = $stat->mode();\nReturns the mode of the data. The mode is the most commonly occurring datum. See\n<http://en.wikipedia.org/wiki/Mode%28statistics%29> . If all values occur only once, then\nmode() will return undef.\n\n$stat->sumsq()\nThe sum of squares.\n\n$stat->trimmedmean(ltrim[,utrim]);\n\"trimmedmean(ltrim)\" returns the mean with a fraction \"ltrim\" of entries at each end\ndropped. \"trimmedmean(ltrim,utrim)\" returns the mean after a fraction \"ltrim\" has been\nremoved from the lower end of the data and a fraction \"utrim\" has been removed from the\nupper end of the data. This method sorts the data before beginning to analyze it.\n\nAll calls to trimmedmean() are cached so that they don't have to be calculated a second\ntime.\n\n$stat->frequencydistributionref($partitions);\n$stat->frequencydistributionref(\\@bins);\n$stat->frequencydistributionref();\n\"frequencydistributionref($partitions)\" slices the data into $partition sets (where\n$partition is greater than 1) and counts the number of items that fall into each partition.\nIt returns a reference to a hash where the keys are the numerical values of the partitions\nused. The minimum value of the data set is not a key and the maximum value of the data set\nis always a key. The number of entries for a particular partition key are the number of\nitems which are greater than the previous partition key and less then or equal to the\ncurrent partition key. As an example,\n\n$stat->adddata(1,1.5,2,2.5,3,3.5,4);\n$f = $stat->frequencydistributionref(2);\nfor (sort {$a <=> $b} keys %$f) {\nprint \"key = $, count = $f->{$}\\n\";\n}\n\nprints\n\nkey = 2.5, count = 4\nkey = 4, count = 3\n\nsince there are four items less than or equal to 2.5, and 3 items greater than 2.5 and less\nthan 4.\n\n\"frequencydistributionrefs(\\@bins)\" provides the bins that are to be used for the\ndistribution. This allows for non-uniform distributions as well as trimmed or sample\ndistributions to be found. @bins must be monotonic and contain at least one element. Note\nthat unless the set of bins contains the range that the total counts returned will be less\nthan the sample size.\n\nCalling \"frequencydistributionref()\" with no arguments returns the last distribution\ncalculated, if such exists.\n\nmy %hash = $stat->frequencydistribution($partitions);\nmy %hash = $stat->frequencydistribution(\\@bins);\nmy %hash = $stat->frequencydistribution();\nSame as \"frequencydistributionref()\" except that returns the hash clobbered into the\nreturn list. Kept for compatibility reasons with previous versions of\nStatistics::Descriptive and using it is discouraged.\n\n$stat->leastsquaresfit();\n$stat->leastsquaresfit(@x);\n\"leastsquaresfit()\" performs a least squares fit on the data, assuming a domain of @x or\na default of 1..$stat->count(). It returns an array of four elements \"($q, $m, $r, $rms)\"\nwhere\n\n\"$q and $m\"\nsatisfy the equation C($y = $m*$x + $q).\n\n$r  is the Pearson linear correlation cofficient.\n\n$rms\nis the root-mean-square error.\n\nIf case of error or division by zero, the empty list is returned.\n\nThe array that is returned can be \"coerced\" into a hash structure by doing the following:\n\nmy %hash = ();\n@hash{'q', 'm', 'r', 'err'} = $stat->leastsquaresfit();\n\nBecause calling \"leastsquaresfit()\" with no arguments defaults to using the current\nrange, there is no caching of the results.\n"
                    }
                ]
            },
            "REPORTING ERRORS": {
                "content": "I read my email frequently, but since adopting this module I've added 2 children and 1 dog to my\nfamily, so please be patient about my response times. When reporting errors, please include the\nfollowing to help me out:\n\n*   Your version of perl. This can be obtained by typing perl \"-v\" at the command line.\n\n*   Which version of Statistics::Descriptive you're using. As you can see below, I do make\nmistakes. Unfortunately for me, right now there are thousands of CD's with the version of\nthis module with the bugs in it. Fortunately for you, I'm a very patient module maintainer.\n\n*   Details about what the error is. Try to narrow down the scope of the problem and send me\ncode that I can run to verify and track it down.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Shlomi Fish <shlomif@cpan.org>\n",
                "subsections": []
            },
            "CONTRIBUTORS": {
                "content": "Fabio Ponciroli & Adzuna Ltd. team (outliers handling)\n",
                "subsections": []
            },
            "REFERENCES": {
                "content": "RFC2330, Framework for IP Performance Metrics\n\nThe Art of Computer Programming, Volume 2, Donald Knuth.\n\nHandbook of Mathematica Functions, Milton Abramowitz and Irene Stegun.\n\nProbability and Statistics for Engineering and the Sciences, Jay Devore.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (c) 1997,1998 Colin Kuskie. All rights reserved. This program is free software; you\ncan redistribute it and/or modify it under the same terms as Perl itself.\n\nCopyright (c) 1998 Andrea Spinelli. All rights reserved. This program is free software; you can\nredistribute it and/or modify it under the same terms as Perl itself.\n\nCopyright (c) 1994,1995 Jason Kastner. All rights reserved. This program is free software; you\ncan redistribute it and/or modify it under the same terms as Perl itself.\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "",
                "subsections": [
                    {
                        "name": "Websites",
                        "content": "The following websites have more information about this module, and may be of help to you. As\nalways, in addition to those websites please use your favorite search engine to discover more\nresources.\n\n*   MetaCPAN\n\nA modern, open-source CPAN search engine, useful to view POD in HTML format.\n\n<https://metacpan.org/release/Statistics-Descriptive>\n\n*   RT: CPAN's Bug Tracker\n\nThe RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.\n\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Statistics-Descriptive>\n\n*   CPANTS\n\nThe CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.\n\n<http://cpants.cpanauthors.org/dist/Statistics-Descriptive>\n\n*   CPAN Testers\n\nThe CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN\ndistributions.\n\n<http://www.cpantesters.org/distro/S/Statistics-Descriptive>\n\n*   CPAN Testers Matrix\n\nThe CPAN Testers Matrix is a website that provides a visual overview of the test results for\na distribution on various Perls/platforms.\n\n<http://matrix.cpantesters.org/?dist=Statistics-Descriptive>\n\n*   CPAN Testers Dependencies\n\nThe CPAN Testers Dependencies is a website that shows a chart of the test results of all\ndependencies for a distribution.\n\n<http://deps.cpantesters.org/?module=Statistics::Descriptive>\n\nBugs / Feature Requests\nPlease report any bugs or feature requests by email to \"bug-statistics-descriptive at\nrt.cpan.org\", or through the web interface at\n<https://rt.cpan.org/Public/Bug/Report.html?Queue=Statistics-Descriptive>. You will be\nautomatically notified of any progress on the request by the system.\n"
                    },
                    {
                        "name": "Source Code",
                        "content": "The code is open to the world, and available for you to hack on. Please feel free to browse it\nand play with it, or whatever. If you want to contribute patches, please send me a diff or prod\nme to pull from your repository :)\n\n<https://github.com/shlomif/perl-Statistics-Descriptive>\n\ngit clone git://github.com/shlomif/perl-Statistics-Descriptive.git\n"
                    }
                ]
            },
            "BUGS": {
                "content": "Please report any bugs or feature requests on the bugtracker website\n<https://github.com/shlomif/perl-Statistics-Descriptive/issues>\n\nWhen submitting a bug or request, please include a test-file or a patch to an existing test-file\nthat illustrates the bug or desired feature.\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "This software is copyright (c) 1997 by Jason Kastner, Andrea Spinelli, Colin Kuskie, and others.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
                "subsections": []
            }
        }
    }
}