plotTrainTest            package:hddplot            R Documentation

_P_l_o_t _p_r_e_d_i_c_t_i_o_n_s _f_o_r _b_o_t_h _a _I/_I_I _t_r_a_i_n/_t_e_s_t _s_p_l_i_t, _a_n_d _t_h_e _r_e_v_e_r_s_e

_D_e_s_c_r_i_p_t_i_o_n:

     A division of data is specified, for use of linear discriminant
     analysis, into a training and test set. Feature selection and
     model fitting is  formed, first with I/II as training/test, then
     with II/I as training/test. Two graphs are plotted - for the I
     (training) /II (test) scores, and for the II/I scores.

_U_s_a_g_e:

     plotTrainTest(x = Golub.BM, nfeatures = c(11, 11), cl = cancer.BM, traintest = divideUp(cancer.BM), titles = c("A: I/II (train with I, scores are for II)", "B: II/I (train with II, scores are for I)"))

_A_r_g_u_m_e_n_t_s:

       x: Matrix; rows are features, and columns are observations 
          ('samples')

nfeatures: integer: numbers of features for which calculations are
          required

      cl: Factor that classifies columns into groups that will classify
          the data for purposes of discriminant calculations

traintest: Values that specify a division of observations into two
          groups. In the first pass (fold), one to be training and the
          other test, with the roles then reversed in a second pass or
          fold.

  titles: A character vector of length 2 giving titles for the two
          graphs

_D_e_t_a_i_l_s:

_V_a_l_u_e:

     Two graphs are plotted.

_N_o_t_e:

_A_u_t_h_o_r(_s):

     John Maindonald

_R_e_f_e_r_e_n_c_e_s:

_S_e_e _A_l_s_o:

_E_x_a_m_p_l_e_s:

     mat <- matrix(rnorm(1000), ncol=20)
     cl <- factor(rep(1:3, c(7,9,4)))
     gp.id <- divideUp(cl, nset=2)
     plotTrainTest(x=mat, cl=cl, traintest=gp.id, nfeatures=c(2,3))


     ## The function is currently defined as
     function(x=Golub.BM, nfeatures=c(11,11), cl=cancer.BM,
                traintest=divideUp(cancer.BM),
                titles=c("A: I/II (train with I, scores are for II)",
                  "B: II/I (train with II, scores are for I)")){
         oldpar <- par(mfrow=c(1,2), pty="s")
         on.exit(par(oldpar))
         if(length(nfeatures)==1)nfeatures <- rep(nfeatures,2)
         traintest <- factor(traintest)
         train <- traintest==levels(traintest)[1]
         testset <- traintest==levels(traintest)[2]
         cl1 <- cl[train]
         cl2 <- cl[testset]
         nf1 <- nfeatures[1]
         ord1 <- orderFeatures(x, cl, subset=train)
         df1 <- data.frame(t(x[ord1[1:nf1], train]))
         df2 <- data.frame(t(x[ord1[1:nf1], testset]))
         df1.lda <- lda(df1, cl1)    
         scores <- predict(df1.lda, newdata=df2)$x
         scoreplot(scorelist=list(scores=scores, cl=cl2,
                  nfeatures=nfeatures[1], other=NULL, cl.other=NULL),
                prefix.title="")
         mtext(side=3, line=2, titles[1], adj=0)
         nf2 <- nfeatures[2]
         ord2 <- orderFeatures(x, cl, subset=testset)
         df2 <- data.frame(t(x[ord2[1:nf2], testset]))
         df1 <- data.frame(t(x[ord2[1:nf2], train]))
         df2.lda <- lda(df2, cl2)    
         scores <- predict(df2.lda, newdata=df1)$x
         scoreplot(scorelist=list(scores=scores, cl=cl1,
                  nfeatures=nfeatures[2], other=NULL, cl.other=NULL),
                prefix.title="")
         mtext(side=3, line=2, titles[2], adj=0)    
       }

