Last updated: 2018-10-05
workflowr checks: (Click a bullet for more information) ✔ R Markdown file: up-to-date 
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.
 ✔ 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: 0daae69 
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:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    data/.DS_Store
Untracked files:
    Untracked:  analysis/literature.Rmd
    Untracked:  analysis/meeting1005.Rmd
    Untracked:  data/chipexo_examples/
    Untracked:  data/chipseq_examples/
Unstaged changes:
    Modified:   analysis/sigma.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. 
| File | Version | Author | Date | Message | 
|---|---|---|---|---|
| Rmd | 0daae69 | Dongyue Xie | 2018-10-05 | add files | 
Generalized additve model can be written as \(g(E(Y))=\beta_0+f_1(x_1)+f_2(x_2)+...+f_p(x_p)\), where \(f_i\) is smooth, either parametric, nonparametric or semi-parametric. The model is interpretable and flexible.
Let’s try GAM on smoothing poisson and binomial data.
library(mgcv)
Loading required package: nlme
This is mgcv 1.8-24. For overview type 'help("mgcv-package")'.
set.seed(12345)
n=512
m=c(rep(3,128), rep(5, 128), rep(6, 128), rep(3, 128))
y=rpois(n,m)
x=1:n
gam.mod=gam(y~s(x,bs='cr'),family = poisson())
plot(y,col='grey80',main='cubic regression splines')
lines(gam.mod$fitted.values)
lines(m,col='grey80')

set.seed(12345)
n=512
spike.f = function(x) (0.75 * exp(-500 * (x - 0.23)^2) + 1.5 * exp(-2000 * (x - 0.33)^2) + 3 * exp(-8000 * (x - 0.47)^2) + 2.25 * exp(-16000 * 
    (x - 0.69)^2) + 0.5 * exp(-32000 * (x - 0.83)^2))
t = 1:n/n
m = spike.f(t)
y=rpois(n,m)
x=t
gam.mod=gam(y~s(x,bs='cr'),family = poisson())
plot(y,col='grey80',main='cubic regression splines')
lines(gam.mod$fitted.values)
lines(m,col='grey80')

set.seed(12345)
p=c(rep(-2,128), rep(0, 128), rep(2, 128), rep(-2, 128))
p=exp(p)/(1+exp(p))
ntri=rpois(n,30)
y=rbinom(n,ntri,p)
gam.mod=gam(y/ntri~s(x,bs='cr'),family = binomial())
plot(y/ntri,col='grey80',main='cubic regression splines')
lines(gam.mod$fitted.values)
lines(p,col='grey80')

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] mgcv_1.8-24  nlme_3.1-137
loaded via a namespace (and not attached):
 [1] workflowr_1.1.1   Rcpp_0.12.18      lattice_0.20-35  
 [4] digest_0.6.17     rprojroot_1.3-2   R.methodsS3_1.7.1
 [7] grid_3.5.1        backports_1.1.2   git2r_0.23.0     
[10] magrittr_1.5      evaluate_0.11     stringi_1.2.4    
[13] whisker_0.3-2     R.oo_1.22.0       R.utils_2.7.0    
[16] Matrix_1.2-14     rmarkdown_1.10    tools_3.5.1      
[19] stringr_1.3.1     yaml_2.2.0        compiler_3.5.1   
[22] htmltools_0.3.6   knitr_1.20       
This reproducible R Markdown analysis was created with workflowr 1.1.1