I would like to plot in R a discrete uniform random variable having variance 1, with an interval of [-a,a].
I have tried using Var(X)= (n^2-1)/12
Then getting that n should be n = sqrt(13)
Plugging this into
n=b-a+1=a-(-a)+1
a=(sqrt(13)-1)/2 = 1.302776
Trying this in R with the code
X <- sample(-1.302276:1.30227,1000, replace=TRUE)
The variance becomes around 0.65
The variance of a uniform distribution between a
and b
is (b - a) * (b - a) / 12
.
Therefore, for the interval [-a, +a]
to have a variance of 1, you need to set
a = sqrt(3)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.