带 bo​​xcox 的线性模型,用于带零的数据框。无法预测所需值

Linear model with boxcox for data frame with zeros. Unable to predict for required values

我正在尝试使用 boxcox 来规范化我拥有的数据。但是我生成了一个无法在我想要的条件下进行预测的模型。为什么会这样?

我有一个数据框:

    a<-data.frame(Output=c(0.065,8.00,2.320,0.128,42.500,35.200,18.200,2.94,1.68,13.90,43.50,3.810,2.600),
                  Carbon=c(20.0,22.5,10.0,7.0,35.0,20.,35.0,2.0,10.0,25.0,30.0,10.0,8.0),               
                  Cooling=c(0.0,50.0,12.0,0.0,12.70,12.70,5.0,2.0,0.00,0.00,12.70,10.00,14.69),
                  Drying=c(0.0,70.00,0.00,0.00,0.90,0.90,0.90,55.80,0.00,0.00,0.90,15.00,35.56))

使用以下库:

library(MASS)

我运行以下代码:

bc<-boxcox(a$Output~a$Cooling*a$Drying+a$Carbon)
lambda<-bc$x[which.max(bc$y)]
new.model<-lm(((a$Output^lambda-1)/lambda)~a$Drying*a$Cooling+a$Carbon)

数据集中有零,想要对它们进行 t运行 变形,以便我得到正态性。有了这个,我想建立一个预测模型并测试以下条件的“输出”: 碳=2,冷却=10,干燥=20

但是,我的输出中总是出现 NaN。是我做错了 t运行 还是模型有缺陷?

我认为你不应该像以前那样使用 $,因为如果你那样使用,系数的创建就像 a$some_variable,而预测变量的名称却是 some_variable不是 a$some_variable 在您给定的测试记录中,您可以尝试以下方法。如果它解决了您的问题,请告诉我。

bc<-boxcox(Output~ Cooling* Drying + Carbon, data=a)
lambda<-bc$x[which.max(bc$y)]
a$lambda <- lambda
new.model<-lm(((Output^lambda-1)/lambda)~Drying* Cooling+ Carbon, data=a)

predict(new.model, data.frame(Carbon=2, Cooling=10, Drying=10, lambda = lambda))

输出:

           1 
0.1812739866 

看看当你对 lms 使用 $ 方法时会发生什么:

                       Estimate   Std. Error  t value  Pr(>|t|)   
(Intercept)        -3.141173410  1.342601277 -2.33962 0.0474440 * 
a$Drying            0.060882585  0.039681152  1.53429 0.1635024   
a$Cooling           0.275926915  0.102135431  2.70158 0.0270079 * 
a$Carbon            0.219900733  0.059038120  3.72472 0.0058317 **
a$Drying:a$Cooling -0.004854491  0.001593430 -3.04657 0.0159038 * 

但是如果没有 $,这看起来像:

Coefficients:
                   Estimate   Std. Error  t value  Pr(>|t|)   
(Intercept)    -3.141173410  1.342601277 -2.33962 0.0474440 * 
Drying          0.060882585  0.039681152  1.53429 0.1635024   
Cooling         0.275926915  0.102135431  2.70158 0.0270079 * 
Carbon          0.219900733  0.059038120  3.72472 0.0058317 **
Drying:Cooling -0.004854491  0.001593430 -3.04657 0.0159038 *