Skip to content

Commit

Permalink
Added genlasso to Suggests; compressed data sets; other various impro…
Browse files Browse the repository at this point in the history
…vements and revisions throughout.
  • Loading branch information
pcarbo committed Jul 1, 2020
1 parent 08c1e49 commit efa66a1
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
^\.Rproj\.user$
^\.travis\.yml$
^.*\.Rproj$
^data/N3finemapping\.CAVIAR\.RData$
^data/N3finemapping\.DAP\.RData$
^data/N3finemapping\.FINEMAP\.RData$

5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Description: Implements methods for variable selection in linear
and fast, allowing the SuSiE model be fit to large data sets
(thousands of samples and hundreds of thousands of variables).
Date: 2020-06-30
Version: 0.9.5
Version: 0.9.6
Authors@R: c(person("Gao","Wang",role="aut",email="[email protected]"),
person("Yuxin","Zou",role="aut"),
person("Kaiqian","Zhang",role="aut"),
Expand All @@ -40,7 +40,8 @@ Suggests:
microbenchmark,
knitr,
rmarkdown,
L0Learn
L0Learn,
genlasso
LazyData: true
NeedsCompilation: no
RoxygenNote: 7.1.0
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ importFrom(stats,sd)
importFrom(stats,summary.lm)
importFrom(stats,uniroot)
importFrom(stats,var)
importFrom(utils,head)
importFrom(utils,modifyList)
20 changes: 11 additions & 9 deletions R/elbo.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#' @title Get objective function from data and susie fit object.
#' @param data A flash data object.
#' @param f A flash fit object.
#' @keywords internal
# @title Get objective function from data and susie fit object.
# @param data A flash data object.
# @param f A flash fit object.
# @keywords internal
get_objective = function(X, Y, s) {
return(Eloglik(X,Y,s)-sum(s$KL))
}

# @title expected loglikelihood for a susie fit
# Expected loglikelihood for a susie fit.
Eloglik = function(X,Y,s){
n = nrow(X)
result = -(n/2) * log(2*pi* s$sigma2) - (1/(2*s$sigma2)) * get_ER2(X,Y,s)
result = -(n/2) * log(2*pi* s$sigma2) - (1/(2*s$sigma2)) * get_ER2(X,Y,s)
return(result)
}

# expected squared residuals
# Expected squared residuals.
get_ER2 = function(X,Y,s){
# Xr_L is L by N matrix
# s$Xr is column sum of Xr_L
Xr_L = compute_MXt(s$alpha*s$mu, X)
postb2 = s$alpha * s$mu2 #posterior second moment
postb2 = s$alpha * s$mu2 # posterior second moment
return(sum((Y-s$Xr)^2) - sum(Xr_L^2) + sum(attr(X, "d")*t(postb2)))
}

Expand All @@ -30,5 +30,7 @@ get_ER2 = function(X,Y,s){
# @param Eb2 the posterior second moment of b (p vector) (alpha * mu2)
SER_posterior_e_loglik = function(X,Y,s2,Eb,Eb2){
n = nrow(X)
return(-0.5*n*log(2*pi*s2) - (0.5/s2) * (sum(Y*Y) - 2*sum(Y*compute_Xb(X, Eb)) + sum(attr(X,'d')*Eb2)))
return(-0.5*n*log(2*pi*s2)
- (0.5/s2) * (sum(Y*Y) - 2*sum(Y*compute_Xb(X, Eb))
+ sum(attr(X,'d')*Eb2)))
}
1 change: 0 additions & 1 deletion R/susie.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ susie <- function(X,Y,L = min(10,ncol(X)),scaled_prior_variance = 0.2,
elbo[1] = -Inf;
tracking = list()


for(i in 1:max_iter){
#s = add_null_effect(s,0)
if (track_fit)
Expand Down
4 changes: 2 additions & 2 deletions R/susie_ss.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
#' X <- matrix(rnorm(n*p),nrow=n,ncol=p)
#' y <- c(X %*% beta + rnorm(n))
#' input_ss <- compute_ss(X,y,standardize = TRUE)
#' ss = susieR:::univariate_regression(X, y)
#' R = with(input_ss, cov2cor(XtX))
#' ss <- susieR:::univariate_regression(X, y)
#' R <- with(input_ss, cov2cor(XtX))
#' res1 <- with(input_ss,susie_suff_stat(XtX = XtX,Xty = Xty, yty = yty,n=n))
#' coef(res1)
#' res2 <- with(ss,susie_suff_stat(bhat = betahat, shat = sebetahat, R = R, n=n, var_y = var(y)))
Expand Down
4 changes: 3 additions & 1 deletion R/susie_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ calc_z = function(X,Y,center=FALSE,scale=FALSE){
#' @param b for simulated data, specify b = true effects (highlights in red).
#' @param max_cs the biggest CS to display, based on purity (set max_cs in between 0 and 1) or size (>1).
#' @param add_legend if TRUE, add a legend to annotate the size and purity of each CS discovered.
#'
#' @importFrom utils head
#' @importFrom stats pnorm
#' @importFrom graphics plot
#' @importFrom graphics segments
Expand Down Expand Up @@ -505,4 +507,4 @@ susie_get_posterior_sd = function(res){
#' @export
susie_get_niter = function(res) {
return(res$niter)
}
}
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ but they are too correlated to be sure which one.

The package is developed by Gao Wang, Peter Carbonetto, Yuxin Zou,
Kaiqian Zhang, and Matthew Stephens from the
[Stephens Lab](http://stephenslab.uchicago.edu/) at the University of
[Stephens Lab](http://stephenslab.uchicago.edu) at the University of
Chicago.

This is very much work in progress. Please
Expand All @@ -39,7 +39,7 @@ questions, get our support or provide us feedback; please
[send pull requests](https://github.com/stephenslab/susieR/pulls) if
you have helped fixing bugs or making improvements to the source code.

## Setup
## Quick Start

To automatically retrieve and install `susieR` from this repository,
with the vignettes included, run:
Expand All @@ -48,8 +48,6 @@ with the vignettes included, run:
devtools::install_github("stephenslab/[email protected]")
```

## Quick Start

See [here](https://stephenslab.github.io/susieR/articles/mwe.html) for
a brief illustration of `susieR`. For more documentation and examples
please visit https://stephenslab.github.io/susieR
Expand All @@ -59,23 +57,15 @@ please visit https://stephenslab.github.io/susieR
If you find the `susieR` package or any of the source code in this
repository useful for your work, please cite:

> G Wang, A K Sarkar, P Carbonetto and M Stephens. A simple new approach to variable selection in regression, with application to genetic fine-mapping.
> [bioRxiv](https://www.biorxiv.org/content/10.1101/501114v2) doi:10.1101/501114.
> G Wang, A K Sarkar, P Carbonetto and M Stephens. [A simple new
> approach to variable selection in regression, with application to
> genetic fine-mapping.][susie-preprint] *bioRxiv* doi:10.1101/501114.
## Developer notes

+ When any changes are made to `roxygen2` markup, simply run
`devtools::document()` to update package `NAMESPACE`
and documentation files.

+ To install and test the development version of susieR, run the
following commands in the shell:

```bash
R CMD build --resave-data --no-build-vignettes susieR
R CMD INSTALL susieR_0.9.0.tar.gz
R CMD check --as-cran --ignore-vignettes susieR_0.9.0.tar.gz
```
+ When any changes are made to `roxygen2` markup, run
`devtools::document()` to update package `NAMESPACE` and documentation
files.

+ Run `pkgdown::build_site()` to build the website. Getting `pkgdown`
to work properly can be frustrating due to numerous & fragile dependencies.
Expand All @@ -87,3 +77,5 @@ docker run --rm --security-opt label:disable -t -P -w $PWD -v $PWD:$PWD \
-u $UID:${GROUPS[0]} -e HOME=/home/$USER -e USER=$USER gaow/susie \
R --slave -e "pkgdown::build_site(lazy=TRUE, examples=FALSE)"
```

[susie-preprint]: https://doi.org/10.1101/501114
8 changes: 7 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
to do
=====

+ Improve Description in DESCRIPTION.
+ Update (and shorten) description in README.

+ Fill out roxygen2 docs for N2finemapping data set.

+ Fill out roxygen2 docs for N3finemapping data set.

+ Update pkgdown site.

Binary file modified data/N2finemapping.RData
Binary file not shown.
Binary file modified data/N3finemapping.CAVIAR.RData
Binary file not shown.
Binary file modified data/N3finemapping.DAP.RData
Binary file not shown.
Binary file modified data/N3finemapping.FINEMAP.RData
Binary file not shown.
Binary file modified data/N3finemapping.RData
Binary file not shown.
17 changes: 0 additions & 17 deletions man/get_objective.Rd

This file was deleted.

4 changes: 2 additions & 2 deletions man/susie_suff_stat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efa66a1

Please sign in to comment.