[R] Output results to a single postscript document
Mark Difford
mark_difford at yahoo.co.uk
Sat Feb 7 15:42:46 CET 2009
Sorry, the message seems to have got botched. Here it is again:
Pele does open a PDF device (previously it was a postscript device). It
looks like what Pele is trying to do is "plot" the printed results of the
summary of a model + the AIC, together with the acf() and pacf() plots.
As Dieter indicated, Gavin Snow's textplot() function [in gplots package]
might help. This really is a job for Sweave, which Pele should have look at.
Pele: you could also look at Prof. Harrell's text.anova.Design function,
which you may be able to adapt to your needs. Even "simpler" would be to
write a function that uses text() [see: ?text] to plot the parts of your
model-summary and the AIC to an empty graph.
Regards, Mark.
Hello R users,
Below is the code and output of what I am trying to do. My goal is to
insert/print all items in the chart function into a pdf document. Only the
acf and pacf charts gets printed.
Again, thanks in advance for any help I can get!
####################################
options (scipen=999, digits=7)
library(lmtest)
library(dyn)
tdata <- ts(read.table("C:/test/data.csv" ,sep = ",",header=TRUE))
print(tdata)
res <- function(dep, indep, fn, env = parent.frame()) {
depnm <- deparse(substitute(dep))
indepnm <- deparse(substitute(indep))
fo <- sprintf("%s ~ lag(%s, -1) + %s", depnm, depnm, indepnm)
fo <- as.formula(fo, env = env)
mod <- do.call(dyn$lm, list(fo))
chart <- function(mod) {
pdf(file="results.pdf")
par(mfrow=c(2,1))
acf(residuals(mod))
pacf(residuals(mod))
summ<- summary(mod)
aic <- AIC(mod)
dev.off() }
output <- return(list(Charts=chart(mod))) }
results <- res(tdata[ ,"Y"], tdata[ ,"X_VARY"]) ; results
############output###############
> options (scipen=999, digits=7)
>
> library(lmtest)
> library(dyn)
>
> tdata <- ts(read.table("C:/test/data.csv" ,sep = ",",header=TRUE))
> print(tdata)
Time Series:
Start = 1
End = 20
Frequency = 1
Unit Y X_VARY K D_WAY
1 1 3 2 4 50
2 2 5 3 9 50
3 3 6 11 22 50
4 4 8 4 7 2
5 5 9 11 11 2
6 6 12 13 13 2
7 7 23 25 12 2
8 8 22 30 31 3
9 9 23 3 3 3
10 10 19 21 21 32
11 11 3 2 4 34
12 12 5 3 9 4
13 13 6 11 22 4
14 14 8 4 7 4
15 15 9 11 11 4
16 16 12 13 13 4
17 17 23 25 12 4
18 18 22 30 31 4
19 19 23 3 3 4
20 20 19 21 21 5
>
> res <- function(dep, indep, fn, env = parent.frame()) {
+ depnm <- deparse(substitute(dep))
+ indepnm <- deparse(substitute(indep))
+ fo <- sprintf("%s ~ lag(%s, -1) + %s", depnm, depnm, indepnm)
+ fo <- as.formula(fo, env = env)
+ mod <- do.call(dyn$lm, list(fo))
+
+ chart <- function(mod) {
+ pdf(file="results.pdf")
+ par(mfrow=c(2,1))
+ acf(residuals(mod))
+ pacf(residuals(mod))
+ summ<- summary(mod)
+ aic<- AIC(mod)
+ dev.off() }
+
+ output <- return(list(Charts=chart(mod))) }
>
> results <- res(tdata[ ,"Y"], tdata[ ,"X_VARY"]) ; results
$Charts
null device
http://www.nabble.com/file/p21888211/results.pdf results.pdf
Pele wrote:
>
> Hello R users,
>
> I have been trying to output all my results (text, plots, etc) into the
> same postscript file as
>
> one document, but have been unable to...Can anyone help me improve my code
> below so that I can
>
> accomplish this? Currently I have to output them separately then piece
> them back together into
>
> one document..
>
[[elided Yahoo spam]]
>
>
>
> http://www.nabble.com/file/p21888211/data.csv data.csv
>
--
View this message in context: http://www.nabble.com/Output-results-to-a-single-postscript-document-tp21884901p21889042.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list