简体   繁体   中英

Generate probabilities of a normal distribution under special condition

In my work, I need to use normal distribution in order to generate probabilities, where sum of these probabilities are less than or equal to 1, it means:

generate P1,P2,..,Pt where P1+P2+..+Pt <= 1 I want to do that with R , but I don't know exactly how should I do that.

Are you sure about what you are asking?

x <- rnorm(100)
Fn <- ecdf(x)
#plot(Fn)
Fn(max(x))
> Fn(max(x))
[1] 1

If I understand correctly. If you want to generate 4 probabilities from 4 normal random variables, you can do

x <- rnorm(4)
p <- exp(x)/sum(exp(x))
all(p<1) == TRUE
sum(p) == 1

If you want a sum that's less than or equal to 1, here's a transformation that may work (not sure how to make it pretty).

x <- rnorm(4)
p <- exp(x)/sum(exp(x))
b<-numeric(4)
b[1]<-p[1]
b[2]<-p[2]-p[1]*p[2]
b[3]<-p[3]-p[2]*p[3]+p[1]*p[2]*p[3]
b[4]<-p[4]-p[3]*p[4]+p[2]*p[3]*p[4]-p[1]*p[2]*p[3]*p[4]
all(b<1) == TRUE
sum(b) <= 1

Although i'm worried this method may have a bias. Right now the p 's sum to 1. It would be better if there were a way to make each p a number 0-1 (so the sum may be 0-4).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM