Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vignette with Multiple Groups and Specifying Null Genes #2

Open
dcgerard opened this issue Dec 26, 2020 · 0 comments
Open

Add Vignette with Multiple Groups and Specifying Null Genes #2

dcgerard opened this issue Dec 26, 2020 · 0 comments

Comments

@dcgerard
Copy link
Owner

A frequent question concerns setting up multiple groups and specifying the null genes. Adding a vignette would help out a lot.

Here is the script I usually send folks, and this could easily be turned into a vignette if it's cleaned up a little.

library(seqgendiff)
set.seed(1)

## Generate some simulated data. In practice you would use real data.
n <- 100
p <- 1000
Y <- rpois(n = n*p, lambda = 100)
dim(Y) <- c(p, n)

## Subsample individuals so that simulation does not depend on quirks
## of some genes.
Ysub <- select_counts(mat = Y, nsamp = 50, ngene = 1000)

## Generate design and coefficient matrices
group <- sample(c(1:4), size = ncol(Ysub), replace = TRUE)
group <- as.factor(group)
X <- model.matrix(~group)
X <- X[, -1, drop = FALSE] ## Remove intercept
betamat <- rnorm(ncol(X) * nrow(Ysub))
dim(betamat) <- c(nrow(Ysub), ncol(X))

## Choose which genes are null by setting those rows in betamat to 0
nullvec <- sample(x = c(TRUE, FALSE),
                  size = nrow(betamat),
                  replace = TRUE,
                  prob = c(0.9, 0.1))
betamat[nullvec, ] <- 0

## X is the design matrix representing group.
X

## betamat is the coefficient matrix containing effect sizes for
## each group at each gene
head(betamat)

## Thin
thout <- thin_diff(mat = Ysub, design_perm = X, coef_perm = betamat)
Ynew <- thout$mat
Xnew <- thout$designmat
betanew <- thout$coefmat

## Compare linear regression estimates with true coefficients
coefest <- t(coef(lm(log2(t(Ynew) + 0.5) ~ Xnew))[-1, , drop = FALSE])
plot(coefest, betanew)
abline(0, 1, lty = 2, col = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant