forked from stephenslab/susieR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove some unused functions, commented code etc from old elbo comput…
…atinos
- Loading branch information
1 parent
ef191ed
commit 9460e90
Showing
9 changed files
with
142 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: susieR | ||
Type: Package | ||
Title: Fit Sum of Single Effects linear regression model | ||
Version: 0.1.3 | ||
Version: 0.1.4 | ||
Author: Matthew Stephens | ||
Maintainer: <[email protected]> | ||
Description: Fits a sparse regression model with up to $L$ effects, where $L$ is user-specified. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
title: "optimize" | ||
author: "Matthew Stephens" | ||
date: "4/15/2018" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
Diagnose optimization issues with Lei's example | ||
```{r} | ||
set.seed(777) | ||
devtools::load_all(".") | ||
X <- matrix(rnorm(1010 * 1000), 1010, 1000) | ||
beta <- rep(0, 1000) | ||
beta[1 : 200] <- 100 | ||
y <- X %*% beta + rnorm(1010) | ||
s = susie(X,y,L=1,estimate_sa2 = TRUE) | ||
Y = y-s$Xr | ||
s2 = s$sigma2 | ||
x = seq(1,100000,length=100) | ||
l = rep(0,100) | ||
lg = rep(0,100) | ||
for(i in 1:100){ | ||
l[i] = loglik(x[i],Y,X,s2) | ||
lg[i] = loglik.grad(x[i],Y,X,s2) | ||
} | ||
plot(x,l) | ||
plot(x,lg) | ||
# > which.max(l) | ||
# [1] 23 | ||
# > lg[23] | ||
# [1] -2.398905e-07 | ||
# > lg[22] | ||
# [1] 6.282734e-07 | ||
lx = log(x) | ||
l2=l | ||
lg2=lg | ||
for(i in 1:100){ | ||
l2[i] = negloglik.logscale(lx[i],Y,X,s2) | ||
lg2[i] = negloglik.grad.logscale(lx[i],Y,X,s2) | ||
} | ||
plot(lx,l2) | ||
plot(lx,lg2) | ||
y = seq(0,20,length=100) | ||
l3=l2 | ||
lg3=lg2 | ||
for(i in 1:100){ | ||
l3[i] = negloglik.logscale(y[i],Y,X,s2) | ||
lg3[i] = negloglik.grad.logscale(y[i],Y,X,s2) | ||
} | ||
plot(y,l3) | ||
plot(y,lg3) | ||
uniroot(negloglik.grad.logscale,c(-20,20),extendInt = "upX",Y=Y,X=X,s2=s2) | ||
``` | ||
|
||
So, to summarize, problem seems to be that optim has issues with | ||
very flat initial gradient near 0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: "test.Rmd" | ||
author: "Matthew Stephens" | ||
date: "4/14/2018" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
# simulate data | ||
|
||
This is Lei's example | ||
```{r} | ||
set.seed(777) | ||
library(susieR) | ||
X <- matrix(rnorm(1010 * 1000), 1010, 1000) | ||
beta <- rep(0, 1000) | ||
beta[1 : 200] <- 100 | ||
y <- X %*% beta + rnorm(1010) | ||
s = susie(X,y,L=200) | ||
plot(coef(s),beta) | ||
s$sigma2 | ||
# fit <- lm(y ~ X - 1) | ||
# mlr.p <- log(summary(fit)$coefficients[, 4]) | ||
# | ||
mar.p <- c() | ||
mar.betahat = c() | ||
for (i in 1 : 1000) { | ||
fit <- lm(y ~ X[, i] - 1) | ||
mar.p[i] <- log(summary(fit)$coefficients[, 4]) | ||
mar.betahat[i] <- summary(fit)$coefficients[, 1] | ||
} | ||
# | ||
# pdf("pvalue.pdf", width = 10, height = 5) | ||
# par(mfrow = c(1, 2)) | ||
# plot(mlr.p, ylab = "log(p-value)", main = "Multiple Linear Regression") | ||
# abline(h = log(0.05 / 1000), lty = 2, col = "red") | ||
# legend("right", lty = 2, col = "red", "log(0.05/p)") | ||
# | ||
# plot(mar.p, ylab = "log(p-value)", main = "One-on-One Linear Regression") | ||
# abline(h = log(0.05 / 1000), lty = 2, col = "red") | ||
``` | ||
|
||
Notice that the coefficients are monotonic with betahat. Some shrinkage of zero values is evident, but it is not enough... presumably because sigma2 is way over-estimated. And further we see excessive shrinkage of true signals, presumably because sa2 is too small. | ||
```{r} | ||
plot(coef(s),mar.betahat) | ||
``` | ||
|
||
|
||
Here we try fixing sigma2 to true value. | ||
```{r} | ||
s2 = susie(X,y,L=300,sigma2=1,estimate_sigma2=FALSE) | ||
plot(coef(s2),beta) | ||
``` | ||
it works!! | ||
|
||
```{r} | ||
plot(s$alpha[1,]) | ||
plot(s$alpha[2,]) | ||
``` | ||
|
||
Try with larger prior on effect sizes | ||
```{r} | ||
s3 = susie(X,y,L=200, sa2 = 100) | ||
``` | ||
|
||
|