Skip to content

Commit

Permalink
More revisions to the roxygen2 docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarbo committed Jul 1, 2020
1 parent b9f0fa5 commit e585e3f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 97 deletions.
2 changes: 1 addition & 1 deletion 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.7
Version: 0.9.8
Authors@R: c(person("Gao","Wang",role="aut",email="[email protected]"),
person("Yuxin","Zou",role="aut"),
person("Kaiqian","Zhang",role="aut"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export(susie_plot_iteration)
export(susie_rss)
export(susie_suff_stat)
export(susie_trendfilter)
importFrom(Matrix,colMeans)
importFrom(Matrix,colSums)
importFrom(Matrix,crossprod)
importFrom(Matrix,diag)
importFrom(Matrix,rowSums)
importFrom(Matrix,t)
importFrom(Matrix,tcrossprod)
importFrom(grDevices,dev.off)
Expand Down
11 changes: 6 additions & 5 deletions R/set_R_attributes.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#' @title sets the attributes for the R matrix
#' @param R a p by p LD matrix
#' @param r_tol tolerance level for eigen value check of positive semidefinite matrix of R
#' @return R with attribute e.g.
#' attr(R, 'eigenR') is the eigen decomposition of R.
# @title sets the attributes for the R matrix
# @param R a p by p LD matrix
# @param r_tol tolerance level for eigen value check of positive
# semidefinite matrix of R.
# @return R with attribute e.g., attr(R, 'eigenR') is the eigen
# decomposition of R.
set_R_attributes = function(R, r_tol){
if(is.null(attr(R, 'eigen')))
eigenR = eigen(R, symmetric = TRUE)
Expand Down
54 changes: 27 additions & 27 deletions R/set_X_attributes.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#' @title sets three attributes for matrix X
#' @param X an n by p data matrix that can be either a trend filtering matrix or a regular dense/sparse matrix
#' @param center boolean indicating centered by column means or not
#' @param scale boolean indicating scaled by column standard deviations or not
#' @return X with three attributes e.g.
#' attr(X, 'scaled:center') is a p vector of column means of X if center=TRUE, a p vector of 0s otherwise.
#' attr(X, 'scaled:scale') is a p vector of column standard deviations of X if scale=TRUE, a p vector of 1s otherwise.
#' attr(X, 'd') is a p vector of column sums of X.standardized^2,
#' where X.standardized is the matrix X centered by attr(X, 'scaled:center') and scaled by attr(X, 'scaled:scale').
set_X_attributes = function(X,
center = TRUE,
scale = TRUE) {
# @title sets three attributes for matrix X
# @param X an n by p data matrix that can be either a trend filtering
# matrix or a regular dense/sparse matrix
# @param center boolean indicating centered by column means or not
# @param scale boolean indicating scaled by column standard deviations or not
# @return X with three attributes e.g. `attr(X, 'scaled:center') is a
# p vector of column means of X if center=TRUE, a p vector of zeros
# otherwise. 'attr(X, 'scaled:scale') is a p vector of columan standard
# deviations of X if scale=TRUE, a p vector of 1s otherwise. 'attr(X,
# 'd') is a p vector of column sums of X.standardized^2,' where
# X.standardized is the matrix X centered by attr(X, 'scaled:center')
# and scaled by attr(X, 'scaled:scale').
#
#' @importFrom Matrix rowSums
#' @importFrom Matrix colMeans
set_X_attributes = function(X, center = TRUE, scale = TRUE) {
# if X is a trend filtering matrix
if (!is.null(attr(X, "matrix.type"))) {
order <- attr(X,"order")
Expand All @@ -18,40 +22,36 @@ set_X_attributes = function(X,
attr(X, "scaled:center") <- compute_tf_cm(order, n)
attr(X, "scaled:scale") <- compute_tf_csd(order, n)
attr(X, "d") <- compute_tf_d(order,n,attr(X, "scaled:center"),attr(X, "scaled:scale"),scale,center)
if (!center) {
if (!center)
attr(X, "scaled:center") <- rep(0, n)
}
if (!scale) {
if (!scale)
attr(X, "scaled:scale") <- rep(1, n)
}
} else {
# if X is either a dense or sparse ordinary matrix
# get column means
cm = Matrix::colMeans(X, na.rm = TRUE)
cm = colMeans(X, na.rm = TRUE)
# get column standard deviations
csd = compute_colSds(X)
# set sd = 1 when the column has variance 0
csd[csd == 0] = 1
if (!center) {
if (!center)
cm = rep(0, length = length(cm))
}
if (!scale) {
if (!scale)
csd = rep(1, length = length(cm))
}
X.std = (t(X) - cm) / csd
# set three attributes for X
attr(X, "d") <- Matrix::rowSums(X.std * X.std)
attr(X, "d") <- rowSums(X.std * X.std)
attr(X, "scaled:center") <- cm
attr(X, "scaled:scale") <- csd
}
return(X)
}


#' @title computes column standard deviations for any type of matrix
#' replace matrixStats::colSds since this function only takes a dense matrix
#' @param X an n by p matrix of any type, e.g. sparse, dense
#' @return a p vector of column standard deviations
# @title computes column standard deviations for any type of matrix
# @details Replace matrixStats::colSds since this function only takes
# a dense matrix.
# @param X an n by p matrix of any type, e.g. sparse, dense.
# @return a p vector of column standard deviations.
compute_colSds = function(X){
n = nrow(X)
return(sqrt((colSums(X^2)/n - (colSums(X)/n)^2)*(n/(n-1))))
Expand Down
19 changes: 0 additions & 19 deletions man/compute_colSds.Rd

This file was deleted.

20 changes: 0 additions & 20 deletions man/set_R_attributes.Rd

This file was deleted.

25 changes: 0 additions & 25 deletions man/set_X_attributes.Rd

This file was deleted.

0 comments on commit e585e3f

Please sign in to comment.