Home > OS >  How to resolve Inf. $y values when using MASS::boxcox?
How to resolve Inf. $y values when using MASS::boxcox?

Time:10-23

I am getting Inf. output for $y when running a box cox transformation using the MASS package. Here is a sample of the code I am running:

sb2<- as.formula("yes~no insured sex2 racethx mnhlth53 rthlth53 age13x")

 meps_analytic2 %>%
   filter(as.logical(yes))%>%
   MASS::boxcox(sb2,lambda=seq(-1,1,len=5),plotit=FALSE,data=.)
$x
[1] -1.0 -0.5  0.0  0.5  1.0

$y
[1] Inf Inf Inf Inf Inf

> summary(meps_analytic2)
     age13x      racethx   mnhlth53 rthlth53 sex2          no           yes       
 19     :  579   1: 7792   1:9329   1:6252   0:13967   FALSE: 1875   FALSE:24304  
 26     :  559   2:10196   2:7354   2:8163   1:12212   TRUE :24304   TRUE : 1875  
 22     :  539   3: 5435   3:7187   3:7759                                        
 21     :  534   4: 2094   4:1887   4:3125                                        
 25     :  533   5:  662   5: 422   5: 880                                        
 29     :  533                                                                    
 (Other):22902                                                                    
 insured  
 0: 7264  
 1:18915 

I've tried running is.finite() and is.nan() for all variables that make up sb2, but no infinite values or NaNs are found. What would cause me to keep getting Inf responses for $y?? I have also tried changing class of variables to as.logical, as.numeric, etc.

CodePudding user response:

You've filtered your data set so that there is no variation in your response variable (they are all yes == TRUE, which will get coerced to a numeric value of 1.0);

dd <- data.frame(y=1, x = 1:10)
MASS::boxcox(y~x, data = dd, plotit = FALSE)

results:

$x
 [1] -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6
[16] -0.5 -0.4 -0.3 -0.2 -0.1  0.0  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9
[31]  1.0  1.1  1.2  1.3  1.4  1.5  1.6  1.7  1.8  1.9  2.0

$y
 [1] Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
[20] Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
[39] Inf Inf Inf
  • Related