Last data update: 2014.03.03

R: Examples of fitting models, predicting class labels,...
d1:bcbcsfexamplesR Documentation

Examples of fitting models, predicting class labels, evaluating prediction, and analyzing fitting results

Description

These examples demonstrate how to use BCBCSF package. They use all prior and Markov chain sampling settings by default (except no_rmc as noted below). The methods for setting others can be found from documents for specific functions. However, the default settings may work well for a wide range of gene expression data.

References

Li, L. (2012), Bias-corrected Hierarchical Bayesian Classification with a Selected Subset of High-dimensional Features, Journal of American Statistical Association,107:497,120-134

See Also

bcbcsf_fitpred, bcbcsf_pred, cross_vld, eval_pred, reload_fit_bcbcsf, bcbcsf_sumfit, bcbcsf_plotsumfit

Examples


##dontrun{
## load lymphoma microarray data
data (lymphoma)

## select some cases as testing data set
ts <- c (sort(sample (1:42,5)), 43:44, 61:62)

## training data
X_tr <- lymph.X[-ts,] 
y_tr <- lymph.y[-ts]
## test data 
X_ts <- lymph.X[ts,] 
y_ts <- lymph.y[ts] 

##########################################################################
######################## training and prediction #########################
##########################################################################
## fitting training data with top features selected by F-statistic 
out_fit <- bcbcsf_fitpred (X_tr = X_tr, y_tr = y_tr, nos_fsel = c(20, 50),
                           no_rmc = 100)
## note 1: if 'X_ts' is given above, prediction is made after fitting
## note 2: no_rmc = 100 is too small, omit it and use the default

## predicting class labels of test cases 
out_pred <- bcbcsf_pred (X_ts = X_ts, out_fit = out_fit)

## evaluate prediction given true labels
eval_pred (out_pred = out_pred, y_ts = y_ts)

##########################################################################
####################### visualizing prediction results ###################
##########################################################################
## reload one bcbcsf fit result from hardrive
fit_bcbcsf <- reload_fit_bcbcsf (out_fit$fitfiles[1])
## the fitting result for no_fsel = 50 can be retrieved directly from
## out_fit:
fit_bcbcsf_fsel50 <- out_fit$fit_bcbcsf
## summarize the fitting result
sum_fit <- bcbcsf_sumfit (fit_bcbcsf)

## visualize fitting result
bcbcsf_plotsumfit (sum_fit)

##########################################################################
############################ cross validation ############################
##########################################################################
## doing cross validation with bcbcsf_fitpred on lymphoma data 
cv_pred <- cross_vld (
       ##################### classifier, data, and fold ###################
       fitpred_func = bcbcsf_fitpred, X = lymph.X, y = lymph.y, nfold = 2,
       ################ all other arguments passed classifier ############
       nos_fsel = c(20,50), no_rmc = 100 )
## note: no_rmc = 100 is too small, omit it and use the default in practice

## evaluate prediction given true labels            
eval_pred (out_pred = cv_pred, y_ts = lymph.y)   

