I posted this question a couple of minutes ago and it got instant minuses so I figured that it was stupid and deleted it. After reconsideration I still can think of a solution.
This might be due I'm new to R, coding in general, and all those things that are not point and click analysis in SPSS followed by MS Word description of results.
So please forgive me if the answer is basic - I clearly lack intelligence or can't find proper wording for a successful search.
I'm looking for a way to automatically (in order to reduce chance of mistyping errors) pass test results into text (within rmarkdown written in rstudio).
I'm wondering if it's possible to include results from R functions within plain text? If yes, is it matter of markdown formatting or do I need some additional R packages?
For example if I want to describe results of a simple anova
set.seed(111)
y = rnorm(18, 0, 1)
x = rnorm(18, 1, 1)
a = c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3)
df<- data.frame(a, x, y)
anova<- aov(x~a)
summary(anova)
Df Sum Sq Mean Sq F value Pr(>F)
a 1 0.39 0.3882 0.178 0.678
Residuals 16 34.84 2.1775
Instead of writing by hand:
"We conducted a one way anova that showed no effect of a over x (F(1;16)=0.93; p=0.347 (ns)
I'd like to go with (or anything similar):
"We conducted a one way anova that showed no effect of a over x code pasting results in proper format
"
I know I can use `r followed by a function to inline simple results, but it's still not clear if this would work for formatted tests and if so, how.
The more general the solution the better - as I'm describing mostly linear models, mixed linear models and lot's of descriptive statistics.
Once again, sorry if it's too basic and not worth answering - I can delete it again if anyone comments so. Regards
答案 0 :(得分:3)
您必须自己提取不同的统计信息并将它们组合在一起。对于上面显示的anova示例,这样的事情应该让你开始:
F(`r summary(anova)[[1]] [1,“Df”]`;`r summary(anova)[[1]] [2, “Df”]`)=`r格式(摘要(anova)[[1]] [1,“F值”],数字= 2, nsmall = 2)`;
要提取统计信息,您应该查看帮助文件。它们通常包含返回值的详细描述。或者,您可以查看结果的名称。在您的示例names((anova))
和names(summary(anova)[[1]])
中。
答案 1 :(得分:1)
虽然@shadow发布的方法适用于任何结果,但为了我的研究,更简单快捷的方法是使用@ apa
开发的anova<- aov(x~a)
包https://github.com/dgromer/apa
对于我原始问题中给出的示例,从单向anova
发布内联结果devtools::install_github("dgromer/apa")
anova_apa(anova, a) # where "a" is effect name
只需要一行代码
F(1, 16) = 0.18, p = .678, petasq = .01
并生成内联文本:{{1}}