From 66723c8f49ccf9dcf41748fd3f82c85292739fc6 Mon Sep 17 00:00:00 2001 From: AnqiWang2021 Date: Mon, 22 Apr 2024 09:59:12 -0400 Subject: [PATCH] small fix --- DESCRIPTION | 2 +- R/mash.R | 6 +++ man/create_cov_canonical.Rd | 4 +- man/mvsusie.Rd | 98 +++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 51 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1f224db..afbeed9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,6 +42,6 @@ Remotes: stephenslab/susieR LazyData: true NeedsCompilation: no -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 VignetteBuilder: knitr Roxygen: list(r6 = FALSE) diff --git a/R/mash.R b/R/mash.R index 50ad45e..83baa80 100644 --- a/R/mash.R +++ b/R/mash.R @@ -65,7 +65,13 @@ create_mixture_prior <- function(mixture_prior, R, null_weight = NULL, } if (!missing(R)) { Ulist <- create_cov_canonical(R, ...) + Ulist <- lapply(Ulist, function(mat) { + rownames(mat) <- include_indices + colnames(mat) <- include_indices + return(mat) + }) weights <- rep(1 / length(Ulist), length(Ulist)) + weights <- setNames(weights, names(Ulist)) if (max_mixture_len < length(Ulist) && max_mixture_len > 0) { stop(paste0( "Automatically generated uniform mixture prior is of ", diff --git a/man/create_cov_canonical.Rd b/man/create_cov_canonical.Rd index c20a6eb..17d1603 100644 --- a/man/create_cov_canonical.Rd +++ b/man/create_cov_canonical.Rd @@ -28,8 +28,8 @@ This function computes canonical covariance matrices } \examples{ mvsusieR:::create_cov_canonical(3) -mvsusieR:::create_cov_canonical(3,singletons = FALSE) -mvsusieR:::create_cov_canonical(3,hetgrid = NULL) +mvsusieR:::create_cov_canonical(3, singletons = FALSE) +mvsusieR:::create_cov_canonical(3, hetgrid = NULL) } \keyword{internal} diff --git a/man/mvsusie.Rd b/man/mvsusie.Rd index 8d47ccf..46739ce 100644 --- a/man/mvsusie.Rd +++ b/man/mvsusie.Rd @@ -86,7 +86,7 @@ variables.} \item{prior_variance}{Can be either (1) a vector of length L, or a scalar, for scaled prior variance when Y is univariate (which should then be equivalent to \code{\link[susieR]{susie}}); or (2) a -matrix for a simple multivariate regression; or (3) a mixture prior +matrix for a simple multivariate regression; or (3) a mixture prior from \code{\link{create_mixture_prior}}.} \item{residual_variance}{The residual variance} @@ -281,63 +281,65 @@ Performs a Bayesian multiple linear regression of Y on X. \examples{ # Example with one response. set.seed(1) -n = 2000 -p = 1000 -beta = rep(0,p) -beta[1:4] = 1 -X = matrix(rnorm(n*p),n,p) -Y = X \%*\% beta + rnorm(n) -fit = mvsusie(X,Y,L = 10) +n <- 2000 +p <- 1000 +beta <- rep(0, p) +beta[1:4] <- 1 +X <- matrix(rnorm(n * p), n, p) +Y <- X \%*\% beta + rnorm(n) +fit <- mvsusie(X, Y, L = 10) # Sufficient statistics example with one response. -X_colmeans = colMeans(X) -Y_colmeans = colMeans(Y) -X = scale(X,center = TRUE,scale = FALSE) -Y = scale(Y,center = TRUE,scale = FALSE) -XtX = crossprod(X) -XtY = crossprod(X,Y) -YtY = crossprod(Y) -res = mvsusie_suff_stat(XtX,XtY,YtY,n,L = 10,X_colmeans,Y_colmeans) +X_colmeans <- colMeans(X) +Y_colmeans <- colMeans(Y) +X <- scale(X, center = TRUE, scale = FALSE) +Y <- scale(Y, center = TRUE, scale = FALSE) +XtX <- crossprod(X) +XtY <- crossprod(X, Y) +YtY <- crossprod(Y) +res <- mvsusie_suff_stat(XtX, XtY, YtY, n, L = 10, X_colmeans, Y_colmeans) # RSS example with one response. -R = crossprod(X) -z = susieR:::calc_z(X,Y) -res = mvsusie_rss(z,R,N=n,L = 10) +R <- crossprod(X) +z <- susieR:::calc_z(X, Y) +res <- mvsusie_rss(z, R, N = n, L = 10) # Example with three responses. set.seed(1) -n = 500 -p = 1000 -true_eff = 2 -X = sample(c(0,1,2),size = n*p,replace = TRUE) -X = matrix(X,n,p) -beta1 = rep(0,p) -beta2 = rep(0,p) -beta3 = rep(0,p) -beta1[1:true_eff] = runif(true_eff) -beta2[1:true_eff] = runif(true_eff) -beta3[1:true_eff] = runif(true_eff) -y1 = X \%*\% beta1 + rnorm(n) -y2 = X \%*\% beta2 + rnorm(n) -y3 = X \%*\% beta3 + rnorm(n) -Y = cbind(y1,y2,y3) -prior = create_mixture_prior(R=3) -fit = mvsusie(X,Y,prior_variance = prior) +n <- 500 +p <- 1000 +true_eff <- 2 +X <- sample(c(0, 1, 2), size = n * p, replace = TRUE) +X <- matrix(X, n, p) +beta1 <- rep(0, p) +beta2 <- rep(0, p) +beta3 <- rep(0, p) +beta1[1:true_eff] <- runif(true_eff) +beta2[1:true_eff] <- runif(true_eff) +beta3[1:true_eff] <- runif(true_eff) +y1 <- X \%*\% beta1 + rnorm(n) +y2 <- X \%*\% beta2 + rnorm(n) +y3 <- X \%*\% beta3 + rnorm(n) +Y <- cbind(y1, y2, y3) +prior <- create_mixture_prior(R = 3) +fit <- mvsusie(X, Y, prior_variance = prior) # Sufficient statistics example with three responses. -X_colmeans = colMeans(X) -Y_colmeans = colMeans(Y) -X = scale(X,center = TRUE,scale = FALSE) -Y = scale(Y,center = TRUE,scale = FALSE) -XtX = crossprod(X) -XtY = crossprod(X,Y) -YtY = crossprod(Y) -res = mvsusie_suff_stat(XtX,XtY,YtY,n,L = 10,X_colmeans,Y_colmeans, - prior_variance = prior) +X_colmeans <- colMeans(X) +Y_colmeans <- colMeans(Y) +X <- scale(X, center = TRUE, scale = FALSE) +Y <- scale(Y, center = TRUE, scale = FALSE) +XtX <- crossprod(X) +XtY <- crossprod(X, Y) +YtY <- crossprod(Y) +res <- mvsusie_suff_stat(XtX, XtY, YtY, n, + L = 10, X_colmeans, Y_colmeans, + prior_variance = prior +) # RSS example with three responses. -R = crossprod(X) -Z = susieR:::calc_z(X,Y) -res = mvsusie_rss(Z,R,N=n,L = 10,prior_variance = prior) +R <- crossprod(X) +Z <- susieR:::calc_z(X, Y) +res <- mvsusie_rss(Z, R, N = n, L = 10, prior_variance = prior) }