+ Reply to Thread
Results 1 to 4 of 4

Thread: Contrast drop off from factor x in using predict in decision tree in R

  1. #1
    Points: 2,328, Level: 29
    Level completed: 19%, Points required for next Level: 122

    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Contrast drop off from factor x in using predict in decision tree in R




    Hi,
    I have tried research about this error warning message for several days without any info, e.g. ": contrasts dropped from factor staffx.f" etc..
    as I tried to use newly decision tree model with the predict function on test data within the rpaprt package.


    Here are the scripts that I used to create decision tree model :

    db$staff.f<- as.factor(db$staff)
    ...create same for other categorical variables.

    contrasts(db$staff.f) = contr.treatment(8) .... create same for other categorical variables.

    tree<-rpart(L2 ~ .,method = "class", data = Train )

    cpok<-db$cptable[which.min(db$cptable[,"xerror"]),"CP"]

    tree.pruned<-prune(db,cp=bestcp)

    pred1 <- predict(tree,Testdata,type="class")

    Is there certain parts of the scripts that needs to amend? as it is strange to me that the contrast is drop off even though it is used to create dummy variables and also factor has been created to recognize the certain variables. Much grateful for all advice.

    Thank you!

  2. #2
    Omega Contributor
    Points: 39,045, Level: 100
    Level completed: 0%, Points required for next Level: 0
    hlsmith's Avatar
    Location
    Not Ames, IA
    Posts
    7,070
    Thanks
    402
    Thanked 1,192 Times in 1,153 Posts

    Re: Contrast drop off from factor x in using predict in decision tree in R

    I am not overly familiar with rpart, only used it a couple of times. Question, does all of code work up until predict?

    What does contrast do, set a reference level?
    Stop cowardice, ban guns!

  3. #3
    Points: 2,328, Level: 29
    Level completed: 19%, Points required for next Level: 122

    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Contrast drop off from factor x in using predict in decision tree in R

    It is suppose to create dummy variables.

  4. #4
    TS Contributor
    Points: 12,501, Level: 73
    Level completed: 13%, Points required for next Level: 349
    rogojel's Avatar
    Location
    I work in Europe, live in Hungary
    Posts
    1,491
    Thanks
    162
    Thanked 334 Times in 314 Posts

    Re: Contrast drop off from factor x in using predict in decision tree in R


    hi,
    my guess would be that this has to do with the pruning. Maybe the contrasts are not defined in the pruned tree anymore?

    regards

+ Reply to Thread

           




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats