简体   繁体   中英

Generating random variables from a mixture of Weibull(0,1) and Uniform(0,1)

How would I create an R code algorithm to sample a mixture distribution of a truncated Weibull(0,1) and a Uniform(2,4) . The main part that is giving me difficulties is the truncated Weibull distribution. Typically, the Weibull distribution is defined on the positive real line so I can't use the built in functions that R provides. The mixture distribution is as follows:

f(x) = 0.3 × Weibull(0,1) + 0.7 ×U(2,4)

note: the truncated Weibull's distribution is as follows:

f(x; k, λ) = c(k/λ)[(x/λ)^(k−1)]exp{−(x/λ)^k}, x ∈ (0, 1)

where

c=1/{1 − exp(−1/(λ^k))}

The uniform numbers are generated by runif(100,2,4) . Given that the truncated Weibull has been generated somehow, you can mix them as follows:

u <- runif(100,2,4)
w <- ... # truncated weibull, see below
s <- runif(100)            # s <- rbinom(n,2,0.3)
x <- ifelse(s<0.3, w, u)   # x <- ifelse(s==1,w,u)

For the truncated Weibull, see page 6 of https://www.jstatsoft.org/article/view/v016c02/v16c02.pdf found by Google search. Alternatively, I would just generate Weibull random numbers (using rweibull ) and then truncate. Note: Are you sure that your shape parameter for weibull is zero?

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