Skip to content

Instantly share code, notes, and snippets.

View hakyim's full-sized avatar

Hae Kyung Im hakyim

View GitHub Profile
X = GXM
filename = paste0(data.dir,"tempo/gcta-run/gxm.grm")
ids = rnadata$sidno
write_GRMgz = function(X,filename,ids)
{
#X[upper.tri(X,diag=TRUE)]
rmat = row(X)
cmat = col(X)
omat = cbind(cmat[upper.tri(cmat,diag=TRUE)],rmat[upper.tri(rmat,diag=TRUE)],ncol(rnamat),X[upper.tri(X,diag=TRUE)])
write_tsv(data.frame(omat),path=filename,col_names = FALSE)
@hakyim
hakyim / fastlm.R
Last active January 21, 2021 23:46
## Relatively fast linear regression
fastlm = function(xx,yy)
{
## compute betahat (regression coef) and pvalue with Ftest
## for now it does not take covariates
df1 = 2
df0 = 1
ind = !is.na(xx) & !is.na(yy)
@hakyim
hakyim / fn_ratxcan.R
Last active May 1, 2024 01:35
RatXcan functions
# calculate ptrs function
calc_ptrs <- function(expr, weights)
{
fast_generate_trait(expr, weights) %>% as.data.frame() %>% rownames_to_column(var = "IID") %>% tibble()
}
fast_generate_trait <- function(expr, weights){
# convert the predicted df into a matrix
if(!is.matrix(expr)) test <- expr %>% column_to_rownames(var = "IID") %>%
as.matrix() else test <- expr