RE: [R] How to write the output of a function into a file?

2003-03-26 Thread Gavin Simpson
does sink()

do what you want?

see ?sink for more

 #divert printed results to file
 sink(file = output.txt)
 #commands here
 chisq.test(x,p=probs)
 #turn off sink
 sink(file = NULL)

If you are not typing the commands at the prompt but are using an external
editor or text file for your commands via source() then you need to wrap
chisq.test(x,p=probs) in print() eg:

print(chisq.test(x,p=probs))

Hope this helps

Gavin

%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [T] +44 (0)20 7679 5522
ENSIS Research Fellow [F] +44 (0)20 7679 7565
ENSIS Ltd.  ECRC [E] [EMAIL PROTECTED]
UCL Department of Geography   [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: 25 March 2003 23:59
To: r-help
Subject: [R] How to write the output of a function into a file?


I cannot find the solutions in the mannual about import and export of
data.
For example, I run 
chisq.test(x,p=probs)
chi-squared.

.

How can I write the output into a file? Is there some file operations in R?
Actually, I only want to save the P-value. But I don't know how I can
extract the P-value field only from the output
of chisq.test. So, I think I would better save all the output. I tried
cat/writeThey cannot do this.

Thanks in advance.

[[alternate HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Re: Bar plot with variable width (down a drill hole) - n

2003-03-26 Thread Ted Harding
On 25-Mar-03 Phillip J. Allen wrote:
 Thanks Ted and Marc its works.  But of course after pulling in in some 
 real life data I discoverd one hitch.  Often there are missing 
 intervals.  For example:
 from - c(0, 1.2, 4.0, 4.2, 5.0, 25.0, 30.1, 45)
 to - c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50)
 intensity - c(0, 1, 3, 2, 1, 0, 2, 5)
 barplot(intensity, width = -(to - from),
 space = 0, horiz = TRUE, ylim = c(-40, 0))
 
 And it appears a barplot() is just stacking bars one on top the other 
 and the help page doesn't indicate anyway to position the bar along the
 y-axis.  So does anyone have a nifty trick to to fill in blank gaps? 
 At least my database can check for overlaping intervals before I
 get the data into R.

Well, I have constructed by hand for the above example a way of
doing it. First, I have used the add a small bit to true zeros
trick to make these stand out from the line of the axis; secondly,
I have filled in the gap where there are no data by inserting
the width of the gap into width (which I call w), and inserting
a true zero into intensity (which I call y). This one-off code
is as follows (starting with your 3 lines which define the data):

from - c(0, 1.2, 4.0, 4.2, 5.0, 25.0, 30.1, 45)
to - c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50)
intensity - c(0, 1, 3, 2, 1, 0, 2, 5)

y-intensity;
y[y==0]-0.005;
y-c(y[1:7],0,y[8])

w-(-(to - from))
w-c(w[1:7],-(45-36.2),w[8])

barplot(y, w, space = 0, horiz = TRUE, ylim = c(-50, 0))

This does produce a plot which represents the full situation:
positive intensities get a proper bar; gaps with missing
data are represented by the line of the vertical axis;
intervals with intensity=0 are represented by a thickened
segment of the vertical axis.

However, this kind of situation needs thought about alternative
ways of representing it.

One possibility might be to have the vertical axis invisible,
so that gaps in the data are represented by gaps in the axis
(and then there would be no need for adding a bit to true zeros).
Possibly this can be arranged by some setting of par, though
I can't seem to achieve it with barplot. Ideas, anyone?
(It looks as though axis in barplot means the scale which is
plotted below or on the side, and not the lines which bound the
barplot itself).

Other thoughts are based on how I might approach this plotting
problem outside R. In particular, I might draw this kind of
graph using the 'pic' program in troff (groff for GNU people).
With this, it would be straightforward to draw the vertical
axis dotted, or dashed, or blank, wherever there is an interval
with missing data; otherwise, as an unbroken line.

Best wishes,
Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 167 1972
Date: 26-Mar-03   Time: 09:59:23
-- XFMail --

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] ifelse()

2003-03-26 Thread Ko-Kang Kevin Wang
Hi,

I'm not sure if this can be done but..

I know that with ifelse() I can do something like:
  ifelse(x = 3, 1, 2)
to go through each element in my vector x, and if x_i = 3 substitute the 
number with 1 else with 2.  Essentially I'll get a vector with 2 levels.

Can I tweak it so I can get 3-levels?  For example:
  if(x = 3) then 1
  elseif(3  x = 4) then 2
  elseif(x  4) then 3

-- 
Cheers,

Kevin

--
/* Time is the greatest teacher, unfortunately it kills its students */

--
Ko-Kang Kevin Wang
Master of Science (MSc) Student
SLC Tutor and Lab Demonstrator
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022
Ph: 373-7599
x88475 (City)
x88480 (Tamaki)

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] ifelse()

2003-03-26 Thread Jason Turner
On Wed, Mar 26, 2003 at 11:20:04PM +1200, Ko-Kang Kevin Wang wrote:
 Hi,
 
 I'm not sure if this can be done but..
 
 I know that with ifelse() I can do something like:
   ifelse(x = 3, 1, 2)
 to go through each element in my vector x, and if x_i = 3 substitute the 
 number with 1 else with 2.  Essentially I'll get a vector with 2 levels.
 
 Can I tweak it so I can get 3-levels?  For example:
   if(x = 3) then 1
   elseif(3  x = 4) then 2
   elseif(x  4) then 3

You can, like this (1 if zz  5, 2 if  5 = zz  10, 3 if zz = 10) 
 zz - 1:20
 ifelse(zz  5, 1, ifelse(zz  10, 2,3))
 [1] 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Re: ifelse()

2003-03-26 Thread Ko-Kang Kevin Wang
Hi,

I've found a much better solution than using ifelse().  I found about 
cut() from MASS4 Page 383, which actually does a better job .

On Wed, 26 Mar 2003, Ko-Kang Kevin Wang wrote:

 Date: Wed, 26 Mar 2003 23:20:04 +1200 (NZST)
 From: Ko-Kang Kevin Wang [EMAIL PROTECTED]
 To: R Help [EMAIL PROTECTED]
 Subject: ifelse()
 
 Hi,
 
 I'm not sure if this can be done but..
 
 I know that with ifelse() I can do something like:
   ifelse(x = 3, 1, 2)
 to go through each element in my vector x, and if x_i = 3 substitute the 
 number with 1 else with 2.  Essentially I'll get a vector with 2 levels.
 
 Can I tweak it so I can get 3-levels?  For example:
   if(x = 3) then 1
   elseif(3  x = 4) then 2
   elseif(x  4) then 3
 
 

-- 
Cheers,

Kevin

--
/* Time is the greatest teacher, unfortunately it kills its students */

--
Ko-Kang Kevin Wang
Master of Science (MSc) Student
SLC Tutor and Lab Demonstrator
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022
Ph: 373-7599
x88475 (City)
x88480 (Tamaki)

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Re: Bar plot with variable width (down a drill hole) - n

2003-03-26 Thread Ted Harding
On 26-Mar-03 Ted Harding wrote:
 On 25-Mar-03 Phillip J. Allen wrote:
 However, this kind of situation needs thought about alternative
 ways of representing it.
 
 One possibility might be to have the vertical axis invisible,
 so that gaps in the data are represented by gaps in the axis
 (and then there would be no need for adding a bit to true zeros).
 Possibly this can be arranged by some setting of par, though
 I can't seem to achieve it with barplot. Ideas, anyone?
 (It looks as though axis in barplot means the scale which is
 plotted below or on the side, and not the lines which bound the
 barplot itself).

Just had a thought on this front, and it works!

Where there are missing data, give intensity the value NA, but
fill in the gaps in width as before (and you don't need to thicken
true zeros any more -- unless you want to):

from - c(0, 1.2, 4.0, 4.2, 5.0, 25.0, 30.1, 45)
to - c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50)
intensity - c(0, 1, 3, 2, 1, 0, 2, 5)

y-intensity;
y-c(y[1:7],NA,y[8])

w-(-(to - from))
w-c(w[1:7],-(45-36.2),w[8])

barplot(y, w, space = 0, horiz = TRUE, ylim = c(-50, 0))

