Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

R function to save posthoc test results in dataframe

Hi guys I am running a statistical test with a follow up of a Dunnetts-Test using this code:

dun_4h_noS9 <- DunnettTest(x=fourh_noS9_table$MN_rate, g=fourh_noS9_table$Dose, control ="0")

which works great and I get the output:

Dunnett's test for comparing several treatments with a control :  
    95% family-wise confidence level

$`0`
                  diff  lwr.ci  upr.ci   pval    
0.01-0          0.0667 -1.9119  2.0452 1.0000    
0.03-0          0.0167 -1.9619  1.9952 1.0000    
0.08-0         -0.0667 -2.0452  1.9119 1.0000    
0.25-0         -0.0333 -2.0119  1.9452 1.0000    
0.74-0          0.2222 -1.7563  2.2008 1.0000    
2.22-0          1.2833 -0.6952  3.2619 0.3704    
6.67-0          6.6056  4.6270  8.5841 <2e-16 ***
20-0           28.8853 26.9067 30.8639 <2e-16 ***
Mitomycin C -0 12.6833 10.7048 14.6619 <2e-16 ***

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

When trying to save that list to a tibble I keep loosing the Information about which groups were compared in the test and also the significancies ( which is not that much of a problem):

tibble <- map(dun_4h_noS9,~data.frame(.))
tibble<-map_dfr(tibble,~mutate_all(.,as.character))

Output:

 diff  lwr.ci  upr.ci   pval
1  0.0667 -1.9119  2.0452      1
2  0.0167 -1.9619  1.9952      1
3 -0.0667 -2.0452  1.9119      1
4 -0.0333 -2.0119  1.9452      1
5  0.2222 -1.7563  2.2008      1
6  1.2833 -0.6952  3.2619 0.3704
7  6.6056   4.627  8.5841      0
8 28.8853 26.9067 30.8639      0
9 12.6833 10.7048 14.6619      0

Does a way exist where I can keep the infos about the group comparissons?

Thankyou for your help

question from:https://stackoverflow.com/questions/66061884/r-function-to-save-posthoc-test-results-in-dataframe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your case, you could save the results with:

test_df <- data.frame(dun_4h_noS9$`0`)

test_df$comparisons <- row.names(test_df)

This stores the results as a data frame then creates a new column called comparisons since the comparisons are stored as the row names. Consider providing a reproducible answer to get a faster more reliable answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...