dimanche 12 août 2018

Sampling from a specific part of a normal distribution in R

I'm trying to first extract all values <= -4 (call these p1) from a mother normal distribution. Then, randomly sample 50 of p1s with replacement according to their probability of being selected in the mother (call these 50s p2).

I was wondering if my R code below correctly captures what I described above?

mother <- rnorm(1e6)
p1 <- mother[mother <= -4]
p2 <- sample(p1, 50, replace = T)

enter image description here




Aucun commentaire:

Enregistrer un commentaire