I have a decision tree stored as follows(using data.tree)(in R) :
Sex
¦--Male
¦ °--Class
¦ ¦--3rd
¦ ¦ °--Age
¦ ¦ ¦--Child
¦ ¦ ¦ °--No
¦ ¦ °--Adult
¦ ¦ °--No
¦ ¦--1st
¦ ¦ °--Age
¦ ¦ ¦--Adult
¦ ¦ ¦ °--No
¦ ¦ °--Child
¦ ¦ °--Yes
¦ ¦--2nd
¦ ¦ °--Age
¦ ¦ ¦--Adult
¦ ¦ ¦ °--No
¦ ¦ °--Child
¦ ¦ °--Yes
¦ °--Crew
¦ °--Age
¦ °--Adult
¦ °--No
°--Female
°--Class
¦--3rd
¦ °--Age
¦ ¦--Child
¦ ¦ °--No
¦ °--Adult
¦ °--No
¦--1st
¦ °--Age
¦ ¦--Adult
¦ ¦ °--Yes
¦ °--Child
¦ °--Yes
¦--2nd
¦ °--Age
¦ ¦--Adult
¦ ¦ °--Yes
¦ °--Child
¦ °--Yes
°--Crew
°--Age
°--Adult
°--Yes
This tree is stored in a variable : root
I want to prune the tree(calculate the chi-square values for all nodes with level = 6 and if their chi-square values are less than a threshold(example 6), then delete that node from the tree).
Any help would be much appreciated.
EDIT:
I'm using the following dataset :
"","Class","Sex","Age","Survived"
"1","1st","Male","Child","No"
"2","2nd","Male","Child","No"
"3","3rd","Male","Child","No"
.
.
.
Using This, I use ID3 algorithm to create a decision tree. Now, I wanted to prune it.