Looking for help with the following problem. Given a sample of zeros and ones, for example:> VECTOR1<-rep(c(1,0),c(15,10))> VECTOR1[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 How would I create a new sample (VECTOR2) also containing zeros and ones, in which the phi-coefficient between the two sample vectors was drawn from a population with a known phi-coefficient value? Basically, I have a vector of zeros and ones and want to simulate another vector such that the two vectors have a known phi-coefficient. I know there are ways to do this with normally distributed numbers (for example the mvrnorm function in MASS), but am stumped when dealing with dichotomous variables. Appreciate any thoughts. Paul [[alternative HTML version deleted]]
Please pardon my ignorance, but what's a "phi coefficient" in this context? RSiteSearch("phi coefficient") produced 36 hits that seemed to discuss issues unrelated to your question. If it refers to correlation, have you considered something like the following: VECTOR1<-rep(c(1,0),c(15,10)) n <- length(VECTOR1) library(MASS) Sig <- array(c(1,.5, .5, 1), dim=c(2,2)) z <- mvrnorm(n, mu=c(0,0), Sigma=Sig) p <- mean(VECTOR1) q. <- qnorm(p) Z <- 0+(z<q.) hope this helps. spencer graves Bliese, Paul D LTC USAMH wrote:> Looking for help with the following problem. > > > > Given a sample of zeros and ones, for example: > > > > >>VECTOR1<-rep(c(1,0),c(15,10)) > > >>VECTOR1 > > > [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 > > > > How would I create a new sample (VECTOR2) also containing zeros and > ones, in which the phi-coefficient between the two sample vectors was > drawn from a population with a known phi-coefficient value? > > > > Basically, I have a vector of zeros and ones and want to simulate > another vector such that the two vectors have a known phi-coefficient. > > > > I know there are ways to do this with normally distributed numbers (for > example the mvrnorm function in MASS), but am stumped when dealing with > dichotomous variables. > > > > Appreciate any thoughts. > > > > Paul > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves at pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915
> From: "Bliese, Paul D LTC USAMH" <paul.bliese at us.army.mil> > > Given a sample of zeros and ones, for example: > > VECTOR1<-rep(c(1,0),c(15,10)) > How would I create a new sample (VECTOR2) also containing zeros and > ones, in which the phi-coefficient between the two sample vectors was > drawn from a population with a known phi-coefficient value? > > I know there are ways to do this with normally distributed numbers (for > example the mvrnorm function in MASS), but am stumped when dealing with > dichotomous variables. > > PaulOne way is to sample from the 2x2 table with the specified means and pearson correlation (phi): for a fourfold table, a b c d with marginal proportions p1 and p2 cov <- phi * sqrt(p1*(1-p1)*p2*(1-p2)) a <- p1*p2 + cov b <- p1*(1-p2) - cov c <- (1-p1)*p2 - cov d <- (1-p1)*(1-p2) + cov expand.grid(0:1,0:1)[sample(1:4, size=25, replace=TRUE, prob=c(a,b,c,d)),] David. | David Duffy (MBBS PhD) ,-_|\ | email: davidD at qimr.edu.au ph: INT+61+7+3362-0217 fax: -0101 / * | Epidemiology Unit, Queensland Institute of Medical Research \_,-._/ | 300 Herston Rd, Brisbane, Queensland 4029, Australia GPG 4D0B994A v