elki
New Member
Posts: 3
|
Post by elki on Jun 21, 2017 13:25:29 GMT
Hello I am quite new in this area and just trying to use GRM made in GCTA software in R script. It works well to read GRM in R, but it create a Large list (4 elements: diag, off, id, N). How could I make it to Large matrix with all estimated elements (902500 in my case)?
Thanks in advance!
|
|
|
Post by Zhihong Zhu on Jun 22, 2017 3:41:16 GMT
Hi there,
Please find the R script which would return the whole matrix.
Cheers, Zhihong
GRMreader=function(filenm, flag=1) { xDt.bin <- paste(filenm, ".grm.bin", sep="") xDt.nfl <- paste(filenm, ".grm.N.bin", sep="") xDt.gid <- paste(filenm, ".grm.id", sep="") xDt.id <- read.table(xDt.gid) xDt.n <- dim(xDt.id)[1] xDt.grm <- readBin(file(xDt.bin, "rb"), n=xDt.n*(xDt.n+1)/2, what=numeric(0), size=4) sn <- sapply(1:xDt.n, sum_i) off <- xDt.grm[-sn] diag <- xDt.grm[sn] if(flag==1) return(list(diag=diag, off=off, n=xDt.n)) else { xDt.mat <- matrix(data=NA, nrow=xDt.n, ncol=xDt.n) xDt.mat[upper.tri(xDt.mat)] <- off xDt.mat <- t(xDt.mat) xDt.mat[upper.tri(xDt.mat)] <- off diag(xDt.mat) <- diag return(list(mat=xDt.mat, n=xDt.n)) } }
|
|
elki
New Member
Posts: 3
|
Post by elki on Jun 22, 2017 7:01:48 GMT
Thank you for your answer!
I have tested your script, but get some Error massage about object sum_i not found in match.fun(FUN). What should that object (sum_i) include?
Regards, Elena
|
|
|
Post by Zhihong Zhu on Jun 22, 2017 7:12:58 GMT
Hi Elena,
Please find the function as below.
Cheers, Zhihong
sum_i=function(i) { return(sum(1:i)) }
|
|
elki
New Member
Posts: 3
|
Post by elki on Jun 22, 2017 8:35:52 GMT
Thanks Regards, Elena
|
|