The DO Loop
Statistical programming in SAS with an emphasis on SAS/IML programs![The expected value of the tail of a distribution Expected value for the tail of a distribution](https://blogs.sas.com/content/iml/files/2020/11/ExpectTails1-640x336.png)
The expected value of a random variable is essentially a weighted mean over all possible values. You can compute it by summing (or integrating) a probability-weighted quantity over all possible values of the random variable. The expected value is a measure of the "center" of a probability distribution. You can
![Tips to simulate binary and categorical variables](https://blogs.sas.com/content/iml/files/2020/10/simBinCat3.png)
When there are two equivalent ways to do something, I advocate choosing the one that is simpler and more efficient. Sometimes, I encounter a SAS program that simulates random numbers in a way that is neither simple nor efficient. This article demonstrates two improvements that you can make to your
![The sample skewness is a biased statistic Monte Carlo distribution of skewness statistic (B=10000, N=100)](https://blogs.sas.com/content/iml/files/2020/10/SkewBias1-640x336.png)
The skewness of a distribution indicates whether a distribution is symmetric or not. The Wikipedia article about skewness discusses two common definitions for the sample skewness, including the definition used by SAS. In the middle of the article, you will discover the following sentence: In general, the [estimators]are both biased
![Confidence intervals for eigenvalues of a correlation matrix Graphical comparison of two methods for estimating confidence intervals of eigenvalues of a correlation matrix](https://blogs.sas.com/content/iml/files/2020/10/bootEigen4-480x336.png)
A fundamental principle of data analysis is that a statistic is an estimate of a parameter for the population. A statistic is calculated from a random sample. This leads to uncertainty in the estimate: a different random sample would have produced a different statistic. To quantify the uncertainty, SAS procedures
![Generate random points in a polygon Decomposition of a convex polygon into triangles](https://blogs.sas.com/content/iml/files/2020/10/RandPoly2-400x336.png)
The triangulation theorem for polygons says that every simple polygon can be triangulated. In fact, if the polygon has V vertices, you can decompose it into V-2 non-overlapping triangles. In this article, a "polygon" always means a simple polygon. Also, a "random point" means one that is drawn at random
![Generate random points in a triangle Random uniform points in a triangle](https://blogs.sas.com/content/iml/files/2020/10/RandTri3-480x336.png)
How can you efficiently generate N random uniform points in a triangular region of the plane? There is a very cool algorithm (which I call the reflection method) that makes the process easy. I no longer remember where I saw this algorithm, but it is different from the "weighted average"