Conditional Inference Trees in R Programming - GeeksforGeeks (2024)

Last Updated : 10 Jul, 2020

Comments

Improve

Conditional Inference Trees is a non-parametric class of decision trees and is also known as unbiased recursive partitioning. It is a recursive partitioning approach for continuous and multivariate response variables in a conditional inference framework. To perform this approach in R Programming, ctree() function is used and requires partykit package. In this article, let’s learn about conditional inference trees, syntax, and its implementation with the help of examples.

Conditional Inference Trees

Conditional Inference Trees is a different kind of decision tree that uses recursive partitioning of dependent variables based on the value of correlations. It avoids biasing just like other algorithms of classification and regression in machine learning. Thus, avoiding vulnerability to the errors making it more flexible for the problems in the data. Conditional inference trees use a significance test which is a permutation test that selects covariate to split and recurse the variable. The p-value is calculated in this test. The significance test is executed at each start of the algorithm. This algorithm is not good for data with missing values for learning.
Algorithm:

  1. Test the global null hypothesis between random input and response variables and select the input variable with the highest p-value with response variable.
  2. Perform binary split on the selected input variable.
  3. Recursively perform step 1 and 2.

How Conditional Inference Trees differs from Decision Trees?

Conditional Inference Trees is a tree-based classification algorithm. It is similar to the decision trees as ctree() also performs recursively partitioning of data just like decision trees. The only procedure that makes conditional inference trees different from decision trees is that conditional inference trees use a significance test to select input variables rather than selecting the variable that maximizes the information measure. For example, the Gini coefficient is used in traditional decision trees to select the variable that maximizes the information measure.

Implementation in R

Syntax:
ctree(formula, data)

Parameters:
formula: represents formula on the basis of which model is to be fit
data: represents dataframe containing the variables in the model

Example 1:

In this example, let’s use the regression approach of Condition Inference trees on the air quality dataset which is present in the R base package. After the execution, different levels of ozone will be determined based on different environmental conditions. This helps in learning the different behavior of ozone value in different environmental conditions.

Step 1: Installing the required packages.

# Install the required

# Package for function

install.packages("partykit")

Step 2: Loading the required package.

# Load the library

library(partykit)

Step 3: Creating regression model of Condition inference tree.

Step 4: Print regression model.

# Print model

print(airConInfTree)

Output:

Model formula:Ozone ~ Solar.R + Wind + Temp + Month + DayFitted party:[1] root| [2] Temp <= 82| | [3] Wind 6.9| | | [5] Temp 77: 31.143 (n = 21, err = 4620.6)| [7] Temp > 82| | [8] Wind 10.3: 48.714 (n = 7, err = 1183.4)Number of inner nodes: 4Number of terminal nodes: 5

Step 4: Plotting the graph.

# Output to be present as PNG file

png(file = "conditionalRegression.png")

# Plotting graph

plot(airConInfTree)

# Save the file

dev.off()

Output:
Conditional Inference Trees in R Programming - GeeksforGeeks (1)

Explanation:
After executing, the above code produces a graph of conditional inference tree that shows the ozone value in the form of a box plot in each node in different environmental conditions. As in the above output image, Node 5 shows the minimum ozone value. Further, learning the behavior shows Temp6.9 shows the least ozone value in air quality.

Example 2:

In this example, let’s use the classification approach of Condition Inference trees on the iris dataset present in the R base package. After executing the code, different species of iris plants will be determined on the basis of petal length and width.

Step 1: Installing the required packages.

# Install the required

# Package for function

install.packages("partykit")

Step 2: Loading the required package.

# Load the library

library(partykit)

Step 3: Creating classification model of Condition inference tree

irisConInfTree <- ctree(Species ~ .,

data = iris)

Step 4: Print classification model

# Print model

print(irisConInfTree)

Output:

Model formula:Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.WidthFitted party:[1] root| [2] Petal.Length 1.9| | [4] Petal.Width <= 1.7| | | [5] Petal.Length 4.8: versicolor (n = 8, err = 50.0%)| | [7] Petal.Width > 1.7: virginica (n = 46, err = 2.2%)Number of inner nodes: 3Number of terminal nodes: 4

Step 4: Plotting the graph

# Output to be present as PNG file

png(file = "conditionalClassification.png",

width = 1200, height = 400)

# Plotting graph

plot(irisConInfTree)

# Save the file

dev.off()

Output:
Conditional Inference Trees in R Programming - GeeksforGeeks (2)
Explanation:
After executing the above code, species of iris plants are classified based on petal length and width. As in above graph, setosa species have petal length <= 1.9.



utkarsh_kumar

Improve

Next Article

Condition Handling in R Programming

Please Login to comment...

Conditional Inference Trees in R Programming - GeeksforGeeks (2024)
Top Articles
How to download and install Minecraft Maps Minecraft Blog
EaglerCraft and Education: Learning through Gaming
Www.mytotalrewards/Rtx
Frank Lloyd Wright, born 150 years ago, still fascinates
Ross Dress For Less Hiring Near Me
2024 Fantasy Baseball: Week 10 trade values chart and rest-of-season rankings for H2H and Rotisserie leagues
Steamy Afternoon With Handsome Fernando
Mail Healthcare Uiowa
Atrium Shift Select
No Credit Check Apartments In West Palm Beach Fl
Purple Crip Strain Leafly
Connexus Outage Map
อพาร์ทเมนต์ 2 ห้องนอนในเกาะโคเปนเฮเกน
Miss America Voy Forum
How Much Is Tj Maxx Starting Pay
Summoner Class Calamity Guide
Meritas Health Patient Portal
Dit is hoe de 130 nieuwe dubbele -deckers -treinen voor het land eruit zien
State HOF Adds 25 More Players
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Michigan cannot fire coach Sherrone Moore for cause for known NCAA violations in sign-stealing case
Costco Great Oaks Gas Price
Gopher Hockey Forum
Quadcitiesdaily
How to Download and Play Ultra Panda on PC ?
Aes Salt Lake City Showdown
Drift Hunters - Play Unblocked Game Online
Papa Johns Mear Me
Firefly Festival Logan Iowa
Marlene2995 Pagina Azul
Evil Dead Rise Ending Explained
Duke University Transcript Request
Miles City Montana Craigslist
Desales Field Hockey Schedule
Wisconsin Volleyball Team Leaked Uncovered
Landing Page Winn Dixie
Appleton Post Crescent Today's Obituaries
Kelsey Mcewen Photos
R&J Travel And Tours Calendar
Usf Football Wiki
Avance Primary Care Morrisville
Dr Adj Redist Cadv Prin Amex Charge
The Syracuse Journal-Democrat from Syracuse, Nebraska
Empires And Puzzles Dark Chest
Barber Gym Quantico Hours
Questions answered? Ducks say so in rivalry rout
The best specialist spirits store | Spirituosengalerie Stuttgart
Frigidaire Fdsh450Laf Installation Manual
A rough Sunday for some of the NFL's best teams in 2023 led to the three biggest upsets: Analysis
The Cutest Photos of Enrique Iglesias and Anna Kournikova with Their Three Kids
Heat Wave and Summer Temperature Data for Oklahoma City, Oklahoma
2487872771
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 6347

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.