Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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:

(* 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} *)

(* {0.0528327, 0.106301, 0.40623, 0.543126, 0.60996, 0.615194, 0.711574, 0.812796, 0.814802, 0.839422} *)

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

(* 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.

  • Statistics`Library`UnivariateDomainSpecificationQ can be applied to a domain specification

  • Statistics`Library`UnivariateDistributionQ can be applied to a distribution and is based on the function above.

There is also Statistics`Library`Dump`HeldDistributionDomain which prevents Range from expanding in the domain of some discrete distributions, for example:

Statistics`Library`Dump`HeldDistributionDomain[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, Statistics`Library`DistributionDimensionality 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.

share|improve this answer
I've never used this function before, I found it using some spelunking when I saw your question. –  Szabolcs Apr 17 '14 at 18:43
There is also StatisticsLibraryDistributionDimensionality but I make no promises that it is robust. –  Andy Ross Apr 17 '14 at 19:54
@Andy I think you're in a much better position to answer this ... Is DistributionDomain robust? It's not documented but it is in the System context. –  Szabolcs Apr 17 '14 at 20:03
Looks like @AndyRoss's DistributionDimensionality handles the corner cases that break DistributionDomain as @Szabolcz pointed out in the main answer –  Daniel Mahler Apr 17 '14 at 20:25
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 ;) –  Daniel Mahler Apr 17 '14 at 20:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.