## warning: this function is slow if nfold is large; if you have a 
## computer cluster, you better parallel the cross validation folds.
##}

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BCBCSF)
Loading required package: abind
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BCBCSF/example.Rd_%03d_medium.png", width=480, height=480)
> ### Name: d1:bcbcsfexamples
> ### Title: Examples of fitting models, predicting class labels, evaluating
> ###   prediction, and analyzing fitting results
> ### Aliases: bcbcsfexamples
> 
> ### ** Examples
> 
> 
> ##dontrun{
> ## load lymphoma microarray data
> data (lymphoma)
> 
> ## select some cases as testing data set
> ts <- c (sort(sample (1:42,5)), 43:44, 61:62)
> 
> ## training data
> X_tr <- lymph.X[-ts,] 
> y_tr <- lymph.y[-ts]
> ## test data 
> X_ts <- lymph.X[ts,] 
> y_ts <- lymph.y[ts] 
> 
> ##########################################################################
> ######################## training and prediction #########################
> ##########################################################################
> ## fitting training data with top features selected by F-statistic 
> out_fit <- bcbcsf_fitpred (X_tr = X_tr, y_tr = y_tr, nos_fsel = c(20, 50),
+                            no_rmc = 100)
   Be Patient ... BCBCSF is fitting...  
   |                                                                               |                                                                      |   0%   |                                                                               |                                                                      |   1%   |                                                                               |=                                                                     |   1%   |                                                                               |=                                                                     |   2%   |                                                                               |==                                                                    |   2%   |                                                                               |==                                                                    |   3%   |                                                                               |===                                                                   |   4%   |                                                                               |===                                                                   |   5%   |                                                                               |====                                                                  |   5%   |                                                                               |====                                                                  |   6%   |                                                                               |=====                                                                 |   7%   |                                                                               |=====                                                                 |   8%   |                                                                               |======                                                                |   8%   |                                                                               |======                                                                |   9%   |                                                                               |=======                                                               |   9%   |                                                                               |=======                                                               |  10%   |                                                                               |=======                                                               |  11%   |                                                                               |========                                                              |  11%   |                                                                               |========                                                              |  12%   |                                                                               |=========                                                             |  12%   |                                                                               |=========                                                             |  13%   |                                                                               |==========                                                            |  14%   |                                                                               |==========                                                            |  15%   |                                                                               |===========                                                           |  15%   |                                                                               |===========                                                           |  16%   |                                                                               |============                                                          |  17%   |                                                                               |============                                                          |  18%   |                                                                               |=============                                                         |  18%   |                                                                               |=============                                                         |  19%   |                                                                               |==============                                                        |  19%   |                                                                               |==============                                                        |  20%   |                                                                               |==============                                                        |  21%   |                                                                               |===============                                                       |  21%   |                                                                               |===============                                                       |  22%   |                                                                               |================                                                      |  22%   |                                                                               |================                                                      |  23%   |                                                                               |=================                                                     |  24%   |                                                                               |=================                                                     |  25%   |                                                                               |==================                                                    |  25%   |                                                                               |==================                                                    |  26%   |                                                                               |===================                                                   |  27%   |                                                                               |===================                                                   |  28%   |                                                                               |====================                                                  |  28%   |                                                                               |====================                                                  |  29%   |                                                                               |=====================                                                 |  30%   |                                                                               |======================                                                |  31%   |                                                                               |======================                                                |  32%   |                                                                               |=======================                                               |  33%   |                                                                               |========================                                              |  34%   |                                                                               |========================                                              |  35%   |                                                                               |=========================                                             |  36%   |                                                                               |==========================                                            |  36%   |                                                                               |==========================                                            |  37%   |                                                                               |==========================                                            |  38%   |                                                                               |===========================                                           |  39%   |                                                                               |============================                                          |  39%   |                                                                               |============================                                          |  40%   |                                                                               |============================                                          |  41%   |                                                                               |=============================                                         |  41%   |                                                                               |==============================                                        |  42%   |                                                                               |==============================                                        |  43%   |                                                                               |==============================                                        |  44%   |                                                                               |===============================                                       |  44%   |                                                                               |================================                                      |  45%   |                                                                               |================================                                      |  46%   |                                                                               |=================================                                     |  47%   |                                                                               |==================================                                    |  48%   |                                                                               |==================================                                    |  49%   |                                                                               |===================================                                   |  50%   |                                                                               |====================================                                  |  51%   |                                                                               |====================================                                  |  52%   |                                                                               |=====================================                                 |  53%   |                                                                               |======================================                                |  54%   |                                                                               |======================================                                |  55%   |                                                                               |=======================================                               |  56%   |                                                                               |========================================                              |  56%   |                                                                               |========================================                              |  57%   |                                                                               |========================================                              |  58%   |                                                                               |=========================================                             |  59%   |                                                                               |==========================================                            |  59%   |                                                                               |==========================================                            |  60%   |                                                                               |==========================================                            |  61%   |                                                                               |===========================================                           |  61%   |                                                                               |============================================                          |  62%   |                                                                               |============================================                          |  63%   |                                                                               |============================================                          |  64%   |                                                                               |=============================================                         |  64%   |                                                                               |==============================================                        |  65%   |                                                                               |==============================================                        |  66%   |                                                                               |===============================================                       |  67%   |                                                                               |================================================                      |  68%   |                                                                               |================================================                      |  69%   |                                                                               |=================================================                     |  70%   |                                                                               |==================================================                    |  71%   |                                                                               |==================================================                    |  72%   |                                                                               |===================================================                   |  73%   |                                                                               |====================================================                  |  74%   |                                                                               |====================================================                  |  75%   |                                                                               |=====================================================                 |  76%   |                                                                               |======================================================                |  76%   |                                                                               |======================================================                |  77%   |                                                                               |======================================================                |  78%   |                                                                               |=======================================================               |  79%   |                                                                               |========================================================              |  79%   |                                                                               |========================================================              |  80%   |                                                                               |========================================================              |  81%   |                                                                               |=========================================================             |  81%   |                                                                               |==========================================================            |  82%   |                                                                               |==========================================================            |  83%   |                                                                               |==========================================================            |  84%   |                                                                               |===========================================================           |  84%   |                                                                               |============================================================          |  85%   |                                                                               |============================================================          |  86%   |                                                                               |=============================================================         |  87%   |                                                                               |==============================================================        |  88%   |                                                                               |==============================================================        |  89%   |                                                                               |===============================================================       |  90%   |                                                                               |================================================================      |  91%   |                                                                               |================================================================      |  92%   |                                                                               |=================================================================     |  93%   |                                                                               |==================================================================    |  94%   |                                                                               |==================================================================    |  95%   |                                                                               |===================================================================   |  96%   |                                                                               |====================================================================  |  96%   |                                                                               |====================================================================  |  97%   |                                                                               |====================================================================  |  98%   |                                                                               |===================================================================== |  99%   |                                                                               |======================================================================|  99%   |                                                                               |======================================================================| 100%
