[R] Random unit vectors in R^{n}
Thomas Lumley
tlumley at u.washington.edu
Tue Aug 27 01:50:43 CEST 2002
On 26 Aug 2002, A.J. Rossini wrote:
> >>>>> "tom" == Tom Richards <Richards> writes:
>
> tom> Hello: Can you tell me if there's a simple way to generate in
> tom> R random vectors on the unit sphere in R^{n}? Additionally,
> tom> are there references for this question? Thanks in advance.
>
>
> I suspect that you can generate them in R^n and then scale? (i.e.
> use (x/|x|) ).
If you use a spherically symmetric distribution to generate them from, eg
making the coordinates independent standard Normals rather than
independent uniform[-1,1] or, say, Cauchy
eg
x<-matrix(rnorm(n*nsamples),nrow=nsamples)
r<-x/sqrt(rowSums(x*x))
works.
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list