首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对rms软件包中安装的ols模型使用校准功能时出错

对rms软件包中安装的ols模型使用校准功能时出错
EN

Stack Overflow用户
提问于 2018-05-05 10:47:28
回答 1查看 465关注 0票数 1

我正在尝试使用R中的rms package来评估线性模型的预测精度,但由于某些原因,我在生成校准图时遇到了困难。

具体地说,我在使用calibrate()时收到错误消息:"Error in !fail : invalid argument type"

下面是一个简单的可重现的例子来演示我的问题:

代码语言:javascript
运行
复制
> library(rms)
> library(MASS)
> data(whiteside)
> w.Before <- whiteside[whiteside$Insul=="Before",]
# For comparability with an example in MASS.
> dd <- datadist(w.Before)
> options(datadist="dd")

> mod1 <- ols(Gas ~ Temp,data=w.Before,
                         x=TRUE,y=TRUE)
> mod1
            Coef    S.E.   t      Pr(>|t|)
 Intercept  6.8538 0.1184  57.88 <0.0001 
 Temp      -0.3932 0.0196 -20.08 <0.0001

# ols() estimates the coefficients correctly

# Five-fold cross-validation for this model fit:
> validate(mod1,bw=FALSE,method="crossvalidation",B=5)
           index.orig training    test optimism index.corrected n
 R-square      0.9438   0.9431  0.8460   0.0971          0.8467 5
 MSE           0.0731   0.0709  0.0929  -0.0220          0.0951 5
 g             1.2791   1.2664  1.2222   0.0442          1.2349 5
 Intercept     0.0000   0.0000 -0.1661   0.1661         -0.1661 5
 Slope         1.0000   1.0000  1.0360  -0.0360          1.0360 5

# try using default argument options:
> calibrate(mod1)
Error in !fail : invalid argument type

# try using some arguments specific to the fitted ols object:
> calibrate(mod1,predy=median(w.Before$Gas),method="crossvalidation",B=5)
Error in !fail : invalid argument type

我已经做了一些初步的调试(见下文)--也许这能提供一些线索?

代码语言:javascript
运行
复制
mod1 <- ols(Gas ~ Temp,data=w.Before,
                         x=TRUE,y=TRUE)

# Switch on debug argument:
> calibrate(mod1, debug = TRUE)

Subscripts of training sample:
 [1]  3  9 15 22 21  4  7 22  8  5 11 10 25  4 10  5 18 23  6  1 19 10  9  6 22 25

Subscripts of test sample:
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

Error in !fail : invalid argument type
> traceback()
3: predab.resample(fit, method = method, fit = fitit, measure = cal.error, 
   pr = pr, B = B, bw = bw, rule = rule, type = type, sls = sls, 
   aics = aics, force = force, estimates = estimates, non.slopes.in.x = 
model == 
       "ol", smoother = smoother, predy = predy, model = model, 
   kint = kint, penalty.matrix = penalty.matrix, ...)
2: calibrate.default(mod1, debug = TRUE)
1: calibrate(mod1, debug = TRUE)

> options(error = recover)
> calibrate(mod1)
Error in !fail : invalid argument type

Enter a frame number, or 0 to exit   

1: calibrate(mod1)
2: calibrate.default(mod1)
3: predab.resample(fit, method = method, fit = fitit, measure = cal.error, pr = p

Selection: 3
Called from: calibrate.default(mod1)

# Entering object names in predab.resample function from last object in this function until I find an error / missing or suspect values:
Browse[1]> res                      
Error during wrapup: object 'res' not found

Browse[1]> varin                                                            
Error during wrapup: object 'varin' not found

Browse[1]> index.orig
 [1] -0.0146323 -0.0095743 -0.0052462 -0.0023136  0.0004922  0.0032980  0.0061038
 [8]  0.0081017  0.0111468  0.0147536  0.0183605  0.0219674  0.0255743  0.0291812
 [15]  0.0346582  0.0427575  0.0513092  0.0584638  0.0626379  0.0668120  0.0709861
 [22]  0.0751603  0.0793344  0.0832308  0.0830547  0.0828785  0.0827024  0.08 25263
 [29]  0.0823502  0.0821740  0.0819979  0.0818218  0.0816456  0.0814695  0.0812934
 [36]  0.0820341  0.0833151  0.0845299  0.0857447  0.0858007  0.0842924  0.0827842
 [43]  0.0801835  0.0750078  0.0698321  0.0646565  0.0591428  0.0513195  0.0434962
 [50]  0.0356728
attr(,"keepinfo")
attr(,"keepinfo")$orig.cal
 [1] 3.851 3.893 3.935 3.976 4.017 4.057 4.098 4.137 4.178 4.219 4.261 4.302 4.343
 [14] 4.385 4.428 4.474 4.520 4.565 4.607 4.649 4.691 4.732 4.774 4.816 4.854 4.891
 [27] 4.929 4.966 5.004 5.041 5.079 5.116 5.154 5.191 5.229 5.267 5.306 5.345 5.384
[40] 5.422 5.458 5.494 5.530 5.562 5.595 5.627 5.659 5.689 5.719 5.749

Browse[1]> optimism      
Error during wrapup: object 'optimism' not found

希望这能提供一些线索。有没有人可以帮我解决这个错误,最好是得到这个ols模型的校准图?

谢谢,提前说好。

罗斯。

EN

回答 1

Stack Overflow用户

发布于 2018-12-04 05:22:23

我也遇到了同样的错误,在浏览了一下Github之后,我发现这是一个已知的问题。

https://github.com/harrelfe/rms/issues/61

看起来早在四月份就有一个解决问题的承诺,但是更新的包还没有发布到CRAN上。

https://github.com/harrelfe/rms/commit/6bcaee45455c0e0c4ec163cd1ac325010f7648fa

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50185222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档