以下代码是我想到的,有点慢,有什么建议吗?谢谢!
细节是首先proc iml
使用 R 代码创建一个数据集,然后将其传输到常规 SASproc mixed
语句中进行分析,然后用于proc append
存储结果,然后迭代该过程 10000 次。
proc iml;
do i= 1 to 100000;
submit / R;
library(mvtnorm)
library(dplyr)
library(tidyr)
beta <- matrix(1:50, byrow = TRUE,10,5)
sigma <- matrix(1:25, 5)
sigma [lower.tri(sigma )] = t(sigma )[lower.tri(sigma )]
sample <- t(apply(beta, 1, function(m) rmvnorm(1, mean=m, sigma=sigma)))
Group = rep(factor(LETTERS[1:2]),each=5,1)
sample <- cbind(sample,Group,c(1:5))
concat <- function(x) paste0('Visit', x[, 2], 'Time', x[, 1])
cnames <- c(paste0("Time", 1:5),"Group","ID")
colnames(sample) <- cnames
sample <- data.frame(sample)
sample <- gather(sample, Visit, Response, paste0("Time", 1:5), factor_key=TRUE)
endsubmit;
call ImportDataSetFromR( "rdata", "sample" );
submit;
Proc mixed data=rdata;
ods select none;
class Group Visit ID;
model Response = Visit|Group;
repeated Visit/ subject=ID type=un;
ods output Tests3=Test;
run;
proc append data=Test base=result force ;
run;
ENDSUBMIT;
end;
Quit;
proc print data=result;
run;