Last updated: 2018-05-05
workflowr checks: (Click a bullet for more information) ✖ R Markdown file: uncommitted changes 
 The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.
 ✔ Environment: empty 
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.
 ✔ Seed: 
set.seed(20180501) 
The command set.seed(20180501) 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.
 ✔ Session information: recorded 
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
 ✔ Repository version: b7e89a3 
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/
    Ignored:    docs/figure/
    Ignored:    log/
Untracked files:
    Untracked:  analysis/nugget.Rmd
    Untracked:  analysis/poireview.Rmd
    Untracked:  analysis/simu1.Rmd
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. 
Examine the performance of smash-gen(known \(\sigma\)) under different simulation settings.
Let \(X_t\) be a Poisson observation, \(t=1,2,\dots,T\).
smash.gaus and obtain \(\hat\mu_t\).Convergence criteria: \(||\mu_t^{(i)}-\mu_t^{(i-1)}||_2\leq \epsilon\).
#' smash generaliation function
#' This function is for $Y_t=\mu_t+N(0,s_t^2)+N(0,\sigma^2)$ with known $s_t^2$ and $\sigma^2$.
#' @param x: a vector of observations
#' @param sigma: standard deviations, scalar.
#' @param family: choice of wavelet basis to be used, as in wavethresh.
#' @param niter: number of iterations for IRLS
#' @param tol: criterion to stop the iterations
smash.gen=function(x,sigma,family='DaubExPhase',niter=100,tol=1e-2){
  mu=c()
  s=c()
  mu=rbind(mu,rep(mean(x),length(x)))
  s=rbind(s,rep(1/mu[1],length(x)))
  y=log(mean(x))+(x-mean(x))/mean(x)
  for(i in 1:niter){
    mu.hat=smash.gaus(y,sigma=sigma+s[i,])
    mu=rbind(mu,mu.hat)
    #update m and s_t
    s=rbind(s,1/mu.hat)
    #update y
    mt=exp(mu.hat)
    y=log(mt)+(x-mt)/mt
    #y=log(mu.hat)+(x-mu.hat)/mu.hat
    if(norm(mu.hat-mu[i,],'2')<tol){
      break
    }
  }
  return(list(mu.hat=mu.hat,mu=mu,s=s))
}
Data generation by Poisson glm:
\(\lambda_t=\exp(m_t+\epsilon_t)\), where \(\epsilon_t\sim N(0,\sigma^2)\).
\(X_t\sim Poi(\lambda_t)\).
#' Simulation study comparing smash and smashgen
simu_study=function(m,sigma,seed=1234,
                    niter=100,family='DaubExPhase',tol=1e-2,
                    reflect=FALSE){
  set.seed(seed)
  lamda=exp(m+rnorm(length(m),0,sigma))
  x=rpois(length(m),lamda)
  #fit data
  smash.out=smash.poiss(x,reflect=FALSE)
  smash.gen.out=smash.gen(x,sigma=sigma,niter=niter,family = family,tol=tol)
  return(list(smash.out=smash.out,smash.gen.out=exp(smash.gen.out$mu.hat),smash.gen.est=smash.gen.out,x=x))
}
\(\sigma=0.01\)
library(smashr)
m=rep(3,256)
simu.out=simu_study(m,0.01)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", # places a legend at the appropriate place
       c("truth","smash-gen"), # puts text in the legend
       lty=c(1,1), # gives the legend appropriate symbols (lines)
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.1\)
simu.out=simu_study(m,0.1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.5\)
simu.out=simu_study(m,0.5)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m),col='gray80')
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m),col='gray80')
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))
 \(\sigma=1\)
simu.out=simu_study(m,1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m),col='black')
legend("topleft", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m),col='black')
legend("topleft", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.01\)
m=c(rep(3,128), rep(5, 128), rep(6, 128), rep(4, 128))
simu.out=simu_study(m,0.01)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.1\)
simu.out=simu_study(m,0.1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.5\)
simu.out=simu_study(m,0.5)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=1\)
simu.out=simu_study(m,1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topleft", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topleft", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.01\)
m=c()
for(k in 1:8){
    m=c(m, rep(1,16), rep(5, 16))
}
simu.out=simu_study(m,0.01)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=0.1\)
simu.out=simu_study(m,0.1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=0.5\)
simu.out=simu_study(m,0.5)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=1\)
simu.out=simu_study(m,1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=0.01\)
m=c()
for(k in 1:32){
    m=c(m, c(1,5))
}
simu.out=simu_study(m,0.01)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=0.1\)
simu.out=simu_study(m,0.1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=0.5\)
simu.out=simu_study(m,0.5)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=1\)
simu.out=simu_study(m,1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '',main='smash-gen')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))

plot(simu.out$x,col = "gray80" ,ylab = '',main='smash')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))

\(\sigma=0.01\)
m = seq(-1,1,length.out = 256)
m = m^3-2*m+1
simu.out=simu_study(m,0.01)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.1\)
m = seq(-1,1,length.out = 256)
m = m^3-2*m+1
simu.out=simu_study(m,0.1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=0.5\)
m = seq(-1,1,length.out = 256)
m = m^3-2*m+1
simu.out=simu_study(m,0.5)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

\(\sigma=1\)
m = seq(-1,1,length.out = 256)
m = m^3-2*m+1
simu.out=simu_study(m,1)
#par(mfrow = c(1,2))
plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.gen.out, col = "red", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth","smash-gen"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black","red", "blue"))

plot(simu.out$x,col = "gray80" ,ylab = '')
lines(simu.out$smash.out, col = "blue", lwd = 2)
lines(exp(m))
legend("topright", 
       c("truth", "smash"), 
       lty=c(1,1), 
       lwd=c(1,1),
       cex = 1,
       col=c("black", "blue"))

sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] smashr_1.1-1    workflowr_1.0.1 rmarkdown_1.8  
loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16        compiler_3.4.0      git2r_0.21.0       
 [4] R.methodsS3_1.7.1   R.utils_2.6.0       bitops_1.0-6       
 [7] iterators_1.0.8     tools_3.4.0         digest_0.6.13      
[10] evaluate_0.10       lattice_0.20-35     Matrix_1.2-9       
[13] foreach_1.4.3       rstudioapi_0.7      yaml_2.1.19        
[16] parallel_3.4.0      stringr_1.3.0       knitr_1.20         
[19] REBayes_1.3         caTools_1.17.1      rprojroot_1.3-2    
[22] grid_3.4.0          glue_1.2.0          data.table_1.10.4-3
[25] R6_2.2.2            ashr_2.2-7          magrittr_1.5       
[28] whisker_0.3-2       backports_1.0.5     codetools_0.2-15   
[31] htmltools_0.3.5     MASS_7.3-47         assertthat_0.2.0   
[34] wavethresh_4.6.8    stringi_1.1.6       Rmosek_8.0.69      
[37] doParallel_1.0.11   pscl_1.4.9          truncnorm_1.0-7    
[40] SQUAREM_2017.10-1   crayon_1.3.4        R.oo_1.21.0        
This reproducible R Markdown analysis was created with workflowr 1.0.1