Type: Package
Version: 0.1.3
Title: Projection Pursuit Classification Forest
Author: Natalia da Silva, Eun-Kyung Lee, Di Cook
Maintainer: Natalia da Silva <natalia.dasilva@fcea.edu.uy>
Description: Implements projection pursuit forest algorithm for supervised classification.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
URL: https://github.com/natydasilva/PPforest
LazyData: yes
Depends: R (≥ 3.2.0)
Imports: Rcpp (≥ 0.12.7), magrittr, plyr, dplyr (≥ 0.7.5), tidyr, doParallel, tibble
Suggests: knitr, gridExtra, GGally, ggplot2, RColorBrewer, roxygen2 (≥ 3.0.0), PPtreeViz, rmarkdown
VignetteBuilder: knitr
LinkingTo: Rcpp,RcppArmadillo
Encoding: UTF-8
RoxygenNote: 7.2.1
NeedsCompilation: yes
Packaged: 2022-09-09 23:14:21 UTC; natydasilva
Repository: CRAN
Date/Publication: 2022-09-09 23:32:55 UTC

NCI60 data set

Description

cDNA microarrays were used to examine the variation in gene expression among the 60 cell lines. The cell lines are derived from tumors with different sites of origin. This data set contain 61 observations and 30 feature variables from 8 different tissue types.

Usage

data(NCI60)

Format

A data frame with 61 rows and 31 variables

Source

Dudoit, S., Fridlyand, J. and Speed, T. P. (2002). Comparison of Discrimination Methods for the Classification of Tumors Using Gene Expression Data. Journal of the American statistical Association 97 77-87.


Predict class for the test set and calculate prediction error after finding the PPtree structure, .

Description

Predict class for the test set and calculate prediction error after finding the PPtree structure, .

Usage

PPclassify2( Tree.result, test.data = NULL, Rule = 1, true.class = NULL)

Arguments

Tree.result

the result of PP.Tree

test.data

the test dataset

Rule

split rule 1:mean of two group means, 2:weighted mean, 3: mean of max(left group) and min(right group), 4: weighted mean of max(left group) and min(right group)

true.class

true class of test dataset if available

Value

predict.class predicted class

predict.error prediction error

References

Lee, YD, Cook, D., Park JW, and Lee, EK(2013) PPtree: Projection pursuit classification tree, Electronic Journal of Statistics, 7:1369-1386.

Examples

#crab data set

Tree.crab <- PPtree_split('Type~.', data = crab, PPmethod = 'LDA', size.p = 0.5)
Tree.crab

PPclassify2(Tree.crab)


Projection Pursuit Random Forest

Description

PPforest implements a random forest using projection pursuit trees algorithm (based on PPtreeViz package).

Usage

PPforest(data, class, std = TRUE, size.tr, m, PPmethod, size.p,
 lambda = .1, parallel = FALSE, cores = 2, rule = 1)

Arguments

data

Data frame with the complete data set.

class

A character with the name of the class variable.

std

if TRUE standardize the data set, needed to compute global importance measure.

size.tr

is the size proportion of the training if we want to split the data in training and test.

m

is the number of bootstrap replicates, this corresponds with the number of trees to grow. To ensure that each observation is predicted a few times we have to select this number no too small. m = 500 is by default.

PPmethod

is the projection pursuit index to optimize in each classification tree. The options are LDA and PDA, linear discriminant and penalized linear discriminant. By default it is LDA.

size.p

proportion of variables randomly sampled in each split.

lambda

penalty parameter in PDA index and is between 0 to 1 . If lambda = 0, no penalty parameter is added and the PDA index is the same as LDA index. If lambda = 1 all variables are treated as uncorrelated. The default value is lambda = 0.1.

parallel

logical condition, if it is TRUE then parallelize the function

cores

number of cores used in the parallelization

rule

split rule 1: mean of two group means 2: weighted mean of two group means - weight with group size 3: weighted mean of two group means - weight with group sd 4: weighted mean of two group means - weight with group se 5: mean of two group medians 6: weighted mean of two group medians - weight with group size 7: weighted mean of two group median - weight with group IQR 8: weighted mean of two group median - weight with group IQR and size

Value

An object of class PPforest with components.

prediction.training

predicted values for training data set.

training.error

error of the training data set.

prediction.test

predicted values for the test data set if testap = TRUE(default).

