Bug 16569 - rpart.residuals are +/- Inf
Summary: rpart.residuals are +/- Inf
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Add-ons (show other bugs)
Version: R 3.2.1
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-10-15 22:54 UTC by Sam Buttrey
Modified: 2015-10-15 22:54 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Buttrey 2015-10-15 22:54:11 UTC
Greetings. I want to compute Pearson residuals from an rpart model built using method=”poisson.” I'm using R 3.2.1 under Windows 7, 64-bit. 

Here I create some data, run the model, and tabulate the residuals.
require (rpart)
# Create data
> a <- data.frame (X = 1:20)
> set.seed (123); a$Y <- rpois (nrow (a), lambda = a$X)
# Build model, tabulate residuals
> table (residuals (rpart (cbind (1, Y) ~ X, method = "poisson", data = a), type = "pearson"))
-Inf  Inf 
  10   10 
# Unsurprisingly this is true using just Y as the response:
> table (residuals (rpart (Y ~ X, method = "poisson", data = a), type = "pearson"))
-Inf  Inf 
  10   10 
I think the problem is in residuals.rpart(), in the line 
temp <- ifelse(expect == 0, 1e-04, 0)
Should that not be 
temp <- ifelse(expect == 0, 1e-04, expect)?