Multiple aov outputs with titles in one text file
1
0
Entering edit mode
5.1 years ago
wkmustahs21 ▴ 30

Hello,

I need some help on figuring out how to add titles to multiple outputs into one text file. I have tried to use the cat() and sink() function but it's not really producing the output I want. Here is an example of what I want. For example say that I have 3 linear models:

model1 --> lm(weight~variety, data=testdat)
model2 --> lm(height ~ variety, data = testdat)
model3 ---> lm(N2conc ~ variety, data =testdat) 

aov(model1)
aov(model2)
aov(model3)

I want to make a text file that has a list of all the anovas with the model for each anova in a text file. I want something like this:


**Anova_output.txt**

model1 --> lm(weight~variety, data=testdat) ### I want model as the title so I can distinguish each anova data
[anova data of model 1]

model2 --> lm(height ~ variety, data = testdat)
[anova data of model 2]

model3 ---> lm(N2conc ~ variety, data =testdat) 
[anova data model3]

Any guidance on this would be helpful. Thanks!

R • 999 views
ADD COMMENT
0
Entering edit mode

Hello

This seems to be for only one model. I was looking for something with multiple models all into one text file.

ADD REPLY
0
Entering edit mode
5.1 years ago
zx8754 12k

aov already stores that information in $call, try this example:

for(i in c("cyl", "disp")){
  f <- as.formula(paste("mpg", i, sep = "~"))
  x <- aov(lm(f, mtcars))
  x$call <- f
  capture.output(x, file = "tmp_1.txt", append = i!="cyl")
}

Anova_output.txt

Call:
   mpg ~ cyl

Terms:
                     cyl Residuals
Sum of Squares  817.7130  308.3342
Deg. of Freedom        1        30

Residual standard error: 3.205902
Estimated effects may be unbalanced
Call:
   mpg ~ disp

Terms:
                    disp Residuals
Sum of Squares  808.8885  317.1587
Deg. of Freedom        1        30

Residual standard error: 3.251454
Estimated effects may be unbalanced
ADD COMMENT

Login before adding your answer.

Traffic: 1595 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6