[R] A vector of normal distributed values with a sum-to-zero constraint
boris.steipe at utoronto.ca
Tue Apr 1 15:29:46 CEST 2014
Make a copy with opposite sign. This is Normal, symmetric, but no longer random.
x <- rnorm(5000, 0, 0.5)
x <- c(x, -x)
On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote:
> Dear all,
> Anyone knows how to generate a vector of Normal distributed values
> (for example N(0,0.5)), but with a sum-to-zero constraint??
> The sum would be exactly zero, without decimals.
> I made some attempts:
>> l <- 1000000
>> aux <- rnorm(l,0,0.5)
>> s <- sum(aux)/l
>> aux2 <- aux-s
>  -0.000000000006131392
>> aux<- -sum(aux[2:l])
>  -0.00000000000003530422
> but the sum is not exactly zero and not all parameters are N(0,0.5)
> Perhaps is obvious but I can't find the way to do it..
> Thank you very much!
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help