Hi Marc
I think that we could help you better if we knew in which context you need
sample from a sum constrained normal distribution. However this is more a
question on probability theory than on how to do it in R.
The proposal so far has been linear transformation of multivariate normal
On 01 Apr 2014, at 17:22 , Rui Barradas ruipbarra...@sapo.pt wrote:
Hello,
One way is to use ?scale.
...except that the sd will be less than 0.5 (not obvious at n=1e6, though).
However, if you want
- normal distribution
- symmetry
- constant marginal variance of sigma^2
- fixed sum = 0
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 - 100
aux - rnorm(l,0,0.5)
s - sum(aux)/l
aux2 - aux-s
sum(aux2)
[1]
You are on a fool's errand. Read FAQ 7.31.
---
Jeff NewmillerThe . . Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go...
Make a copy with opposite sign. This is Normal, symmetric, but no longer random.
set.seed(112358)
x - rnorm(5000, 0, 0.5)
x - c(x, -x)
sum(x)
hist(x)
B.
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
The sum-to-zero constraint imposes a loss of one degree of freedom. Of N
samples, only (N-1) can be random. Thus the solution is
N - 100
x - rnorm(N-1)
x - c(x, -sum(x))
sum(x)
[1] -7.199102e-17
Boris Steipe boris.ste...@utoronto.ca
Sent by: r-help-boun...@r-project.org
But the result is not Normal. Consider:
set.seed(112358)
N - 100
x - rnorm(N-1)
sum(x)
[1] 1.759446 !!!
i.e. you have an outlier at 1.7 sigma, and for larger N...
set.seed(112358)
N - 1
x - rnorm(N-1)
sum(x)
[1] -91.19731
B.
On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote:
Boris is right. I need this vector to include as initial values of a
MCMC process (with openbugs) and If I use this last approach sum(x)
could be a large (or extreme) value and can cause problems.
The other approach x - c(x, -x) has the problem that only vectors
with even values are obtained.
It seems so simple to me, that I must be missing something.
Subject to Jeff Newmiller's reminder of FAQ 7.31; if the sum is zero
then the mean is zero and vice versa.
The OP's original attempt of:
-
l - 100
aux - rnorm(l,0,0.5)
s - sum(aux)/l
aux2 - aux-s
sum(aux2)
Then what's wrong with centering your initial values around the mean?
Marc Marí Dell'Olmo marceivi...@gmail.com
04/01/2014 10:56 AM
To
Boris Steipe boris.ste...@utoronto.ca,
cc
jlu...@ria.buffalo.edu, r-help@r-project.org r-help@r-project.org
Subject
Re: [R] A vector of normal distributed
Hello,
One way is to use ?scale.
set.seed(4867)
l - 100
aux - rnorm(l, 0, 0.5)
aux - scale(aux, scale = FALSE)
sum(aux)
hist(aux, prob = TRUE)
curve(dnorm(x, 0, 0.5), from = -2, to = 2, add = TRUE)
Hope this helps,
Rui Barradas
Em 01-04-2014 16:01, jlu...@ria.buffalo.edu escreveu:
Then
Here is one approach to generating a set (or in this case multiple
sets) of normals that sum to 0 (with a little round off error) and
works for an odd number of points:
v - matrix(-1/8, 9, 9)
diag(v) - 1
eigen(v)
x - mvrnorm(100,mu=rep(0,9), Sigma=v, empirical=TRUE)
rowSums(x)
range(.Last.value)
12 matches
Mail list logo