Hi, All,

 

I have a question about how to generate correlated data with non-normal
distribution? Basic, I have a variable a that follows a normal distribution,
a ~ N(0,1), then I want to generate another variable b that follows a
uniform distribution, b ~ U(0, 1). Most importantly, I want the correlation
between a and b to be fixed at -.9, cor(a,b) = -.90

 

I tried the following code,

 

### Correlation matrix rmvnorm() function ###

  Cormat <- matrix(c(1, -.9, -.9, 1), ncol = 2)   # Here, I want to create 2
variables that have correlation -.9

  

  ### Theta-Transform-Guessing ###

  DataSet <- data.frame(rmvnorm(1000, mean=c(0, 0), sigma=Cormat))

  Names(DataSet) <- c("a", "trans")

  

  ### Using trans to be transformed into guessing parameters ###

  DataSet$b <- pnorm(DataSet$trans, mean=mean(DataSet$trans),
sd=sd(DataSet$trans)) # Here, I used the pnorm() function to transform one
variable to a U(0, 1)

 

However, the correlation is changed. Can anyone give me some suggestion that
how can I generate the data?

 

Thanks,

Ruofei


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to