尝试运行许多方差分析并为每一行获取 F 值 [英] Trying to run many anovas and get an F value for each row

查看:35
本文介绍了尝试运行许多方差分析并为每一行获取 F 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个如下所示的数据集.现在我知道这不是 R 喜欢的格式类型.我知道如何整理数据,但是我不确定我会做什么才能为每个 unique_id 获得 F 统计,这是我的目标.有没有简单的方法来做到这一点?否则,有没有一种方法可以使用某种类型的应用函数来独立整理每一行、执行、方差分析,然后将 F 统计信息添加为新列?

I'm working with a dataset that looks like what is shown below. Now I know that this is not the type of format that R likes. I know how to tidy up the data, but then I'm not sure what I'd do in order to obtain an F statistic for each unique_id, which is my goal. Is there an easy way to do that? Otherwise is there a way I could use some type of apply function to tidy up each row independently, perform, the anova, and then add F statistics as a new column?

unique_id   heart   heart   heart   kidney  kidney  kidney  cortex  cortex  cortex
373020.8    1.39    1.18    1.30    2.71    2.96    2.52    1.97    1.67    1.44
371588.9    1.93    2.35    2.50    2.54    1.63    2.23    2.68    2.89    1.86
367772.8    0.42    0.51    0.97    1.02    0.03    0.82    0.01    0.90    1.01

推荐答案

我偏爱 data.tables,您可以在融合数据后使用 DT 轻松完成此操作.这是我的看法,将 DT 作为包含您提供的信息的数据表.

I'm partial to data.tables and you can easily do this with a DT after melting your data. Here's my take, with DT as your data.table containing the info you provided.

DT <- dt<- melt(dt, 
      id.vars = c("unique_id"),
      measure.vars = c("heart","cortex","kidney"))

DT[,fstat:=summary(aov(value~variable))[[1]][1,"F value"],by=unique_id]

这通过 unique_id 计算 F-Stat 并且应该可以工作.

This calculates the F-Stat by unique_id and should work.

这篇关于尝试运行许多方差分析并为每一行获取 F 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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