[R] A vector of normal distributed values with a sum-to-zero constraint
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Tue Apr 1 15:27:03 CEST 2014
You are on a fool's errand. Read FAQ 7.31.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
On April 1, 2014 5:56:24 AM PDT, "Marc Marí Dell'Olmo" <marceivissa at gmail.com> 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
>> sum(aux2)
>[1] -0.000000000006131392
>>
>> aux[1]<- -sum(aux[2:l])
>> sum(aux)
>[1] -0.00000000000003530422
>
>
>but the sum is not exactly zero and not all parameters are N(0,0.5)
>distributed...
>
>Perhaps is obvious but I can't find the way to do it..
>
>Thank you very much!
>
>Marc
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>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
mailing list