error.test

error of the test data set if testap = TRUE(default).

oob.error.forest

out of bag error in the forest.

oob.error.tree

out of bag error for each tree in the forest.

boot.samp

information of bootrap samples.

output.trees

output from a trees_pp for each bootrap sample.

proximity

Proximity matrix, if two cases are classified in the same terminal node then the proximity matrix is increased by one in PPforest there are one terminal node per class.

votes

a matrix with one row for each input data point and one column for each class, giving the fraction of (OOB) votes from the PPforest.

n.tree

number of trees grown in PPforest.

n.var

number of predictor variables selected to use for spliting at each node.

type

classification.

confusion

confusion matrix of the prediction (based on OOB data).

call

the original call to PPforest.

train

is the training data based on size.tr sample proportion

test

is the test data based on 1-size.tr sample proportion

References

Natalia da Silva, Dianne Cook & Eun-Kyung Lee (2021) A Projection Pursuit Forest Algorithm for Supervised Classification, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2020.1870480

Examples

#crab example with all the observations used as training

pprf.crab <- PPforest(data = crab, class = 'Type',
 std = FALSE, size.tr = 1, m = 200, size.p = .5, 
 PPmethod = 'LDA' , parallel = TRUE, cores = 2, rule=1)
pprf.crab


Projection pursuit classification tree with random variable selection in each split

Description

Find tree structure using various projection pursuit indices of classification in each split.

Usage

PPtree_split(form, data, PPmethod='LDA', 
size.p=1,  lambda = 0.1,...)

Arguments

form

A character with the name of the class variable.

data

Data frame with the complete data set.

PPmethod

index to use for projection pursuit: 'LDA', 'PDA'

size.p

proportion of variables randomly sampled in each split, default is 1, returns a PPtree.

lambda

penalty parameter in PDA index and is between 0 to 1 . If lambda = 0, no penalty parameter is added and the PDA index is the same as LDA index. If lambda = 1 all variables are treated as uncorrelated. The default value is lambda = 0.1.

...

arguments to be passed to methods

Value

An object of class PPtreeclass with components

Tree.Struct

Tree structure of projection pursuit classification tree

projbest.node

1-dim optimal projections of each split node

splitCutoff.node

cutoff values of each split node

origclass

original class

origdata

original data

References

Lee, YD, Cook, D., Park JW, and Lee, EK (2013) PPtree: Projection pursuit classification tree, Electronic Journal of Statistics, 7:1369-1386.

Examples

#crab data set

Tree.crab <- PPtree_split('Type~.', data = crab, PPmethod = 'LDA', size.p = 0.5)
Tree.crab


For each bootstrap sample grow a projection pursuit tree (PPtree object).

Description

For each bootstrap sample grow a projection pursuit tree (PPtree object).

Usage

baggtree(
  data,
  class,
  m = 500,
  PPmethod = "LDA",
  lambda = 0.1,
  size.p = 1,
  parallel = FALSE,
  cores = 2
)

Arguments

data

Data frame with the complete data set.

class

A character with the name of the class variable.

m

is the number of bootstrap replicates, this corresponds with the number of trees to grow. To ensure that each observation is predicted a few times we have to select this number no too small. m = 500 is by default.

PPmethod

is the projection pursuit index to be optimized, options LDA or PDA, by default it is LDA.

lambda

a parameter for PDA index

size.p

proportion of random sample variables in each split.

parallel

logical condition, if it is TRUE then parallelize the function

cores

number of cores used in the parallelization

Value

data frame with trees_pp output for all the bootstraps samples.

Examples

#crab data set
crab.trees <- baggtree(data = crab, class = 'Type',
m =  200, PPmethod = 'LDA', lambda = .1, size.p = 0.5 , parallel = TRUE, cores = 2)
str(crab.trees, max.level = 1)


Astralian crabs

Description

Measurements on rock crabs of the genus Leptograpsus. The data set contains 200 observations from two species of crab (blue and orange), there are 50 specimens of each sex of each species, collected on site at Fremantle, Western Australia.

Usage

data(crab)

Format

A data frame with 200 rows and 6 variables

Source

Campbell, N. A. & Mahon, R. J. (1974), A Multivariate Study of Variation in Two Species of Rock Crab of genus Leptograpsus, Australian Journal of Zoology 22(3), 417 - 425.


Fish catch data set

Description

There are 159 fishes of 7 species are caught and measured. Altogether there are 7 variables. All the fishes are caught from the same lake(Laengelmavesi) near Tampere in Finland.

Usage

data(fishcatch)

Format

A data frame with 159 rows and 7 variables

Source

urlhttp://www.amstat.org/publications/jse/jse_data_archive.htm


Glass data set

Description

Contains measurements 214 observations of 6 types of glass; defined in terms of their oxide content.

Usage

data(glass)

Format

A data frame with 214 rows and 10 variables


The image data set

Description

contains 2310 observations of instances from 7 outdoor images

Usage

data(image)

Format

A data frame contains 2310 observations and 19 variables


Leukemia data set

Description

This dataset comes from a study of gene expression in two types of acute leukemias, acute lymphoblastic leukemia (ALL) and acute myeloid leukemia (AML). Gene expression levels were measured using Affymetrix high density oligonucleotide arrays containing 6817 human genes. A data set containing 72 observations from 3 leukemia types classes.

Usage

data(leukemia)

Format

A data frame with 72 rows and 41 variables

Source

Dudoit, S., Fridlyand, J. and Speed, T. P. (2002). Comparison of Discrimination Methods for the Classification of Tumors Using Gene Expression Data. Journal of the American statistical Association 97 77-87.


Lymphoma data set

Description

Gene expression in the three most prevalent adult lymphoid malignancies: B-cell chronic lymphocytic leukemia (B-CLL), follicular lymphoma (FL), and diffuse large B-cell lym- phoma (DLBCL). Gene expression levels were measured using a specialized cDNA microarray, the Lymphochip, containing genes that are preferentially expressed in lymphoid cells or that are of known immunologic or oncologic importance. This data set contain 80 observations from 3 lymphoma types.

Usage

data(lymphoma)

Format

A data frame with 80 rows and 51 variables

Source

Dudoit, S., Fridlyand, J. and Speed, T. P. (2002). Comparison of Discrimination Methods for the Classification of Tumors Using Gene Ex- pression Data. Journal of the American statistical Association 97 77-87.


Data structure with the projected and boundary by node and class.

Description

Data structure with the projected and boundary by node and class.

Usage

node_data(ppf, tr, Rule = 1)

Arguments

ppf

is a PPforest object

tr

numerical value to identify a tree

Rule

split rule 1:mean of two group means, 2:weighted mean, 3: mean of max(left group) and min(right group), 4: weighted mean of max(left group) and min(right group)

Value

Data frame with projected data for each class and node id and the boundaries

Examples

#crab data set with all the observations used as training

pprf.crab <- PPforest(data = crab, std =TRUE, class = 'Type',
 size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA')
node_data(ppf = pprf.crab, tr = 1) 


The olive data set

Description

contains 572 observations and 10 variables

Usage

data(olive)

Format

A data frame contains 573 observations and 10 variables


Parkinson data set

Description

A data set containing 195 observations from 2 parkinson types.

Usage

data(parkinson)

Format

A data frame with 195 rows and 23 variables

Source

urlhttps://archive.ics.uci.edu/ml/datasets/Parkinsons


Obtain the permuted importance variable measure

Description

Obtain the permuted importance variable measure

Usage

permute_importance(ppf)

Arguments

ppf

is a PPforest object

Value

A data frame with permuted importance measures, imp is the permuted importance measure defined in Brieman paper, imp2 is the permuted importance measure defined in randomForest package, the standard deviation (sd.im and sd.imp2) for each measure is computed and the also the standardized mesure.

Examples

pprf.crab <- PPforest(data = crab, class = 'Type',
std = TRUE, size.tr = 1, m = 100, size.p = .4, PPmethod = 'LDA', parallel = TRUE, core = 2)
permute_importance(ppf = pprf.crab) 


Global importance measure for a PPforest object as the average IMP PPtree measure over all the trees in the forest

Description

Global importance measure for a PPforest object as the average IMP PPtree measure over all the trees in the forest

Usage

ppf_avg_imp(ppf, class)

Arguments

ppf

is a PPforest object

class

A character with the name of the class variable.

Value

Data frame with the global importance measure

Examples

#crab data set with all the observations used as training

pprf.crab <- PPforest(data = crab, std =TRUE, class = 'Type',
 size.tr = 1, m = 100, size.p = .5, PPmethod = 'LDA')
 ppf_avg_imp(pprf.crab, 'Type') 
 

Global importance measure for a PPforest object

Description

Global importance measure for a PPforest object

Usage

ppf_global_imp(data, class, ppf)

Arguments

data

Data frame with the complete data set.

class

A character with the name of the class variable.

ppf

is a PPforest object

Value

Data frame with the global importance measure

Examples

#crab data set with all the observations used as training

pprf.crab <- PPforest(data = crab, std = TRUE, class = 'Type',
 size.tr = 1, m = 200, size.p = .5, PPmethod = 'LDA', parallel = TRUE, cores = 2)
 
ppf_global_imp(data = crab, class = 'Type', pprf.crab) 


Print PPforest object

Description

Print PPforest object

Usage

## S3 method for class 'PPforest'
print(x, ...)

Arguments

x

is a PPforest class object

...

additional parameter

Value

printed results for PPforest object


Data structure with the projected and boundary by node and class.

Description

Data structure with the projected and boundary by node and class.

Usage

ternary_str(ppf, id, sp, dx, dy)

Arguments

ppf

is a PPforest object

id

is a vector with the selected projection directions

sp

is the simplex dimensions, if k is the number of classes sp = k - 1

dx

first direction included in id

dy

second direction included in id

Value

Data frame needed to visualize a ternary plot

Examples

#crab data set with all the observations used as training
pprf.crab <- PPforest(data = crab, std =TRUE, class = "Type",
 size.tr = 1, m = 100, size.p = .5, PPmethod = 'LDA')
 require(dplyr)
pl_ter <- function(dat, dx, dy ){
  p1  <- dat[[1]] %>% dplyr::filter(pair %in% paste(dx, dy, sep = "-") ) %>%
    dplyr::select(Class, x, y) %>%
    ggplot2::ggplot(ggplot2::aes(x, y, color = Class)) +
    ggplot2::geom_segment(data = dat[[2]], ggplot2::aes(x = x1, xend = x2,
                                               y = y1, yend = y2), color = "black" ) +
    ggplot2::geom_point(size = I(3), alpha = .5) +
    ggplot2::labs(y = " ",  x = " ") +
    ggplot2::theme(legend.position = "none", aspect.ratio = 1) +
    ggplot2::scale_colour_brewer(type = "qual", palette = "Dark2") +
    ggplot2::labs(x = paste0("T", dx, " "), y = paste0("T", dy, " ")) +
    ggplot2::theme(aspect.ratio = 1)
  p1
}
#ternary plot in tree different selected dierections
 pl_ter(ternary_str(pprf.crab, id = c(1, 2, 3), sp = 3, dx = 1, dy = 2), 1, 2 )


Obtain predicted class for new data from baggtree function or PPforest

Description

Obtain predicted class for new data from baggtree function or PPforest

Usage

trees_pred(object, xnew, parallel = FALSE, cores = 2, rule = 1)

Arguments

object

Projection pursuit classification forest structure from PPforest or baggtree

xnew

data frame with explicative variables used to get new predicted values.

parallel

logical condition, if it is TRUE then parallelize the function

cores

number of cores used in the parallelization

rule

split rule 1: mean of two group means 2: weighted mean of two group means - weight with group size 3: weighted mean of two group means - weight with group sd 4: weighted mean of two group means - weight with group se 5: mean of two group medians 6: weighted mean of two group medians - weight with group size 7: weighted mean of two group median - weight with group IQR 8: weighted mean of two group median - weight with group IQR and size

Value

predicted values from PPforest or baggtree

Examples

## Not run: 
crab.trees <- baggtree(data = crab, class = 'Type', 
m =  200, PPmethod = 'LDA', lambda = .1, size.p = 0.4 )
 
pr <- trees_pred(  crab.trees,xnew = crab[, -1], parallel= FALSE, cores = 2)

pprf.crab <- PPforest(data = crab, class = 'Type',
 std = FALSE, size.tr = 2/3, m = 100, size.p = .4, PPmethod = 'LDA', parallel = TRUE )
 
trees_pred(pprf.crab, xnew = pprf.crab$test ,parallel = TRUE)

## End(Not run)

Wine data set

Description

A data set containing 178 observations from 3 wine grown cultivares in Italy.

Usage

data(wine)

Format

A data frame with 178 rows and 14 variables

Details