[R] generate multivariate F with specified correlation matrix

Ben Bolker bolker at ufl.edu
Sat Nov 17 18:20:05 CET 2007




Jiao Yang wrote:
> 
> Dear all,
> 
> In MATLAB, to generate multivariate F with specified correlation matrix Pn
> I can use the code such as
> 
> Z = mvnrnd([0 0 0 0 0], Pn, N);
> U = normcdf(Z,0,1);
> X = [finv(U(:,1),5,15) finv(U(:,2),5,15) finv(U(:,3),5,15)
> finv(U(:,4),5,15) finv(U(:,5),5,15)];
> 
> Is there something similar in R?
> 
> 

  mvnrnd  -> mvrnorm (MASS package)
  normcdf -> pnorm
  finv -> qf (I think)

so 

library(MASS)
vcmat <- diag(5)
vcmat[row(vcmat)!=col(vcmat)] <- 0.1

Z <- mvrnorm(n=10,mu=rep(0,5),Sigma=vcmat)
U <- pnorm(Z,0,1)
X <- qf(U,5,15)

   Of course, I haven't really tested to see that this makes sense --
you can do that.  (Note that mvrnorm takes a variance-covariance
matrix, not a correlation matrix, as an argument -- I suspect this
is true of mvnrnd as well.)

  cheers
      Ben Bolker
-- 
View this message in context: http://www.nabble.com/generate-multivariate-F-with-specified-correlation-matrix-tf4824153.html#a13811194
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list