Last updated: 2019-02-27
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: 9d13bf6
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: .Rproj.user/
Ignored: data/.DS_Store
Untracked files:
Untracked: analysis/chipexoeg.Rmd
Untracked: analysis/efsd.Rmd
Untracked: analysis/pre0221.Rmd
Untracked: analysis/smashadditive.Rmd
Untracked: analysis/talk1011.Rmd
Untracked: data/chipexo_examples/
Untracked: data/chipseq_examples/
Untracked: docs/figure/pre0221.Rmd/
Untracked: talk.Rmd
Untracked: talk.pdf
Unstaged changes:
Modified: analysis/binomial.Rmd
Modified: analysis/fda.Rmd
Modified: analysis/protein.Rmd
Modified: analysis/r2.Rmd
Modified: analysis/r2b.Rmd
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 | 9d13bf6 | Dongyue Xie | 2019-02-27 | wflow_publish(“analysis/smashgenfda.Rmd”) |
Assume we obseve \(Y\in R^{N*T}\): N curves(count) and each has length T from N individuals. We also obseve a \(X\in R^{N*p}\) data matrix whose columns are covariates. We can model \(g(Y)=XB+E\), where \(B\in R^{p*T}\) is coefficient matrix, whose rows are smooth curves, and \(E\in R^{N*T}\) is a random error matrix.
Model framework:
ash
to each row of \(\hat B^*\) and obtain new \(\hat B^*\)wavelet_fda=function(Y,X,sigma=1,ca=0,trans='log',filter.number=1,family='DaubExPhase'){
N=nrow(Y)
Tt=ncol(Y)
p=ncol(X)
if(length(sigma)==1){sigma=rep(sigma,N)}
W=GenW(n=Tt,filter.number=filter.number,family=family)
if(trans=='log'){
Y.t=matrix(nrow=N,ncol=Tt)
set2=matrix(nrow=N,ncol=Tt)
for (n in 1:N) {
x=Y[n,]
x.ash=ash(rep(0,Tt),1,lik=lik_pois(x))$result$PosteriorMean
m.hat=x.ash
m.hat[which(x!=0)]=(x[which(x!=0)])
ys=log(m.hat)+(x-m.hat)/m.hat
st2=1/(m.hat)
Y.t[n,]=W%*%ys
set2[n,]=diag(W%*%diag(sigma[n]^2+st2)%*%t(W))
}
}
if(trans=='vst'){
Y.t=t(apply(Y, 1, function(x){W%*%sqrt(x+ca)}))
set2=matrix(nrow=N,ncol=Tt)
for (n in 1:N) {
st2=1/4
set2[n,]=diag(W%*%diag(rep(sigma[n]^2+st2,Tt))%*%t(W))
}
}
beta.hat=matrix(nrow=p+1,ncol=Tt)
beta.hat.se=matrix(nrow=p+1,ncol=Tt)
for (t in 1:Tt) {
wls.fit=lm(y~.,data.frame(y=Y.t[,t],x=X),weights = 1/set2[,t])
beta.hat[,t]=coefficients(wls.fit)
smy=summary(wls.fit)
beta.hat.se[,t]=smy$coefficients[,2]
}
beta.hat.shrink=matrix(nrow=p+1,ncol=Tt)
for (j in 1:(p+1)) {
beta.hat.shrink[j,]=ashr::ash(beta.hat[j,],beta.hat.se[j,])$result$PosteriorMean
}
return(beta.hat.shrink%*%W)
}
Let N=100, p=3(includes \(1_N\)).
library(wavethresh)
library(ashr)
Tt=512
beta1=c(rep(2,Tt/4), rep(5, Tt/4), rep(6, Tt/4), rep(2, Tt/4))
beta1=5*beta1/sqrt(norm(beta1,'2'))
r=function(x,c){return((x-c)^2*(x>c)*(x<=1))}
f=function(x){return(0.8 - 30*r(x,0.1) + 60*r(x, 0.2) - 30*r(x, 0.3) +
500*r(x, 0.35) -1000*r(x, 0.37) + 1000*r(x, 0.41) - 500*r(x, 0.43) +
7.5*r(x, 0.5) - 15*r(x, 0.7) + 7.5*r(x, 0.9))}
mu=f(1:Tt/Tt)
mu=mu
beta2=5*mu/sqrt(norm(mu,'2'))
f=function(x){return(0.5 + 2*cos(4*pi*x) + 2*cos(24*pi*x))}
mu=f(1:Tt/Tt)
mu=mu-min(mu)
mu=5*mu/sqrt(norm(mu,'2'))
set.seed(12345)
N=100
Y=matrix(nrow = N,ncol = Tt)
X=matrix(rnorm(N*2),nrow=N,ncol=2)
sigma=0.3
for (i in 1:Tt) {
Y[,i]=mu[i]+X%*%rbind(beta1[i],beta2[i])+rnorm(N,0,sigma)
}
for (i in 1:N) {
Y[i,]=rpois(Tt,exp(Y[i,]))
}
r1=wavelet_fda(Y,X,0.1,trans='log')
plot(r1[1,],type='l',ylab='',main='Estimate of Beta')
lines(mu,col='grey80')
plot(r1[2,],type='l',ylab='',main='Estimate of Beta')
lines(beta1,col='grey80')
plot(r1[3,],type='l',ylab='',main='Estimate of Beta')
lines(beta2,col='grey80')
set.seed(12345)
N=100
Y=matrix(nrow = N,ncol = Tt)
X=matrix(rnorm(N*2),nrow=N,ncol=2)
sigma=0.1
for (i in 1:Tt) {
Y[,i]=mu[i]+X%*%rbind(beta1[i],beta2[i])+rnorm(N,0,sigma)
}
for (i in 1:N) {
Y[i,]=rpois(Tt,(Y[i,])^2)
}
r1=wavelet_fda(Y,X,0.1,trans='vst')
plot(r1[1,],type='l',ylab='',main='Estimate of Beta')
lines(mu,col='grey80')
plot(r1[2,],type='l',ylab='',main='Estimate of Beta')
lines(beta1,col='grey80')
plot(r1[3,],type='l',ylab='',main='Estimate of Beta')
lines(beta2,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] ashr_2.2-7 wavethresh_4.6.8 MASS_7.3-51.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 knitr_1.20 whisker_0.3-2
[4] magrittr_1.5 workflowr_1.1.1 REBayes_1.3
[7] pscl_1.5.2 doParallel_1.0.14 SQUAREM_2017.10-1
[10] lattice_0.20-35 foreach_1.4.4 stringr_1.3.1
[13] tools_3.5.1 parallel_3.5.1 grid_3.5.1
[16] R.oo_1.22.0 git2r_0.23.0 iterators_1.0.10
[19] htmltools_0.3.6 assertthat_0.2.0 yaml_2.2.0
[22] rprojroot_1.3-2 digest_0.6.18 Matrix_1.2-14
[25] codetools_0.2-15 R.utils_2.7.0 evaluate_0.11
[28] rmarkdown_1.10 stringi_1.2.4 compiler_3.5.1
[31] Rmosek_8.0.69 backports_1.1.2 R.methodsS3_1.7.1
[34] truncnorm_1.0-8
This reproducible R Markdown analysis was created with workflowr 1.1.1