Last updated: 2022-09-23

Checks: 6 1

Knit directory: Immunue_Cell_Study/

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


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.

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(20220920) 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 716cb2a. 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/
    Ignored:    analysis/.Rhistory

Untracked files:
    Untracked:  analysis/12month_analysis_GEE.Rmd
    Untracked:  analysis/6week_analysis_GEE.Rmd

Unstaged changes:
    Modified:   analysis/12month_analysis.Rmd
    Modified:   analysis/6week_analysis.Rmd
    Modified:   analysis/glm without modeling correlation.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis/marginal_model_complete.Rmd
    Deleted:    analysis/marginal_model_with_independence.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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


clean the data

library(gee)
source("./code/datacleaning.r")
index=which(longidata$time==6)

Regression analysis

Microbes associated with Bcell

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~bcell + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longibcell[index,],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    next()
  }else{
    fm=gee(cbind(y1,y2)~bcell + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longibcell[index,],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=c(r1,r2,r3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}
colnames(rrbcell)=c("coef","pvalue","lower","upper")
fdr=p.adjust(rrbcell[,2],method = "BH")
rrbcell=data.frame(microbe,rrbcell,fdr)
rrbcell=rrbcell[order(rrbcell[,3]),]
rrbcellfdr=rrbcell[which(rrbcell[,6]<0.3),]
         microbe       coef      pvalue       lower      upper        fdr
10 Lactobacillus -0.3008183 0.003305039 -0.50151102 -0.1001255 0.04296550
5   Enterobacter  0.1678784 0.007035647  0.04579193  0.2899650 0.04573170
12 Streptococcus  0.1495325 0.016616601  0.02716359  0.2719014 0.07200527

Microbes associated with CD4

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~cd4t + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longicd4t[index,],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    print(k)
    next()
  }else{
    fm=gee(cbind(y1,y2)~cd4t + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longicd4t[index],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=c(r1,r2,r3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}
For CD4, GEE method does not yield any significant results.

Microbes associated with CD8

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~cd8t + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longicd8t[index,],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    print(k)
    next()
  }else{
    fm=gee(cbind(y1,y2)~cd8t + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longicd8t[index,],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=c(r1,r2,r3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}

For CD8, GEE method does not yield any significant results. <>

Microbes associated with Mono

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~mono + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longimono[index],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    next()
  }else{
    fm=gee(cbind(y1,y2)~mono + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longimono[index,],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=c(r1,r2,r3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}

Microbes associated with NK

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~nk + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longink[index,],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    next()
  }else{
    fm=gee(cbind(y1,y2)~nk + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longink[index,],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=c(r1,r2,r3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}
colnames(rrbcell)=c("coef","pvalue","lower","upper")
fdr=p.adjust(rrbcell[,2],method = "BH")
rrbcell=data.frame(microbe,rrbcell,fdr)
rrbcell=rrbcell[order(rrbcell[,3]),]
rrbcellfdr=rrbcell[which(rrbcell[,6]<0.3),]
                 microbe        coef      pvalue       lower       upper
7  F__Enterobacteriaceae  0.26550851 0.001078572  0.10632619  0.42469082
1        Bifidobacterium -0.18344675 0.005159483 -0.31200161 -0.05489189
9          Lactobacillus -0.19257079 0.067160002 -0.39875367  0.01361209
6   Escherichia/Shigella -0.13991086 0.104339350 -0.30875103  0.02892931
10        Staphylococcus -0.09077586 0.122768888 -0.20606509  0.02451336
11         Streptococcus  0.11723465 0.130910187 -0.03488486  0.26935417
          fdr
7  0.01294286
1  0.03095690
9  0.26182037
6  0.26182037
10 0.26182037
11 0.26182037

Microbes associated with NRBC

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~nrbc + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longinrbc[index,],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    next()
  }else{
    fm=gee(cbind(y1,y2)~nrbc + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longinrbc[index,],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=c(r1,r2,r3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}
colnames(rrbcell)=c("coef","pvalue","lower","upper")
fdr=round(p.adjust(rrbcell[,2],method = "BH"),3)
rrbcell=data.frame(microbe,rrbcell,fdr)
rrbcell=rrbcell[order(rrbcell[,3]),]
rrbcellfdr=rrbcell[which(rrbcell[,6]<0.3),]
[1] microbe coef    pvalue  lower   upper   fdr    
<0 rows> (or 0-length row.names)

Microbes associated with Gran

Click me
options(warn = 2)
m=ncol(longidata)-2
n=nrow(longidata)
name=colnames(longidata)[-c(1,2)]
microbe=c()                            
rrbcell=data.frame()
for (k in 1:m) {
  y1=longidata[index,k+2]
  y2=apply(longidata[index,-c(1,2,k+2)],1,sum)
  fm=try({gee(cbind(y1,y2)~gran + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longigran[index,],family="binomial",corstr="independence")},silent = T)
  if (inherits(fm,"try-error")){
    next()
  }else{
    fm=gee(cbind(y1,y2)~gran + bbymale + enrollment_age + imrbthwghtg_all +gestage_all+evercigpreg+alpha+deliver ,id=subject6w, data=longigran[index,],family="binomial",corstr="independence")   
   a=summary(fm)
   r1=a$coefficients[2,1]
   r2=2*(1-pnorm(abs(a$coefficients[2,5])))
   r3= c(r1-1.96*a$coefficients[2,4],r1+ 1.96*a$coefficients[2,4])
   rr=round(c(r1,r2,r3),3)
   microbe=c(microbe,name[k])
    rrbcell=rbind(rrbcell,rr)
     }

}
colnames(rrbcell)=c("coef","pvalue","lower","upper")
fdr=round(p.adjust(rrbcell[,2],method = "BH"),3)
rrbcell=data.frame(microbe,rrbcell,fdr)
rrbcell=rrbcell[order(rrbcell[,3]),]
rrbcellfdr=rrbcell[which(rrbcell[,6]<0.4),]
          microbe coef pvalue lower upper   fdr
1 Bifidobacterium 0.05  0.013 0.011 0.089 0.156

<>


sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

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] vegan_2.6-2     lattice_0.20-45 permute_0.9-7   gee_4.13-23    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9       pillar_1.8.0     compiler_4.1.2   bslib_0.4.0     
 [5] later_1.3.0      jquerylib_0.1.4  git2r_0.30.1     workflowr_1.7.0 
 [9] tools_4.1.2      digest_0.6.29    nlme_3.1-153     jsonlite_1.8.0  
[13] evaluate_0.15    lifecycle_1.0.1  tibble_3.1.7     mgcv_1.8-38     
[17] pkgconfig_2.0.3  rlang_1.0.4      Matrix_1.3-4     cli_3.3.0       
[21] rstudioapi_0.13  parallel_4.1.2   yaml_2.3.5       xfun_0.31       
[25] fastmap_1.1.0    cluster_2.1.2    stringr_1.4.0    knitr_1.39      
[29] fs_1.5.2         vctrs_0.4.1      sass_0.4.2       grid_4.1.2      
[33] rprojroot_2.0.3  glue_1.6.2       R6_2.5.1         fansi_1.0.3     
[37] rmarkdown_2.14   magrittr_2.0.3   splines_4.1.2    MASS_7.3-54     
[41] promises_1.2.0.1 ellipsis_0.3.2   htmltools_0.5.2  httpuv_1.6.5    
[45] utf8_1.2.2       stringi_1.7.6    cachem_1.0.6