Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
`glmRob()`在给定'newdata'参数时不进行预测_R_Glm_Robust - Fatal编程技术网

`glmRob()`在给定'newdata'参数时不进行预测

`glmRob()`在给定'newdata'参数时不进行预测,r,glm,robust,R,Glm,Robust,下面是glmRob()示例中的一些稍加修改的代码。当给定newdata参数时,predict.glmRob()会出错。我做错什么了吗 suppressMessages(library(robust)) data(breslow.dat) bres.rob <- glmRob(sumY ~ Age10 + Base4 * Trt, family = poisson(), data = breslow.dat) predict(bres.rob, newdata = breslow.dat)

下面是
glmRob()
示例中的一些稍加修改的代码。当给定
newdata
参数时,
predict.glmRob()
会出错。我做错什么了吗

suppressMessages(library(robust))
data(breslow.dat)
bres.rob <- glmRob(sumY ~ Age10 + Base4 * Trt, family = poisson(), data = breslow.dat)
predict(bres.rob, newdata = breslow.dat)
由(v0.3.0)于2020年12月14日创建

值得注意的是,与常规
glm()
完全相同的事情也适用

suppressMessages(库(健壮))
数据(breslow.dat)
bres.glm 1 2 3 4 5 6 7 8
#> 2.957756 2.933407 2.704879 3.015431 3.913226 3.250763 2.979112 4.101214 
#>        9       10       11       12       13       14       15       16 
#> 3.360129 2.863352 3.955120 3.257157 2.912460 3.741554 4.459110 3.668917 
#>       17       18       19       20       21       22       23       24 
#> 3.034205 5.093412 3.131601 2.906475 2.930414 2.671553 3.110244 3.174723 
#>       25       26       27       28       29       30       31       32 
#> 3.873096 3.134184 2.644211 3.507451 3.917288 3.375050 2.641300 2.675629 
#>       33       34       35       36       37       38       39       40 
#> 2.592602 2.854897 3.163672 2.890335 2.625822 3.756825 3.201280 2.557211 
#>       41       42       43       44       45       46       47       48 
#> 2.784067 2.988840 3.585320 3.060731 3.448097 2.484164 3.182476 2.577124 
#>       49       50       51       52       53       54       55       56 
#> 5.757692 3.003209 3.274328 3.308657 3.525533 3.268830 2.863768 2.857114 
#>       57       58       59 
#> 2.805090 2.891444 2.892553

由(v0.3.0)于2020-12-14创建,只需去掉
newdata
参数,因为您在相同的数据上运行它

从健壮的文档

newdata—可选的数据框,在其中查找用于预测的变量。如果省略,则使用拟合的线性预测值

编辑以添加

其中一位作者回复并建议使用“robustbase”(他是该软件包的维护者)而不是“robust”,因为前者使用的方法更为现代,并且有更广泛的测试和示例支持

下面是我的示例代码,用于对两者进行快速比较。注意,robustbase的glmrob中的“r”是小写的

library(robustbase)
library(robust)
data(breslow.dat)

## Comparison of methods.

bres.robustbase <- glmrob(sumY ~ Age10 + Base4 * Trt, family = poisson, data = breslow.dat)
predict(bres.robustbase, newdata = breslow.dat)

bres.robust <- glmRob(sumY ~ Age10 + Base4 * Trt, family = poisson(), data = breslow.dat)
predict(bres.robust)

## predict handling test data on robustbase's glmrob object.

lastIndex = round(nrow(breslow.dat)*0.7)
train = breslow.dat[1:lastIndex,]
test = breslow.dat[(lastIndex + 1):nrow(breslow.dat),]

bres.robustbase <- glmrob(sumY ~ Age10 + Base4 * Trt, family = poisson, data = train)
predict(bres.robustbase, newdata = test)
库(robustbase)
图书馆(稳健)
数据(breslow.dat)
##方法比较。

这很有趣,但实际上可能无法解决OP的问题。(我花了一点时间在S3方法分派等方面进行挖掘,但没有走多远…)是的,看起来下一个方法没有正确通过&也许
family(object)$inverse
应该是
family(object)$linkinv
。我认为应该向
维护人员(“robust”)
提出一个bug,以便澄清。我通常希望使用
newdata
参数来预测新数据。在这里,我只是将拟合数据传递到
newdata
中,以表明该模型甚至无法对其自身的数据进行预测(以澄清任何问题都与我传递的数据的格式无关)。@ecoundrums;谢谢你的跟进。关于系数,在我的电脑上,系数在
glmRob
下是不稳定的,也就是说,它们在不同的运行中变化很大,因此可以得到一些粗略的预测。@user20650我想使用robustbase的理由更多了;)
library(robustbase)
library(robust)
data(breslow.dat)

## Comparison of methods.

bres.robustbase <- glmrob(sumY ~ Age10 + Base4 * Trt, family = poisson, data = breslow.dat)
predict(bres.robustbase, newdata = breslow.dat)

bres.robust <- glmRob(sumY ~ Age10 + Base4 * Trt, family = poisson(), data = breslow.dat)
predict(bres.robust)

## predict handling test data on robustbase's glmrob object.

lastIndex = round(nrow(breslow.dat)*0.7)
train = breslow.dat[1:lastIndex,]
test = breslow.dat[(lastIndex + 1):nrow(breslow.dat),]

bres.robustbase <- glmrob(sumY ~ Age10 + Base4 * Trt, family = poisson, data = train)
predict(bres.robustbase, newdata = test)