rpart icon indicating copy to clipboard operation
rpart copied to clipboard

Why do "printcp"and "plotcp" disagree?

Open A-Pai opened this issue 3 years ago • 8 comments

library(modeldata) data(credit_data) fit <- rpart(Status~.,data = credit_data) printcp(fit) plotcp(fit)

Why do "printcp"and "plotcp" disagree? image

image

A-Pai avatar Oct 05 '21 03:10 A-Pai

The plot and the values of xerror in the table look like they agree to me - what doesn't look right to you?


From: lg21c @.> Sent: Monday, October 4, 2021 10:30 PM To: bethatkinson/rpart @.> Cc: Subscribed @.***> Subject: [EXTERNAL] [bethatkinson/rpart] Why do "printcp"and "plotcp" disagree? (#32)

library(modeldata) data(credit_data) fit <- rpart(Status~.,data = credit_data) printcp(fit) plotcp(fit)

Why do they disagree? [image]https://user-images.githubusercontent.com/5112397/135955177-dbe581c1-3344-4808-9f4e-bfe02cfac880.png [image]https://user-images.githubusercontent.com/5112397/135955274-ea70918b-819a-42f4-991c-097a2d6aabdf.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/bethatkinson/rpart/issues/32, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWQG53GSBHYV4LV7D32FPLUFJWPDANCNFSM5FKYTFFQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bethatkinson avatar Oct 05 '21 12:10 bethatkinson

My point is the cp value in the plotcp does not agree with that of printcp

The plot and the values of xerror in the table look like they agree to me - what doesn't look right to you? ________________________________ From: lg21c @.> Sent: Monday, October 4, 2021 10:30 PM To: bethatkinson/rpart @.> Cc: Subscribed @.***> Subject: [EXTERNAL] [bethatkinson/rpart] Why do "printcp"and "plotcp" disagree? (#32) library(modeldata) data(credit_data) fit <- rpart(Status~.,data = credit_data) printcp(fit) plotcp(fit) Why do they disagree? [image]https://user-images.githubusercontent.com/5112397/135955177-dbe581c1-3344-4808-9f4e-bfe02cfac880.png [image]https://user-images.githubusercontent.com/5112397/135955274-ea70918b-819a-42f4-991c-097a2d6aabdf.png — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub<#32>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWQG53GSBHYV4LV7D32FPLUFJWPDANCNFSM5FKYTFFQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

My point is the cp value in the plotcp does not agree with that of printcp

A-Pai avatar Oct 05 '21 13:10 A-Pai

Looks to be a point between - which is also accurate. Any CP value between the 2 will work. Found this line in the code (function contributed by Brian Ripley).

cp <- sqrt(cp0 * c(Inf, cp0[-length(cp0)]))


From: lg21c @.> Sent: Tuesday, October 5, 2021 8:01 AM To: bethatkinson/rpart @.> Cc: Atkinson, Elizabeth J. (Beth), M.S. @.>; Comment @.> Subject: [EXTERNAL] Re: [bethatkinson/rpart] Why do "printcp"and "plotcp" disagree? (#32)

My point is the cp value in the plotcp does not agree with that of printcp

The plot and the values of xerror in the table look like they agree to me - what doesn't look right to you? … ________________________________ From: lg21c @.> Sent: Monday, October 4, 2021 10:30 PM To: bethatkinson/rpart @.> Cc: Subscribed @.***> Subject: [EXTERNAL] [bethatkinson/rpart] Why do "printcp"and "plotcp" disagree? (#32https://github.com/bethatkinson/rpart/issues/32) library(modeldata) data(credit_data) fit <- rpart(Status~.,data = credit_data) printcp(fit) plotcp(fit) Why do they disagree? [image]https://user-images.githubusercontent.com/5112397/135955177-dbe581c1-3344-4808-9f4e-bfe02cfac880.png [image]https://user-images.githubusercontent.com/5112397/135955274-ea70918b-819a-42f4-991c-097a2d6aabdf.png — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub<#32https://github.com/bethatkinson/rpart/issues/32>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWQG53GSBHYV4LV7D32FPLUFJWPDANCNFSM5FKYTFFQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

My point is the cp value in the plotcp does not agree with that of printcp

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bethatkinson/rpart/issues/32#issuecomment-934390170, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWQG564GPR3NO4EFNTCB5LUFLZJRANCNFSM5FKYTFFQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bethatkinson avatar Oct 05 '21 13:10 bethatkinson

Any CP value between the 2 will work

---yes,but where does the cp value in the plotcp come from?0.066,0.037,0.015,0.011

A-Pai avatar Oct 05 '21 14:10 A-Pai

see the code that I sent


From: lg21c @.> Sent: Tuesday, October 5, 2021 9:13 AM To: bethatkinson/rpart @.> Cc: Atkinson, Elizabeth J. (Beth), M.S. @.>; Comment @.> Subject: [EXTERNAL] Re: [bethatkinson/rpart] Why do "printcp"and "plotcp" disagree? (#32)

Any CP value between the 2 will work

---yes,but where does the cp value in the plotcp come from?0.066,0.037,0.015,0.011

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bethatkinson/rpart/issues/32#issuecomment-934452144, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWQG5YOP5LKASFAKKEB3OTUFMBXJANCNFSM5FKYTFFQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bethatkinson avatar Oct 05 '21 14:10 bethatkinson

@A-Pai If you take a look at the rpart/R/plotcp.R file in this repo, you'll see on line 17 that the CP values are monotonically transformed using the sqrt after multiplying by the first CP value (cp0):

cp <- sqrt(cp0 * c(Inf, cp0[-length(cp0)]))

You can verify the first couple of x-axis values, for example:

> sqrt(0.064593 * 0.067783)  # sqrt(CP1 * CP0)
[1] 0.06616878
> sqrt(0.020999 * 0.067783)  # sqrt(CP2 * CP0)
[1] 0.03772765

Not sure of the exact reason (perhaps for plotting purposes), but maybe a small note could be added to the plotcp() docs to clarify.

bgreenwell avatar Oct 06 '21 02:10 bgreenwell

yep - good point.


From: Brandon Greenwell @.> Sent: Tuesday, October 5, 2021 9:32 PM To: bethatkinson/rpart @.> Cc: Atkinson, Elizabeth J. (Beth), M.S. @.>; Comment @.> Subject: [EXTERNAL] Re: [bethatkinson/rpart] Why do "printcp"and "plotcp" disagree? (#32)

If you take a look at the rpart/R/plotcp.Rhttps://github.com/bethatkinson/rpart/blob/master/R/plotcp.R file in this repo, you'll see on line 17 that the CP values are monotonically transformed using the sqrt after multiplying by the first CP value:

cp <- sqrt(cp0 * c(Inf, cp0[-length(cp0)]))

Not sure of the exact reason (maybe for plotting purposes), but maybe a small note could be added to the plotcp() docs to clarify.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bethatkinson/rpart/issues/32#issuecomment-935288193, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWQG54RABSAGWJ6P4QZ6MTUFOYKTANCNFSM5FKYTFFQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bethatkinson avatar Oct 22 '21 19:10 bethatkinson

I got it,thank you

A-Pai avatar Oct 23 '21 00:10 A-Pai