Cheers,
Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 167 1972
Date: 26-Mar-03   Time: 10:41:45
-- XFMail --

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] ifelse()

2003-03-26 Thread Martin Maechler
 Jason == Jason Turner [EMAIL PROTECTED]
 on Wed, 26 Mar 2003 22:49:27 +1200 writes:

Jason On Wed, Mar 26, 2003 at 11:20:04PM +1200, Ko-Kang
Jason Kevin Wang wrote:
 Hi,
 
 I'm not sure if this can be done but..
 
 I know that with ifelse() I can do something like:
 ifelse(x = 3, 1, 2) to go through each element in my
 vector x, and if x_i = 3 substitute the number with 1
 else with 2.  Essentially I'll get a vector with 2
 levels.
 
 Can I tweak it so I can get 3-levels?  For example: if(x
 = 3) then 1 elseif(3  x = 4) then 2 elseif(x  4) then
 3

Jason You can, like this (1 if zz  5, 2 if 5 = zz  10, 3
Jason if zz = 10)
 zz - 1:20 ifelse(zz  5, 1, ifelse(zz  10, 2,3))
Jason  [1] 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3

Yes, but for cases like this (interval cutting),
the function
cut()
will be much more efficient (and its call easier to read).
Martin

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] RODBC and Excel in Widows

2003-03-26 Thread r.ghezzo
HI,
 no sorry, so far nobody answer. So it probably does not have a solution.
 Excell is from you.know.who

= Original Message From Meinhard Ploner [EMAIL PROTECTED] 
=
Hello!
Did you resolve the problem?
I'm interested in the solution, too.
Meinhard

On Thursday, March 13, 2003, at 07:21  PM, R. Heberto Ghezzo wrote:

 Hello, I have some problems with RODBC and Excel in Win98
 I am using R 1.6.2 and just upgraded RODBC to the last version on CRAN.
 I have an Excel file with columns Number, Name, Sex, Age, FEV1 on Sheet
 1 and Number, Age, FEV1, Name, Sex on Sheet 2.
 Now I open the channel to the file
 chan1 - odbcConnectExcel(c:/testOdbc.xls)
 tables(chan1)
 and the list appears with the 2 tables
 aa - sqlFetch(chan1,Sheet1)
 and aa has the Number, Name and Sex columns correct but Age and FEV1
 are
 all NAs
 bb - sqlfetch(chan1,Sheet2)
 and bb is correct!
 So all numeric columns after a column of characters become NAs
 Is this an Excel problem or an sql problem.? I did not find anything in
 the r-help archives relative to this problem.
 Thanks for any help

 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help


R. Heberto Ghezzo Ph.D.
Meakins-Christie Labs
McGill University
Montreal - Que - Canada

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] CMDS

2003-03-26 Thread Heeringa W.J.
Dear statisticians,

I have a small question about the Classifical Multidimensional scaling 
routine in R. Is this procedure always metric?

Best regards,

Wilbert Heeringa

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] RODBC and Excel in Widows

2003-03-26 Thread David Meyer
You might look at Thomas Baier's DCOM interface as an alternative to the
odbc-method for accessing EXCEL-files.

-d

r.ghezzo wrote:
 
 HI,
  no sorry, so far nobody answer. So it probably does not have a solution.
  Excell is from you.know.who
 
 = Original Message From Meinhard Ploner [EMAIL PROTECTED]
 =
 Hello!
 Did you resolve the problem?
 I'm interested in the solution, too.
 Meinhard
 
 On Thursday, March 13, 2003, at 07:21  PM, R. Heberto Ghezzo wrote:
 
  Hello, I have some problems with RODBC and Excel in Win98
  I am using R 1.6.2 and just upgraded RODBC to the last version on CRAN.
  I have an Excel file with columns Number, Name, Sex, Age, FEV1 on Sheet
  1 and Number, Age, FEV1, Name, Sex on Sheet 2.
  Now I open the channel to the file
  chan1 - odbcConnectExcel(c:/testOdbc.xls)
  tables(chan1)
  and the list appears with the 2 tables
  aa - sqlFetch(chan1,Sheet1)
  and aa has the Number, Name and Sex columns correct but Age and FEV1
  are
  all NAs
  bb - sqlfetch(chan1,Sheet2)
  and bb is correct!
  So all numeric columns after a column of characters become NAs
  Is this an Excel problem or an sql problem.? I did not find anything in
  the r-help archives relative to this problem.
  Thanks for any help
 
  __
  [EMAIL PROTECTED] mailing list
  https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 
 
 R. Heberto Ghezzo Ph.D.
 Meakins-Christie Labs
 McGill University
 Montreal - Que - Canada
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
Mag. David MeyerWiedner Hauptstrasse 8-10
Vienna University of Technology A-1040 Vienna/AUSTRIA
 Department of  Tel.: (+431) 58801/10772
Statistics and Probability Theory   Fax.: (+431) 58801/10798

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] RODBC and Excel in Widows

2003-03-26 Thread ripley
Why don't you debug the code and send the patch needed to the maintainer?
R is supposed to be a collaborative project, and we need more 
contributors, especially on Windows.

Looking forwards to your positive contribution 

On Wed, 26 Mar 2003, r.ghezzo wrote:

 HI,
  no sorry, so far nobody answer. So it probably does not have a solution.
  Excell is from you.know.who
 
 = Original Message From Meinhard Ploner [EMAIL PROTECTED] 
 =
 Hello!
 Did you resolve the problem?
 I'm interested in the solution, too.
 Meinhard
 
 On Thursday, March 13, 2003, at 07:21  PM, R. Heberto Ghezzo wrote:
 
  Hello, I have some problems with RODBC and Excel in Win98
  I am using R 1.6.2 and just upgraded RODBC to the last version on CRAN.
  I have an Excel file with columns Number, Name, Sex, Age, FEV1 on Sheet
  1 and Number, Age, FEV1, Name, Sex on Sheet 2.
  Now I open the channel to the file
  chan1 - odbcConnectExcel(c:/testOdbc.xls)
  tables(chan1)
  and the list appears with the 2 tables
  aa - sqlFetch(chan1,Sheet1)
  and aa has the Number, Name and Sex columns correct but Age and FEV1
  are
  all NAs
  bb - sqlfetch(chan1,Sheet2)
  and bb is correct!
  So all numeric columns after a column of characters become NAs
  Is this an Excel problem or an sql problem.? I did not find anything in
  the r-help archives relative to this problem.
  Thanks for any help
 
  __
  [EMAIL PROTECTED] mailing list
  https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 
 
 R. Heberto Ghezzo Ph.D.
 Meakins-Christie Labs
 McGill University
 Montreal - Que - Canada
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Spatial Clustering

2003-03-26 Thread Philippe Hupé
Hello,

Does anyone know any package which can perform spatial clustering ?

Thanks.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Interest Calculator for Lawyers

2003-03-26 Thread David James Thorpe JD
Have you ever been in this situation?  You are representing a client
who is supposed to receive a monthly payment. On some months, that payment
has been made on time, but on other months it has been paid late and
often not at all. Your client is entitled to interest on amounts owing,
but figuring out how much interest precisely is another matter.

In these situations, our Interest Wizard can reliably help you determine
the correct amounts owed.  Whether your client is owed Child Support, Rent,
or any judgment or debt payable in monthly, weekly, or yearly installments,
our Interest Wizard can help you calculate what's owed and generate
a professional looking report to attach to a court filing.

Simply enter the monthly obligation and any payments actually received.
Click on the Calculate button and you have a chart reflecting the total
obligation owed, every payment actually received, the amount due after
each payment, and the accrued interest. When you're done, you can print
your chart and save the file under your client's name.

Give our Interest Wizard a try today. It's just $69.95, and it's guaranteed
to satisfy or your money back. To place an order, visit our website at:
http://www.ThorpeForms.com/lib/mrktAds.php?ad=iwiz022003
Join the thousands of attorneys that already use our legal software!
Thank you for your time.

Sincerely,
David James Thorpe, Esq.
Offices of David Thorpe Legal Software


* To be removed from this mailing list please visit 
  http://www.thorpeforms.com/mlist.php.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Simple NLME problem (I hope)

2003-03-26 Thread Vumani Dlamini
Dear R-Users:

I would like to fit a multilevel model using LME such that the parameters 
after fitting the multilevel in two separate groups and when I use the 
complete data (with interactions between the grouping variable and the other 
variables) set are comparable (or the same).

The problem I am having currently is that I am not sure whether it is 
possible to let the random error term to vary by group such that the models 
are comparable. At present only one random error term is estimate and this 
sort of distorts the parameter estimates for the fixed and other random 
effects.

Looking forward to your help.



Vumani Dlamini

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] 2 scatter plots in the same graphic window....

2003-03-26 Thread Vasudevan, Geetha
Hello,

I am trying to do a scatter plot of x1,y1 and x2,y2 in the same graphics window with 
diff col/pch values. i cannot get it to do them in the same window. 

what is the cmd to do this? thanks.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] 2 scatter plots in the same graphic window....

2003-03-26 Thread Henrik Bengtsson
plot() and points(), e.g.

x - matrix(rnorm(300), ncol=3)
plot(x[,1],x[,2], pch=1, col=red)
points(x[,1],x[,3], pch=2, col=blue)

Cheers

Henrik Bengtsson
Lund University

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 Vasudevan, Geetha
 Sent: den 26 mars 2003 19:35
 To: [EMAIL PROTECTED]
 Subject: [R] 2 scatter plots in the same graphic window
 
 
 Hello,
 
 I am trying to do a scatter plot of x1,y1 and x2,y2 in the 
 same graphics window with diff col/pch values. i cannot get 
 it to do them in the same window. 
 
 what is the cmd to do this? thanks.
 
 __
 [EMAIL PROTECTED] mailing list 
 https://www.stat.math.ethz.ch/mailman/listinfo /r-help
 


__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] 2 scatter plots in the same graphic window....

2003-03-26 Thread Ben Bolker

  Either

n1 - length(x1)
n2 - length(x2)
plot(c(x1,x2),c(y1,y2),col=rep(c(1,2),c(n1,n2)), pch=rep(c(1,2),c(n1,n2))

OR

plot(x1,y1,xlim=range(c(x1,x2)),ylim=range(c(y1,y2)),col=1,pch=1)
points(x2,y2,col=2,pch=2)

will work.

  Ben Bolker

On Wed, 26 Mar 2003, Vasudevan, Geetha wrote:

 Hello,
 
 I am trying to do a scatter plot of x1,y1 and x2,y2 in the same graphics
 window with diff col/pch values. i cannot get it to do them in the same
 window.
 
 what is the cmd to do this? thanks.
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

-- 
318 Carr Hall[EMAIL PROTECTED]
Zoology Department, University of Floridahttp://www.zoo.ufl.edu/bolker
Box 118525   (ph)  352-392-5697
Gainesville, FL 32611-8525   (fax) 352-392-3704

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] hist overlay...

2003-03-26 Thread Vasudevan, Geetha
thanks to all for the 2d scatter plot.

i have one more. 

how do i plot 'hist(y1, col=red) and hist(y2,col=blue) in the same window? 

thanks again.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] a statistic question about chisq.test()

2003-03-26 Thread aprilsun
Hi, 
In the chisq.test(), if the expected frequency for some categories is 5, there will 
be a warning message which says
Warning message: 
Chi-squared approximation may be incorrect in: chisq.test(x, p = probs)

I am wondering whether there are some methods to get rid of this mistake... Seems the 
?chisq.test() doesn't provide more
options to solve this problem. Or, the only choice is to preprocess the data to avoid 
this situation?

Thanks a lot!

aprilsun

[[alternate HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] hist overlay...

2003-03-26 Thread Jerome Asselin

Do you mean two separate plots in the same window? If so, read the 
documentation on multiple figure environment in the chapter on Graphical 
Procedures in the manual An Introduction to R.

Alternately, reading plot help file will lead you to the par help file, which 
will enable you to do multiple figure environment and lots more...

Jerome Asselin

On March 26, 2003 11:35 am, Vasudevan, Geetha wrote:
 thanks to all for the 2d scatter plot.

 i have one more.

 how do i plot 'hist(y1, col=red) and hist(y2,col=blue) in the same
 window?

 thanks again.

 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] hist overlay...

2003-03-26 Thread Vasudevan, Geetha
Cool, thanks!


-Original Message-
From:   Ross Ihaka [mailto:[EMAIL PROTECTED]
Sent:   Wed 3/26/2003 12:26 PM
To: Vasudevan, Geetha
Cc: [EMAIL PROTECTED]
Subject:Re: [R] hist overlay...
Vasudevan, Geetha wrote:
 thanks to all for the 2d scatter plot.
 
 i have one more. 
 
 how do i plot 'hist(y1, col=red) and hist(y2,col=blue) in the same window? 

Here are a couple of ways to do what you have asked for
(as oppposed to want you want :-).

I'm assuming that you precompute the histograms as follows:

x - rnorm(100)
y - rnorm(100)
xh = hist(x, plot=FALSE)
yh = hist(y, plot=FALSE)

You can customize these two hist calls anyway you like.

Here is a function which will plot the result as superimposed bars.

hist2v -
function(xh, yh) {
   plot.new()
   plot.window(xlim=range(xh$breaks, yh$breaks),
   ylim=range(0, xh$density, yh$density))
   rect(xh$breaks[-length(xh$breaks)], 0,
xh$breaks[-1], xh$density, border=blue)
   rect(yh$breaks[-length(yh$breaks)], 0,
yh$breaks[-1], yh$density, border=red)
   axis(1)
   axis(2)
}

and one which will plot only the tops of the bars:

hist2v -
function(xh, yh) {
   plot.new()
   plot.window(xlim=range(xh$breaks, yh$breaks),
   ylim=range(0, xh$density, yh$density))
   nx = length(xh$density)
   ny = length(yh$density)
   lines(rep(xh$breaks, c(1, rep(2, nx - 1), 1)),
 rep(xh$density, each = 2), col = red)
   lines(rep(yh$breaks, c(1, rep(2, ny - 1), 1)),
 rep(yh$density, each = 2), col = blue)
   axis(1)
   axis(2)
}

Either of these functions could be called as

hist2v(xh, yh)

It would be easy to add colour and line texture arguments.

-- 
Ross Ihaka Email:  [EMAIL PROTECTED]
Department of Statistics   Phone:  (64-9) 373-7599 x 85054
University of Auckland Fax:(64-9) 373-7018
Private Bag 92019, Auckland
New Zealand

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Categorical data (Monte Carlo exact p-value)

2003-03-26 Thread Jorge Magalhes
In R program, I can perform categorical data test analysis like  Odds ratio 
test  in stratified 2x2 contingency tables? I do that in statistical package 
StatXact, but i would like perform the same test in R environment.

Thanks very much

Jorge Magalhães

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] R TclTk iwidgets::comboboc

2003-03-26 Thread James Wettenhall
Hi,

I am trying to create a drop-down combobox in R TclTk.  

The following works fine for a ListBox but fails for a combobox:

# THIS WORKS FINE - CREATES AN EMPTY LISTBOX ##
tt-tktoplevel()
win - .Tk.subwin(tt)
.Tcl(paste(listbox,.Tk.ID(win),.Tcl.args()))
tkpack(win)

## THIS FAILS - ATTEMPTS TO CREATE A COMBOBOX ##
tt-tktoplevel()
win - .Tk.subwin(tt)
.Tcl(paste(iwidgets::combobox,.Tk.ID(win),.Tcl.args()))
Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), 
class = tclObj) : 
[tcl] .

I am using R 1.6.2 (with tcltk package 1.6.2) and ActiveTcl 
8.3.5.0 in Windows 2000.  Below I've included some of the 
relevant ActiveTcl help.  I'm not sure why it has funny characters.


#
# Nonâ.editable Dropdown Combobox
#
iwidgets::combobox .cb1 â.labeltext Month: \ â.selectioncommand 
{puts «selected: [.cb1 getcurselection]} \ â.editable false 
â.listheight 185 â.popupcursor hand1 .cb1 insert list end Jan 
Feb Mar Apr May June Jul Aug Sept Oct Nov Dec

