Learn R Programming

PrInDT (version 2.0.1)

SimRPrInDT: Interdependent estimation for regression

Description

The function SimRPrInDT applies structured subsampling for finding an optimal subsample to model the relationship between the continuous variables with indices 'inddep' and all other factor and numerical variables in the data frame 'datain'.
The substructure of the observations used for subsampling is specified by the list 'Struc' which consists of the variable 'name' representing the substructure, the name 'check' of the 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).
In structured subsampling first 'M' repetitions of subsampling of the variable 'name' with 'nsub' different elements of the substructure are realized. If 'nsub' is a list, each entry is employed individually. Then, for each of the subsamples 'N' repetitions of subsampling of 'ppre' percentages of the predictors are carried out.
Subsampling of observations can additionally be restricted to 'pobs' percentages.
The optimization citerion is the goodness of fit R2 on the full sample. At stage 2, the models are optimized individually. At stage 3, the mean of accuracies is optimized over all models.
Struc=NA causes random subsampling of observations instead of structured subsampling.
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 parameters 'conf.level', 'minsplit', and 'minbucket' can be used to control the size of the trees.

Usage

SimRPrInDT(data,ctestv=NA,Struc=NA,inddep,N=99,pobs=0.9,ppre=c(0.9,0.7),
                M=1,nsub=1,conf.level=0.95,minsplit=NA,minbucket=NA)

Value

modelsF

Best trees at stage 1

modelsI

Best trees for the different values of 'nsub' at stage 2

modelsJ

Best trees for the different values of 'nsub' after mean optimization

Struc

Used structure

msub

Best numbers of elements in substructure: 2nd stage, 3rd stage

depnames

names of dependent variables

R2All

R2s of best trees at stages 1, 2, mean max.

Arguments

data

Input data frame with continuous target variables with column indices 'inddep' and the
influential variables, which need to be factors or numericals (transform logicals and character variables to factors)

ctestv

Vector of character strings of forbidden split results;
Example: ctestv <- rbind('variable1 == {value1, value2}','variable2 <= value3'), where character strings specified in 'value1', 'value2' are not allowed as results of a splitting operation in variable 1 in a tree.
For restrictions of the type 'variable <= xxx', all split results in a tree are excluded with 'variable <= yyy' and yyy <= xxx.
Trees with split results specified in 'ctestv' are not accepted during optimization.
A concrete example is: 'ctestv <- rbind('ETH == {C2a, C1a}','AGE <= 20')' for variables 'ETH' and 'AGE' and values 'C2a','C1a', and '20';
If no restrictions exist, the default = NA is used.

Struc

= list(name,check,labs), cf. description for explanations

inddep

Column indices of target variables in datain

N

Number of repetitions of subsampling (integer) of predictors; default = 99

pobs

Percentage(s) of observations for subsampling; default=0.9

ppre

Percentage(s) of predictors for subsampling; default=c(0.9,0.7)

M

Number of repetitions of subsampling of elements of substructure

nsub

(List of) numbers of different elements of substructure per subsample

conf.level

(1 - significance level) in function ctree (numerical, > 0 and <= 1);
default = 0.95

minsplit

Minimum number of elements in a node to be splitted;
default = 20

minbucket

Minimum number of elements in a node;
default = 7

Details

See Buschfeld & Weihs (2025), Optimizing decision trees for the analysis of World Englishes and sociolinguistic data. Cambridge University Press, section 4.5.6.2, for further information.

Standard output can be produced by means of print(name) or just name as well as plot(name where 'name' is the output data frame of the function.

Examples

Run this code
data <- PrInDT::data_vowel
data <- na.omit(data)
CHILDvowel <- data$Nickname
data$Nickname <- NULL
syllable <- 3 - data$syllables
data$syllabels <- NULL
data$syllables <- syllable
data$speed <- data$word_duration / data$syllables
names(data)[names(data) == "target"] <- "vowel_length"
# interpretation restrictions (split exclusions)
ctestv <- rbind('ETH == {C2a, C1a}','MLU == {1, 3}') # split exclusions
# structure definition
name <- CHILDvowel
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)
# column indices of dependent variables
inddep <- c(13,9) 
outSimR <- SimRPrInDT(data,ctestv=ctestv,Struc=Struc,inddep=inddep,N=3,M=2,
                   nsub=c(19,20),conf.level=0.99)
outSimR
plot(outSimR)

Run the code above in your browser using DataLab