Random Extensions.Correlated Samples Method
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.3
public static Vector<double>[] CorrelatedSamples(
this Random random,
int numberOfSamples,
Distribution[] distributions,
SymmetricMatrix<double> correlations
)
Parameters
- random Random
- A random number generator used to generate samples from the distributions.
- numberOfSamples Int32
- The number of
- distributions Distribution[]
- An array of Distribution objects that specifies the probability distribution of each variable.
- correlations SymmetricMatrix<Double>
- A SymmetricMatrix<T> that specifies the desired correlation matrix.
Return Value
Vector<Double>[]An array of real vectors with approximately the specified correlation matrix.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type Random. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).Remarks
Use this method to generate a series of correlated numerical variables. Each variable is composed of random samples taken from the corresponding distribution in the distributions array. Both continuous and discrete distributions are allowed. correlations must be a correlation matrix. It must be positive definite with ones on the diagonal. The size of the correlation matrix must match the length of distributions. The number of samples must be at least two.
The correlation matrix of the variables will be approximately equal to correlations. Larger sample sizes will generally yield a better approximation, especially if the probability distributions are fairly symmetrical. For very asymmetrical distributions, it may be difficult to produce the desired correlation.
This method uses the algorithm of Iman-Conover.
Exceptions
Argument | random is null. correlations is null. distributions is null. |
Argument | numberOfSamples is less than two. |
Dimension | The size of correlations does not equal the length of distributions. |
Argument | correlations is not a correlation matrix. |