annotate templateLibrary.py @ 0:2cb81da69c73 draft

planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
author anmoljh
date Thu, 31 May 2018 11:58:59 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1 def __template4Rnw():
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
2
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
3 template4Rnw = r'''%% Classification Modeling Script
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
4 %% Max Kuhn (max.kuhn@pfizer.com, mxkuhn@gmail.com)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
5 %% Version: 1.00
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
6 %% Created on: 2010/10/02
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
7 %%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
8 %% The originla file hs been improved by
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
9 %% Deepak Bharti, Andrew M. Lynn , Anmol J. Hemrom
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
10 %% Version : 1.01
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
11 %% created on : 2014/08/12
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
12 %% This is an Sweave template for building and describing
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
13 %% classification models. It mixes R and LaTeX code. The document can
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
14 %% be processing using R's Sweave function to produce a tex file.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
15 %%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
16 %% The inputs are:
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
17 %% - the initial data set in a data frame called 'rawData'
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
18 %% - a factor column in the data set called 'class'. this should be the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
19 %% outcome variable
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
20 %% - all other columns in rawData should be predictor variables
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
21 %% - the type of model should be in a variable called 'modName'.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
22 %%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
23 %% The script attempts to make some intelligent choices based on the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
24 %% model being used. For example, if modName is "pls", the script will
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
25 %% automatically center and scale the predictor data. There are
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
26 %% situations where these choices can (and should be) changed.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
27 %%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
28 %% There are other options that may make sense to change. For example,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
29 %% the user may want to adjust the type of resampling. To find these
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
30 %% parts of the script, search on the string 'OPTION'. These parts of
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
31 %% the code will document the options.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
32
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
33 \documentclass[14pt]{report}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
34 \usepackage{amsmath}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
35 \usepackage[pdftex]{graphicx}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
36 \usepackage{color}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
37 \usepackage{ctable}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
38 \usepackage{xspace}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
39 \usepackage{fancyvrb}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
40 \usepackage{fancyhdr}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
41 \usepackage{lastpage}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
42 \usepackage{longtable}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
43 \usepackage{algorithm2e}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
44 \usepackage[
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
45 colorlinks=true,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
46 linkcolor=blue,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
47 citecolor=blue,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
48 urlcolor=blue]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
49 {hyperref}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
50 \usepackage{lscape}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
51 \usepackage{Sweave}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
52 \SweaveOpts{keep.source = TRUE}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
53
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
55
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
56 % define new colors for use
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
57 \definecolor{darkgreen}{rgb}{0,0.6,0}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
58 \definecolor{darkred}{rgb}{0.6,0.0,0}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
59 \definecolor{lightbrown}{rgb}{1,0.9,0.8}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
60 \definecolor{brown}{rgb}{0.6,0.3,0.3}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
61 \definecolor{darkblue}{rgb}{0,0,0.8}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
62 \definecolor{darkmagenta}{rgb}{0.5,0,0.5}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
63
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
65
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
66 \newcommand{\bld}[1]{\mbox{\boldmath $$#1$$}}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
67 \newcommand{\shell}[1]{\mbox{$$#1$$}}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
68 \renewcommand{\vec}[1]{\mbox{\bf {#1}}}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
69
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
70 \newcommand{\ReallySmallSpacing}{\renewcommand{\baselinestretch}{.6}\Large\normalsize}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
71 \newcommand{\SmallSpacing}{\renewcommand{\baselinestretch}{1.1}\Large\normalsize}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
72
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
73 \newcommand{\halfs}{\frac{1}{2}}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
74
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
75 \setlength{\oddsidemargin}{-.25 truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
76 \setlength{\evensidemargin}{0truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
77 \setlength{\topmargin}{-0.2truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
78 \setlength{\textwidth}{7 truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
79 \setlength{\textheight}{8.5 truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
80 \setlength{\parindent}{0.20truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
81 \setlength{\parskip}{0.10truein}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
82
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
83 \setcounter{LTchunksize}{50}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
84
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
86 \pagestyle{fancy}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
87 \lhead{}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
88 %% OPTION Report header name
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
89 \chead{Classification Model Script}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
90 \rhead{}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
91 \lfoot{}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
92 \cfoot{}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
93 \rfoot{\thepage\ of \pageref{LastPage}}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
94 \renewcommand{\headrulewidth}{1pt}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
95 \renewcommand{\footrulewidth}{1pt}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
97
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
98 %% OPTION Report title and modeler name
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
99 \title{Classification Model Script using $METHOD}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
100 \author{"Lynn Group with M. Kuhn, SCIS, JNU, New Delhi"}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
101
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
102 \begin{document}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
103
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
104 \maketitle
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
105
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
106 \thispagestyle{empty}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
107 <<dummy, eval=TRUE, echo=FALSE, results=hide>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
108 # sets values for variables used later in the program to prevent the \Sexpr error on parsing with Sweave
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
109 numSamples=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
110 classDistString=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
111 missingText=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
112 numPredictors=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
113 numPCAcomp=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
114 pcaText=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
115 nzvText=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
116 corrText=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
117 ppText=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
118 varText=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
119 splitText="Dummy Text"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
120 nirText="Dummy Text"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
121 # pctTrain is a variable that is initialised in Data splitting, and reused later in testPred
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
122 pctTrain=0.8
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
123 Smpling=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
124 nzvText1=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
125 classDistString1=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
126 dwnsmpl=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
127 upsmpl=''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
128
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
129 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
130 <<startup, eval= TRUE, results = hide, echo = FALSE>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
131 library(Hmisc)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
132 library(caret)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
133 library(pROC)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
134 versionTest <- compareVersion(packageDescription("caret")$$Version,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
135 "4.65")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
136 if(versionTest < 0) stop("caret version 4.65 or later is required")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
137
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
138 library(RColorBrewer)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
139
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
140
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
141 listString <- function (x, period = FALSE, verbose = FALSE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
142 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
143 if (verbose) cat("\n entering listString\n")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
144 flush.console()
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
145 if (!is.character(x))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
146 x <- as.character(x)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
147 numElements <- length(x)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
148 out <- if (length(x) > 0) {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
149 switch(min(numElements, 3), x, paste(x, collapse = " and "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
150 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
151 x <- paste(x, c(rep(",", numElements - 2), " and", ""), sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
152 paste(x, collapse = " ")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
153 })
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
154 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
155 else ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
156 if (period) out <- paste(out, ".", sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
157 if (verbose) cat(" leaving listString\n\n")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
158 flush.console()
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
159 out
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
160 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
161
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
162 resampleStats <- function(x, digits = 3)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
163 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
164 bestPerf <- x$$bestTune
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
165 colnames(bestPerf) <- gsub("^\\.", "", colnames(bestPerf))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
166 out <- merge(x$$results, bestPerf)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
167 out <- out[, colnames(out) %in% x$$perfNames]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
168 names(out) <- gsub("ROC", "area under the ROC curve", names(out), fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
169 names(out) <- gsub("Sens", "sensitivity", names(out), fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
170 names(out) <- gsub("Spec", "specificity", names(out), fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
171 names(out) <- gsub("Accuracy", "overall accuracy", names(out), fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
172 names(out) <- gsub("Kappa", "Kappa statistics", names(out), fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
173
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
174 out <- format(out, digits = digits)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
175 listString(paste(names(out), "was", out))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
176 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
177
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
178 twoClassNoProbs <- function (data, lev = NULL, model = NULL)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
179 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
180 out <- c(sensitivity(data[, "pred"], data[, "obs"], lev[1]),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
181 specificity(data[, "pred"], data[, "obs"], lev[2]),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
182 confusionMatrix(data[, "pred"], data[, "obs"])$$overall["Kappa"])
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
183
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
184 names(out) <- c("Sens", "Spec", "Kappa")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
185 out
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
186 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
187
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
188
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
189
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
190 ##OPTION: model name: see ?train for more values/models
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
191 modName <- "$METHOD"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
192
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
193
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
194 load("$RDATA")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
195 rawData <- dataX
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
196 rawData$$outcome <- dataY
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
197
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
198 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
199
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
200
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
201 \section*{Data Sets}\label{S:data}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
202
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
203 %% OPTION: provide some background on the problem, the experimental
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
204 %% data, how the compounds were selected etc
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
205
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
206 <<getDataInfo, eval = $GETDATAINFOEVAL, echo = $GETDATAINFOECHO, results = $GETDATAINFORESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
207 if(!any(names(rawData) == "outcome")) stop("a variable called outcome should be in the data set")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
208 if(!is.factor(rawData$$outcome)) stop("the outcome should be a factor vector")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
209
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
210 ## OPTION: when there are only two classes, the first level of the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
211 ## factor is used as the "positive" or "event" for calculating
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
212 ## sensitivity and specificity. Adjust the outcome factor accordingly.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
213 numClasses <- length(levels(rawData$$outcome))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
214 numSamples <- nrow(rawData)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
215 numPredictors <- ncol(rawData) - 1
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
216 predictorNames <- names(rawData)[names(rawData) != "outcome"]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
217
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
218 isNum <- apply(rawData[,predictorNames, drop = FALSE], 2, is.numeric)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
219 if(any(!isNum)) stop("all predictors in rawData should be numeric")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
220
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
221 classTextCheck <- all.equal(levels(rawData$$outcome), make.names(levels(rawData$$outcome)))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
222 if(!classTextCheck) warning("the class levels are not valid R variable names; this may cause errors")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
223
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
224 ## Get the class distribution
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
225 classDist <- table(rawData$$outcome)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
226 classDistString <- paste("``",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
227 names(classDist),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
228 "'' ($$n$$=",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
229 classDist,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
230 ")",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
231 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
232 classDistString <- listString(classDistString)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
233 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
234
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
235 <<missingFilter, eval = $MISSINGFILTEREVAL, echo = $MISSINGFILTERECHO, results = $MISSINGFILTERRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
236 colRate <- apply(rawData[, predictorNames, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
237 2, function(x) mean(is.na(x)))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
238
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
239 ##OPTION thresholds can be changed
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
240 colExclude <- colRate > $MISSINGFILTERTHRESHC
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
241
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
242 missingText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
243
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
244 if(any(colExclude))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
245 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
246 missingText <- paste(missingText,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
247 ifelse(sum(colExclude) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
248 " There were ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
249 " There was "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
250 sum(colExclude),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
251 ifelse(sum(colExclude) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
252 " predictors ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
253 " predictor "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
254 "with an excessive number of ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
255 "missing data. ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
256 ifelse(sum(colExclude) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
257 " These were excluded. ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
258 " This was excluded. "))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
259 predictorNames <- predictorNames[!colExclude]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
260 rawData <- rawData[, names(rawData) %in% c("outcome", predictorNames), drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
261 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
262
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
263
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
264 rowRate <- apply(rawData[, predictorNames, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
265 1, function(x) mean(is.na(x)))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
266
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
267 rowExclude <- rowRate > $MISSINGFILTERTHRESHR
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
268
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
269
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
270 if(any(rowExclude)) {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
271 missingText <- paste(missingText,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
272 ifelse(sum(rowExclude) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
273 " There were ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
274 " There was "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
275 sum(colExclude),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
276 ifelse(sum(rowExclude) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
277 " samples ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
278 " sample "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
279 "with an excessive number of ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
280 "missing data. ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
281 ifelse(sum(rowExclude) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
282 " These were excluded. ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
283 " This was excluded. "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
284 "After filtering, ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
285 sum(!rowExclude),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
286 " samples remained.")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
287 rawData <- rawData[!rowExclude, ]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
288 hasMissing <- apply(rawData[, predictorNames, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
289 1, function(x) mean(is.na(x)))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
290 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
291 hasMissing <- apply(rawData[, predictorNames, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
292 1, function(x) any(is.na(x)))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
293 missingText <- paste(missingText,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
294 ifelse(missingText == "",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
295 "There ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
296 "Subsequently, there "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
297 ifelse(sum(hasMissing) == 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
298 "was ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
299 "were "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
300 ifelse(sum(hasMissing) > 0,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
301 sum(hasMissing),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
302 "no"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
303 ifelse(sum(hasMissing) == 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
304 "sample ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
305 "samples "),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
306 "with missing values.")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
307
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
308 rawData <- rawData[complete.cases(rawData),]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
309
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
310 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
311
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
312 rawData1 <- rawData[,1:length(rawData)-1]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
313 rawData2 <- rawData[,length(rawData)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
314
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
315 set.seed(222)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
316 nzv1 <- nearZeroVar(rawData1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
317 if(length(nzv1) > 0)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
318 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
319 nzvVars1 <- names(rawData1)[nzv1]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
320 rawData <- rawData1[, -nzv1]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
321 rawData$outcome <- rawData2
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
322 nzvText1 <- paste("There were ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
323 length(nzv1),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
324 " predictors that were removed from original data due to",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
325 " severely unbalanced distributions that",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
326 " could negatively affect the model fit",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
327 ifelse(length(nzv1) > 10,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
328 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
329 paste(": ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
330 listString(nzvVars1),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
331 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
332 sep = "")),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
333 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
334
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
335 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
336 rawData <- rawData1
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
337 rawData$outcome <- rawData2
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
338 nzvText1 <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
339
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
340 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
341
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
342 remove("rawData1")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
343 remove("rawData2")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
344
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
345 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
346
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
347 The initial data set consisted of \Sexpr{numSamples} samples and
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
348 \Sexpr{numPredictors} predictor variables. The breakdown of the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
349 outcome data classes were: \Sexpr{classDistString}.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
350
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
351 \Sexpr{missingText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
352
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
353 \Sexpr{nzvText1}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
354
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
355 <<pca, eval= $PCAEVAL, echo = $PCAECHO, results = $PCARESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
356
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
357 predictorNames <- names(rawData)[names(rawData) != "outcome"]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
358 numPredictors <- length(predictorNames)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
359 predictors <- rawData[, predictorNames, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
360 ## PCA will fail with predictors having less than 2 unique values
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
361 isZeroVar <- apply(predictors, 2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
362 function(x) length(unique(x)) < 2)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
363 if(any(isZeroVar)) predictors <- predictors[, !isZeroVar, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
364 ## For whatever, only the formula interface to prcomp
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
365 ## handles missing values
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
366 pcaForm <- as.formula(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
367 paste("~",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
368 paste(names(predictors), collapse = "+")))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
369 pca <- prcomp(pcaForm,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
370 data = predictors,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
371 center = TRUE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
372 scale. = TRUE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
373 na.action = na.omit)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
374 ## OPTION: the number of components plotted/discussed can be set
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
375 numPCAcomp <- $PCACOMP
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
376 pctVar <- pca$$sdev^2/sum(pca$$sdev^2)*100
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
377 pcaText <- paste(round(pctVar[1:numPCAcomp], 1),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
378 "\\\\%",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
379 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
380 pcaText <- listString(pcaText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
381 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
382
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
383 To get an initial assessment of the separability of the classes,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
384 principal component analysis (PCA) was used to distill the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
385 \Sexpr{numPredictors} predictors down into \Sexpr{numPCAcomp}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
386 surrogate variables (i.e. the principal components) in a manner that
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
387 attempts to maximize the amount of information preserved from the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
388 original predictor set. Figure \ref{F:inititalPCA} contains plots of
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
389 the first \Sexpr{numPCAcomp} components, which accounted for
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
390 \Sexpr{pcaText} percent of the variability in the original predictors
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
391 (respectively).
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
392
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
393
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
394 %% OPTION: remark on how well (or poorly) the data separated
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
395
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
396 \setkeys{Gin}{width = 0.8\textwidth}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
397 \begin{figure}[p]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
398 \begin{center}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
399
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
400 <<pcaPlot, eval = $PCAPLOTEVAL, echo = $PCAPLOTECHO, results = $PCAPLOTRESULT, fig = $PCAPLOTFIG, width = 8, height = 8>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
401 trellis.par.set(caretTheme(), warn = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
402 if(numPCAcomp == 2)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
403 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
404 axisRange <- extendrange(pca$$x[, 1:2])
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
405 print(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
406 xyplot(PC1 ~ PC2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
407 data = as.data.frame(pca$$x),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
408 type = c("p", "g"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
409 groups = rawData$$outcome,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
410 auto.key = list(columns = 2),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
411 xlim = axisRange,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
412 ylim = axisRange))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
413 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
414 axisRange <- extendrange(pca$$x[, 1:numPCAcomp])
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
415 print(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
416 splom(~as.data.frame(pca$$x)[, 1:numPCAcomp],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
417 type = c("p", "g"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
418 groups = rawData$$outcome,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
419 auto.key = list(columns = 2),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
420 as.table = TRUE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
421 prepanel.limits = function(x) axisRange
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
422 ))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
423
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
424 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
425
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
426 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
427
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
428 \caption[PCA Plot]{A plot of the first \Sexpr{numPCAcomp}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
429 principal components for the original data set.}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
430 \label{F:inititalPCA}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
431 \end{center}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
432 \end{figure}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
433
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
434
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
435
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
436 <<initialDataSplit, eval = $INITIALDATASPLITEVAL, echo = $INITIALDATASPLITECHO, results = $INITIALDATASPLITRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
437
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
438 ## OPTION: in small samples sizes, you may not want to set aside a
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
439 ## training set and focus on the resampling results.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
440
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
441 set.seed(1234)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
442 dataX <- rawData[,1:length(rawData)-1]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
443 dataY <- rawData[,length(rawData)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
444
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
445 Smpling <- "$SAAMPLING"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
446
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
447 if(Smpling=="downsampling")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
448 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
449 dwnsmpl <- downSample(dataX,dataY)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
450 rawData <- dwnsmpl[,1:length(dwnsmpl)-1]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
451 rawData$outcome <- dwnsmpl[,length(dwnsmpl)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
452 remove("dwnsmpl")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
453 remove("dataX")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
454 remove("dataY")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
455 }else if(Smpling=="upsampling"){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
456 upsmpl <- upSample(dataX,dataY)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
457 rawData <- upsmpl[,1:length(upsmpl)-1]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
458 rawData$outcome <- upsmpl[,length(upsmpl)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
459 remove("upsmpl")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
460 remove("dataX")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
461 remove("dataY")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
462 }else{remove("dataX")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
463 remove("dataY")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
464 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
465
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
466
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
467
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
468 numSamples <- nrow(rawData)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
469
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
470 predictorNames <- names(rawData)[names(rawData) != "outcome"]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
471 numPredictors <- length(predictorNames)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
472
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
473
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
474 classDist1 <- table(rawData$outcome)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
475 classDistString1 <- paste("``",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
476 names(classDist1),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
477 "'' ($n$=",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
478 classDist1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
479 ")",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
480 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
481 classDistString1 <- listString(classDistString1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
482
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
483 pctTrain <- $PERCENT
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
484
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
485 if(pctTrain < 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
486 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
487 ## OPTION: seed number can be changed
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
488 set.seed(1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
489 inTrain <- createDataPartition(rawData$$outcome,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
490 p = pctTrain,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
491 list = FALSE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
492 trainX <- rawData[ inTrain, predictorNames]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
493 testX <- rawData[-inTrain, predictorNames]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
494 trainY <- rawData[ inTrain, "outcome"]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
495 testY <- rawData[-inTrain, "outcome"]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
496 splitText <- paste("The original data were split into ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
497 "a training set ($$n$$=",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
498 nrow(trainX),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
499 ") and a test set ($$n$$=",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
500 nrow(testX),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
501 ") in a manner that preserved the ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
502 "distribution of the classes.",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
503 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
504 isZeroVar <- apply(trainX, 2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
505 function(x) length(unique(x)) < 2)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
506 if(any(isZeroVar))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
507 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
508 trainX <- trainX[, !isZeroVar, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
509 testX <- testX[, !isZeroVar, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
510 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
511
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
512 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
513 trainX <- rawData[, predictorNames]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
514 testX <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
515 trainY <- rawData[, "outcome"]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
516 testY <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
517 splitText <- "The entire data set was used as the training set."
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
518 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
519 trainDist <- table(trainY)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
520 nir <- max(trainDist)/length(trainY)*100
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
521 niClass <- names(trainDist)[which.max(trainDist)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
522 nirText <- paste("The non--information rate is the accuracy that can be ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
523 "achieved by predicting all samples using the most ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
524 "dominant class. For these data, the rate is ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
525 round(nir, 2), "\\\\% using the ``",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
526 niClass,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
527 "'' class.",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
528 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
529
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
530 remove("rawData")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
531
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
532 if((!is.null(testX)) && (!is.null(testY))){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
533 #save(trainX,trainY,testX,testY,file="datasets.RData")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
534 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
535 save(trainX,trainY,file="datasets.RData")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
536 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
537
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
538 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
539
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
540 \Sexpr{splitText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
541
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
542 \Sexpr{nirText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
543
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
544 The data set for model building consisted of \Sexpr{numSamples} samples and
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
545 \Sexpr{numPredictors} predictor variables. The breakdown of the
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
546 outcome data classes were: \Sexpr{classDistString1}.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
547
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
548 <<nzv, eval= $NZVEVAL, results = $NZVRESULT, echo = $NZVECHO>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
549 ## OPTION: other pre-processing steps can be used
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
550 ppSteps <- caret:::suggestions(modName)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
551
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
552 set.seed(2)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
553 if(ppSteps["nzv"])
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
554 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
555 nzv <- nearZeroVar(trainX)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
556 if(length(nzv) > 0)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
557 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
558 nzvVars <- names(trainX)[nzv]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
559 trainX <- trainX[, -nzv]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
560 nzvText <- paste("There were ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
561 length(nzv),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
562 " predictors that were removed from train set due to",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
563 " severely unbalanced distributions that",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
564 " could negatively affect the model",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
565 ifelse(length(nzv) > 10,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
566 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
567 paste(": ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
568 listString(nzvVars),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
569 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
570 sep = "")),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
571 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
572 testX <- testX[, -nzv]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
573 } else nzvText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
574 } else nzvText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
575 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
576
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
577 \Sexpr{nzvText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
578
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
579
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
580 <<corrFilter, eval = $CORRFILTEREVAL, results = $CORRFILTERRESULT, echo = $CORRFILTERECHO>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
581 if(ppSteps["corr"])
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
582 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
583 ## OPTION:
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
584 corrThresh <- $THRESHHOLDCOR
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
585 highCorr <- findCorrelation(cor(trainX, use = "pairwise.complete.obs"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
586 corrThresh)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
587 if(length(highCorr) > 0)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
588 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
589 corrVars <- names(trainX)[highCorr]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
590 trainX <- trainX[, -highCorr]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
591 corrText <- paste("There were ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
592 length(highCorr),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
593 " predictors that were removed due to",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
594 " large between--predictor correlations that",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
595 " could negatively affect the model fit",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
596 ifelse(length(highCorr) > 10,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
597 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
598 paste(": ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
599 listString(highCorr),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
600 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
601 sep = "")),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
602 " Removing these predictors forced",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
603 " all pair--wise correlations to be",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
604 " less than ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
605 corrThresh,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
606 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
607 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
608 testX <- testX[, -highCorr]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
609 } else corrText <- "No correlation among data on given threshold"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
610 }else corrText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
611 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
612
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
613 \Sexpr{corrText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
614
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
615 <<preProc, eval = $PREPROCEVAL, echo = $PREPROCECHO, results = $PREPROCRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
616 ppMethods <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
617 if(ppSteps["center"]) ppMethods <- c(ppMethods, "center")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
618 if(ppSteps["scale"]) ppMethods <- c(ppMethods, "scale")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
619 if(any(hasMissing) > 0) ppMethods <- c(ppMethods, "knnImpute")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
620 ##OPTION other methods, such as spatial sign, can be added to this list
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
621
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
622 if(length(ppMethods) > 0)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
623 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
624 ppInfo <- preProcess(trainX, method = ppMethods)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
625 trainX <- predict(ppInfo, trainX)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
626 if(pctTrain < 1) testX <- predict(ppInfo, testX)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
627 ppText <- paste("The following pre--processing methods were",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
628 " applied to the training",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
629 ifelse(pctTrain < 1, " and test", ""),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
630 " data: ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
631 listString(ppMethods),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
632 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
633 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
634 ppText <- gsub("center", "mean centering", ppText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
635 ppText <- gsub("scale", "scaling to unit variance", ppText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
636 ppText <- gsub("knnImpute",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
637 paste(ppInfo$$k, "--nearest neighbor imputation", sep = ""),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
638 ppText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
639 ppText <- gsub("spatialSign", "the spatial sign transformation", ppText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
640 ppText <- gsub("pca", "principal component feature extraction", ppText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
641 ppText <- gsub("ica", "independent component feature extraction", ppText)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
642 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
643 ppInfo <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
644 ppText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
645 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
646
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
647 predictorNames <- names(trainX)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
648 if(nzvText != "" | corrText != "" | ppText != "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
649 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
650 varText <- paste("After pre--processing, ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
651 ncol(trainX),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
652 "predictors remained for modeling.")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
653 } else varText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
654
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
655 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
656
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
657 \Sexpr{ppText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
658 \Sexpr{varText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
659
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
660 \clearpage
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
661
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
662 \section*{Model Building}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
663
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
664 <<setupWorkers, eval = TRUE, echo = $SETUPWORKERSECHO, results = $SETUPWORKERSRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
665 numWorkers <- $NUMWORKERS
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
666 ##OPTION: turn up numWorkers to use MPI
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
667 if(numWorkers > 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
668 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
669 mpiCalcs <- function(X, FUN, ...)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
670 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
671 theDots <- list(...)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
672 parLapply(theDots$$cl, X, FUN)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
673 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
674
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
675 library(snow)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
676 cl <- makeCluster(numWorkers, "MPI")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
677 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
678 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
679
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
680 <<setupResampling, echo = $SETUPRESAMPLINGECHO, results = $SETUPRESAMPLINGRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
681 ##OPTION: the resampling options can be changed. See
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
682 ## ?trainControl for details
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
683
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
684 resampName <- "$RESAMPNAME"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
685 resampNumber <- $RESAMPLENUMBER
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
686 numRepeat <- $NUMREPEAT
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
687 resampP <- $RESAMPLENUMBERPERCENT
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
688
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
689 modelInfo <- modelLookup(modName)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
690
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
691 if(numClasses == 2)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
692 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
693 foo <- if(any(modelInfo$$probModel)) twoClassSummary else twoClassNoProbs
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
694 } else foo <- defaultSummary
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
695
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
696 set.seed(3)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
697 ctlObj <- trainControl(method = resampName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
698 number = resampNumber,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
699 repeats = numRepeat,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
700 p = resampP,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
701 classProbs = any(modelInfo$$probModel),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
702 summaryFunction = foo)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
703
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
704
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
705 ##OPTION select other performance metrics as needed
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
706 optMetric <- if(numClasses == 2 & any(modelInfo$$probModel)) "ROC" else "Kappa"
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
707
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
708 if(numWorkers > 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
709 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
710 ctlObj$$workers <- numWorkers
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
711 ctlObj$$computeFunction <- mpiCalcs
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
712 ctlObj$$computeArgs <- list(cl = cl)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
713 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
714 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
715
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
716 <<setupGrid, results = $SETUPGRIDRESULT, echo = $SETUPGRIDECHO>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
717 ##OPTION expand or contract these grids as needed (or
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
718 ## add more models
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
719
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
720 gridSize <- $SETUPGRIDSIZE
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
721
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
722 if(modName %in% c("svmPoly", "svmRadial", "svmLinear", "lvq", "ctree2", "ctree")) gridSize <- 5
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
723 if(modName %in% c("earth", "fda")) gridSize <- 7
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
724 if(modName %in% c("knn", "rocc", "glmboost", "rf", "nodeHarvest")) gridSize <- 10
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
725
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
726 if(modName %in% c("nb")) gridSize <- 2
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
727 if(modName %in% c("pam", "rpart")) gridSize <- 15
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
728 if(modName %in% c("pls")) gridSize <- min(20, ncol(trainX))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
729
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
730 if(modName == "gbm")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
731 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
732 tGrid <- expand.grid(.interaction.depth = -1 + (1:5)*2 ,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
733 .n.trees = (1:10)*20,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
734 .shrinkage = .1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
735 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
736
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
737 if(modName == "nnet")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
738 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
739 tGrid <- expand.grid(.size = -1 + (1:5)*2 ,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
740 .decay = c(0, .001, .01, .1))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
741 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
742
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
743 if(modName == "ada")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
744 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
745 tGrid <- expand.grid(.maxdepth = 1, .iter = c(100,200,300,400), .nu = 1 )
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
746
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
747 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
748
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
749
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
750 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
751
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
752 <<fitModel, results = $FITMODELRESULT, echo = $FITMODELECHO, eval = $FITMODELEVAL>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
753 ##OPTION alter as needed
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
754
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
755 set.seed(4)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
756 modelFit <- switch(modName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
757 gbm =
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
758 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
759 mix <- sample(seq(along = trainY))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
760 train(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
761 trainX[mix,], trainY[mix], modName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
762 verbose = FALSE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
763 bag.fraction = .9,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
764 metric = optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
765 trControl = ctlObj,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
766 tuneGrid = tGrid)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
767 },
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
768
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
769 multinom =
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
770 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
771 train(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
772 trainX, trainY, modName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
773 trace = FALSE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
774 metric = optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
775 maxiter = 1000,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
776 MaxNWts = 5000,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
777 trControl = ctlObj,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
778 tuneLength = gridSize)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
779 },
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
780
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
781 nnet =
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
782 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
783 train(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
784 trainX, trainY, modName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
785 metric = optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
786 linout = FALSE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
787 trace = FALSE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
788 maxiter = 1000,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
789 MaxNWts = 5000,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
790 trControl = ctlObj,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
791 tuneGrid = tGrid)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
792
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
793 },
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
794
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
795 svmRadial =, svmPoly =, svmLinear =
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
796 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
797 train(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
798 trainX, trainY, modName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
799 metric = optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
800 scaled = TRUE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
801 trControl = ctlObj,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
802 tuneLength = gridSize)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
803 },
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
804 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
805 train(trainX, trainY, modName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
806 trControl = ctlObj,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
807 metric = optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
808 tuneLength = gridSize)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
809 })
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
810
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
811 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
812
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
813 <<modelDescr, echo = $MODELDESCRECHO, results = $MODELDESCRRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
814 summaryText <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
815
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
816 resampleName <- switch(tolower(modelFit$$control$$method),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
817 boot = paste("the bootstrap (", length(modelFit$$control$$index), " reps)", sep = ""),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
818 boot632 = paste("the bootstrap 632 rule (", length(modelFit$$control$$index), " reps)", sep = ""),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
819 cv = paste("cross-validation (", modelFit$$control$$number, " fold)", sep = ""),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
820 repeatedcv = paste("cross-validation (", modelFit$$control$$number, " fold, repeated ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
821 modelFit$$control$$repeats, " times)", sep = ""),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
822 lgocv = paste("repeated train/test splits (", length(modelFit$$control$$index), " reps, ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
823 round(modelFit$$control$$p, 2), "$$\\%$$)", sep = ""))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
824
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
825 tuneVars <- latexTranslate(tolower(modelInfo$$label))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
826 tuneVars <- gsub("\\#", "the number of ", tuneVars, fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
827 if(ncol(modelFit$$bestTune) == 1 && colnames(modelFit$$bestTune) == ".parameter")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
828 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
829 summaryText <- paste(summaryText,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
830 "\n\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
831 "There are no tuning parameters associated with this model.",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
832 "To characterize the model performance on the training set,",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
833 resampleName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
834 "was used.",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
835 "Table \\\\ref{T:resamps} and Figure \\\\ref{F:profile}",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
836 "show summaries of the resampling results. ")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
837
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
838 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
839 summaryText <- paste("There",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
840 ifelse(nrow(modelInfo) > 1, "are", "is"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
841 nrow(modelInfo),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
842 ifelse(nrow(modelInfo) > 1, "tuning parameters", "tuning parameter"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
843 "associated with this model:",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
844 listString(tuneVars, period = TRUE))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
845
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
846
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
847
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
848 paramNames <- gsub(".", "", names(modelFit$$bestTune), fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
849 ## (i in seq(along = paramNames))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
850 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
851 ## check <- modelInfo$$parameter %in% paramNames[i]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
852 ## if(any(check))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
853 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
854 ## paramNames[i] <- modelInfo$$label[which(check)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
855 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
856 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
857
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
858 paramNames <- gsub("#", "the number of ", paramNames, fixed = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
859 ## Check to see if there was only one combination fit
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
860 summaryText <- paste(summaryText,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
861 "To choose",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
862 ifelse(nrow(modelInfo) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
863 "appropriate values of the tuning parameters,",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
864 "an appropriate value of the tuning parameter,"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
865 resampleName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
866 "was used to generated a profile of performance across the",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
867 nrow(modelFit$$results),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
868 ifelse(nrow(modelInfo) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
869 "combinations of the tuning parameters.",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
870 "candidate values."),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
871
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
872 "Table \\\\ref{T:resamps} and Figure \\\\ref{F:profile} show",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
873 "summaries of the resampling profile. ", "The final model fitted to the entire training set was:",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
874 listString(paste(latexTranslate(tolower(paramNames)), "=", modelFit$$bestTune[1,]), period = TRUE))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
875
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
876 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
877 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
878
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
879 \Sexpr{summaryText}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
880
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
881 <<resampTable, echo = $RESAMPTABLEECHO, results = $RESAMPTABLERESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
882 tableData <- modelFit$$results
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
883
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
884 if(all(modelInfo$$parameter == "parameter") && resampName == "boot632")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
885 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
886 tableData <- tableData[,-1, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
887 colNums <- c( length(modelFit$$perfNames), length(modelFit$$perfNames), length(modelFit$$perfNames))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
888 colLabels <- c("Mean", "Standard Deviation","Apparant")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
889 constString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
890 isConst <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
891 } else if (all(modelInfo$$parameter == "parameter") && (resampName == "boot" | resampName == "cv" | resampName == "repeatedcv" )){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
892 tableData <- tableData[,-1, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
893 colNums <- c(length(modelFit$$perfNames), length(modelFit$$perfNames))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
894 colLabels <- c("Mean", "Standard Deviation")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
895 constString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
896 isConst <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
897 } else if (all(modelInfo$$parameter == "parameter") && resampName == "LOOCV" ){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
898 tableData <- tableData[,-1, drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
899 colNums <- length(modelFit$$perfNames)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
900 colLabels <- c("Measures")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
901 constString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
902 isConst <- NULL
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
903 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
904 if (all(modelInfo$$parameter != "parameter") && resampName == "boot632" ){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
905 isConst <- apply(tableData[, modelInfo$$parameter, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
906 2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
907 function(x) length(unique(x)) == 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
908
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
909 numParamInTable <- sum(!isConst)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
910
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
911 if(any(isConst))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
912 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
913 constParam <- modelInfo$$parameter[isConst]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
914 constValues <- format(tableData[, constParam, drop = FALSE], digits = 4)[1,,drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
915 tableData <- tableData[, !(names(tableData) %in% constParam), drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
916 constString <- paste("The tuning",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
917 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
918 "parmeters",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
919 "parameter"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
920 listString(paste("``", names(constValues), "''", sep = "")),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
921 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
922 "were",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
923 "was"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
924 "held constant at",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
925 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
926 "a value of",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
927 "values of"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
928 listString(constValues[1,]))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
929
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
930 } else constString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
931
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
932 cn <- colnames(tableData)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
933 ## for(i in seq(along = cn))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
934 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
935 ## check <- modelInfo$$parameter %in% cn[i]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
936 ## if(any(check))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
937 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
938 ## cn[i] <- modelInfo$$label[which(check)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
939 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
940 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
941 ## colnames(tableData) <- cn
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
942
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
943 colNums <- c(numParamInTable,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
944 length(modelFit$$perfNames),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
945 length(modelFit$$perfNames),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
946 length(modelFit$$perfNames))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
947 colLabels <- c("", "Mean", "Standard Deviation", "Apparant")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
948
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
949 }else if (all(modelInfo$$parameter != "parameter") && (resampName == "boot" | resampName == "repeatedcv" | resampName == "cv") ){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
950 isConst <- apply(tableData[, modelInfo$$parameter, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
951 2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
952 function(x) length(unique(x)) == 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
953
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
954 numParamInTable <- sum(!isConst)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
955
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
956 if(any(isConst))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
957 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
958 constParam <- modelInfo$$parameter[isConst]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
959 constValues <- format(tableData[, constParam, drop = FALSE], digits = 4)[1,,drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
960 tableData <- tableData[, !(names(tableData) %in% constParam), drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
961 constString <- paste("The tuning",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
962 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
963 "parmeters",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
964 "parameter"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
965 listString(paste("``", names(constValues), "''", sep = "")),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
966 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
967 "were",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
968 "was"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
969 "held constant at",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
970 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
971 "a value of",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
972 "values of"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
973 listString(constValues[1,]))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
974
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
975 } else constString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
976
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
977 cn <- colnames(tableData)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
978 ## for(i in seq(along = cn))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
979 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
980 ## check <- modelInfo$$parameter %in% cn[i]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
981 ## if(any(check))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
982 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
983 ## cn[i] <- modelInfo$$label[which(check)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
984 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
985 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
986 ## colnames(tableData) <- cn
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
987
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
988 colNums <- c(numParamInTable,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
989 length(modelFit$$perfNames),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
990 length(modelFit$$perfNames))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
991 colLabels <- c("", "Mean", "Standard Deviation")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
992
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
993 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
994 else if (all(modelInfo$$parameter != "parameter") && resampName == "LOOCV"){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
995 isConst <- apply(tableData[, modelInfo$$parameter, drop = FALSE],
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
996 2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
997 function(x) length(unique(x)) == 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
998
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
999 numParamInTable <- sum(!isConst)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1000
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1001 if(any(isConst))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1002 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1003 constParam <- modelInfo$$parameter[isConst]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1004 constValues <- format(tableData[, constParam, drop = FALSE], digits = 4)[1,,drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1005 tableData <- tableData[, !(names(tableData) %in% constParam), drop = FALSE]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1006 constString <- paste("The tuning",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1007 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1008 "parmeters",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1009 "parameter"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1010 listString(paste("``", names(constValues), "''", sep = "")),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1011 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1012 "were",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1013 "was"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1014 "held constant at",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1015 ifelse(sum(isConst) > 1,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1016 "a value of",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1017 "values of"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1018 listString(constValues[1,]))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1019
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1020 } else constString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1021
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1022 cn <- colnames(tableData)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1023 ## for(i in seq(along = cn))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1024 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1025 ## check <- modelInfo$$parameter %in% cn[i]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1026 ## if(any(check))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1027 ## {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1028 ## cn[i] <- modelInfo$$label[which(check)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1029 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1030 ## }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1031 ## colnames(tableData) <- cn
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1032
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1033 colNums <- c(numParamInTable,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1034 length(modelFit$$perfNames))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1035 colLabels <- c("", "Measures")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1036
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1037 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1038
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1039 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1040
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1041
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1042
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1043 colnames(tableData) <- gsub("SD$$", "", colnames(tableData))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1044 colnames(tableData) <- gsub("Apparent$$", "", colnames(tableData))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1045 colnames(tableData) <- latexTranslate(colnames(tableData))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1046 rownames(tableData) <- latexTranslate(rownames(tableData))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1047
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1048 latex(tableData,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1049 rowname = NULL,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1050 file = "",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1051 cgroup = colLabels,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1052 n.cgroup = colNums,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1053 where = "h!",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1054 digits = 4,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1055 longtable = nrow(tableData) > 30,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1056 caption = paste(resampleName, "results from the model fit.", constString),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1057 label = "T:resamps")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1058 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1059
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1060 \setkeys{Gin}{ width = 0.9\textwidth}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1061 \begin{figure}[b]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1062 \begin{center}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1063
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1064 <<profilePlot, echo = $PROFILEPLOTECHO, fig = $PROFILEPLOTFIG, width = 8, height = 6>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1065 trellis.par.set(caretTheme(), warn = TRUE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1066 if(all(modelInfo$$parameter == "parameter") | all(isConst) | modName == "nb")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1067 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1068 resultsPlot <- resampleHist(modelFit)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1069 plotCaption <- paste("Distributions of model performance from the ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1070 "training set estimated using ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1071 resampleName)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1072 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1073 if(modName %in% c("svmPoly", "svmRadial", "svmLinear"))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1074 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1075 resultsPlot <- plot(modelFit,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1076 metric = optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1077 xTrans = function(x) log10(x))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1078 resultsPlot <- update(resultsPlot,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1079 type = c("g", "p", "l"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1080 ylab = paste(optMetric, " (", resampleName, ")", sep = ""))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1081
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1082 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1083 resultsPlot <- plot(modelFit,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1084 metric = optMetric)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1085 resultsPlot <- update(resultsPlot,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1086 type = c("g", "p", "l"),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1087 ylab = paste(optMetric, " (", resampleName, ")", sep = ""))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1088 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1089 plotCaption <- paste("A plot of the estimates of the",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1090 optMetric,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1091 "values calculated using",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1092 resampleName)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1093 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1094 print(resultsPlot)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1095 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1096 \caption[Performance Plot]{\Sexpr{plotCaption}.}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1097 \label{F:profile}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1098 \end{center}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1099 \end{figure}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1100
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1101
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1102 <<stopWorkers, echo = $STOPWORKERSECHO, results = $STOPWORKERSRESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1103 if(numWorkers > 1) stopCluster(cl)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1104 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1105
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1106 <<testPred, results = $TESTPREDRESULT, echo = $TESTPREDECHO>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1107 if((!is.null(testX)) && (!is.null(testY))){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1108 save(trainX,trainY,testX,testY,file="datasets.RData")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1109 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1110 save(trainX,trainY,file="datasets.RData")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1111 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1112
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1113 if(pctTrain < 1)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1114 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1115 cat("\\clearpage\n\\section*{Test Set Results}\n\n")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1116 classPred <- predict(modelFit, testX)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1117 cm <- confusionMatrix(classPred, testY)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1118 values <- cm$$overall[c("Accuracy", "Kappa", "AccuracyPValue", "McnemarPValue")]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1119
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1120 values <- values[!is.na(values) & !is.nan(values)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1121 values <- c(format(values[1:2], digits = 3),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1122 format.pval(values[-(1:2)], digits = 5))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1123 nms <- c("the overall accuracy", "the Kappa statistic",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1124 "the $$p$$--value that accuracy is greater than the no--information rate",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1125 "the $$p$$--value of concordance from McNemar's test")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1126 nms <- nms[seq(along = values)]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1127 names(values) <- nms
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1128
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1129 if(any(modelInfo$$probModel))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1130 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1131 classProbs <- extractProb(list(fit = modelFit),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1132 testX = testX,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1133 testY = testY)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1134 classProbs <- subset(classProbs, dataType == "Test")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1135 if(numClasses == 2)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1136 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1137 tmp <- twoClassSummary(classProbs, lev = levels(classProbs$$obs))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1138 tmp <- c(format(tmp, digits = 3))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1139 names(tmp) <- c("the area under the ROC curve", "the sensitivity", "the specificity")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1140
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1141 values <- c(values, tmp)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1142
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1143 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1144 probPlot <- plotClassProbs(classProbs)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1145 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1146 testString <- paste("Based on the test set of",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1147 nrow(testX),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1148 "samples,",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1149 listString(paste(names(values), "was", values), period = TRUE),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1150 "The confusion matrix for the test set is shown in Table",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1151 "\\\\ref{T:cm}.")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1152 testString <- paste(testString,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1153 " Using ", resampleName,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1154 ", the training set estimates were ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1155 resampleStats(modelFit),
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1156 ".",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1157 sep = "")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1158
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1159 if(any(modelInfo$$probModel)) testString <- paste(testString,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1160 "Histograms of the class probabilities",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1161 "for the test set samples are shown in",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1162 "Figure \\\\ref{F:probs}",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1163 ifelse(numClasses == 2,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1164 " and the test set ROC curve is in Figure \\\\ref{F:roc}.",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1165 "."))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1166
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1167
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1168
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1169 latex(cm$$table,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1170 title = "",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1171 file = "",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1172 where = "h",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1173 cgroup = "Observed Values",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1174 n.cgroup = numClasses,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1175 caption = "The confusion matrix for the test set",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1176 label = "T:cm")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1177
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1178 } else testString <- ""
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1179 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1180 \Sexpr{testString}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1181
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1182
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1183 <<classProbsTex, results = $CLASSPROBSTEXRESULT, echo = $CLASSPROBSTEXECHO>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1184 if(any(modelInfo$probModel) && pctTrain < 1 ) {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1185 cat(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1186 paste("\\begin{figure}[p]\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1187 "\\begin{center}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1188 "\\includegraphics{classProbs}",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1189 "\\caption[PCA Plot]{Class probabilities",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1190 "for the test set. Each panel contains ",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1191 "separate classes}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1192 "\\label{F:probs}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1193 "\\end{center}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1194 "\\end{figure}"))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1195 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1196 if(any(modelInfo$$probModel) & numClasses == 2 & pctTrain < 1 )
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1197 {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1198 cat(
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1199 paste("\\begin{figure}[p]\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1200 "\\begin{center}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1201 "\\includegraphics[clip, width = .8\\textwidth]{roc}",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1202 "\\caption[ROC Plot]{ROC Curve",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1203 "for the test set.}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1204 "\\label{F:roc}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1205 "\\end{center}\n",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1206 "\\end{figure}"))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1207 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1208 cat (paste(""))
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1209 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1210
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1211 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1212 <<classProbsTex, results = $CLASSPROBSTEXRESULT1, echo = $CLASSPROBSTEXECHO1 >>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1213 if(any(modelInfo$probModel) && pctTrain < 1) {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1214 pdf("classProbs.pdf", height = 7, width = 7)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1215 trellis.par.set(caretTheme(), warn = FALSE)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1216 print(probPlot)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1217 dev.off()
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1218 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1219 if(any(modelInfo$probModel) & numClasses == 2 & pctTrain < 1) {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1220 resPonse<-testY
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1221 preDictor<-classProbs[, levels(trainY)[1]]
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1222 pdf("roc.pdf", height = 8, width = 8)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1223 # from pROC example at http://web.expasy.org/pROC/screenshots.htm
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1224 plot.roc(resPonse, preDictor, # data
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1225 percent=TRUE, # show all values in percent
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1226 partial.auc=c(100, 90), partial.auc.correct=TRUE, # define a partial AUC (pAUC)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1227 print.auc=TRUE, #display pAUC value on the plot with following options:
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1228 print.auc.pattern="Corrected pAUC (100-90%% SP):\n%.1f%%", print.auc.col="#1c61b6",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1229 auc.polygon=TRUE, auc.polygon.col="#1c61b6", # show pAUC as a polygon
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1230 max.auc.polygon=TRUE, max.auc.polygon.col="#1c61b622", # also show the 100% polygon
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1231 main="Partial AUC (pAUC)")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1232 plot.roc(resPonse, preDictor,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1233 percent=TRUE, add=TRUE, type="n", # add to plot, but don't re-add the ROC itself (useless)
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1234 partial.auc=c(100, 90), partial.auc.correct=TRUE,
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1235 partial.auc.focus="se", # focus pAUC on the sensitivity
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1236 print.auc=TRUE, print.auc.pattern="Corrected pAUC (100-90%% SE):\n%.1f%%", print.auc.col="#008600",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1237 print.auc.y=40, # do not print auc over the previous one
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1238 auc.polygon=TRUE, auc.polygon.col="#008600",
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1239 max.auc.polygon=TRUE, max.auc.polygon.col="#00860022")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1240 dev.off()
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1241 } else {
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1242 cat("")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1243 }
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1244
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1245 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1246
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1247 \section*{Versions}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1248
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1249 <<versions, echo = FALSE, results = tex>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1250 toLatex(sessionInfo())
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1251
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1252 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1253
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1254 <<save-data, echo = $SAVEDATAECHO, results = $SAVEDATARESULT>>=
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1255 ## change this to the name of modName....
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1256 Fit <- modelFit
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1257 if(exists('ppInfo') && !is.null(ppInfo)){
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1258 save(Fit,ppInfo,cm,file="$METHOD-Fit.RData")
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1259 } else {save(Fit,cm,file="$METHOD-Fit.RData")}
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1260
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1261 @
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1262 The model was built using $METHOD and is saved as $METHOD Model for reuse. This contains the variable Fit.
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1263
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1264 \end{document}'''
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1265
2cb81da69c73 planemo upload commit a1f4dd8eb560c649391ada1a6bb9505893a35272
anmoljh
parents:
diff changeset
1266 return template4Rnw