1

我正在使用 reshape2 包来塑造我的数据并将其用于 t 检验。对我来说,在单独的列中可视化数据更容易。我有三种处理组合,其中“wat”嵌套在“spp”中,“ins”嵌套在水中。我的演示表包含 3 个响应变量,即“tyr”、“esc”和“esc_R”。我很想看看 ins 如何影响响​​应->“spp”中的“tyr”-> Bl,处理“wat”-> High(只是一个例子)。

这是我的数据: demo.data

## Use orderBy function to sort data
library(doBy)
demo <- orderBy(~spp+wat+ins, data = demo)
## Create an unique data frame for a specific variable
df.bl.ins.1 <- demo[demo$spp == "Bl", c(1:3, 4)]
df.bl.ins.2 <- df.bl.ins.1[df.bl.ins.1$wat == "High", ]

然后我在执行 dcast 功能时遇到了麻烦。

df.bl.ins.tmp <- dcast(df.bl.ins.2, spp + wat ~ ins, value.var = "tyr")

我在以下线程中发现了有趣的信息

  1. Dason 的建议- 与 ToothGrowth 演示数据集配合得非常好。不幸的是,当表格有多个处理(超过 2 个)时,解决方案并不简单。我同意 Maiasaura 的建议,即创建唯一变量是解决此问题的关键。但是,我很难理解 function(x) 的作用或如何在我的表中使用它。

非常感谢这方面的任何帮助。

此外,如果您有其他建议可以在不操纵原始数据框(演示)的情况下进行 t-test,我会很高兴听到它。

提前致谢。

编辑 这是我所期待的,对于“tyr”。在以下格式中,我希望使用 t 检验比较“否”与“是”。

spp wat ins No  Yes
Bl  High    No  0.3036  0.1987
Bl  High    No  0.2577  0.1112
Bl  High    No  NA  0.199
Bl  High    No  0.3299  0.1886
Bl  High    No  0.3301  0.2332
4

1 回答 1

1

Perhaps I don't understand exactly what you want to do, but I think you could run linear regression directly on your data. In this way, you could do t-tests on whether the coefficients of your model were zero or not. I think this might suffice, and serve also to tease apart the effects of each of your independent variables. Here is an example:

summary(lm(tyr~spp+wat+ins,data=read.table('http://pastebin.com/raw.php?i=sR2MvBBA')))
Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.286386   0.016500  17.356  < 2e-16 ***
sppMan      -0.159514   0.015811 -10.089  1.3e-11 ***
watLow      -0.005501   0.015858  -0.347 0.730861    
insYes      -0.066741   0.015858  -4.209 0.000185 ***

This will get you a t test for just the groups that you showed in your example:

t.test(tyr~ins,data=df[df$spp=='Bl' & df$wat=='High',])
于 2012-10-19T18:46:33.970 回答