Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Conditional Inference Trees in R Programming
Next article icon

Conditional Inference Trees in R Programming

Last Updated : 10 Jul, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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. r
# Install the required  # Package for function install.packages("partykit") 
Step 2: Loading the required package. r
# Load the library library(partykit) 
Step 3: Creating regression model of Condition inference tree. r
air <- subset(airquality, !is.na(Ozone)) airConInfTree <- ctree(Ozone ~ .,                         data = air) 
Step 4: Print regression model. r
# Print model print(airConInfTree) 
Output:
  Model formula:  Ozone ~ Solar.R + Wind + Temp + Month + Day    Fitted 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:    4  Number of terminal nodes: 5  
Step 4: Plotting the graph. r
# Output to be present as PNG file png(file = "conditionalRegression.png")  # Plotting graph plot(airConInfTree)  # Save the file dev.off() 
Output: output-screen 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. r
# Install the required  # Package for function install.packages("partykit") 
Step 2: Loading the required package. r
# Load the library library(partykit) 
Step 3: Creating classification model of Condition inference tree r
irisConInfTree <- ctree(Species ~ .,                          data = iris) 
Step 4: Print classification model r
# Print model print(irisConInfTree) 
Output:
  Model formula:  Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width    Fitted 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:    3  Number of terminal nodes: 4  
Step 4: Plotting the graph r
# 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: output-screen 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.

Next Article
Conditional Inference Trees in R Programming

U

utkarsh_kumar
Improve
Article Tags :
  • R Language
  • R Machine-Learning

Similar Reads

    Condition Handling in R Programming
    Decision handling or Condition handling is an important point in any programming language. Most of the use cases result in either positive or negative results. Sometimes there is the possibility of condition checking of more than one possibility and it lies with n number of possibilities. In this ar
    5 min read
    Decision Tree in R Programming
    In this article, we’ll explore how to implement decision trees in R, covering key concepts, step-by-step examples, and tuning strategies.A decision tree is a flowchart-like model where each internal node represents a decision based on a feature, each branch represents an outcome of that decision, an
    3 min read
    Control Statements in R Programming
    Control statements are expressions used to control the execution and flow of the program based on the conditions provided in the statements. These structures are used to make a decision after assessing the variable. In this article, we'll discuss all the control statements with the examples. In R pr
    4 min read
    Decision Tree Classifiers in R Programming
    Classification is the task in which objects of several categories are categorized into their respective classes using the properties of classes. A classification model is typically used to, Predict the class label for a new unlabeled data objectProvide a descriptive model explaining what features ch
    4 min read
    How to Code in R programming?
    R is a powerful programming language and environment for statistical computing and graphics. Whether you're a data scientist, statistician, researcher, or enthusiast, learning R programming opens up a world of possibilities for data analysis, visualization, and modeling. This comprehensive guide aim
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences