Skip to content

Commit 2721eaa

Browse files
committed
Create README.R
1 parent 0553348 commit 2721eaa

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

README.R

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
################################################################################
2+
# File: README.R
3+
# Aim : A brief introduction about the usage for classo and SparCC
4+
#-------------------------------------------------------------------------------
5+
# Author: Fang Huaying (Peking University)
6+
7+
# Date : 2015-01-08
8+
#-------------------------------------------------------------------------------
9+
# Package required:
10+
# gtools for SparCC
11+
# Files needed:
12+
# cclasso.R for cclasso (including cclasso)
13+
# SparCC.R for SparCC (including SparCC.count and SparCC.frac)
14+
#-------------------------------------------------------------------------------
15+
# Function parameter description:
16+
# function: cclasso
17+
# Input:
18+
# x ------ n x p data matrix (row/column is sample/variable)
19+
# n samples & p compositional variables
20+
# counts ------ Is the compositional data matrix a count matrix?
21+
# Default: FALSE
22+
# pseudo ------ pseudo count if counts = TRUE
23+
# Default: 0.5
24+
# k_cv ------ folds of cross validation
25+
# Default: 3
26+
# lam_int ------ tuning parameter interval
27+
# Default: [1e-4, 1]
28+
# k_max ------ maximum iterations for golden section method
29+
# Default: 20
30+
# n_boot ------ Bootstrap times
31+
# Default: 20
32+
# Output:
33+
# A list structure contains:
34+
# var_w ------ variance estimation
35+
# cor_w ------ correlation estimation
36+
# p_vals ------ p-values for elements of cor_w equal 0 or not
37+
# lambda ------ final tuning parameter
38+
# info_cv ------ information for cross validation
39+
#-------------------------------------------------------------------------------
40+
# function: SparCC.count
41+
# input:
42+
# x ------ nxp count data matrix, row is sample, col is variable
43+
# imax ------ resampling times from posterior distribution
44+
# default: 20
45+
# kmax ------ max iteration steps for SparCC
46+
# default: 10
47+
# alpha ------ the threshold for strong correlation
48+
# default: 0.1
49+
# Vmin ------ minimal variance if negative variance appears
50+
# default: 1e-4
51+
# output: a list structure
52+
# cov.w ------ covariance estimation
53+
# cor.w ------ correlation estimation
54+
#
55+
# function: SparCC.frac
56+
# input:
57+
# x ------ nxp fraction data matrix, row is sample, col is variable
58+
# kmax ------ max iteration steps for SparCC
59+
# default: 10
60+
# alpha ------ the threshold for strong correlation
61+
# default: 0.1
62+
# Vmin ------ minimal variance if negative variance appears
63+
# default: 1e-4
64+
# output: a list structure
65+
# cov.w ------ covariance estimation
66+
# cor.w ------ correlation estimation
67+
#-------------------------------------------------------------------------------
68+
# Basic example
69+
source("R/cclasso.R");
70+
source("R/SparCC.R");
71+
# 1. generate logistic normal variables
72+
n <- 100;
73+
p <- 20;
74+
x <- matrix(rnorm(n * p), nrow = n);
75+
x.frac <- exp(x) / rowSums(exp((x)));
76+
totCount <- round(runif(n = n, min = 1000, max = 2000));
77+
x.count <- x.frac * totCount;
78+
# 2. run cclasso
79+
# using fraction
80+
res_ccl_frac <- cclasso(x = x.frac, counts = F);
81+
# using counts
82+
res_ccl_count <- cclasso(x = x.count, counts = T);
83+
# 3. run SparCC.count and SparCC.frac
84+
res_spa_count <- SparCC.count(x = x.count);
85+
res_spa_frac <- SparCC.frac(x = x.frac);
86+
# 4. get the correlation matrix
87+
{
88+
cat("CCLasso using fraction data:\n");
89+
print(round(res_ccl_frac$cor_w, 2));
90+
cat("CCLasso using count data:\n");
91+
print(round(res_ccl_count$cor_w, 2));
92+
cat("SparCC using fraction data:\n");
93+
print(round(res_spa_frac$cor.w, 2));
94+
cat("SparCC using count data:\n");
95+
print(round(res_spa_count$cor.w, 2));
96+
}
97+
#-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)