na.fail.default中的错误:对象中缺少值-但没有任何值 [英] Error in na.fail.default: missing values in object - but no missing values

查看:2565
本文介绍了na.fail.default中的错误:对象中缺少值-但没有任何值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下数据运行lme模型:

I am trying to run a lme model with these data:

tot_nochc=runif(10,1,15)
cor_partner=factor(c(1,1,0,1,0,0,0,0,1,0))
age=runif(10,18,75)
agecu=age^3
day=factor(c(1,2,2,3,3,NA,NA,4,4,4))
dt=as.data.frame(cbind(tot_nochc,cor_partner,agecu,day))
attach(dt)

corpart.lme.1=lme(tot_nochc~cor_partner+agecu+cor_partner *agecu, 
                  random = ~cor_partner+agecu+cor_partner *agecu |day, 
                  na.exclude(day))

我收到此错误代码:

na.fail.default中的错误(list(cor_partner = c(1L,1L,2L,1L,1L,1L,: 对象中缺少值

Error in na.fail.default(list(cor_partner = c(1L, 1L, 2L, 1L, 1L, 1L, : missing values in object

我知道论坛中也有类似的问题.但是,就我而言:

I am aware there are similar questions in the forum. However, in my case:

  • cor_partner没有丢失的值;
  • 整个对象被编码为一个因素(至少从全球环境显示的情况来看).

我可以使用na.action排除那些NA值,但是我宁愿知道函数为何读取缺失值-准确了解我的数据正在发生什么.

I could exclude those NA values with an na.action, but I'd rather know why the function is reading missing values - to understand exactly what is happening to my data.

推荐答案

tl; dr ,您必须一次在整个数据帧上使用na.exclude()(或其他),以便其余观察结果在各个变量之间保持匹配...

tl;dr you have to use na.exclude() (or whatever) on the whole data frame at once, so that the remaining observations stay matched up across variables ...

set.seed(101)
tot_nochc=runif(10,1,15)
cor_partner=factor(c(1,1,0,1,0,0,0,0,1,0))
age=runif(10,18,75)
agecu=age^3
day=factor(c(1,2,2,3,3,NA,NA,4,4,4))
## use data.frame() -- *DON'T* cbind() first
dt=data.frame(tot_nochc,cor_partner,agecu,day)
## DON'T attach(dt) ...

现在尝试:

library(nlme)
corpart.lme.1=lme(tot_nochc~cor_partner+agecu+cor_partner *agecu, 
              random = ~cor_partner+agecu+cor_partner *agecu |day, 
              data=dt,
              na.action=na.exclude)

我们收到收敛错误和警告,但是我认为这是因为我们使用的是一个很小的,没有足够信息的虚构数据集,而不是因为代码存在任何固有问题.

We get convergence errors and warnings, but I think that's now because we're using a tiny made-up data set without enough information in it and not because of any inherent problem with the code.

这篇关于na.fail.default中的错误:对象中缺少值-但没有任何值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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