> ## note 1: if 'X_ts' is given above, prediction is made after fitting
> ## note 2: no_rmc = 100 is too small, omit it and use the default
> 
> ## predicting class labels of test cases 
> out_pred <- bcbcsf_pred (X_ts = X_ts, out_fit = out_fit)
> 
> ## evaluate prediction given true labels
> eval_pred (out_pred = out_pred, y_ts = y_ts)
$probs_at_truelabels
          fsel1     fsel2
Case1 1.0000000 1.0000000
Case2 1.0000000 1.0000000
Case3 1.0000000 1.0000000
Case4 1.0000000 1.0000000
Case5 1.0000000 1.0000000
Case6 0.9775752 0.9999999
Case7 0.9864736 0.9999997
Case8 0.2664777 0.6955399
Case9 0.5488585 0.7758773

$summary
      No.Features Error.Rate       AMLP
fsel1          20  0.1111111 0.21763089
fsel2          50  0.0000000 0.06853646

> 
> ##########################################################################
> ####################### visualizing prediction results ###################
> ##########################################################################
> ## reload one bcbcsf fit result from hardrive
> fit_bcbcsf <- reload_fit_bcbcsf (out_fit$fitfiles[1])
> ## the fitting result for no_fsel = 50 can be retrieved directly from
> ## out_fit:
> fit_bcbcsf_fsel50 <- out_fit$fit_bcbcsf
> ## summarize the fitting result
> sum_fit <- bcbcsf_sumfit (fit_bcbcsf)
> 
> ## visualize fitting result
> bcbcsf_plotsumfit (sum_fit)
> 
> ##########################################################################
> ############################ cross validation ############################
> ##########################################################################
> ## doing cross validation with bcbcsf_fitpred on lymphoma data 
> cv_pred <- cross_vld (
+        ##################### classifier, data, and fold ###################
+        fitpred_func = bcbcsf_fitpred, X = lymph.X, y = lymph.y, nfold = 2,
+        ################ all other arguments passed classifier ############
+        nos_fsel = c(20,50), no_rmc = 100 )
Fold 1:    Be Patient ... BCBCSF is fitting...  
   |                                                                               |                                                                      |   0%   |                                                                               |                                                                      |   1%   |                                                                               |=                                                                     |   1%   |                                                                               |=                                                                     |   2%   |                                                                               |==                                                                    |   2%   |                                                                               |==                                                                    |   3%   |                                                                               |===                                                                   |   4%   |                                                                               |===                                                                   |   5%   |                                                                               |====                                                                  |   5%   |                                                                               |====                                                                  |   6%   |                                                                               |=====                                                                 |   7%   |                                                                               |=====                                                                 |   8%   |                                                                               |======                                                                |   8%   |                                                                               |======                                                                |   9%   |                                                                               |=======                                                               |   9%   |                                                                               |=======                                                               |  10%   |                                                                               |=======                                                               |  11%   |                                                                               |========                                                              |  11%   |                                                                               |========                                                              |  12%   |                                                                               |=========                                                             |  12%   |                                                                               |=========                                                             |  13%   |                                                                               |==========                                                            |  14%   |                                                                               |==========                                                            |  15%   |                                                                               |===========                                                           |  15%   |                                                                               |===========                                                           |  16%   |                                                                               |============                                                          |  17%   |                                                                               |============                                                          |  18%   |                                                                               |=============                                                         |  18%   |                                                                               |=============                                                         |  19%   |                                                                               |==============                                                        |  19%   |                                                                               |==============                                                        |  20%   |                                                                               |==============                                                        |  21%   |                                                                               |===============                                                       |  21%   |                                                                               |===============                                                       |  22%   |                                                                               |================