1 Introduction

In many analyses, a large amount of variables have to be tested independently against the trait/endpoint of interest, and also adjusted for covariates and confounding factors at the same time. The major bottleneck in these is the amount of time that it takes to complete these analyses.

With RegParallel, a large number of tests can be performed simultaneously. On a 12-core system, 144 variables can be tested simultaneously, with 1000s of variables processed in a matter of seconds via ‘nested’ parallel processing.

Works for logistic regression, linear regression, conditional logistic regression, Cox proportional hazards and survival models, and Bayesian logistic regression.

2 Installation

2.2 2. Load the package into R session

3 Quick start

For this quick start, we will follow the tutorial (from Section 3.1) of RNA-seq workflow: gene-level exploratory analysis and differential expression. Specifically, we will load the ‘airway’ data, where different airway smooth muscle cells were treated with dexamethasone.

Normalise the raw counts in DESeq2 and produce regularised log expression levels:

3.2 Perform a basic linear regression

Here, we will perform the linear regression using both glmParallel and lmParallel. We will appreciate that a linear regression is the same using either function with the default settings.

Regularised log expression levels from our DESeq2 data will be used.

##             Variable        Term        Beta StandardError          t
##   1: ENSG00000001461 cellN061011 -0.46859875    0.10526111  -4.451775
##   2: ENSG00000001461 cellN080611 -0.84020922    0.10526111  -7.982143
##   3: ENSG00000001461  cellN61311 -0.87778101    0.10526111  -8.339082
##   4: ENSG00000001561 cellN080611 -1.71802758    0.13649920 -12.586357
##   5: ENSG00000001561  cellN61311 -1.05328889    0.13649920  -7.716448
##  ---                                                                 
## 519: ENSG00000092108 cellN061011 -0.12721659    0.01564082  -8.133625
## 520: ENSG00000092108  cellN61311 -0.12451203    0.01564082  -7.960708
## 521: ENSG00000092148 cellN080611 -0.34988071    0.10313461  -3.392467
## 522: ENSG00000092200 cellN080611  0.05906656    0.01521063   3.883241
## 523: ENSG00000092208 cellN080611 -0.28587683    0.08506716  -3.360602
##                 P        OR   ORlower   ORupper
##   1: 0.0112313246 0.6258787 0.5092039 0.7692873
##   2: 0.0013351958 0.4316202 0.3511586 0.5305181
##   3: 0.0011301853 0.4157043 0.3382098 0.5109554
##   4: 0.0002293465 0.1794197 0.1373036 0.2344544
##   5: 0.0015182960 0.3487887 0.2669157 0.4557753
##  ---                                           
## 519: 0.0012429963 0.8805429 0.8539591 0.9079544
## 520: 0.0013489163 0.8829276 0.8562718 0.9104133
## 521: 0.0274674209 0.7047722 0.5757851 0.8626549
## 522: 0.0177922771 1.0608458 1.0296864 1.0929482
## 523: 0.0282890537 0.7513552 0.6359690 0.8876762
##             Variable        Term        Beta StandardError          t
##   1: ENSG00000001461 cellN061011 -0.46859875    0.10526111  -4.451775
##   2: ENSG00000001461 cellN080611 -0.84020922    0.10526111  -7.982143
##   3: ENSG00000001461  cellN61311 -0.87778101    0.10526111  -8.339082
##   4: ENSG00000001561 cellN080611 -1.71802758    0.13649920 -12.586357
##   5: ENSG00000001561  cellN61311 -1.05328889    0.13649920  -7.716448
##  ---                                                                 
## 519: ENSG00000092108 cellN061011 -0.12721659    0.01564082  -8.133625
## 520: ENSG00000092108  cellN61311 -0.12451203    0.01564082  -7.960708
## 521: ENSG00000092148 cellN080611 -0.34988071    0.10313461  -3.392467
## 522: ENSG00000092200 cellN080611  0.05906656    0.01521063   3.883241
## 523: ENSG00000092208 cellN080611 -0.28587683    0.08506716  -3.360602
##                 P        OR   ORlower   ORupper
##   1: 0.0112313246 0.6258787 0.5092039 0.7692873
##   2: 0.0013351958 0.4316202 0.3511586 0.5305181
##   3: 0.0011301853 0.4157043 0.3382098 0.5109554
##   4: 0.0002293465 0.1794197 0.1373036 0.2344544
##   5: 0.0015182960 0.3487887 0.2669157 0.4557753
##  ---                                           
## 519: 0.0012429963 0.8805429 0.8539591 0.9079544
## 520: 0.0013489163 0.8829276 0.8562718 0.9104133
## 521: 0.0274674209 0.7047722 0.5757851 0.8626549
## 522: 0.0177922771 1.0608458 1.0296864 1.0929482
## 523: 0.0282890537 0.7513552 0.6359690 0.8876762

3.3 Survival analysis via Cox Proportional Hazards regression

For this example, we will load breast cancer gene expression data with recurrence free survival (RFS) from Gene Expression Profiling in Breast Cancer: Understanding the Molecular Basis of Histologic Grade To Improve Prognosis. Specifically, we will encode each gene’s expression into Low|Mid|High based on Z-scores and compare these against RFS while adjusting for tumour grade in a Cox Proportional Hazards model.

First, let’s read in and prepare the data:

## [1] TRUE

With the data prepared, we can now apply a Cox Proportional Hazards model independently for each probe in the dataset against RFS.

In this we also increase the default blocksize to 2000 in order to speed up the analysis.

##           Variable        Term          Beta StandardError             Z
##     1:  X1007_s_at  X1007_s_at  0.3780639987     0.3535022  1.0694811914
##     2:    X1053_at    X1053_at  0.1177398813     0.2275041  0.5175285346
##     3:     X117_at     X117_at  0.6265036787     0.6763106  0.9263549892
##     4:     X121_at     X121_at -0.6138126274     0.6166626 -0.9953783151
##     5:  X1255_g_at  X1255_g_at -0.2043297829     0.3983930 -0.5128849375
##    ---                                                                  
## 22211:   X91703_at   X91703_at -0.4124539527     0.4883759 -0.8445419981
## 22212: X91816_f_at X91816_f_at  0.0482030943     0.3899180  0.1236236554
## 22213:   X91826_at   X91826_at  0.0546751431     0.3319572  0.1647053850
## 22214:   X91920_at   X91920_at -0.6452125945     0.8534623 -0.7559942684
## 22215:   X91952_at   X91952_at -0.0001396044     0.7377681 -0.0001892254
##                P       LRT      Wald   LogRank        HR    HRlower  HRupper
##     1: 0.2848529 0.2826716 0.2848529 0.2848400 1.4594563 0.72994385 2.918050
##     2: 0.6047873 0.6085603 0.6047873 0.6046839 1.1249515 0.72024775 1.757056
##     3: 0.3542615 0.3652989 0.3542615 0.3541855 1.8710573 0.49706191 7.043097
##     4: 0.3195523 0.3188303 0.3195523 0.3186921 0.5412832 0.16162940 1.812712
##     5: 0.6080318 0.6084157 0.6080318 0.6077573 0.8151935 0.37337733 1.779809
##    ---                                                                      
## 22211: 0.3983666 0.3949865 0.3983666 0.3981244 0.6620237 0.25419512 1.724169
## 22212: 0.9016133 0.9015048 0.9016133 0.9016144 1.0493838 0.48869230 2.253373
## 22213: 0.8691759 0.8691994 0.8691759 0.8691733 1.0561974 0.55103934 2.024453
## 22214: 0.4496526 0.4478541 0.4496526 0.4498007 0.5245510 0.09847349 2.794191
## 22215: 0.9998490 0.9998490 0.9998490 0.9998490 0.9998604 0.23547784 4.245498
##         P.adjust LRT.adjust Wald.adjust LogRank.adjust
##     1: 0.9999969  0.9999969   0.9999969      0.9999969
##     2: 0.9999969  0.9999969   0.9999969      0.9999969
##     3: 0.9999969  0.9999969   0.9999969      0.9999969
##     4: 0.9999969  0.9999969   0.9999969      0.9999969
##     5: 0.9999969  0.9999969   0.9999969      0.9999969
##    ---                                                
## 22211: 0.9999969  0.9999969   0.9999969      0.9999969
## 22212: 0.9999969  0.9999969   0.9999969      0.9999969
## 22213: 0.9999969  0.9999969   0.9999969      0.9999969
## 22214: 0.9999969  0.9999969   0.9999969      0.9999969
## 22215: 0.9999969  0.9999969   0.9999969      0.9999969

We now take the top probes from the model by Log Rank p-value and use biomaRt to look up the corresponding gene symbols.

not run

Two of the top hits include CXCL12 and MMP10. High expression of CXCL12 was previously associated with good progression free and overall survival in breast cancer in (doi: 10.1016/j.cca.2018.05.041.)[https://www.ncbi.nlm.nih.gov/pubmed/29800557] , whilst high expression of MMP10 was associated with poor prognosis in colon cancer in (doi: 10.1186/s12885-016-2515-7)[https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4950722/].

We can further explore the role of these genes to RFS by dividing their gene expression Z-scores into tertiles for low, mid, and high expression:

Plot the survival curves and place Log Rank p-value in the plots:

Survival analysis via Cox Proportional Hazards regression.

Survival analysis via Cox Proportional Hazards regression.

Survival analysis via Cox Proportional Hazards regression.

Survival analysis via Cox Proportional Hazards regression.

3.4 Perform a conditional logistic regression

In this example, we will re-use the Cox data for the purpose of performing conditional logistic regression with tumour grade as our grouping / matching factor. For this example, we will use ER status as the dependent variable and also adjust for age.

##        Variable         Term       Beta StandardError         Z           P
## 1:   X204667_at   X204667_at  0.9940504     0.3628087  2.739875 0.006146252
## 2:   X205225_at   X205225_at  0.4444556     0.1633857  2.720285 0.006522559
## 3: X207813_s_at X207813_s_at  0.8218501     0.3050777  2.693904 0.007062046
## 4:   X212108_at   X212108_at  1.9610211     0.7607284  2.577820 0.009942574
## 5: X219497_s_at X219497_s_at -1.0249671     0.3541401 -2.894242 0.003800756
##            LRT       Wald    LogRank        HR   HRlower   HRupper
## 1: 0.006808415 0.02212540 0.02104525 2.7021573 1.3270501  5.502169
## 2: 0.010783544 0.01941078 0.01701248 1.5596409 1.1322713  2.148319
## 3: 0.037459927 0.02449358 0.02424809 2.2747043 1.2509569  4.136257
## 4: 0.033447973 0.03356050 0.03384960 7.1065797 1.6000274 31.564132
## 5: 0.005153233 0.01387183 0.01183245 0.3588083 0.1792329  0.718302

not run

Oestrogen receptor (ESR1) comes out - makes sense! Also, although 204667_at is not listed in biomaRt, it overlaps an exon of FOXA1, which also makes sense in relation to oestrogen signalling.

##            used  (Mb) gc trigger  (Mb) max used  (Mb)
## Ncells  6909606 369.1   10922901 583.4 10922901 583.4
## Vcells 14163556 108.1   51793018 395.2 51793018 395.2

4 Advanced features

Advanced features include the ability to modify block size, choose different numbers of cores, enable ‘nested’ parallel processing, modify limits for confidence intervals, and exclude certain model terms from output.

4.1 Speed up processing

First create some test data for the purpose of benchmarking:

4.1.2 ~2000 tests; blocksize, 500; cores, 2; nestedParallel, FALSE

##    user  system elapsed 
##   3.966   0.368   4.321

Focusing on the elapsed time (as system time only reports time from the last core that finished), we can see that nested processing has negligible improvement or may actually be slower under certain conditions when tested over a small number of variables. This is likely due to the system being slowed by simply managing the larger number of threads. Nested processing’s benefits can only be gained when processing a large number of variables:

4.1.4 ~40000 tests; blocksize, 2000; cores, 2; nestedParallel, FALSE

##    user  system elapsed 
##  89.936   0.704  90.873

Performance is system-dependent and even increasing cores may not result in huge gains in time. Performance is a trade-off between cores, forked threads, blocksize, and the number of terms in each model.

4.1.5 ~40000 tests; blocksize, 5000; cores, 3; nestedParallel, TRUE

In this example, we choose a large blocksize and 3 cores. With nestedParallel enabled, this translates to 9 simultaneous threads.

##    user  system elapsed 
## 283.121  11.189  64.317

4.2 Modify confidence intervals

##       Variable         Term       Beta StandardError         Z        P
##    1:    gene1        gene1  0.1633546     0.1001188  1.631607 0.102762
##    2:    gene1 cellB:dosage  0.3071268     0.5706994  0.538159 0.590468
##    3:    gene1 cellT:dosage  0.7677605     0.9174614  0.836831 0.402687
##    4:    gene2        gene2 -0.2003716     0.1255234 -1.596288 0.110424
##    5:    gene2 cellB:dosage -0.1970543     0.6095298 -0.323289 0.746476
##   ---                                                                  
## 1487:  gene496 cellB:dosage  0.2656961     0.5905463  0.449916 0.652771
## 1488:  gene496 cellT:dosage  0.9435383     0.7000838  1.347751 0.177739
## 1489:  gene497      gene497  0.0750102     0.0548166  1.368384 0.171192
## 1490:  gene497 cellB:dosage  0.2836236     0.5795322  0.489401 0.624558
## 1491:  gene497 cellT:dosage  1.1794796     0.7638082  1.544209 0.122538
##             OR  ORlower  ORupper
##    1: 1.177454 0.909796  1.52386
##    2: 1.359513 0.312579  5.91299
##    3: 2.154935 0.202814 22.89651
##    4: 0.818427 0.592326  1.13083
##    5: 0.821146 0.170828  3.94714
##   ---                           
## 1487: 1.304339 0.284948  5.97057
## 1488: 2.569055 0.423265 15.59319
## 1489: 1.077895 0.935955  1.24136
## 1490: 1.327933 0.298450  5.90855
## 1491: 3.252681 0.454772 23.26428
##       Variable         Term       Beta StandardError         Z        P
##    1:    gene1        gene1  0.1633546     0.1001188  1.631607 0.102762
##    2:    gene1 cellB:dosage  0.3071268     0.5706994  0.538159 0.590468
##    3:    gene1 cellT:dosage  0.7677605     0.9174614  0.836831 0.402687
##    4:    gene2        gene2 -0.2003716     0.1255234 -1.596288 0.110424
##    5:    gene2 cellB:dosage -0.1970543     0.6095298 -0.323289 0.746476
##   ---                                                                  
## 1487:  gene496 cellB:dosage  0.2656961     0.5905463  0.449916 0.652771
## 1488:  gene496 cellT:dosage  0.9435383     0.7000838  1.347751 0.177739
## 1489:  gene497      gene497  0.0750102     0.0548166  1.368384 0.171192
## 1490:  gene497 cellB:dosage  0.2836236     0.5795322  0.489401 0.624558
## 1491:  gene497 cellT:dosage  1.1794796     0.7638082  1.544209 0.122538
##             OR  ORlower  ORupper
##    1: 1.177454 0.967660  1.43273
##    2: 1.359513 0.444225  4.16067
##    3: 2.154935 0.356853 13.01304
##    4: 0.818427 0.639932  1.04671
##    5: 0.821146 0.248650  2.71177
##   ---                           
## 1487: 1.304339 0.409936  4.15015
## 1488: 2.569055 0.651420 10.13178
## 1489: 1.077895 0.968092  1.20015
## 1490: 1.327933 0.426459  4.13499
## 1491: 3.252681 0.727925 14.53437

4.3 Remove some terms from output / include the intercept

##      Variable        Term        Beta StandardError         Z        P       OR
##   1:    gene1 (Intercept) -2.06983440     1.2911741 -1.603064 0.108921 0.126207
##   2:    gene1       gene1  0.16335463     0.1001188  1.631607 0.102762 1.177454
##   3:    gene2 (Intercept)  0.80218031     1.2643226  0.634474 0.525771 2.230399
##   4:    gene2       gene2 -0.20037160     0.1255234 -1.596288 0.110424 0.818427
##   5:    gene3 (Intercept) -2.08673533     1.3609498 -1.533293 0.125204 0.124092
##  ---                                                                           
## 990:  gene495     gene495  0.06273501     0.0578662  1.084139 0.278303 1.064745
## 991:  gene496 (Intercept) -0.85749696     1.0476290 -0.818512 0.413065 0.424223
## 992:  gene496     gene496  0.00824453     0.0770678  0.106978 0.914807 1.008279
## 993:  gene497 (Intercept) -1.84404692     1.2645364 -1.458279 0.144764 0.158176
## 994:  gene497     gene497  0.07501016     0.0548166  1.368384 0.171192 1.077895
##         ORlower  ORupper
##   1: 0.01004692  1.58537
##   2: 0.96765982  1.43273
##   3: 0.18714971 26.58128
##   4: 0.63993222  1.04671
##   5: 0.00861588  1.78725
##  ---                    
## 990: 0.95058218  1.19262
## 991: 0.05443151  3.30626
## 992: 0.86692261  1.17268
## 993: 0.01326677  1.88589
## 994: 0.96809176  1.20015
##      Variable    Term        Beta StandardError          Z        P       OR
##   1:    gene1   gene1  0.16335463     0.1001188  1.6316074 0.102762 1.177454
##   2:    gene2   gene2 -0.20037160     0.1255234 -1.5962884 0.110424 0.818427
##   3:    gene3   gene3  0.07870824     0.0562520  1.3992088 0.161750 1.081889
##   4:    gene4   gene4 -0.07007512     0.0602889 -1.1623218 0.245105 0.932324
##   5:    gene5   gene5  0.02223889     0.0568126  0.3914430 0.695470 1.022488
##  ---                                                                        
## 493:  gene493 gene493  0.15553665     0.1018218  1.5275375 0.126627 1.168285
## 494:  gene494 gene494 -0.00160817     0.0576039 -0.0279178 0.977728 0.998393
## 495:  gene495 gene495  0.06273501     0.0578662  1.0841391 0.278303 1.064745
## 496:  gene496 gene496  0.00824453     0.0770678  0.1069776 0.914807 1.008279
## 497:  gene497 gene497  0.07501016     0.0548166  1.3683841 0.171192 1.077895
##       ORlower ORupper
##   1: 0.967660 1.43273
##   2: 0.639932 1.04671
##   3: 0.968949 1.20799
##   4: 0.828417 1.04926
##   5: 0.914743 1.14292
##  ---                 
## 493: 0.956925 1.42633
## 494: 0.891803 1.11772
## 495: 0.950582 1.19262
## 496: 0.866923 1.17268
## 497: 0.968092 1.20015

5 Acknowledgments

Thanks to Horácio Montenegro and GenoMax for testing cross-platform differences, and Wolfgang Huber for providing the nudge that FDR correction needed to be implemented.

Thanks to Michael Barnes in London for introducing me to parallel processing in R.

Finally, thanks to Juan Celedón at Children’s Hospital of Pittsburgh.

6 Session info

## R version 4.0.0 (2020-04-24)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.11-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.11-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [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] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] survminer_0.4.6             ggpubr_0.3.0               
##  [3] ggplot2_3.3.0               GEOquery_2.56.0            
##  [5] DESeq2_1.28.0               magrittr_1.5               
##  [7] airway_1.8.0                SummarizedExperiment_1.18.1
##  [9] DelayedArray_0.14.0         matrixStats_0.56.0         
## [11] Biobase_2.48.0              GenomicRanges_1.40.0       
## [13] GenomeInfoDb_1.24.0         IRanges_2.22.1             
## [15] S4Vectors_0.26.0            BiocGenerics_0.34.0        
## [17] RegParallel_1.6.0           arm_1.11-1                 
## [19] lme4_1.1-23                 Matrix_1.2-18              
## [21] MASS_7.3-51.6               survival_3.1-12            
## [23] stringr_1.4.0               data.table_1.12.8          
## [25] doParallel_1.0.15           iterators_1.0.12           
## [27] foreach_1.5.0               knitr_1.28                 
## 
## loaded via a namespace (and not attached):
##  [1] minqa_1.2.4            colorspace_1.4-1       ggsignif_0.6.0        
##  [4] ellipsis_0.3.0         rio_0.5.16             XVector_0.28.0        
##  [7] farver_2.0.3           bit64_0.9-7            AnnotationDbi_1.50.0  
## [10] xml2_1.3.2             codetools_0.2-16       splines_4.0.0         
## [13] geneplotter_1.66.0     nloptr_1.2.2.1         km.ci_0.5-2           
## [16] broom_0.5.6            annotate_1.66.0        readr_1.3.1           
## [19] compiler_4.0.0         backports_1.1.6        assertthat_0.2.1      
## [22] limma_3.44.1           htmltools_0.4.0        tools_4.0.0           
## [25] coda_0.19-3            gtable_0.3.0           glue_1.4.0            
## [28] GenomeInfoDbData_1.2.3 dplyr_0.8.5            Rcpp_1.0.4.6          
## [31] carData_3.0-3          cellranger_1.1.0       vctrs_0.2.4           
## [34] nlme_3.1-147           xfun_0.13              openxlsx_4.1.5        
## [37] lifecycle_0.2.0        statmod_1.4.34         rstatix_0.5.0         
## [40] XML_3.99-0.3           zoo_1.8-8              zlibbioc_1.34.0       
## [43] scales_1.1.0           hms_0.5.3              RColorBrewer_1.1-2    
## [46] yaml_2.2.1             curl_4.3               gridExtra_2.3         
## [49] memoise_1.1.0          KMsurv_0.1-5           stringi_1.4.6         
## [52] RSQLite_2.2.0          highr_0.8              genefilter_1.70.0     
## [55] boot_1.3-25            zip_2.0.4              BiocParallel_1.22.0   
## [58] rlang_0.4.6            pkgconfig_2.0.3        bitops_1.0-6          
## [61] evaluate_0.14          lattice_0.20-41        purrr_0.3.4           
## [64] labeling_0.3           bit_1.1-15.2           tidyselect_1.0.0      
## [67] R6_2.4.1               generics_0.0.2         DBI_1.1.0             
## [70] pillar_1.4.4           haven_2.2.0            foreign_0.8-79        
## [73] withr_2.2.0            abind_1.4-5            RCurl_1.98-1.2        
## [76] tibble_3.0.1           crayon_1.3.4           car_3.0-7             
## [79] survMisc_0.5.5         rmarkdown_2.1          locfit_1.5-9.4        
## [82] grid_4.0.0             readxl_1.3.1           blob_1.2.1            
## [85] forcats_0.5.0          digest_0.6.25          xtable_1.8-4          
## [88] tidyr_1.0.2            munsell_0.5.0

7 References

Blighe and Lasky-Su (2018)

Blighe, K, and J Lasky-Su. 2018. “RegParallel: Standard regression functions in R enabled for parallel processing over large data-frames.” https://github.com/kevinblighe/RegParallel.