The following Graph Template Language (GTL) defines a contour plot for irregularly spaced data and creates the contour plot for the random point on the upper hemisphere: Consequently, on the CONTOURPLOTPARM statement in PROC TEMPLATE, you must use the GRIDDED=FALSE option so that the plot interpolates the data onto a rectangular grid. The data in this article have random positions. However, in that article the data were aligned on an evenly spaced grid in the (x,y) plane. In a previous article, I showed how to use PROC TEMPLATE and PROC SGRENDER in SAS to create a contour plot. The exact contours of the upper hemisphere are concentric circles (lines of constant latitude) centered at (x,y)=(0,0).įor these simulated data, a contour plot should display contours that are approximately concentric circles. Observations near for which x 2 + y 2 &asymp 0 have either a pure blue or pure red color since those observations are near one of the poles.Īnother way to visualize the data would be to construct a contour plot of the points in the upper hemisphere of the sphere. ![]() Have a dark color because the z-value is close 1 zero. The graph shows that observations near the (x,y)-plane (for which x 2 + y 2 &asymp 1) Switching to (x,y,z) instead of (x1,x2,x3) notation, Scatter x=x1 y=x2 / colorresponse=x3 transparency= 0.5 markerattrs= (symbol=CircleFilled ) I have also used the TRANSPARENCY= option so that the density of the points is shown. That means that points near the "south pole" (x3 = -1) will be colored blue, points near the equator will be colored black, and points near the "north pole" (x3 = 1) will be colored red. The default color ramp is the ThreeAltColor ramp, which (for my ODS style) is a blue-black-red color ramp. For example, the following call to PROC SGPLOT creates a scatter plot of (x1,x2) and uses the COLORRESPONSE=x3 option to color the markers. One way is to plot the first two coordinates and use colors to represent the value of the points in the third coordinate direction. How can we visualize the points to assure ourselves that the program is running correctly? X = &r * x / norm /* scale point so that distance to origin is r */ end Norm = Euclid ( of x ) /* Euclidean distance to origin */ do j = 1 to &d X = rand ( "Normal" ) /* random point from MVN(0, I(d)) */ end %let N = 1000 /* number of steps in random walk */ %let d = 2 /* S^ sphere embedded in R^d */ %let r = 1 /* radius of sphere */ data RandSphere If you divide the coordinates by the distance, you obtain a point on the unit circle: Thus the expression sqrt(X) gives the Euclidean distance of each row to the origin. The notation X is a subscript reduction operator that returns a row vector that contains the sum of the squared elements of each row of X. The following SAS/IML program simulates N=1000 points from d=2 independent normal distributions. In order to visualize the data, I show how to create a contour plot of ungridded data in SAS.įor simplicity, let's see how to generate random points on the unit circle in 2-D. ![]() I show the computation twice: once by using the SAS/IML matrix language and again by using the SAS DATA step. This article shows how to generate random points uniformly on the unit sphere. Since a unit vector is a vector from the origin to a point on the unit sphere, (In fact, a unit vector is sometimes called a direction vector.) However, for higher-dimensional random walks, I do not suggest using random angles to determine directions.Īlthough it is mathematically possible to use spherical coordinates in d-dimensions, computations in a spherical coordinate system are extremely messy.Ī better alternative is to use random unit vectors to determine a direction for each step in a random walk. I was reminded of this fact recently when I wrote about how to simulate a random walk in high dimensions.Įach step of a random walk needs to generate a random direction and a random step length.įor a 2-D random walk, it is easy to generate a random direction as an angle, θ, chosen from the uniform distribution on the interval [0,2π). If Y is drawn from the uncorrelated multivariate normal distribution, then S = Y / ||Y|| has the uniform distribution on the unit sphere. ![]() In that article, I stated the following fact: In a previous article, I showed how to generate random points uniformly inside a d-dimensional sphere.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |