Re: [R] Query: how to modify the plot of acf

2006-08-18 Thread Matthias Braeunig
Hi Stefano,

the manual tells us that we can access components of an acf object
directly by acf.obj[.], but assignment ]<- does not work this way.

One way of doing what you want is to assign NA to x$acf[x$lag==0] like so:

x <- acf(runif(100))
x$acf[1] <- NA
plot(x)

But I suppose what you actually want is to have a reasonable ylim to be
in effect when plotting your acf. I have struggled with this myself and
found the following solution:

In plot.acf the formula for the white noise confidence interval is
something along the lines of

acf.clim <- function(x=stop("your acf"), n=x$n.used, CL=.95)
{
cl = qnorm((1+CL)/2)/sqrt(n)
attr(cl,"CL") <- CL
return( cl)
}

Using this function you can plot
x <- acf(runif(100),plot=F)
plot(x, ylim=2*acf.clim(x)*c(-1,1)) # adjust magnification as needed


As for your second question we first prevent plotting of x-axis and then
add our custom axis:

x <- acf(runif(1000),100,plot=F)
plot(x, ylim=2*acf.clim(x)*c(-1,1),xaxt='n')# note option 'xaxt'!
axis(1,at=12*(0:8))

Hope that helps,

Matthias


NB: It would be a good idea to include the acf.clim(.) inside of the acf
object... Now it is somewhat hidden inside of plot.acf

x$clim <- acf.clim(x)
str(x)





Stefano Sofia wrote:
> I need to modify the graph of the autocorrelation. I tried to do it through 
> plot.acf but with no success. 
> 
> 1. I would like to get rid of the lag zero
> 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 
> 60, ...
> 
> Could anybody help me in this?
> 
> Any help will be appreciated
> Thank you for your attention
> Stefano
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
Journalist: "Mr. Gandhi, what do you think of Western civilization?"
Gandhi: "I think it would be a good idea."


~   Matthias Braeunig, Dipl.Phys.
~University Medical Center Freiburg
~Institute of Environmental Medicine and Hospital Epidemiology
~ Department of Evaluation Research in Complementary Medicine
~  Hugstetter Str. 55, D - 79106 Freiburg, Germany
~  Phone: +49 (0)761 270-8306, Fax: -8343
~ Web: http://kompmed.uniklinik-freiburg.de
~   Email: [EMAIL PROTECTED]


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] plot.ts panel function

2006-07-11 Thread Matthias Braeunig
How can I set the ylim in individual panels of a "multiple" plot.ts?
The panels are all scaled to fully fit the series inside. But I need
specific scales, and colors 

Here is an example:

plot.ts(cbind(1:10,1:10/10),ylim=c(0,3))# ylim has no effect

Can someone more knowledgable please explain how to use the panel=
option correctly, thanks!

Cheers, m

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] replace values?

2006-07-02 Thread Matthias Braeunig
# reproducing your example
xx<-"x y z
+ 1 2 3
+ 2 3 1
+ 3 2 1
+ 1 1 3
+ 2 1 2
+ 3 2 3
+ 2 1 1"

# you did not tell us the class of your data, assuming data.frame
df<-read.table(textConnection(xx),header=T,colClasses="factor")

# a clean way to do what you want is using factors with ?levels
# (note that data has already been read as factor)
levels(df$x)<-c("a","b","c","d")
levels(df$y)<-c("b","a","c","d")
levels(df$z)<-c("d","c","b","a")

subset(df,x=="a")
  x y z
1 a a b
4 a b b
subset(df,x=="a"&y=="a")
  x y z
1 a a b


HTH, m


zhijie zhang wrote:
> Dear friends,
>   i have a dataset like this:
> x y z
> 1 2 3
> 2 3 1
> 3 2 1
> 1 1 3
> 2 1 2
> 3 2 3
> 2 1 1
> I want to replace x with the following values:1<-a,2<-b,3<-c,4<-d;
>  replace y with the following values:1<-b,2<-a,3<-c,4<-d;
>  replace z with the following values:1<-d,2<-c,3<-b,4<-a;
> Finally,select two subsets:
> 1. if x='a';
> 2.x='a' and y='a';
>  thanks very much!

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] send output to printer

2006-06-30 Thread Matthias Braeunig
It has to be a simple thing, but I could not figure it out:

How do I send the text output from object x to the printer?
As a shell user I would expect a pipe to the printer... "|kprinter" or
"|lpr -Pmyprinter" somehow. And yes, I'm on Linux.

Thanks!

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] reshaping data.frame question

2006-06-26 Thread Matthias Braeunig
Thanks, this is not what what I meant. I need to reshape the original
dataframe that I can access p_f[X] for numerical X. Maybe I was not
clear enough.

The problem really is that X starts at 0. Note that in my example
changing the row names to 0:2 does not have the desired effect.



jim holtman wrote:
> You need to specify the row/column name as character:
> 
>> y
>   X1  X2  X3  X4
> 0 0.1 0.1 0.1 0.1
> 1 0.2 0.2 0.2 0.2
> 2 0.3 0.3 0.3 0.3
> 
>> y[,'X3']
> [1] 0.1 0.2 0.3
>> y['0','X3']
> [1] 0.1
> 
> 
> 
> 
> On 6/26/06, Matthias Braeunig <[EMAIL PROTECTED]> wrote:
>>
> Dear R-helpers,
> 
> 
> my data.frame is of the form
> 
> x <- data.frame( f=gl(4,3), X=rep(0:2,4), p=c(.1,.2,.3))
> x
>   f X   p
> 1  1 0 0.1
> 2  1 1 0.2
> 3  1 2 0.3
> 4  2 0 0.1
> 5  2 1 0.2
> 6  2 2 0.3
> 7  3 0 0.1
> 8  3 1 0.2
> 9  3 2 0.3
> 10 4 0 0.1
> 11 4 1 0.2
> 12 4 2 0.3
> 
> which  tabulates some values p(X) for several factors f.
> 
> Now I want to put it in "wide" format, so that factor levels appear as
> column heads. Note also that X starts from zero. It would be nice if I
> could simply access p_f[X==0] as f[0]. How can I possibly do that?
> 
> (The resilting object does not have to be a data.frame. As there are
> only numeric values, also a matrix would do.)
> 
> I tried the following
> 
> y<-unstack(x,form=p~f)
> row.names(y) <- 0:2
> y
>   X1  X2  X3  X4
> 0 0.1 0.1 0.1 0.1
> 1 0.2 0.2 0.2 0.2
> 2 0.3 0.3 0.3 0.3
> 
> Now, how to access X3[0], say?
> 
> Maybe reshape would be the right tool, but I could not figure it out.
> 
> I appreciate your help. Thanks!

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] reshaping data.frame question

2006-06-26 Thread Matthias Braeunig
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Dear R-helpers,

my data.frame is of the form

x <- data.frame( f=gl(4,3), X=rep(0:2,4), p=c(.1,.2,.3))
x
   f X   p
1  1 0 0.1
2  1 1 0.2
3  1 2 0.3
4  2 0 0.1
5  2 1 0.2
6  2 2 0.3
7  3 0 0.1
8  3 1 0.2
9  3 2 0.3
10 4 0 0.1
11 4 1 0.2
12 4 2 0.3

which  tabulates some values p(X) for several factors f.

Now I want to put it in "wide" format, so that factor levels appear as
column heads. Note also that X starts from zero. It would be nice if I
could simply access p_f[X==0] as f[0]. How can I possibly do that?

(The resilting object does not have to be a data.frame. As there are
only numeric values, also a matrix would do.)

I tried the following

y<-unstack(x,form=p~f)
row.names(y) <- 0:2
y
   X1  X2  X3  X4
0 0.1 0.1 0.1 0.1
1 0.2 0.2 0.2 0.2
2 0.3 0.3 0.3 0.3

Now, how to access X3[0], say?

Maybe reshape would be the right tool, but I could not figure it out.

I appreciate your help. Thanks!


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEn9G2XjamRUP82DkRAorGAJ9JirG7WtNJLWRQkJvgW0zTFHTYagCgvONw
IC4jgoxE2+CsOmmogv5dzF0=
=24Kj
-END PGP SIGNATURE-

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] function environment

2006-06-02 Thread Matthias Braeunig
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

how can I automatically access the functions that I loaded into a
separate environment?

> save(A,B,file="myfun.r")
> load("myfun.r",envir=(ENV<-new.env()))
> ls(ENV)
[1] "A" "B"

?"[" turned up that I can access the functions via

> ENV$A
function ()
{
}
> ENV$A()
NULL

Now, how can they be included in the search() path??
attach() as for data.frames does not work...

Furthermore, if I change a functions environment to ENV, why is it not
listed with ls(ENV)?? Instead it still lives in .GlobalEnv

> C<-function(){}
> environment(C)<-ENV
> ls(ENV)
[1] "A" "B"
> C
function(){}

> ENV


Thanks folks!
I enjoy reading and learning from r-help list!

M
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEgFw2XjamRUP82DkRAooRAJ9sxwERwfXF3l7pssZ081sMC1+nigCgqAPM
OkA1tNJg6MN3l0PQFrwBlIE=
=tGFq
-END PGP SIGNATURE-

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html