BTW, Thanks very much to all organizers and presenters at the 
DSC 2003 - a huge sucess!

Regards,
James

--
James Wettenhall  Tel: (+61 3) 9345 2629
Division of Genetics and Bioinformatics   Fax: (+61 3) 9347 0852
The Walter  Eliza Hall Institute E-mail: [EMAIL PROTECTED]
 of Medical Research, Mobile: (+61 / 0 ) 438 527 921
1G Royal Parade,
Parkville, Vic 3050, Australia
http://www.wehi.edu.au
--

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Categorical data (Monte Carlo exact p-value)

2003-03-26 Thread Spencer Graves
A search in the standard R documentation for Fisher's exact test 
reveals a command fisher.test, and a search for Chi-square reveals a 
chisq.test.

Spencer Graves

Jorge Magalhães wrote:
In R program, I can perform categorical data test analysis like  Odds ratio 
test  in stratified 2x2 contingency tables? I do that in statistical package 
StatXact, but i would like perform the same test in R environment.

Thanks very much

Jorge Magalhães

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] R TclTk iwidgets::combobox

2003-03-26 Thread James Wettenhall
Thanks Peter,

I've started a new R session (in Windows) and managed to get 
both ways working now : 

### THIS WORKS !!! ###
library(tcltk)
tclRequire(IWidgets)
tt-tktoplevel()
combo - tkwidget(tt,iwidgets::combobox)
tkpack(combo)

### AND THIS WORKS TOO !!! ###
tt-tktoplevel()
win - .Tk.subwin(tt)
.Tcl(paste(iwidgets::combobox,.Tk.ID(win),.Tcl.args()))
tkpack(win)

But they both fail in my old R session - maybe I've tclRequired 
another package or loaded another package which is interfering 
or maybe a Tcl object hasn't been cleaned from memory properly.

Thanks very much for your help!
Regards,
James



On 27 Mar 2003, Peter Dalgaard BSA wrote:

 James Wettenhall [EMAIL PROTECTED] writes:
 
  Hi,
  
  I am trying to create a drop-down combobox in R TclTk.  
  
  The following works fine for a ListBox but fails for a combobox:
  
  # THIS WORKS FINE - CREATES AN EMPTY LISTBOX ##
  tt-tktoplevel()
  win - .Tk.subwin(tt)
  .Tcl(paste(listbox,.Tk.ID(win),.Tcl.args()))
  tkpack(win)
  
  ## THIS FAILS - ATTEMPTS TO CREATE A COMBOBOX ##
  tt-tktoplevel()
  win - .Tk.subwin(tt)
  .Tcl(paste(iwidgets::combobox,.Tk.ID(win),.Tcl.args()))
  Error in structure(.External(dotTcl, ..., PACKAGE = tcltk), 
  class = tclObj) : 
  [tcl] .
 
 Hmm, can't see why that shouldn't work. On Linux, this seems to work fine:
 
 tt-tktoplevel()
 combo - tkwidget(tt,iwidgets::combobox)
 tkpack(combo)
 
 and your code seems to work as well...
 
 You remembered to tclRequire(Iwidgets), I assume?
 
 

-- 
--
James Wettenhall  Tel: (+61 3) 9345 2629
Division of Genetics and Bioinformatics   Fax: (+61 3) 9347 0852
The Walter  Eliza Hall Institute E-mail: [EMAIL PROTECTED]
 of Medical Research, Mobile: (+61 / 0 ) 438 527 921
1G Royal Parade,
Parkville, Vic 3050, Australia
http://www.wehi.edu.au
--

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] a statistic question about chisq.test()

2003-03-26 Thread Wiener, Matthew
One other option.

I usually find that when I do the chisq.test with exact p-value calculation,
I find the p-values are nearly identical to the results when I use the
approximation and get the warnings (I'm usually dealing with just a few bins
with less than 5, and many bins with more than 5).

So frequently, when I'm using chisq.test in a program, and expect to do it
many times, I'll sometimes eliminate the warnings this way:

old.warn - options()$warn
options(warn = -1)
 do the chisq.test here 
options(warn = old.warn)

This will suppress the warning messages.  

Hope this helps.

Matt Wiener

