如果您能帮助我从这个简单的data.frame中测量p值,我就徘徊了。我的数据帧称为(my_data)。通过查看它,您可以看到我正在比较的相似值:
my_data <- read.csv("densityleftOK.csv", stringsAsFactors = FALSE [c(1,2,3),]
P1 P2 P3 P4 P5 T1 T2 T3 T4 T5 T6
A 1008 1425 869 1205 954 797 722 471 435 628 925
B 550 443 317 477 337 383 54 111 27 239 379
C 483 574 597 375 593 553 249 325 238 354 411
因此,我想通过比较安慰剂与治疗样品来获得每一行的单个p值。如果您不介意,我也想同时获得安慰剂(P)和已治疗(T)之间的标准差。
感谢您的帮助。谢谢
[您可以尝试如下操作,将数据转换为长格式,按ID分组,引入分组矢量(“ P”或“ T”),然后在t.test上使用整洁的格式将其包装在表格中格式:
library(broom)
library(tidyr)
library(dplyr)
library(tibble)
data = read.table(text="P1 P2 P3 P4 P5 T1 T2 T3 T4 T5 T6
A 1008 1425 869 1205 954 797 722 471 435 628 925
B 550 443 317 477 337 383 54 111 27 239 379
C 483 574 597 375 593 553 249 325 238 354 411",header=TRUE,row.names=1)
res = data %>%
rownames_to_column("id") %>%
pivot_longer(-id) %>%
mutate(grp=sub("[0-9]","",name)) %>%
group_by(id) %>%
do(tidy(t.test(value ~ grp,data=.))) %>%
select(c(id,estimate,estimate1,estimate2,statistic,p.value)) %>%
mutate(stderr = estimate/statistic)
# A tibble: 3 x 7
# Groups: id [3]
id estimate estimate1 estimate2 statistic p.value stderr
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 A 429. 1092. 663 3.40 0.00950 126.
2 B 226. 425. 199. 2.89 0.0192 78.2
3 C 169. 524. 355 2.65 0.0266 64.0