NaNs使用Betareg生产

时间:2018-03-06 20:20:17

标签: r

当尝试对下面的数据集执行Beta回归时,我得到以下错误。 谁能告诉我如何处理这个错误?

提前致谢

Error in quantile.default(x$residuals) : 
  missing values and NaN's not allowed if 'na.rm' is FALSE
In addition: Warning message:
In sqrt(v * (1 - hatvalues(object))) : NaNs produced

model.beta = betareg(Percentage ~ Kuikenweek,data = dieet)
summary(model.beta)

数据

Jaar    Kuikenweek  Percentage  Locatie
2013    Week 1  0,4238  Markenje
2013    Week -1 0,8248  Markenje
2013    Week 2  0,5927  Markenje
2013    Week -2 0,3208  Markenje
2013    Week 3  0,8317  Markenje
2013    Week -3 0,7314  Markenje
2014    Week 1  0,4624  Markenje
2014    Week 2  0,5224  Markenje
2014    Week -2 0,3528  Markenje
2014    Week 3  0,7739  Markenje
2014    Week -3 0,1264  Markenje
2015    Week -1 0,4516  Markenje
2015    Week -2 0,4306  Markenje
2015    Week -3 0,5243  Markenje
2013    Week 1  0,5117  Scheelhoek
2013    Week -1 0,1490  Scheelhoek
2013    Week 2  0,3342  Scheelhoek
2013    Week -2 0,5069  Scheelhoek
2013    Week 3  0,7101  Scheelhoek
2013    Week -3 0,8019  Scheelhoek
2013    Week 4  0,7569  Scheelhoek
2013    Week 5  0,9096  Scheelhoek
2013    Week 6  0,9013  Scheelhoek
2014    Week 1  0,5403  Scheelhoek
2014    Week -1 0,2264  Scheelhoek
2014    Week 2  0,5775  Scheelhoek
2014    Week 3  0,7366  Scheelhoek
2014    Week -3 0,4086  Scheelhoek
2014    Week 4  0,5750  Scheelhoek
2014    Week 5  0,6623  Scheelhoek
2015    Week 1  0,7758  Scheelhoek
2015    Week -1 0,1517  Scheelhoek
2015    Week 2  0,7587  Scheelhoek
2015    Week -2 0,3247  Scheelhoek
2015    Week 3  0,7463  Scheelhoek
2015    Week -3 0,6325  Scheelhoek

1 个答案:

答案 0 :(得分:2)

我在这里重现你的错误:

# here are the data
devtools::source_gist("169bfa3a6c709fd2fd31c5bfa46648ee")
library(betareg)
# fix percentages 
dieet$Percentage <- gsub(",",".",dieet$Percentage)
dieet$Percentage <- as.numeric(dieet$Percentage)
model.beta = betareg(Percentage ~ Kuikenweek,data = dieet)
summary(model.beta)
## Error in quantile.default(x$residuals) : 
##  missing values and NaN's not allowed if 'na.rm' is FALSE
## In addition: Warning message:
## In sqrt(v * (1 - hatvalues(object))) : NaNs produced

问题出现是因为默认残留类型“sweighted2”对您的模型不起作用。所以:

summary(model.beta, type = "deviance")

至少可以获得摘要。有几种类型的残差,哪一种最适合您的目的更多的是统计问题。