Last updated: 2022-03-08

Checks: 7 0

Knit directory: SMF/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190719) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 09cc06e. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  data/count_files.RData
    Untracked:  data/lowgene/
    Untracked:  data/stmGTEx/
    Untracked:  output/luis/

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/stmGTEx.Rmd
    Deleted:    data/GPX3_NMF_mkl_scd_K3.RData
    Deleted:    data/GPX3_NMF_mkl_scd_K3_base10.RData
    Deleted:    data/GPX3_NMF_mkl_scd_K3_base5.RData
    Deleted:    data/GPX3_hals_runmed_K3.RData
    Deleted:    data/GPX3_hals_runmed_K3_base10.RData
    Deleted:    data/GPX3_hals_runmed_K3_base5.RData
    Deleted:    data/GPX3_hals_wavelet_K3.RData
    Deleted:    data/GPX3_hals_wavelet_K3_base10.RData
    Deleted:    data/GPX3_hals_wavelet_K3_base5.RData
    Deleted:    data/GPX3_stm_bmsm_K3.RData
    Deleted:    data/GPX3_stm_bmsm_K3_base10.RData
    Deleted:    data/GPX3_stm_bmsm_K3_base5.RData
    Deleted:    data/GPX3_stm_nugget_K3.RData
    Deleted:    data/GPX3_stm_nugget_K3_base10.RData
    Deleted:    data/GPX3_stm_nugget_K3_base5.RData
    Deleted:    data/GPX3_stm_nugget_robust_K3.RData
    Deleted:    data/GPX3_stm_nugget_robust_K3_base10.RData
    Deleted:    data/GPX3_stm_nugget_robust_K3_base5.RData
    Deleted:    data/PSAP_NMF_mkl_scd_K3.RData
    Deleted:    data/PSAP_NMF_mkl_scd_K3_base10.RData
    Deleted:    data/PSAP_NMF_mkl_scd_K3_base5.RData
    Deleted:    data/PSAP_hals_runmed_K3.RData
    Deleted:    data/PSAP_hals_runmed_K3_base10.RData
    Deleted:    data/PSAP_hals_runmed_K3_base5.RData
    Deleted:    data/PSAP_hals_wavelet_K3.RData
    Deleted:    data/PSAP_hals_wavelet_K3_base10.RData
    Deleted:    data/PSAP_hals_wavelet_K3_base5.RData
    Deleted:    data/PSAP_stm_bmsm_K3.RData
    Deleted:    data/PSAP_stm_bmsm_K3_base10.RData
    Deleted:    data/PSAP_stm_bmsm_K3_base5.RData
    Deleted:    data/PSAP_stm_nugget_K3.RData
    Deleted:    data/PSAP_stm_nugget_K3_base10.RData
    Deleted:    data/PSAP_stm_nugget_K3_base5.RData
    Deleted:    data/PSAP_stm_nugget_robust_K3.RData
    Deleted:    data/PSAP_stm_nugget_robust_K3_base10.RData
    Deleted:    data/PSAP_stm_nugget_robust_K3_base5.RData
    Deleted:    data/RPS13_NMF_mkl_scd_K3.RData
    Deleted:    data/RPS13_NMF_mkl_scd_K3_base10.RData
    Deleted:    data/RPS13_NMF_mkl_scd_K3_base5.RData
    Deleted:    data/RPS13_hals_runmed_K3.RData
    Deleted:    data/RPS13_hals_runmed_K3_base10.RData
    Deleted:    data/RPS13_hals_runmed_K3_base5.RData
    Deleted:    data/RPS13_hals_wavelet_K3.RData
    Deleted:    data/RPS13_hals_wavelet_K3_base10.RData
    Deleted:    data/RPS13_hals_wavelet_K3_base5.RData
    Deleted:    data/RPS13_stm_bmsm_K3.RData
    Deleted:    data/RPS13_stm_bmsm_K3_base10.RData
    Deleted:    data/RPS13_stm_bmsm_K3_base5.RData
    Deleted:    data/RPS13_stm_nugget_K3.RData
    Deleted:    data/RPS13_stm_nugget_K3_base10.RData
    Deleted:    data/RPS13_stm_nugget_K3_base5.RData
    Deleted:    data/RPS13_stm_nugget_robust_K3.RData
    Deleted:    data/RPS13_stm_nugget_robust_K3_base10.RData
    Deleted:    data/RPS13_stm_nugget_robust_K3_base5.RData

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/wdw.Rmd) and HTML (docs/wdw.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 09cc06e DongyueXie 2022-03-08 wflow_publish(“analysis/wdw.Rmd”)

Introduction

The benefit of using EB method in wavelet denoising is that when using Haar basis, we don’t need to use the scaling function(the exact W), but just the original dfference operator.

First define the non-scaled DWT matrix

W = rbind(rep(1,8),
          c(rep(1,4),rep(-1,4)),
          c(1,1,-1,-1,rep(0,4)),
          c(rep(0,4),1,1,-1,-1),
          c(1,-1,rep(0,6)),
          c(0,0,1,-1,0,0,0,0),
          c(0,0,0,0,1,-1,0,0),
          c(rep(0,6),1,-1))
tcrossprod(W)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    8    0    0    0    0    0    0    0
[2,]    0    8    0    0    0    0    0    0
[3,]    0    0    4    0    0    0    0    0
[4,]    0    0    0    4    0    0    0    0
[5,]    0    0    0    0    2    0    0    0
[6,]    0    0    0    0    0    2    0    0
[7,]    0    0    0    0    0    0    2    0
[8,]    0    0    0    0    0    0    0    2
n = 8
d = 1:n

Exact calculation

diag(W%*%diag(d)%*%t(W))
[1] 36 36 10 26  3  7 11 15

Apply DWT to \(d\) and get the summation vector

# @title Shift a vector one unit to the right.
# @param x A vector.
# @return A vector of the same length as that of x.
rshift = function (x) {
  L = length(x)
  return(c(x[L],x[-L]))
}

# @title Shift a vector one unit to the left.
# @param x A vector.
# @return A vector of the same length as that of x.
lshift = function (x)
  c(x[-1],x[1])

# @description Produces two TI tables. One table contains the
#   difference between adjacent pairs of data in the same resolution,
#   and the other table contains the sum.
# @param sig a signal of length a power of 2
titable = function (sig) {
  n = length(sig)
  J = log2(n)
  
  dmat = matrix(0, nrow = J + 1, ncol = n)
  ddmat = matrix(0, nrow = J + 1, ncol = n)
  dmat[1, ] = sig
  ddmat[1, ] = sig
  
  for (D in 0:(J - 1)) {
    nD = 2^(J - D)
    nDo2 = nD/2
    twonD = 2 * nD
    for (l in 0:(2^D - 1)) {
      ind = (l * nD + 1):((l + 1) * nD)
      x = dmat[D + 1, ind]
      lsumx = x[seq(from = 1, to = nD - 1, by = 2)] +
              x[seq(from = 2, to = nD, by = 2)]
      ldiffx = x[seq(from = 1, to = nD - 1, by = 2)] -
               x[seq(from = 2, to = nD, by = 2)]
      rx = rshift(x)
      rsumx = rx[seq(from = 1, to = nD - 1, by = 2)] +
              rx[seq(from = 2, to = nD, by = 2)]
      rdiffx = rx[seq(from = 1, to = nD - 1, by = 2)] -
               rx[seq(from = 2, to = nD, by = 2)]
      dmat[D + 2, ind] = c(lsumx, rsumx)
      ddmat[D + 2, ind] = c(ldiffx, rdiffx)
    }
  }
  return(list(sumtable = dmat, difftable = ddmat))
}
titable(d)$sumtable
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    1    2    3    4    5    6    7    8
[2,]    3    7   11   15    9    5    9   13
[3,]   10   26   18   18   14   22   22   14
[4,]   36   36   36   36   36   36   36   36

But this does not hold if using the exact W:

library(wavethresh)
Loading required package: MASS
WaveThresh: R wavelet software, release 4.6.8, installed
Copyright Guy Nason and others 1993-2016
Note: nlevels has been renamed to nlevelsWT
n = 8 
d = 1:n
W = t(GenW(n,filter.number=1,family = 'DaubExPhase'))

Exact calculation

diag(W%*%diag(d)%*%t(W))
[1] 4.5 1.5 3.5 5.5 7.5 2.5 6.5 4.5

Apply DWT to \(d\) and get the summation vector

fit = wd(d,filter.number=1,family = 'DaubExPhase')
fit$C
 [1]  1.000000  2.000000  3.000000  4.000000  5.000000  6.000000  7.000000
 [8]  8.000000  2.121320  4.949747  7.778175 10.606602  5.000000 13.000000
[15] 12.727922

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] wavethresh_4.6.8 MASS_7.3-51.4    workflowr_1.6.2 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5      rprojroot_2.0.2 digest_0.6.20   later_0.8.0    
 [5] R6_2.4.0        git2r_0.26.1    magrittr_1.5    evaluate_0.14  
 [9] stringi_1.4.3   fs_1.3.1        promises_1.0.1  whisker_0.3-2  
[13] rmarkdown_1.13  tools_3.6.1     stringr_1.4.0   glue_1.3.1     
[17] httpuv_1.5.1    xfun_0.8        yaml_2.2.0      compiler_3.6.1 
[21] htmltools_0.3.6 knitr_1.23