PrInDTCstruc | R Documentation |
The function PrInDTCstruc applies structured subsampling for finding an optimal subsample to model
the relationship between the two-class factor variable 'classname' and all other factor and numerical variables
in the data frame 'datain' by means of 'N' repetitions of subsampling from a substructure and 'Ni' repetitions of subsampling from the predictors.
The optimization citerion is the balanced accuracy on the validation sample 'valdat' (default is the full input sample 'datain').
Other criteria are possible (cf. parameter description of 'crit'). The trees generated from undersampling can be restricted by not accepting trees
including split results specified in the character strings of the vector 'ctestv'.
The substructure of the observations used for subsampling in modelling is specified by the list 'Struc' which consists of the factor variable 'name' representing the substructure,
the name 'check' of the factor variable with the information about the categories of the substructure, and the matrix 'labs' which specifies the values of 'check'
corresponding to two categories in its rows, i.e. in 'labs[1,]' and 'labs[2,]'. The names of the categories have to be specified by rownames(labs)
.
See parameter description of 'Struc' for its specification for 'vers="b"' and 'indrep > 0'.
The number of predictors 'Pit' to be included in the model and the number of elements of the substructure 'Eit' have to be specified (lists allowed), and
undersampling of the categories of 'classname' can be controlled by 'undersamp=TRUE/FALSE'.
In structured subsampling, 'N' repetitions of subsampling of the variable 'name' with 'Eit' different elements of each category in 'check' are realized. If 'Eit' is a list, each entry is employed individually. If 'Eit' is larger than the maximum available number of elements with a certain value of 'check', the maximum possible number of elements is used.
Four different versions of structured subsampling exist:
a) just of the elements in the substructure (possibly with additional undersampling) with parameters 'N' and 'Eit',
b) just of the predictors with parameters 'Ni' and 'Pit',
c) of the predictors and for each subset of predictors subsampling of the elements of the substructure (possibly with additional undersampling)
with parameters 'N', 'Ni', 'Eit', and 'Pit', and
d) of the elements of the substructure (possibly with additional undersampling) and for each of these subsets subsampling of the predictors
with the same parameters as version c).
Sampling of the elements of the substructure can be influenced by using weights of the elements ('weights=TRUE') according to the number of appearances of the smaller
class of 'classnames'. This way, elements with more realisations in the smaller class are preferred in modelling.
The parameters 'conf.level', 'minsplit', and 'minbucket' can be used to control the size of the trees.
The parameter 'indrep' indicates repeated measurement situations ('indrep > 0', only implemented for 'crit="ba"'); default = 0.
Repeated measurements are multiple measurements of the same variable taken on the same subjects (or objects) either under different conditions or over two or more time periods.
The variable with the repeatedly observed subjects (or objects) has to be specified by 'name' in 'Struc'. Only one value of 'classname' is allowed for each value of 'Struc$name'.
In case of 'indrep > 0' it is automatically assumed that the same number of
subjects (or objects) of the two classes under study have to be used for model building. Possible such numbers can be specified by 'Eit'.
For indrep=1, models are optimized for individual observations and the classes of the substructure elements are subsequently determined via the parameter 'thr'.
For indrep=2, models are optimized so that the criterion "ba" is maximal for the substructure elements taking 'thr' into account.
For indrep > 0 and 'valdat' unequal 'datain', the variable 'repvar' defines the substructure for 'valdat', length = dim(valdat)[1] necessary; default = NA'
PrInDTCstruc(datain,classname,ctestv=NA,Struc=NA,vers="d",weight=FALSE,
Eit=NA,Pit=NA,N=99,Ni=99,undersamp=TRUE,crit="ba",ktest=0,
stest=integer(length=0),conf.level=0.95,indrep=0,
minsplit=NA,minbucket=NA,repvar=NA,valdat=datain,thr=0.5)
datain |
Input data frame with class factor variable 'classname' and the |
classname |
Name of class variable (character) |
ctestv |
Vector of character strings of forbidden split results; |
Struc |
= list(name,check,labs), cf. description for explanations; Struc not needed for vers="b"; for indrep=1, Struc = list(name); |
vers |
Version of structured subsampling: "a", "b", "c", "d", cf. description; |
weight |
Weights to be used for subsampling of elements of substructure (logical, TRUE or FALSE); default = FALSE |
Eit |
List of number of elements of substructure (integers); |
Pit |
List of number of predictors (integers) |
N |
Number of repetitions of subsampling from substructure (integer) |
Ni |
Number of repetitions of subsampling from predictors |
undersamp |
Undersampling of categories of 'classname' to be used ((logical, TRUE or FALSE) |
crit |
Optimisation criterion: "ba" for balanced accuracy, "bat" for balanced accuracy on test sets, "ta" for test accuracy,
"tal" for test accuracy of continuing parts of length 'ktest' in substructure elements 'stest'; |
ktest |
Length of continuing parts to be tested (for crit="tal"); |
stest |
Part of substructure to be tested (for crit="tal")(integer vector); |
conf.level |
(1 - significance level) in function |
indrep |
Indicator for repeated measurements, i.e. more than one observation with the same class for each element; |
minsplit |
Minimum number of elements in a node to be splitted; |
minbucket |
Minimum number of elements in a node; |
repvar |
Values of variable defining the substructure corresponding to valdat in the case of repeated measurements, length = dim(valdat)[1] necessary; default = NA |
valdat |
validation data; default = datain |
thr |
threshold for element classfication: minimum percentage of correct class entries; default = 0.5 |
See Buschfeld & Weihs (2025), Optimizing decision trees for the analysis of World Englishes and sociolinguistic data. Cambridge University Press, section 4.5.1, for further information.
Standard output can be produced by means of print(name$besttree)
or just name$besttree
as well as plot(name$besttree)
where 'name' is the output data
frame of the function.
Best tree
Number of interpretable trees, overall number of trees
Number of predictors in training set for best tree
Size of training set for best tree
Accuracy of best tree on large class
Accuracy of best tree on small class
Balanced accuracy of best tree
Test accuracy of best tree
Number of elements with misclassified parts longer than 'ktest' for best tree
Elements with long misclassified parts for best tree
Indices of long misclassified parts for best tree
Elements of 1st category of substructure used by best tree
Elements of 2nd category of substructure used by best tree
Predictors used by best tree
Training set for best tree
Test set for best tree
labs from Struc
Label of large class
Label of small class
Version used for structured subsampling
Accuracy of large class on Elements of best tree
Accuracy of small class on Elements of best tree
Balanced accuracy of best tree on Elements
Names of misclassified Elements of large class
Names of misclassified Elements of small class
Threshold for element classification
data <- PrInDT::data_zero
data <- na.omit(data) # cleaned full data: no NAs
# interpretation restrictions (split exclusions)
ctestv <- rbind('ETH == {C2a, C1a}','MLU == {1, 3}') # split exclusions
# substructure
name <- PrInDT::participant_zero
check <- "data$ETH"
labs <- matrix(1:6,nrow=2,ncol=3)
labs[1,] <- c("C1a","C1b","C1c")
labs[2,] <- c("C2a","C2b","C2c")
rownames(labs) <- c("Children 1","Children 2")
Struc <- list(name=name,check=check,labs=labs)
out <- PrInDTCstruc(data,"real",ctestv,Struc,vers="c",weight=TRUE,N=5,Pit=5,conf.level=0.99)
out
plot(out)
# indrep = 1
Struc <- list(name=name)
out <- PrInDTCstruc(data,"real",Struc=Struc,vers="c",Pit=5,Eit=5,N=5,crit="ba",indrep=1,
conf.level=0.99)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.