错误没有被抛出错误 [英] Error without an error being thrown

查看:219
本文介绍了错误没有被抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试多次估算一些数据,而且它的失败是非常奇怪的。我有选项(error = recover)设置,并且mi()不会引发错误,但是在第一次尝试之后它会停止插补。它也不返回值。因此我不知道从哪里开始调试。

 >图书馆(mi)
>温度< - mi(dat)
开始多重插补(Wed Dec 14 10:44:44 2011):
迭代1
链1:HLTHA5.fac * BMI *收入*
> temp
错误:对象'temp'未找到


dat< --structure(list(treat = c(FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,
FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE,
FALSE,TRUE,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE),NUMADULT = c ,
1,2,1,2,1,2,1,2,4,1,2,2,1,2,1,1,2,1,2,2,
3,3,1),HLTHA5.fac =结构(c(3L,NA,3L,2L,4L,5L,5L,
4L,4L,3L,3L,5L,3L,4L,5L, 4L,2L,2L,3L,5L,4L,5L,4L,
3L,3L),.Label = c(0,1,2,3 ,class =factor),
SOURCEA = structure(c(1L,2L,1L,1L,1L,1L,1L,1L,1L,
2L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L),.Label = c(是,否,不知道,拒绝 ),class =factor),
BMI = c(27.363941459046,24.0265857515842,34.3236939308346,
27.0907152026518,32.6101901381975,34.1643655360753,21.4628674188624,
29.1751398412094,22.5924920198551,39.6719545438 681,38.5220574557939,
20.1156133421915,30.6612391698034,35.7332536282609,26.5664872147956,
25.6016897082437,19.3649931598758,28.1868713091175,NA,
32.4438116170843,32.5507197719099,21.1090717674633,32.2340044872853,
24.3699149340904,27.3369153440247),SMOKE2 =结构(c(2L,
1L,2L,2L,2L,2L,2L,1L,2L,2L,2L,2L,2L,2L,2L,2L,
1L,2L,2L ,2L,1L,2L,2L,2L,1L),.Label = c(是,否
),class =factor),INCOME =结构(c(16L,4L,13L ,
11L,13L,7L,22L,6L,NA,1L,13L,18L,12L,20L,NA,NA,
2L,13L,17L,NA,12L,21L,9L,15L ,13L),.Label = c(少于$ 10,800,
$ 10,800- $ 14,600,$ 14,601- $ 16,250,$ 162,51- $ 18,300,
$ 18,301- $ 21,800,$ 21,801- $ 25,000,$ 25,001- $ 27,500,
$ 27,501- $ 29,300,$ 29,301- $ 33,100,$ 33,101- $ 36,700,
$ 36,701- $ 38,700,$ 38,701 $ 44,500 $ 50,000,
$ 50,001- $ 58,000,$ 58,001- $ 66,500 $ 66,501- $ 73,500,
$ 73,501- $ 80,000,$ 80,001-88,200,$ 88,201- $ 100,000,
$ 100,001- $ 120,000,$ 120,001- $ 130,000,$ 130,001- $ 150,000
$ 150,001- $ 250,000,超过$ 250,000,不知道,拒绝
),class =factor),RESPMAR =结构(c(1L,5L, 1L,4L,
3L,6L,1L,1L,1L,1L,4L,4L,1L,1L,4L,1L,3L,3L,1L,
3L,1L,1L,1L, 1L,1L),.Label = c(已婚,生活伴侣,
寡妇,离婚,分居,单身,其他,不知道 ,
Refused),class =factor),RESPGRAD =结构(c(5L,
1L,2L,5L,3L,3L,5L,2L,4L,2L,4L,3L ,4L,4L,2L,3L,
2L,5L,2L,4L,4L,5L,2L,2L,3L),标号= c( HS 0-11,
HS毕业生,一些colge 13-15,Collge grad 16,Post college 16+,
不知道,拒绝 ),RACEA2 =结构(c(1L,
1L,1L,2L,2L,2L,1L,1L,1L,1L,2L,1L,1L,1L,2L,1L ,
3L,1L,1L,1L,2L,1L,1L,1L,1L),.Label = c(White(Not-Latino),
Black(Not-Latino) ,拉丁(总),亚洲,比利时/多,
美洲原住民,其他,不知道,拒绝),class =factor
INSUREDA =结构(c(1L,2L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,2L,1L,
1L),.Label = c(被保险人,未投保,不知道,拒绝
) =factor),PAP.adj = c(TRUE,FALSE,FALSE,FALSE,
FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,TRUE,
TRUE, TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,
TRUE,TRUE)),.Names = c(treat,NUMADULT,HLTHA5.fac,
SOURCEA ,BMI,SMOKE2,收益,RESPAR,RESPGRAD,
RACEA2,INSUREDA,PAP.adj),row.names = c(1L,13L, 15L,
23L,26L,33L,38L,53L,56L,60L,62L,85L,109L,116L,138L,
217L,240L,262L,264L,269L,277L,295L,328L, 334L,338L),class =data.frame)

关于从哪里开始的任何想法?



更新



感谢下面的诊断技术,我追踪了错误,我在这里总结,因为它似乎我不是唯一有这个问题。



当你有一个无序的分类变量,级别没有价值观。 mi.default调用.initializeConvCheckArray以NAs填充AveVar。该功能使用这些级别,无论是否使用这些级别。相比之下,为了填补AveVar,它调用了.getmean,它会丢弃未使用的级别。因此,尺寸不匹配。



用户端的简单解决方案当然是在调用mi.info和mi之前删除额外的级别。我打算向软件包作者提交一个错误修复,但是已经花了太多时间跟踪这个问题。

解决方案

p>由于 error = recover 选项不起作用,另一种可行的方法是设置 options(error = dump.frames)。这将为您提供有关错误的一些信息,您可以打印出来,或者更有用地使用 debugger()

  ls()
#[1]dat
options(error = dump.frames)
mi(dat)
()
#[1]datlast.dump#显然有一个错误

#INVESTIGATE WITH debugger()
debugger(dump = last。转储)

#ALTERNATIVELY,PRINT last.dump TO CONSOLE
last.dump

$`mi(dat)`
< environment:0x05155c44> ;

$`mi(dat)`
< environment:0x05158f30>

$`.local(object,...)`
< environment:0x05158cac>

$`mi.default(object,info,n.imp,n.iter,R.hat,max.minutes,rand.imp.method`
< environment:0x047dc3a0>

attr(,error.message)
[1]aveVar [s,i,]中的错误< - c(avevar.mean,avevar.sd):
\\\
要替换的项目数不是替换长度的倍数\
attr(,class)
[1]dump.frames


I'm trying to multiply impute some data, and it's failing in a very odd way. I have options(error=recover) set, and mi() doesn't throw an error, but it does stop imputing after the first attempt. It also doesn't return a value. consequently I have no idea where to even start with debugging. minimal reproducible example below.

> library(mi)
> temp <- mi(dat)
Beginning Multiple Imputation ( Wed Dec 14 10:44:44 2011 ):
Iteration 1 
 Chain 1 : HLTHA5.fac*  BMI*  INCOME*  
> temp
Error: object 'temp' not found


dat<-structure(list(treat = c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, 
FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, 
FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE), NUMADULT = c(2, 
1, 2, 1, 2, 1, 2, 1, 2, 4, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 
3, 3, 1), HLTHA5.fac = structure(c(3L, NA, 3L, 2L, 4L, 5L, 5L, 
4L, 4L, 3L, 3L, 5L, 3L, 4L, 5L, 4L, 2L, 2L, 3L, 5L, 4L, 5L, 4L, 
3L, 3L), .Label = c("0", "1", "2", "3", "4"), class = "factor"), 
    SOURCEA = structure(c(1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L), .Label = c("Yes", "No", "Don't know", "Refused"), class = "factor"), 
    BMI = c(27.363941459046, 24.0265857515842, 34.3236939308346, 
    27.0907152026518, 32.6101901381975, 34.1643655360753, 21.4628674188624, 
    29.1751398412094, 22.5924920198551, 39.6719545438681, 38.5220574557939, 
    20.1156133421915, 30.6612391698034, 35.7332536282609, 26.5664872147956, 
    25.6016897082437, 19.3649931598758, 28.1868713091175, NA, 
    32.4438116170843, 32.5507197719099, 21.1090717674633, 32.2340044872853, 
    24.3699149340904, 27.3369153440247), SMOKE2 = structure(c(2L, 
    1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L), .Label = c("Yes", "No"
    ), class = "factor"), INCOME = structure(c(16L, 4L, 13L, 
    11L, 13L, 7L, 22L, 6L, NA, 1L, 13L, 18L, 12L, 20L, NA, NA, 
    2L, 13L, 17L, NA, 12L, 21L, 9L, 15L, 13L), .Label = c("Less than $10,800", 
    "$10,800-$14,600", "$14,601-$16,250", "$16,251-$18,300", 
    "$18,301-$21,800", "$21,801-$25,000", "$25,001-$27,500", 
    "$27,501-$29,300", "$29,301-$33,100", "$33,101-$36,700", 
    "$36,701-$38,700", "$38,701-$44,200", "$44,201-$50,000", 
    "$50,001-$58,000", "$58,001-$66,500", "$66,501-$73,500", 
    "$73,501-$80,000", "$80,001-88,200", "$88,201-$100,000", 
    "$100,001-$120,000", "$120,001-$130,000", "$130,001-$150,000", 
    "$150,001-$250,000", "Over $250,000", "Don't know", "Refused"
    ), class = "factor"), RESPMAR = structure(c(1L, 5L, 1L, 4L, 
    3L, 6L, 1L, 1L, 1L, 1L, 4L, 4L, 1L, 1L, 4L, 1L, 3L, 3L, 1L, 
    3L, 1L, 1L, 1L, 1L, 1L), .Label = c("Married", "Living w partner", 
    "Widowed", "Divorced", "Separated", "Single", "Other", "Don't know", 
    "Refused"), class = "factor"), RESPGRAD = structure(c(5L, 
    1L, 2L, 5L, 3L, 3L, 5L, 2L, 4L, 2L, 4L, 3L, 4L, 4L, 2L, 3L, 
    2L, 5L, 2L, 4L, 4L, 5L, 2L, 2L, 3L), .Label = c("< HS 0-11", 
    "HS graduate", "Some colge 13-15", "Collge grad 16", "Post college 16+", 
    "Don't know", "Refused"), class = "factor"), RACEA2 = structure(c(1L, 
    1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 
    3L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), .Label = c("White (Not-Latino)", 
    "Black (Not-Latino)", "Latino (total)", "Asian", "Biracial/Multi", 
    "Native American", "Other", "Don't know", "Refused"), class = "factor"), 
    INSUREDA = structure(c(1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 
    1L), .Label = c("Insured", "Not insured", "Don't know", "Refused"
    ), class = "factor"), PAP.adj = c(TRUE, FALSE, FALSE, FALSE, 
    FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, 
    TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, 
    TRUE, TRUE)), .Names = c("treat", "NUMADULT", "HLTHA5.fac", 
"SOURCEA", "BMI", "SMOKE2", "INCOME", "RESPMAR", "RESPGRAD", 
"RACEA2", "INSUREDA", "PAP.adj"), row.names = c(1L, 13L, 15L, 
23L, 26L, 33L, 38L, 53L, 56L, 60L, 62L, 85L, 109L, 116L, 138L, 
217L, 240L, 262L, 264L, 269L, 277L, 295L, 328L, 334L, 338L), class = "data.frame")

Any ideas as to where to begin?

Update

Thanks to the diagnostic technique below, I tracked down the error, which I am summarizing here since it appears I am not the only one to have this problem.

The error occurs when you have an unordered categorical variable with levels that have no values. mi.default calls .initializeConvCheckArray to fill in AveVar with NAs. That function uses the levels, regardless of whether those levels are used. By contrast, to fill in AveVar it calls .getmean, which drops unused levels. Therefore the dimensions don't match up.

The easy solution on the user end is of course to drop the extra levels before calling mi.info and mi. I'm going to submit a bug fix to the package authors, though, having spent way too much time tracking this down already.

解决方案

Since the error=recover option is not working, an alternative that does work is to set options(error=dump.frames). That will get you some information about the error, which you can either print out or, more usefully, examine with debugger()

ls()
# [1] "dat"
options(error=dump.frames)
mi(dat)
ls()
# [1] "dat"       "last.dump"  # Apparently there WAS an error

# INVESTIGATE WITH debugger()
debugger(dump=last.dump)

# ALTERNATIVELY, PRINT last.dump TO CONSOLE
last.dump

$`mi(dat)`
<environment: 0x05155c44>

$`mi(dat)`
<environment: 0x05158f30>

$`.local(object, ...)`
<environment: 0x05158cac>

$`mi.default(object, info, n.imp, n.iter, R.hat, max.minutes, rand.imp.method`
<environment: 0x047dc3a0>

attr(,"error.message")
[1] "Error in aveVar[s, i, ] <- c(avevar.mean, avevar.sd) :
\n  number of items to replace is not a multiple of replacement length\n"
attr(,"class")
[1] "dump.frames"

这篇关于错误没有被抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