Learn R Programming

ggm (version 2.5.1)

rsphere: Random vectors on a sphere

Description

Generates a sample of points uniformly distributed on the surface of a sphere in d-space.

Usage

rsphere(n, d)

Value

a matrix of n rows and d columns.

Arguments

n

an integer, the sample size.

d

an integer, the dimension of the space. For example, a circle is defined in 2D-space, a sphere in 3D-space.

Author

Giovanni M. Marchetti

Details

The algorithm is based on normalizing to length 1 each d-vector of a sample from a multivariate normal \(N(0, I)\).

See Also

rnorm, rcorr

Examples

Run this code
## 100 points on circle
z <- rsphere(100,2)
plot(z)

## 100 points on a sphere
z <- rsphere(100, 3)
pairs(z)

Run the code above in your browser using DataLab