[R] Simulating Conditional Distributions

From: Sherri Rose <sherri_at_berkeley.edu>
Date: Fri, 21 Mar 2008 22:37:39 -0700

Dear R-Help List,
I'm trying to simulate data from a conditional distribution, and haven't been able to modify my existing code to do so. I searched the archives, but didn't find any previous post that matched my question.

pop = data.frame(W1 = rbinom(n, 1, .2),

   W2 = runif(n, min = 3, max = 8), W3 = rnorm(n, mean=0, sd=2)) pop = transform(pop,

   A = rbinom(n, 1, .5))
pop = transform(pop,

   Y = rbinom(n, 1, 1/(1+exp(-(1.5*A-.05*W1-2*W2-2*W3+2*A*W1)))))

In this population the probability of being "diseased" (Y=1) is approx 0.030. What I want to be able to do is specify a conditional distribution of (A, W1, W2, W3) given that Y=1 and one for (A, W1, W2, W3) given that Y=0. Then I can sample diseased and non-diseased individuals from these distributions without having to simulate a large base population. This will be particularly useful when the probability of being "diseased" is even smaller and I want a large number of diseased individuals.

Any pointers to do this would be extremely helpful! Thank you,
Sherri Rose

UC Berkeley

        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 22 Mar 2008 - 09:40:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 26 Mar 2008 - 05:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive