Skip to content

Commit

Permalink
cleans check and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystynaGrzesiak committed Oct 3, 2020
1 parent f868869 commit 83c45a6
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 51 deletions.
Empty file added .Rhistory
Empty file.
13 changes: 12 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ Package: gslope
Type: Package
Title: Graphical SLOPE
Version: 0.1.0
Authors: Krystyna Grzesiak, Zofia Dziedzic, Tomasz Kulik, Michał Makowski, Mateusz Staniak
Authors@R:
c(person("Mateusz", "Staniak",
role = c("aut")),
person("Krystyna", "Grzesiak",
role = c("aut", "cre"),
email = "krysiagrzesiak11@wp.pl"),
person("Zofia", "Dziedzic",
role = c("aut")),
person("Tomasz", "Kulik",
role = c("aut")),
person("Michal", "Makowski",
role = c("com", "ths")))
Description: Computation of precision matrix based on graphical SLOPE.
License: GPL-3
Encoding: UTF-8
Expand Down
35 changes: 19 additions & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ export(plot)
export(prepare_lambda)
export(summary)
importFrom(Rcpp,sourceCpp)
importFrom(ggplot2,"aes")
importFrom(ggplot2,"coord_fixed")
importFrom(ggplot2,"element_text")
importFrom(ggplot2,"geom_tile")
importFrom(ggplot2,"ggplot")
importFrom(ggplot2,"ggtitle")
importFrom(ggplot2,"labs")
importFrom(ggplot2,"scale_fill_gradient")
importFrom(ggplot2,"scale_fill_gradient2")
importFrom(ggplot2,"theme")
importFrom(ggplot2,"xlab")
importFrom(ggplot2,"ylab")
importFrom(igraph,"clusters")
importFrom(igraph,"graph_from_adjacency_matrix")
importFrom(igraph,"layout.circle")
importFrom(igraph,"plot.igraph")
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_fixed)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_tile)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_fill_gradient)
importFrom(ggplot2,scale_fill_gradient2)
importFrom(ggplot2,theme)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(igraph,clusters)
importFrom(igraph,graph_from_adjacency_matrix)
importFrom(igraph,layout.circle)
importFrom(igraph,plot.igraph)
importFrom(stats,cov)
importFrom(stats,cov2cor)
importFrom(stats,qt)
useDynLib(gslope, .registration = TRUE)
Empty file added R/.Rhistory
Empty file.
3 changes: 0 additions & 3 deletions R/graph_plot.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#' @importFrom igraph "graph_from_adjacency_matrix"
#' @importFrom igraph "plot.igraph"
#' @importFrom igraph "layout.circle"

#' @title Plot graph for gslope.
#'
Expand Down
28 changes: 24 additions & 4 deletions R/gslope-package.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
## usethis namespace: start
#' gslope
#'
#' @docType package
#' @description R package that estimates a sparse precision matrix based on regularization by the SLOPE.
#' @name gslope-package
#' @useDynLib gslope, .registration = TRUE
## usethis namespace: end
## usethis namespace: start
#' @importFrom Rcpp sourceCpp
## usethis namespace: end
#' @importFrom igraph graph_from_adjacency_matrix
#' @importFrom igraph clusters
#' @importFrom ggplot2 ggplot
#' @importFrom ggplot2 geom_tile
#' @importFrom ggplot2 scale_fill_gradient
#' @importFrom ggplot2 scale_fill_gradient2
#' @importFrom ggplot2 coord_fixed
#' @importFrom ggplot2 aes
#' @importFrom ggplot2 ggtitle
#' @importFrom ggplot2 xlab
#' @importFrom ggplot2 ylab
#' @importFrom ggplot2 theme
#' @importFrom ggplot2 labs
#' @importFrom ggplot2 element_text
#' @importFrom igraph graph_from_adjacency_matrix
#' @importFrom igraph plot.igraph
#' @importFrom igraph layout.circle
#' @importFrom stats cov cov2cor qt
#'
NULL
17 changes: 9 additions & 8 deletions R/gslope.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#' @importFrom igraph "graph_from_adjacency_matrix"
#' @importFrom igraph "clusters"

#' @title Preparation of lambda
#' @description Prepares penalty parameters \eqn{\lambda} for further computations in graphical SLOPE.
Expand Down Expand Up @@ -37,7 +35,6 @@ prepare_lambda = function(lambda, low_tri_size) {
#'
#' @param data a matrix containing observations of variables of interest.
#' @param lambda vector of regularizers for SLOPE. By default computed based on Benjamini-Hochberg's method.
#' @param sample_cov variance-covariance matrix.
#' @param scaled {logical. The data need to be scaled so that it has mean = 0 and variance = 1. If TRUE, build-in data scaling will be omitted.}
#' @param mu correction for lambda scaling in ADMM algorithm.
#' @param max_iter maximum number of iterations allowed in ADMM algorithm. Default 10 000.
Expand Down Expand Up @@ -80,15 +77,19 @@ gslope = function(data,
epsilon = 1e-4,
threshold = 1e-4,
alpha = 0.05) {
sample_cov = NULL

call = match.call()
if(is.null(colnames(data)))
names = 1:ncol(data) else
names = colnames(data)
sample_cov = if(!scaled) cov(scale(data)) else cov(data)
if(is.null(lambda)) {

if(!scaled)
sample_cov = cov(scale(data)) else
sample_cov = cov(data)

if(is.null(lambda))
lambda = gslope::create_lambda(sample_cov, nrow(data), alpha)
}

p = ncol(data)
lambda = prepare_lambda(lambda, p*(p-1)/2)
Expand All @@ -103,7 +104,7 @@ gslope = function(data,
scaled_precision_matrix = -cov2cor(precision_matrix)
scaled_precision_matrix[abs(scaled_precision_matrix) < threshold] = 0

graph = graph_from_adjacency_matrix(scaled_precision_matrix,
graph = igraph::graph_from_adjacency_matrix(scaled_precision_matrix,
mode = c("undirected"),
weighted = TRUE,
diag = FALSE,
Expand All @@ -116,7 +117,7 @@ gslope = function(data,
lambda = lambda,
iterations = ADMM_results[[2]],
graph = graph,
clusters = clusters(graph),
clusters = igraph::clusters(graph),
call = call)
class(result) <- "gslope"
result
Expand Down
20 changes: 5 additions & 15 deletions R/plot.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
#' @importFrom ggplot2 "ggplot"
#' @importFrom ggplot2 "geom_tile"
#' @importFrom ggplot2 "scale_fill_gradient"
#' @importFrom ggplot2 "scale_fill_gradient2"
#' @importFrom ggplot2 "coord_fixed"
#' @importFrom ggplot2 "aes"
#' @importFrom ggplot2 "ggtitle"
#' @importFrom ggplot2 "xlab"
#' @importFrom ggplot2 "ylab"
#' @importFrom ggplot2 "theme"
#' @importFrom ggplot2 "labs"
#' @importFrom ggplot2 "element_text"

#' @title Plot precision matrix
#'
#' @param x an object of class `'gslope'`
#' @param col a character, color name. Default "black"
#' @param plt a plot type. Accepts either \code{'precision'}, \code{'covariance'}, \code{'corr'} or \code{'scaled_precision'}. Default \code{'precision'}.
#'
#' @param ... Other parameters
#' @return Prints output on the screen
#'
#' @examples
Expand All @@ -27,14 +15,16 @@

#' @export

plot <- function(x, plt, col){
plot <- function(x, plt, col, ...){
UseMethod('plot')
}

#' @rdname plot
#' @param ... Other parameters
#' @export
#'
plot.gslope = function(x, plt = "scaled_precision", col = "black"){
plot.gslope = function(x, plt = "scaled_precision", col = "black", ...){
Y = value = NULL

if(!(plt %in% c("precision", "corr", "scaled_precision", "covariance"))) stop("Plt must be either precision, covariance, corr or scaled_precision")

Expand Down
9 changes: 9 additions & 0 deletions man/gslope-package.Rd

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

2 changes: 0 additions & 2 deletions man/gslope.Rd

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

6 changes: 4 additions & 2 deletions man/plot.Rd

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

0 comments on commit 83c45a6

Please sign in to comment.