测试R中每个受试者的多重复制结果的一致性(Test the consistency of the mult

编程入门 行业动态 更新时间:2024-10-28 08:17:48
测试R中每个受试者的多重复制结果的一致性(Test the consistency of the mult-replicate outcomes for each subject in R)

假设我有这样的结果:

df<-data.frame(id=rep(letters[1:4], each=4), stringsAsFactors=FALSE, test=c(rep(FALSE, 4), rep(c(FALSE, TRUE), 4), rep(TRUE, 4))) id test 1 a FALSE 2 a FALSE 3 a FALSE 4 a FALSE 5 b FALSE 6 b TRUE 7 b FALSE 8 b TRUE 9 c FALSE 10 c TRUE 11 c FALSE 12 c TRUE 13 d TRUE 14 d TRUE 15 d TRUE 16 d TRUE

我想看到的是测试结果在每个主题中是否一致。 这样:

id consist 1 a TRUE 2 b FALSE 3 c FALSE 4 d TRUE

在R中实现这一点的简单方法是什么?

Suppose I have an outcome such like:

df<-data.frame(id=rep(letters[1:4], each=4), stringsAsFactors=FALSE, test=c(rep(FALSE, 4), rep(c(FALSE, TRUE), 4), rep(TRUE, 4))) id test 1 a FALSE 2 a FALSE 3 a FALSE 4 a FALSE 5 b FALSE 6 b TRUE 7 b FALSE 8 b TRUE 9 c FALSE 10 c TRUE 11 c FALSE 12 c TRUE 13 d TRUE 14 d TRUE 15 d TRUE 16 d TRUE

What I wanted to see is whether the test results were consistent across each subject. Such that:

id consist 1 a TRUE 2 b FALSE 3 c FALSE 4 d TRUE

What is an easy way to realize this in R?

最满意答案

这是一个使用aggregate的方法:

aggregate(test ~ id, data=df, FUN=function(x) min(x) == max(x)) id test 1 a TRUE 2 b FALSE 3 c FALSE 4 d TRUE

对于每个id,函数检查测试结果的最小值是否等于结果的最大值。

第二种方法是使用diff检查值是否有diff :

aggregate(test ~ id, data=df, FUN=function(x) max(abs(diff(x))) == 0) id test 1 a TRUE 2 b FALSE 3 c FALSE 4 d TRUE

在这里,取绝对值的最大值来得到差异的大小。

Here is a method using aggregate:

aggregate(test ~ id, data=df, FUN=function(x) min(x) == max(x)) id test 1 a TRUE 2 b FALSE 3 c FALSE 4 d TRUE

For each, id, the function checks whether the min of the test results equal the maximum of the results.

A second method is to check if there are any differences in the values using diff:

aggregate(test ~ id, data=df, FUN=function(x) max(abs(diff(x))) == 0) id test 1 a TRUE 2 b FALSE 3 c FALSE 4 d TRUE

Here, taking the maximum of the absolute value to get the magnitude of the differences.

更多推荐

本文发布于:2023-07-19 17:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:受试   测试   一致性   mult   consistency

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!