Question



Error Received in Decision Tree

How can I resolve this recurring error?

(tree <- rpart(yTRAIN ~ ., BasetableTRAIN))
Error in model.frame.default(formula = yTRAIN ~ ., data = BasetableTRAIN, :
variable lengths differ (found for 'tickerSymbol')





Answers and follow-up questions





Answer or follow-up question 1

For the formula parameter, should I have listed yTRAIN, a factor variable of 0 and 1, or DV_Lead calculated a few weeks ago of the formula
you offered on the assignment page?


Answer or follow-up question 2

If the latter, I get a root and no splits as a result.


Answer or follow-up question 3

Dear student,

Please post:

str(yTRAIN)
str(BasetableTRAIN)

Michel Ballings


Answer or follow-up question 4

str(yTRAIN)
Factor w/ 2 levels "0","1": 1 2


str(BasetableTRAIN)
'data.frame': 116057 obs. of 9 variables:
$ tickerSymbol: chr "A" "AA" "ABB" "ABC" ...
$ Date : chr "01-Jan-2001" "01-Jan-2001" "01-Jan-2001" "01-Jan-2001" ...
$ Open : num 54.8 33.5 20.2 12.6 15.3 ...
$ High : num 54.8 33.5 20.2 12.6 15.3 ...
$ Low : num 54.8 33.5 20.2 12.6 15.3 ...
$ Close : num 54.8 33.5 20.2 12.6 15.3 ...
$ Volume : num 0 0 0 0 0 0 0 0 0 0 ...
$ DV : num 0 0 0 0 0 0 0 0 0 0 ...
$ DV_Lead : num 0 1 1 0 0 0 1 1 0 0 ...


Answer or follow-up question 5

I later changed the code to include only those variables that were numeric:
(tree <- rpart(yTRAIN ~ Open+High+Low+Close, BasetableTRAIN))
and
(tree <- rpart(DV_Lead ~ Open+High+Low+Close, BasetableTRAIN))

However, I received the same error



Answer or follow-up question 6

Dear Student,

The problem is that yTRIAN is only length 2, whereas BasetableTRAIN has length 116057.

Michel Ballings



Sign in to be able to add an answer or mark this question as resolved.