# Determining the dimension of a probability distribution

Functions like Mean and RandomVariate clearly infer the dimension of the distribution passed to them. One can also usually determine the dimension of a distribution by calling one of these functions, but this is suboptimal. RandomVariate does not work if some of the parameters of the distribution are symbolic and long tailed distributions may not have a well defined mean. Even when this method works it is overkill. Presumably there is some lower level function that just determines the dimension that Mean and RandomVariate themselves use to determine the dimesion but I have not been able to find it.

You can use DistributionDomain to find the domain of a distribution, which will also tell you the dimension.

I do not know where this is documented, but it does appear in some examples in the documentation.

Usage examples:

DistributionDomain[NormalDistribution[]]
(* Interval[{-∞, ∞}] *)

DistributionDomain[ParetoDistribution[xmin, alpha]]
(* Interval[{xmin, ∞}] *)

DistributionDomain[MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}]]
(* {Interval[{-∞, ∞}], Interval[{-∞, ∞}]} *)

data = RandomReal[1, 10]
(* {0.60996, 0.615194, 0.106301, 0.543126, 0.812796, 0.711574, 0.814802, 0.839422, 0.0528327, 0.40623} *)

DistributionDomain[EmpiricalDistribution[data]]
(* {0.0528327, 0.106301, 0.40623, 0.543126, 0.60996, 0.615194, 0.711574, 0.812796, 0.814802, 0.839422} *)

% == Sort[data]
(* True *)

DistributionDomain[ZipfDistribution[rho]]
(* Range[1, ∞] *)

DistributionDomain[ZipfDistribution[10, rho]]
(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} *)


Notice that a simple Length@DistributionDomain[...] isn't sufficient to determine the dimension. There are helper functions to determine if a distribution (or its domain) are univariate.

• StatisticsLibraryUnivariateDomainSpecificationQ can be applied to a domain specification

• StatisticsLibraryUnivariateDistributionQ can be applied to a distribution and is based on the function above.

There is also StatisticsLibraryDumpHeldDistributionDomain which prevents Range from expanding in the domain of some discrete distributions, for example:

StatisticsLibraryDumpHeldDistributionDomain[ZipfDistribution[10, rho]]
(* Hold[Range][1, 10] *)


Looking at its definition it simple uses Block to temporarily prevent Range from evaluating, which you can do manually yourself to reduce the reliance on private internal functions that might not even be loaded in a fresh kernel (until something else triggers loading them).

As Andy Ross mentioned in the comments, StatisticsLibraryDistributionDimensionality will directly return the dimensionality of the domain.

Warning: As with all undocumented functions that are not in the System context there's no guarantee of reliability or that they'll work in future versions.

• I've never used this function before, I found it using some spelunking when I saw your question. Commented Apr 17, 2014 at 18:43
• There is also StatisticsLibraryDistributionDimensionality but I make no promises that it is robust. Commented Apr 17, 2014 at 19:54
• Together with Andy's comment this answers my question. I guess if @AndyRoss had written a separate answer I would have accepted that since DistributionDimensionality is really what I had in mind, assuming it is robust. Gotta love undocumented functions in closed software ;) Commented Apr 17, 2014 at 20:43
• @DanielMahler ?something* will search in all contexts that are in \$ContextPath and ?*something* will search in all contexts. The latter tends to return a lot of internal stuff that's not useful, so there's more to wade through. The warnings I gave you about undocumented/internal stuff are not meant to deter you, I sometimes use these too. But the problems can and do happen (I've been bitten several times.) Commented Apr 19, 2014 at 23:56
• @Szabolcs I believe DistributionDomain is fairly robust but it may be that the representation of domains may change in the future. Some things are pretty wonky, like held ranges to infinity, and probably need different symbols to represent them. Commented Apr 20, 2014 at 1:20