-Original Message-
From: Uwe Ligges [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 26, 2003 4:24 PM
To: aprilsun
Cc: [EMAIL PROTECTED]
Subject: Re: [R] a statistic question about chisq.test()


aprilsun wrote:
 
 Hi,
 In the chisq.test(), if the expected frequency for some categories is 5,
there will be a warning message which says
 Warning message:
 Chi-squared approximation may be incorrect in: chisq.test(x, p = probs)

It's a warning message, not an error. It point's you to the problem that
a number  5 is not large, whereas in theory large numbers are
assumed when running this test.

 
 I am wondering whether there are some methods to get rid of this
mistake... Seems the ?chisq.test() doesn't provide more
 options to solve this problem. Or, the only choice is to preprocess the
data to avoid this situation?

It depends on the problem. Fisher's exact test (or it's extended
version) might be an alternative, see ?fisher.test and an appropriate
statistics textbook.

Uwe Ligges


 Thanks a lot!
 
 aprilsun

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


--

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Re: Bar plot with variable width (down a drill hole) - nowmissing intervals?

2003-03-26 Thread Marc Schwartz
Phillip J. Allen wrote:
Hi again,

Thanks Ted and Marc its works.  But of course after pulling in in some 
real life data I discoverd one hitch.  Often there are missing 
intervals.  For example:
from - c(0, 1.2, 4.0, 4.2, 5.0, 25.0, 30.1, 45)
to - c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50)
intensity - c(0, 1, 3, 2, 1, 0, 2, 5)
barplot(intensity, width = -(to - from),
   space = 0, horiz = TRUE, ylim = c(-40, 0))

And it appears a barplot() is just stacking bars one on top the other 
and the help page doesn't indicate anyway to position the bar along the 
y-axis.  So does anyone have a nifty trick to to fill in blank gaps?  At 
least my database can check for overlaping intervals before I get the 
data into R.

Thanks,

Phillip J. Allen
Consulting Geochemist/Geologist
Lima Peru
e-mail: [EMAIL PROTECTED]


Phillip,

Sorry for the delay in replying to this e-mail. I was busy much of the 
day catching up on a project for a client and finally had a chance for a 
breather this evening.

I took note of Ted's reply using NA in the intensity vector which is the 
right approach. I thought you might want an automated approach to 
dealing with missing intervals from dataset to dataset. The code below 
should work, with the assumption that at least the first interval is OK 
and should handle multiple missing intervals in one set. I added a 
second missing interval in your example above to the code below. You 
should test this a bit more to be sure.

What this does is to scan the vectors for a break in the sequence and 
inserts (using insert() )the missing interval(s) with an NA value.

Note that a 0 interval value will have a line in the interval, whereas 
a missing interval with an NA will show nothing.

Hope that this helps.

Marc Schwartz



from - c(0, 1.2, 4.0, 4.2,  5.0, 25.0, 30.1, 45, 55)
to -   c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50, 63)
intensity - c(0, 1, 3, 2, 1, 0, 2, 5, 7)
insert - function(old.vec, pos, val)
{
  left - old.vec[1:pos]
  right - old.vec[-(1:pos)]
  new.vec - c(left, val, right)

  invisible(new.vec)
}
i - 1

repeat
{
  if (to[i] != from[i + 1])
  {
from - insert(from, i, to[i])
to - insert(to, i, from[i + 2])
intensity - insert(intensity, i, NA)
i - i + 1
  }
  i - i + 1

  if (i = length(from)) break
}
barplot(intensity, width = -(to - from),
space = 0, horiz = TRUE,
ylab = Depth (m), ylim = c(-63, 0))
barplot(intensity, width = -(to - from),
space = 0, horiz = TRUE,
ylab = Depth (m), ylim = c(-63, 0))
axis(2, labels = seq(60, 0, -10), las = 2)
box()
 from
 [1]  0.0  1.2  4.0  4.2  5.0 25.0 30.1 36.2 45.0 50.0 55.0
 to
 [1]  1.2  4.0  4.2  5.0 25.0 30.1 36.2 45.0 50.0 55.0 63.0
 intensity
 [1]  0  1  3  2  1  0  2 NA  5 NA  7

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help