【问题标题】:Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases in r with repeated mesures ANOVAlm.fit(x,y,offset = offset,singular.ok =singular.ok,...)中的错误:r 中的 0(非 NA)案例重复测量方差分析
【发布时间】:2020-03-03 18:22:02
【问题描述】:

当我使用anova_test()函数(来自rstatix包)做双向重复测量方差分析时,出现错误:

lm.fit(x, y, offset = offset,singular.ok = single.ok, ...) 中的错误:0(非 NA)案例

我检查了我的数据,没有缺失值。

顺便说一句,在我的数据中,并非所有人都有 8 次 outcome。有些人最多3次,有些人最多8次等等。

我参考这个网站做我的双向重复测量方差分析:

https://www.datanovia.com/en/lessons/repeated-measures-anova-in-r/

我已将我的数据集上传到 github。

mydata:https://github.com/lizhiwei1994/testRepo/blob/master/mydata.csv

我的代码:

# load packages
library("tidyverse")
library("ggpubr")
library("rstatix")

# load data and check missing value
mydata <- read.csv(
  url("https://raw.githubusercontent.com/lizhiwei1994/testRepo/master/mydata.csv")
) %>% convert_as_factor(id, time, treatment)
glimpse(mydata)
sum(is.na(mydata))

# error occurring
res.aov <- anova_test(
  data = mydata, dv = outcome, wid = id,
  within = c(treatment, time)
)


get_anova_table(res.aov)

【问题讨论】:

  • 你能写出你想要拟合的 anova 的公式吗?
  • 可能是这样的:aov(outcome ~ time*treatment + Error(id), data = mydata).
  • 当患者接受或不接受治疗时,如何将治疗作为受试者内协变量?

标签: r anova


【解决方案1】:

对于重复测量 anova,您需要对每个时间点、治疗前后的完整观察结果,在进行 anova 之前,检查观察结果总是好的:

tab = table(mydata$time,mydata$treatment,mydata$id)
#subject = 1
tab[,,"1"]

    control2 treat2
  1        1      0
  2        1      0
  3        1      0
  4        1      0
  5        1      0
  6        1      0
  7        1      0
  8        0      0

所以这个主题只有 control2 观察,但没有treatment2 观察。如题录有误,请指正。下面我可以向您展示它何时起作用的示例:

test = expand.grid(id=1:2,time=1:8,treatment=c("a","b"))
test$outcome=rnorm(nrow(test))
table(test$time,test$treatment,test$id)
, ,  = 1


    a b
  1 1 1
  2 1 1
  3 1 1
  4 1 1
  5 1 1
  6 1 1
  7 1 1
  8 1 1

, ,  = 2


    a b
  1 1 1
  2 1 1
  3 1 1
  4 1 1
  5 1 1
  6 1 1
  7 1 1
  8 1 1

anova_test(data=test,dv=outcome,wid=id,within=c("treatment","time"))
ANOVA Table (type III tests)

          Effect DFn DFd       F     p p<.05   ges
1      treatment   1   1 424.283 0.031     * 0.078
2           time   7   7   1.596 0.276       0.422
3 treatment:time   7   7   1.571 0.283       0.422

如果您的数据集是这样的,根据您在评论aov(outcome ~ time*treatment + Error(id), data = mydata) 中提供的公式,它是混合方差分析,但为此您需要经过处理和控制的个体,以控制个体效应,并且这在您的数据集中不存在。

在这种情况下,您可以执行的唯一 anova 是双向 anova:

anova_test(data=test,dv=outcome,between=c(time,treatment))
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

          Effect DFn DFd     F     p p<.05   ges
1           time   7  16 1.668 0.187       0.422
2      treatment   1  16 1.350 0.262       0.078
3 time:treatment   7  16 1.668 0.187       0.422

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 2013-04-20
    • 2020-09-09
    • 1970-01-01
    • 2018-09-26
    • 2020-08-23
    • 2017-09-26
    相关资源
    最近更新 更多