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.


1 Answer 1


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.

  • $\begingroup$ I've never used this function before, I found it using some spelunking when I saw your question. $\endgroup$
    – Szabolcs
    Apr 17, 2014 at 18:43
  • 3
    $\begingroup$ There is also Statistics`Library`DistributionDimensionality but I make no promises that it is robust. $\endgroup$
    – Andy Ross
    Apr 17, 2014 at 19:54
  • 1
    $\begingroup$ 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 ;) $\endgroup$ Apr 17, 2014 at 20:43
  • 1
    $\begingroup$ @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.) $\endgroup$
    – Szabolcs
    Apr 19, 2014 at 23:56
  • 1
    $\begingroup$ @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. $\endgroup$
    – Andy Ross
    Apr 20, 2014 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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