forked from core-methods-in-edm/assignment5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 5.Rmd
More file actions
86 lines (61 loc) · 3.27 KB
/
Assignment 5.Rmd
File metadata and controls
86 lines (61 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: "Assignment 5 - Decision Trees"
author: "Charles Lang"
date: "November 9, 2018"
uni:"jd3603"
output: html_document
---
For this assignment we will be using data from the Assistments Intelligent Tutoring system. This system gives students hints based on how they perform on math problems.
#Install & call libraries
```{r}
install.packages("party", "rpart")
library(rpart)
library(party)
```
## Part I
```{r}
D1 <- read.table("intelligent_tutor.csv", sep = ",", header = TRUE)
```
##Classification Tree
First we will build a classification tree to predict which students ask a teacher for help, which start a new session, or which give up, based on whether or not the student completed a session (D1$complete) and whether or not they asked for hints (D1$hint.y).
```{r}
c.tree <- rpart(action ~ hint.y + complete, method="class", data=D1) #Notice the standard R notion for a formula X ~ Y
#Look at the error of this tree
printcp(c.tree)
#Plot the tree
post(c.tree, file = "tree.ps", title = "Session Completion Action: 1 - Ask teacher, 2 - Start new session, 3 - Give up")
```
## Part II
#Regression Tree
We want to see if we can build a decision tree to help teachers decide which students to follow up with, based on students' performance in Assistments. We will create three groups ("teacher should intervene", "teacher should monitor student progress" and "no action") based on students' previous use of the system and how many hints they use. To do this we will be building a decision tree using the "party" package. The party package builds decision trees based on a set of statistical stopping rules.
#Visualize our outcome variable "score"
```{r}
hist(D1$score)
```
#Create a categorical outcome variable based on student score to advise the teacher using an "ifelse" statement
```{r}
D1$advice <- ifelse(D1$score <=0.4, "intervene", ifelse(D1$score > 0.4 & D1$score <=0.8, "monitor", "no action"))
```
#Build a decision tree that predicts "advice" based on how many problems students have answered before, the percentage of those problems they got correct and how many hints they required
```{r}
score_ctree <- <- ctree(factor(advice) ~ prior_prob_count + prior_percent_correct + hints, D1)
```
#Plot tree
```{r}
plot(score_ctree)
```
Please interpret the tree, which two behaviors do you think the teacher should most closely pay attemtion to?
#Test Tree
Upload the data "intelligent_tutor_new.csv". This is a data set of a differnt sample of students doing the same problems in the same system. We can use the tree we built for the previous data set to try to predict the "advice" we should give the teacher about these new students.
```{r}
#Upload new data
D2 <- read.csv("intelligent_tutor_new.csv", header = TRUE)
#Generate predicted advice using the predict() command for new students based on tree generated from old students
D2$prediction <- predict(score_ctree, D2)
```
## Part III
Compare the predicted advice with the actual advice that these students recieved. What is the difference between the observed and predicted results?
### To Submit Your Assignment
Please submit your assignment by first "knitting" your RMarkdown document into an html file and then commit, push and pull request both the RMarkdown file and the html file.
mean(ifelse(D2$prediction == "no action", 1, 0))
```