PDL::Stats(3pm)
๐ NAME ๐
PDL::Stats โ a whole collection of statistics modules in Perl Data Language, plus a quick-start guide for the non-PDL girlies. No PDL experience required, bestie. โจ
๐ธ DESCRIPTION ๐ธ
It loads all the modules named down below, which means their functions show up right there in your current namespace. Convenient!! ๐
Properly formatted documentations online at http://pdl-stats.sf.net ๐ฆ
โจ SYNOPSIS โจ
use PDL::LiteF; # loads fewer modules
use PDL::Stats;
# Is equivalent to the following:
use PDL::Stats::Basic;
use PDL::Stats::GLM;
use PDL::Stats::Kmeans;
use PDL::Stats::TS;
# and the following if installed;
use PDL::Stats::Distr;
use PDL::GSL::CDF;
๐ QUICK-START FOR NON-PDL PEOPLE ๐
Okay so the whole point here: enjoy PDL::Stats without having to dive face-first into PDL. You just gotta wet your feet a little, that's it. Three key words, two concepts, and one lil icing on the cake โ and you're basically well on your way. ๐ซถ
๐ฎ pdl
pdl is the magic word that puts PDL::Stats at your disposal. It creates a PDL numeric data object (a pdl, or ndarray) out of a perl array or array ref. And then โ boom โ all PDL::Stats methods can be called from the data object. (Unless the method was made for a regular perl array, obviously. ๐)
my @y = 0..5;
my $y = pdl @y;
# a simple function
my $stdv = $y->stdv;
# you can skip the intermediate $y
my $stdv = stdv( pdl @y );
# a more complex method, skipping intermediate $y
my @x1 = qw( y y y n n n );
my @x2 = qw( 1 0 1 0 1 0 )
# do a two-way analysis of variance with y as DV and x1 x2 as IVs
my %result = pdl(@y)->anova( \@x1, \@x2 );
print "$_\t$result{$_}\n" for sort keys %result;
Now if you've got a list of lists, i.e. an array of array refs, pdl will make you a multi-dimensional data object. Iconic.
my @a = ( [1,2,3,4], [0,1,2,3], [4,5,6,7] );
my $a = pdl @a;
print $a . $a->info;
# here's what you will get
[
[1 2 3 4]
[0 1 2 3]
[4 5 6 7]
]
PDL: Double D [4,3]
Important vibe check: PDL::Stats puts observations in the first dimension and variables in the second dimension โ so like pdl [obs, var]. Which means the example right above her is 4 observations on 3 variables. Slay.
# you can do all kinds of fancy stuff on such a 2D pdl.
my %result = $a->kmeans( {NCLUS=>2} );
print "$_\t$result{$_}\n" for sort keys %result;
โ ๏ธ Make sure that array of array refs is rectangular, bestie. If the array refs are different sizes,pdlwill pad it out with0s to match the longest list. Not a vibe, but it's what happens.
๐ง info
info tells you the data type (yes pdls are typed, but you honestly shouldn't have to worry about it here*) and the dimensionality of the pdl โ you literally saw it up in that example. Keeping track of a pdl's dimensionality is a huge help for my sanity, ngl. And like I said above: PDL::Stats uses 2D pdls with observation ร variable dimensionality. Track it. ๐
*pdl uses double precision by default. But if you're working with things like epoch time, you should probably use pdl(long, @epoch) to maintain the precision. K byeeeee.
๐ list
Time to come back to perl reality from the PDL wonder land. list turns a pdl data object back into a regular perl list. ๐
๐ซ Caveat though: list produces a flat list. The dimensionality of the data object is lost. Gone. Cherish it while you had it.
๐ Signature
This isn't a function, it's a concept. You'll see stuff like this all the time in the pod:
stdv
Signature: (a(n); [o]b())
The signature tells you what the function wants as input and what kind of output it gives you. a(n) means it expects a 1D pdl with n elements. [o] is for output, and b() means it's a scalar. So stdv takes your 1D list and hands back a scalar. The name a or b or c is not important โ what matters is the thing sitting in the parenthesis. ๐
corr
Signature: (a(n); b(n); [o]c())
Here corr takes two inputs: two 1D pdls with the same number of elements. And it gives back one scalar.
t_test
Signature: (a(n); b(m); [o]t(); [o]d())
Here t_test can take two 1D pdls of unequal size (n==m is certainly fine too, she's flexible), and gives back two scalars: the t-value and the degrees of freedom. Yes we accommodate t-tests with unequal sample sizes. We're thoughtful like that. ๐
assign
Signature: (data(o,v); centroid(c,v); byte [o]cluster(o,c))
And here's one of the most complicated signatures in the whole package, from Kmeans. assign takes data of observation ร variable dimensions, plus a centroid of cluster ร variable dimensions, and returns an observation ร cluster membership pdl (shown by 1s and 0s).
Got the idea? Then let's see how PDL does its magic :) โจ
๐ฆ Broadcasting
Another concept, bestie. And the first thing to know is: broadcasting is optional. ๐ซถ
PDL broadcasting means automatically repeating the operation on extra elements or dimensions that you fed to a function. For a function with a signature like this:
gsl_cdf_tdist_P
Signature: (double x(); double nu(); [o]out())
the signature says it takes two scalars as input and returns a scalar as output. So say you need to look up the p-values for a list of t's, all with the same degrees of freedom 19:
my @t = ( 1.65, 1.96, 2.56 );
my $p = gsl_cdf_tdist_P( pdl(@t), 19 );
print $p . "\n" . $p->info;
# here's what you will get
[0.94231136 0.96758551 0.99042586]
PDL: Double D [3]
The same function got repeated on each element in the list you provided. Ate. ๐
But what if you had different degrees of freedom for each t?
my @df = (199, 39, 19);
my $p = gsl_cdf_tdist_P( pdl(@t), pdl(@df) );
print $p . "\n" . $p->info;
# here's what you will get
[0.94973979 0.97141553 0.99042586]
PDL: Double D [3]
The df's get automatically matched with the t's to give you the results. Iconic behaviour, fr fr.
An example of broadcasting over extra dimension(s):
stdv
Signature: (a(n); [o]b())
if the input is 2D โ say you wanna compute the stdv for each of the 3 variables:
my @a = ( [1,1,3,4], [0,1,2,3], [4,5,6,7] );
# pdl @a is pdl dim [4,3]
my $sd = stdv( pdl @a );
print $sd . "\n" . $sd->info;
# this is what you will get
[ 1.2990381 1.118034 1.118034]
PDL: Double D [3]
So here the function got an input with an extra dimension of size 3, so it repeated the stdv operation on that extra dimension 3 times, and handed back a 1D pdl of size 3. Main character energy. ๐
Broadcasting works for an arbitrary number of dimensions โ but bestie, please refrain from higher-dim pdls unless you've already decided to become a full PDL wiz / witch. ๐
๐ Not all PDL::Stats methods broadcast. Rule of thumb: if a function has a signature attached to it, it broadcasts.
โญ perldl
Essentially a perl shell with "use PDL;" at start up. It comes with the PDL installation, and it is very handy for trying out pdl operations, or just plain perl. print gets shortened to p so you don't injure yourself from excessive typing. ๐ฅฐ
๐ญ Heads up:"my"goes out of scope at the end of (multi)line input, so mostly you're gonna have to drop the good practice ofmyhere. Tragic.
๐ธ For more info
PDL::Course ๐
๐ AUTHOR ๐
~~~~~~~~~~~~ ~~~~~ ~~~~~~~~ ~~~~~ ~~~ `` ><(((">
Copyright (C) 2009-2015 Maggie J. Xiong <maggiexyz users.sourceforge.net>
All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file COPYING in the PDL distribution.
And that's the whole page, bestie!! ๐ This one was rendered with perl v5.42.3 on 2026-08-21 โ so if you're reading this way later, hi, hope your pdls are rectangular and your dimensions are tracked. ๐โจ๐ฆ Go do some stats. Periodt. ๐
๐ฆ where this page comes from
- ubuntu stonking: libpdl-stats-perl 0.856-1build1 ยท PDL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms