R/runifsphere.R

Defines functions `runifsphere`

`runifsphere` <-
function(n,p)
    {
    p<-as.integer(p)
    if(!is.integer(p)) stop("p must be an integer larger or equal than 2")
    if(p<2) stop("p must be an integer larger or equal than 2")
    
    Mnormal <- matrix(rnorm(n*p,0,1),nrow=n)
    rownorms <- sqrt(rowSums(Mnormal^2))
    
    unifsphere <- sweep(Mnormal,1,rownorms, "/")
    return(unifsphere)
    }

Try the MNM package in your browser

Any scripts or data that you put into this service are public.

MNM documentation built on May 2, 2019, 5:09 a.m.