Question: Multiple aov outputs with titles in one text file
0
gravatar for wkmustahs21
25 days ago by
wkmustahs2130
wkmustahs2130 wrote:

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 • 80 views
ADD COMMENTlink modified 24 days ago • written 25 days ago by wkmustahs2130

Hello

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

ADD REPLYlink written 24 days ago by wkmustahs2130
0
gravatar for zx8754
25 days ago by
zx87548.3k
London
zx87548.3k wrote:

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 COMMENTlink modified 25 days ago • written 25 days ago by zx87548.3k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2275 users visited in the last hour