比较SAS RandNormal和rmvnorm(mvtnorm):rmvnorm出现意外结果

时间:2019-12-12 14:15:58

标签: r sas mixed-models simulate

我在SAS上模拟了数据,其中有861棵杨树。这些树与相关矩阵K相关。假定varcov已知并且等于sigmaG K + sigmaE I。 sigmaG设置为3.5,sigmaE设置为2.5。有1个预测变量beta设置为2.5,截距设置为1。sascode如下:


proc iml;
  use work.dataK;                       /* open the data set */
  read all var _ALL_ into K; 
  close work.dataK;

  use work.snps;                       /* open the data set */
  read all var _ALL_ into GT; 
  close work.snps;

  snp2 = GT[,2]; 

  n=861;                          
  sigma2_g = 3.4;                 
  sigma2_e = 2.5;
  beta = {1, 2.5}; 
    print(beta);

    G = sigma2_g*K ;
    R = sigma2_e*I(n);
    varcov = G + R ;
    print(varcov);

    treeID = colvec(1:n);

    X = J(n,1,1)||GT[,2] ; /*col vector of 1 for intercept*/

    call randseed(1234);
  create simdata2 var {"treeID" "trait1" "snp2"};     

  zero = j(1, n, 0);            /* the zero vector                  */
  eps = RandNormal(1, zero, varcov);   /* eps ~ MVN(0,varcov)                   */
  trait1 = X*beta + eps`;         /* fixed effects, correlated errors */

  append; 
  close;
quit;

并进行以下分析:

Proc mixed data = input METHOD=REML noprofile covtest itdetails ;
        class treeID  ;
        model x = snp&snp /s ddfm=KR vciry outpm=out chisq;
        random treeID / type=lin(1) ldata=kin ;
        parms/ lowerb= 0 0;
run;

这将产生预期的结果

但是,当我在R中进行模拟时:

sigma2_g <- 3.4 
sigma2_e <- 2.5
beta1 <- 2.7

I <- diag(nrow = nrow(X_snps_additive), ncol = nrow(X_snps_additive))
Intercept <- matrix(nrow = nrow(X_snps_additive), ncol = 1, data = 1)

G <- sigma2_g * K
R <- sigma2_e * I
var_cov <- G + R

SNP1 <- X_snps_additive[, colnames(X_snps_additive)=="SNP_SNP_IGA_1_21572990"]
lin1 <- as.matrix(SNP1) %*% beta1

zeros <- replicate(n = dim(K)[1], expr = 0)

library(mvtnorm)
error = mvtnorm::rmvnorm(n = 1, mean = zeros, sigma = var_cov, method="chol")
error = as.vector(error)
trait <- as.vector(lin1 + Intercept + error)

随后在SAS中进行分析,然后对sigmaG的估计关闭了。

0 个答案:

没有答案