[R] Legend and Main Title positioning

2008-12-05 Thread Antje

Hi folks,

can anybody give me a hint how to solve the following problem?
I have several plots in one window like this:

layout(matrix(c(1,2,3,4), nrow = 2, byrow = TRUE))
plot(rnorm(100))
plot(rnorm(200))
plot(rnorm(300))
plot(rnorm(400))

Now, I'd like to create a legend below each plot and generate a common title.
How can I do that?


Antje

__
R-help@r-project.org 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] complex(?) reshaping question

2008-12-05 Thread Lauri Nikkinen
Hello,

I have a problem with data reshaping. Here's my data

DF -
structure(list(idvar1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(patient1, patient2
), class = factor), idvar2 = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(dob, hog), class =
factor),
eka1 = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, 2L, 1L,
NA, NA, NA, NA), .Label = c(as, df), class = factor),
eka2 = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, 2L, 1L,
NA, NA, NA, NA), .Label = c(as, df), class = factor),
eka3 = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, 2L, 1L,
NA, NA, NA, NA), .Label = c(as, df), class = factor),
toka1 = structure(c(NA, NA, NA, NA, NA, NA, 1L, 2L, NA, NA,
NA, NA, NA, 2L), .Label = c(as, fg), class = factor),
toka2 = structure(c(NA, NA, NA, NA, NA, NA, 1L, 2L, NA, NA,
NA, NA, NA, 2L), .Label = c(as, fg), class = factor),
toka3 = structure(c(NA, NA, NA, NA, NA, NA, 1L, 2L, NA, NA,
NA, NA, NA, 2L), .Label = c(as, fg), class = factor),
kol1 = structure(c(NA, NA, NA, NA, 1L, 2L, NA, NA, NA, NA,
1L, 2L, NA, NA), .Label = c(hj, ht), class = factor),
kol2 = structure(c(NA, NA, NA, NA, 1L, 2L, NA, NA, NA, NA,
1L, 2L, NA, NA), .Label = c(hj, ht), class = factor),
kol3 = structure(c(NA, NA, NA, NA, 1L, 2L, NA, NA, NA, NA,
1L, 2L, NA, NA), .Label = c(hj, th), class = factor)),
.Names = c(idvar1,
idvar2, eka1, eka2, eka3, toka1, toka2, toka3,
kol1, kol2, kol3), class = data.frame, row.names = c(NA,
-14L))

I'm trying to omit NA:s in this DF and produce a reduced DF. The
problem is that I cannot completely omit NA rows.

I tried

library(reshape)
g - melt(DF, id=c(idvar1, idvar2))
g - na.omit(g)
reshape(g, idvar=c(idvar1, idvar2), timevar=variable, direction=wide)

But this drops the second row. This is the resulting DF I should be getting

res -
structure(list(idvar1 = structure(c(1L, 1L, 2L, 2L), .Label = c(patient1,
patient2), class = factor), idvar2 = structure(c(1L, 1L,
2L, 2L), .Label = c(dob, hog), class = factor), eka1 = structure(c(NA,
NA, 2L, 1L), .Label = c(as, df), class = factor), eka2 = structure(c(NA,
NA, 2L, 1L), .Label = c(as, df), class = factor), eka3 = structure(c(NA,
NA, 2L, 1L), .Label = c(as, df), class = factor), toka1 = structure(c(1L,
2L, NA, 2L), .Label = c(as, fg), class = factor), toka2 = structure(c(1L,
2L, NA, 2L), .Label = c(as, fg), class = factor), toka3 = structure(c(1L,
2L, NA, 2L), .Label = c(as, fg), class = factor), kol1 = structure(c(1L,
2L, 1L, 2L), .Label = c(hj, ht), class = factor), kol2 = structure(c(1L,
2L, 1L, 2L), .Label = c(hj, ht), class = factor), kol3 = structure(c(1L,
2L, 1L, 2L), .Label = c(hj, th), class = factor)), .Names = c(idvar1,
idvar2, eka1, eka2, eka3, toka1, toka2, toka3,
kol1, kol2, kol3), class = data.frame, row.names = c(NA,
-4L))

Any ideas how to proceed?

Many thanks
Lauri

__
R-help@r-project.org 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.


Re: [R] setwd and list.files / linux

2008-12-05 Thread Lars Beckmann
Hey Marc,

sorry I forgot to mention it. I am the owner of the path, which is in my home 
directory. I can change the read/write/execute privileges.  All users have - at 
least - read privileges for all files and the directory:

hpc36 40: ls -la *.tped
-rw-r--r--  1 cremer C020 205487231 Dec  3 17:35 chr10.tped
-rw-r--r--  1 cremer C020 192067641 Dec  3 17:37 chr11.tped
-rw-r--r--  1 cremer C020 192243483 Dec  3 17:38 chr12.tped

etc
 
A workaround I found now is to start R in the respective directory from the 
command line, which will set working directory to current directory. list.files 
will work then too:

list.file(.,pattern=\\.tped)

The problem now is to start a script via R CMD BATCH from a different 
directory, because setwd() will not work:

 datapath-'/nfs/home/m/cremer/gaw/data/traws_chrs/'

 getwd()
[1] /nfs/home/m/cremer/gaw/code/plink

 setwd(datapath)
Error in setwd(datapath) : cannot change working directory
Execution halted
   
Lars

 Original-Nachricht 
 Datum: Thu, 04 Dec 2008 10:58:16 -0600
 Von: Marc Schwartz [EMAIL PROTECTED]
 An: Lars Beckmann [EMAIL PROTECTED]
 CC: r-help@r-project.org
 Betreff: Re: [R] setwd and list.files / linux

 on 12/04/2008 10:38 AM Lars Beckmann wrote:
  Hey,
  
  two questions regarding setwd and list.files:
  
  I try to use the function list.files:
  
  datapath-'/nfs/home/m/cremer/gaw/data/traws_chrs'
  
  fl-list.files(datapath, pattern=\\.tped)
  
  but I get the following error message:
  
  Warning message:
  In list.files(datapath, pattern = \\.tped) :
list.files: '/nfs/home/m/cremer/gaw/data/traws_chrs/' is not a
 readable directory
  fl
  character(0)
  
  The use of setwd also does not work:
  
  setwd(datapath)
  Error in setwd(datapath) : cannot change working directory
  
  
  datapath exists and it doesn't matter whether I use single quotes ' or
 double quotes 
  
  Any help?
  
  Lars
 
 You do not have read privileges to the path in question. Either you or
 your SysAdmin will have to grant the appropriate privileges so that you
 can read the files in the path.
 
 HTH,
 
 Marc Schwartz
 
 __
 R-help@r-project.org 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.

-- 
Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a

__
R-help@r-project.org 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] help needed

2008-12-05 Thread gauravbhatti

 I need some help in comparing t values avalaible from two data frames. I
have two data frames with each containing a column for t valuse
For example one data frame looks like as follows
  IDlogFCt   P.Value  adj.P.Val
B
39   a39 -1.737037118 -2.861784118 0.004212637 0.3120295 -2.504407
1 a1 -1.66000 -2.734864780 0.006240591 0.3120295 -2.729203
53   a53  1.443725119  2.378549988 0.017380880 0.4517324 -3.305806
52   a52 -1.323602459 -2.180646836 0.029209548 0.4517324 -3.591351
14   a14 -1.288769209 -2.123258747 0.033732176 0.4517324 -3.669516
58   a58  1.286212422  2.119046418 0.034086544 0.4517324 -3.675172
75   a75 -1.268523811 -2.089904273 0.036626400 0.4517324 -3.713989

I have another one like it but the order of the ID column is different as
shown below
  IDlogFCt   P.Value  adj.P.Val
B
76   a1   0.157096693 -0.258818201 0.795775514 0.9146845 -5.075035
63   a53 -0.146205781 -0.240875326 0.809651746 0.9200588 -5.077872
88   a58  0.108707988  0.179097379 0.857861240 0.9638890 -5.086083
23   a52 -0.086871304 -0.143121247 0.886194425 0.9757266 -5.089752
98   a53  0.085552023  0.140947720 0.887911243 0.9757266 -5.089947
90   a14  0.068456451  0.112782613 0.910202903 0.9868965 -5.092209
91   a75 -0.052087970 -0.085815394 0.931613169 0.9868965 -5.093904

I have to plot the t values  obtained for each id against each other. Since
the order of the IDs in the two data frames is different , I am finding it
difficult to plot the t values. Can anyone help in arranging the t values in
the increasing order of the ID values like 
1 a1 ..
2 a2 ..
2 a3 .. 
Thank you
-- 
View this message in context: 
http://www.nabble.com/help-needed-tp20849087p20849087.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] help needed

2008-12-05 Thread Jim Lemon

gauravbhatti wrote:

...
I have to plot the t values  obtained for each id against each other. Since
the order of the IDs in the two data frames is different , I am finding it
difficult to plot the t values. Can anyone help in arranging the t values in
the increasing order of the ID values like 
1 a1 ..

2 a2 ..
2 a3 .. 
  


Hi gauravbhatti,
Try this (assuming your data frame is named gvb):

gvb[order(as.character(gvb[,1])),]

Jim

__
R-help@r-project.org 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] Seasonality in time series

2008-12-05 Thread Matthias

Hi,
I?m looking for a package which includes a test for seasonality in time 
series.

Any help and input would be greatly appreciated.
Thanks,
Matthias

__
R-help@r-project.org 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.


Re: [R] Changing 'record' option in open graphics device

2008-12-05 Thread Prof Brian Ripley

On Thu, 4 Dec 2008, Andrew Hooker wrote:


Hi,



I am wondering if there is a way to change the value of the record option
in a graphics device that is already open (and accepts this option).  I
don't want to open a new device with, for example dev.new(record=T), but
just want to change the settings of the current device.  This can be done by
pointing and clicking on the history tab of a graphics device in windows,
but I would like to do this in a script.


1) AFAIK only one device, windows(), accepts this.
2) That device has no way to do this from R code.


Best regards,

Andy



Andrew Hooker, Ph.D.
Associate Professor of Pharmacometrics
Div. of Pharmacokinetics and Drug Therapy
Dept. of Pharmaceutical Biosciences
Uppsala University
Box 591, 751 24, Uppsala, Sweden
Phone: +46 18 471 4355
Mobile: +46 701 679 048

http://www.farmbio.uu.se/research.php?avd=5
www.farmbio.uu.se/research.php?avd=5

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.



PLEASE do: double-spaced text is unfriendly and is undoubtedly caused by 
sending HTML when asked not to.


--
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

__
R-help@r-project.org 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] Lexical Permutation Algorithm in R

2008-12-05 Thread Rory.WINSTON
Hi all

Here is a rather naive implementation of the SEPA algorithm for generating 
lexical permutations:


lexperm3 - function(x, n=length(x)) {
 perms - list()
 k - 1
 perms[[k]] - x
 k - k + 1

 for (y in 1:(factorial(n)-1)) {
  i - n-1
  while (x[i]  x[i+1]  i  0) {
   i - i - 1
  }

  # i is largest index st x[i]  x[i+1]
  j - n

  # find min{ x[j], st n=j=i+1 and x[j]x[i] }
  while (x[j] = x[i]  j  i) {
   j - j - 1
  }

  # swap x[i] and x[j]
  tmp - x[i];x[i] - x[j]; x[j] - tmp

  # now sort everything from x[i+1]..x[n]
  # by reversing the elements within
  p - i + 1
  q - n
  while (p  q) {
   tmp - x[p]; x[p] - x[q]; x[q] - tmp
   p - p + 1
   q - q - 1
  }

  perms[[k]] - x
  k - k + 1
 }

 perms
}


This, as you can imagine, is severely slow. I would like to speed up this 
function if possible, which I guess would involve vectorizing the inner 
loop..does anyone have any ideas about how to improve this code's runtime?

One small potential optimization I tried was to shorten the sort by reverse 
ordering near the end of the inner loop : I tried replacing it with rev() and 
sort(decreasing=TRUE) over a partial subset of the x vector: however rev() was 
much slower, and I dont think sort() supports lexicographic ordering, so that 
didnt work.

Thanks
rory

Rory Winston
RBS Global Banking  Markets
280 Bishopsgate, London, EC2M 4RB
Office: +44 20 7085 4476



***
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered 
Office: 36 St Andrew Square, Edinburgh EH2 2YB. 
Authorised and regulated by the Financial Services Authority 

This e-mail message is confidential and for use by the=2...{{dropped:25}}

__
R-help@r-project.org 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.


Re: [R] Seasonality in time series

2008-12-05 Thread GR
Here's something that may help you get started:
library(ts)
?decompose
?stl

Thanks,
-Girish

On Dec 5, 1:55 pm, Matthias [EMAIL PROTECTED] wrote:
 Hi,
 I?m looking for a package which includes a test for seasonality in time
 series.
 Any help and input would be greatly appreciated.
 Thanks,
 Matthias

 __
 [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org 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.


Re: [R] Strplit code

2008-12-05 Thread John Fox
Dear Wacek,

I've thought a bit more about this problem, and recall that I originally
wrote Strsplit() [and replacements for sub() and gsub(), which were not then
in S-PLUS] for the version of the car package that I released for S-PLUS,
because other functions in the package used these. The strings involved were
small, so performance issues weren't that important, although of course it's
better to have a more efficient solution.

Although I no longer have an installed copy of S-PLUS to confirm this, I
believe that gregexepr() is still not present in S-PLUS (though I think that
strsplit() is in the latest version). If that's the case, then your function
wouldn't work at all in the context of the original posting, which asked for
a solution in S-PLUS. You could make your code work in S-PLUS, and probably
still have it more efficient than mine, by writing a replacement for
gregexpr().

 -Original Message-
 From: Wacek Kusnierczyk [mailto:[EMAIL PROTECTED]
 Sent: December-04-08 7:29 AM
 To: John Fox
 Cc: R help
 Subject: Re: [R] Strplit code
 
 John Fox wrote:
  Dear Wacek,
 
  Wrong is a bit strong, I think -- limited to single-pattern characters
is
  more accurate.
 
 nothing is ever wrong if seen from an appropriate perspective.  for
 example, there is nothing wrong in that many core functions in r deparse
 some, but not all, of the argument expressions, without any obvious
 pattern -- when you get used to it and learn each single case by heart,
 it's perfectly correct.
 
 
  Moreover, it isn't hard to make the function work with
  multiple-character matches as well:
 
 
 which you probably should have done before posting the flawed version.

Indeed. Had I anticipated the possibility of multiple-character splits I
would have done so.

John

 
  Strsplit - function(x, split){
  if (length(x)  1) {
  return(lapply(x, Strsplit, split))  # vectorization
  }
  result - character(0)
  if (nchar(x) == 0) return(result)
  posn - regexpr(split, x)
  if (posn = 0) return(x)
  c(result, substring(x, 1, posn - 1),
  Recall(substring(x, posn + attr(posn, match.length),
nchar(x)), split))  # recursion
  }
 
  On the other hand, your function is much more efficient.
 
 
 just one order of magnitude in my tests.  might not be completely fool
 proof, though.
 
 vQ

__
R-help@r-project.org 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.


Re: [R] Lexical Permutation Algorithm in R

2008-12-05 Thread Robin Hankin

Rory

there are several packages that perform this.

I would use permn() of the  combinat library, then, if
lexicographical order is important, sort it  explicitly.

HTH

rksh



[EMAIL PROTECTED] wrote:

Hi all

Here is a rather naive implementation of the SEPA algorithm for generating 
lexical permutations:


lexperm3 - function(x, n=length(x)) {
 perms - list()
 k - 1
 perms[[k]] - x
 k - k + 1

 for (y in 1:(factorial(n)-1)) {
  i - n-1
  while (x[i]  x[i+1]  i  0) {
   i - i - 1
  }

  # i is largest index st x[i]  x[i+1]
  j - n

  # find min{ x[j], st n=j=i+1 and x[j]x[i] }
  while (x[j] = x[i]  j  i) {
   j - j - 1
  }

  # swap x[i] and x[j]
  tmp - x[i];x[i] - x[j]; x[j] - tmp

  # now sort everything from x[i+1]..x[n]
  # by reversing the elements within
  p - i + 1
  q - n
  while (p  q) {
   tmp - x[p]; x[p] - x[q]; x[q] - tmp
   p - p + 1
   q - q - 1
  }

  perms[[k]] - x
  k - k + 1
 }

 perms
}


This, as you can imagine, is severely slow. I would like to speed up this 
function if possible, which I guess would involve vectorizing the inner 
loop..does anyone have any ideas about how to improve this code's runtime?

One small potential optimization I tried was to shorten the sort by reverse 
ordering near the end of the inner loop : I tried replacing it with rev() and 
sort(decreasing=TRUE) over a partial subset of the x vector: however rev() was much 
slower, and I dont think sort() supports lexicographic ordering, so that didnt work.

Thanks
rory

Rory Winston
RBS Global Banking  Markets
280 Bishopsgate, London, EC2M 4RB
Office: +44 20 7085 4476



***
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. 
Authorised and regulated by the Financial Services Authority 


This e-mail message is confidential and for use by the=2...{{dropped:25}}

__
R-help@r-project.org 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.
  



--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877

__
R-help@r-project.org 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.


Re: [R] Strplit code

2008-12-05 Thread Wacek Kusnierczyk
John Fox wrote:
 Dear Wacek,

 I've thought a bit more about this problem, and recall that I originally
 wrote Strsplit() [and replacements for sub() and gsub(), which were not then
 in S-PLUS] for the version of the car package that I released for S-PLUS,
 because other functions in the package used these. The strings involved were
 small, so performance issues weren't that important, although of course it's
 better to have a more efficient solution.
   

right.  the speedup is not due to any substantial algorithmic
difference, but rather in that your code is r code, while mine uses
gregexpr, which is i assume is precompiled from c code or the like.

about 'wrong' and 'flawed', again:  what i meant is that as a suggestion
for how strsplit, in general, could be written, it doesn't meet the
challenge, and should at least issue a warning if the split pattern
specifies non-1-length splits.  otherwise, it could be perfectly fit for
a student's exercise.

 Although I no longer have an installed copy of S-PLUS to confirm this, I
 believe that gregexepr() is still not present in S-PLUS (though I think that
 strsplit() is in the latest version). If that's the case, then your function
 wouldn't work at all in the context of the original posting, which asked for
 a solution in S-PLUS. You could make your code work in S-PLUS, and probably
 still have it more efficient than mine, by writing a replacement for
 gregexpr().

possibly, and then it's my code that is wrong and flawed ;)
i haven't used s-plus for ages, jumping to the global frame instead of
lexical scoping scared me away.

vQ

__
R-help@r-project.org 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] constructing a relative path

2008-12-05 Thread Mark Heckmann
Dear R-users,

I want to construct a relative path in R, but I am not able to do it or to
find a function that does it.
My solution is somewhat awkward as it uses string manipulation.

The problem: I have the following folder structure. 

project_folder
   |
   |- data
   |- scripts
   |- output

My working directory is the scripts folder.
Now I want to construct a relative path to the data folder.

Is there an easy way or a function?

TIA

Mark

__
R-help@r-project.org 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.


Re: [R] constructing a relative path

2008-12-05 Thread Prof Brian Ripley

On Fri, 5 Dec 2008, Mark Heckmann wrote:


Dear R-users,

I want to construct a relative path in R, but I am not able to do it or to
find a function that does it.
My solution is somewhat awkward as it uses string manipulation.

The problem: I have the following folder structure.

project_folder
  |
  |- data
  |- scripts
  |- output

My working directory is the scripts folder.
Now I want to construct a relative path to the data folder.

Is there an easy way or a function?


file.path(.., data)

should work on any R platform (actually ../data will on any current R 
platform).


--
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

__
R-help@r-project.org 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] Trouble with gridBase and inset plots

2008-12-05 Thread Lorenzo Isella
Dear All,
I ma having a trouble in generating a figure containing 3 insets with
the gridBase package.
I always get an error message of the kind:

Error in gridPLT() : Figure region too small and/or viewport too large

No matter which parameters I choose. The plots works nicely with two
insets only, but when I try adding the third one, my troubles begin.
I am probably doing something wrong in the generation of the 3rd inset
and I paste below everything I do in this (a bit complicated) figure.
Any suggestion is welcome.
Cheers

Lorenzo


pdf(./post-processing-plots/exploratory_research_figure_2.pdf)
par( mar = c(4.5,5, 2, 1) + 0.1)
plot(time[1:time_end],tot_num_150[1:time_end]/1e6,type=b,lwd=2,col=blue,lty=2,
 xlab=expression(paste(tau,[s])),
 ylab=expression(paste(N[,
cm^{-3},])),cex.lab=1.6,ylim=range(c(7.4e7,1.43e8)),yaxt=n,cex.axis=1.4)
#lines(time[1],ini_pop/1e6, p,col=red,lwd=2,lty=1,pch=5 )
lines(time[time_end],8.25e7, p,col=red,lwd=2,lty=1,pch=5)

axis(side=2, at=c( 7.4e7, 9.6e7, 1.18e8, 1.4e8),
labels=expression(7.4%*%10^7, 9.6%*%10^7,
1.18%*%10^8,1.4%*%10^8),cex.lab=1.6,cex.axis=1.4)
#axis(side=1,cex.axis=1.4)
## lines(time[1:time_end],
N_approx[1:time_end],col=red,type=b,lwd=2,lty=1,pch=4)
## lines(time[1:time_end],
N_approx2[1:time_end],col=black,type=b,lwd=2,lty=1,pch=2)
## lines(time[1:time_end],
N_approx_beta1[1:time_end,2],col=brown,type=b,lwd=2,lty=1,pch=5)
legend(topright,cex=1.2, c(expression(Simulation),
expression(Outlet measurement)),
lwd=c(2,2),lty=c(2,0),pch = c(1,5),col=c(blue, red),box.lwd=0,box.lty=0,
,xjust = 1, yjust = 1)
# abline(v=time[12],lwd=2,pch=2,lty=2)
lines(c(time[14],time[14]), c(0,1.2e8),lwd=2,lty=2,pch=2)
# legend(-0.2,9.2e7,cex=1.2,c(expression(numerical result for a
5m-long pipe)),bty=n)
 arrows(0.8, 9e7, time[14], tot_num_150[14]/1e6, length = 0.15,lwd=2)
text(0.8,8.8e7,cex=1.2,Final concentration for a)
text(0.8,8.5e7,cex=1.2,6.5m long transfer tube (LAT))

text(0.8,8e7,cex=1.2,Final concentration for a)
text(0.68,7.7e7,cex=1.2,9m long transfer tube)
text(0.8,7.4e7,cex=1.2,(VELA))

text(1.3,1.24e8,cex=1.2,Residence time for)
text(1.3,1.21e8,cex=1.2,a 6.5m long transfer tube)


arrows(1.1, 7.7e7, time[21], 7.7e7, length = 0.,lwd=2)
arrows( time[21], 7.7e7, time[21], tot_num_150[21]/1e6, length = 0.15,lwd=2)



par( mar = c(0.,0., 0., 0.) )


#1st inset

vp - baseViewports()
   pushViewport(vp$inner,vp$figure,vp$plot)
   pushViewport(viewport(x=-0.0,y=1.04,width=.4,height=.4,just=c(0,1)))

   par(fig=gridPLT(),new=F)

#grid.rect(gp=gpar(lwd=0,col=red))

   plot(D_mean,data_150[1, ]/log_factor*log(10)/1e6,l,
pch=1,col=black, lwd=2,xlab=,ylab=
,cex.axis=1.,cex.lab=1.,log=x,xaxt=n,yaxt=n,
ylim=range(c(0, 2.4e8)))

## axis(side=2, at=c( 0, 0.6e8, 1.2e8, 1.8e8, 2.4e8),
## labels=expression(0, 6%*%10^7, 1.2%*%10^8,
1.8%*%10^8,2.4%*%10^8),cex.lab=1.4,cex.axis=1.2)


#2nd inset

#vp - baseViewports()
   pushViewport(vp$inner,vp$figure,vp$plot)
   pushViewport(viewport(x=0.5,y=0.65,width=.4,height=.4,just=c(0,1)))

   par(fig=gridPLT(),new=F)

#grid.rect(gp=gpar(lwd=0,col=red))

   plot(D_mean,data_150[21, ]/log_factor*log(10)/1e6,l,lwd=2,
pch=1,col=black,xlab=,ylab=, log=x
,cex.axis=1.4,cex.lab=1.6,xaxt=n,yaxt=n,ylim=range(c(0, 2.4e8)))



#3rd inset

#vp - baseViewports()
   pushViewport(vp$inner,vp$figure,vp$plot)
   pushViewport(viewport(x=0.25,y=0.7,width=.4,height=.4,just=c(0,1)))

   par(fig=gridPLT(),new=T)

#grid.rect(gp=gpar(lwd=0,col=red))

   plot(D_mean,data_150[14, ]/log_factor*log(10)/1e6,l,lwd=2,
pch=1,col=black,xlab=,ylab=, log=x
,cex.axis=1.4,cex.lab=1.6,xaxt=n,yaxt=n,ylim=range(c(0, 2.4e8)))


popViewport(3)


dev.off()

__
R-help@r-project.org 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] Logical inconsistency

2008-12-05 Thread emma jane
Dear colleagues

Please could someone kindly explain the following inconsistencies I've 
discovered when performing logical calculations in R:

8.8 - 7.8  1
 TRUE

8.3 - 7.3  1
 TRUE

Thank you,

Emma Jane



  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Logical inconsistency

2008-12-05 Thread Chuck Cleland
On 12/5/2008 7:23 AM, emma jane wrote:
 Dear colleagues
 
 Please could someone kindly explain the following inconsistencies I've 
 discovered when performing logical calculations in R:
 
 8.8 - 7.8  1
 TRUE
 
 8.3 - 7.3  1
 TRUE

  See R FAQ 7.31
(http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f).

 Thank you,
 
 Emma Jane
   
   [[alternative HTML version deleted]]
 
 
 
 __
 R-help@r-project.org 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@r-project.org 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.


Re: [R] Logical inconsistency

2008-12-05 Thread Berwin A Turlach
Dear Emma,

On Fri, 5 Dec 2008 04:23:53 -0800 (PST)
emma jane [EMAIL PROTECTED] wrote:
 
 Please could someone kindly explain the following inconsistencies
 I've discovered__when performing logical calculations in R:
 
 8.8 - 7.8  1
  TRUE
 
 8.3 - 7.3  1
  TRUE

Gladly:  FAQ 7.31
http://cran.at.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
R-help@r-project.org 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] How to retrieve a method

2008-12-05 Thread Christian Hoffmann

Hi there,

I am interested in the inner workings of wilcox.test:

 wilcox.test
function (x, ...)
UseMethod(wilcox.test)
environment: namespace:stats

how can I get at the code, if it is R-code? For Methods one should be able to 
learn what extension to use, but here default or such do not help.

Is there a wayplot.default to learn which different versions of plot there 
are except trying plot.lm,  ...

best

-c

--
Dr. Christian W. Hoffmann,
Swiss Federal Research Institute WSL
Zuercherstrasse 111, CH-8903 Birmensdorf, Switzerland 
Tel +41-44-7392-277 (office), -111(exchange), -215  (fax)

[EMAIL PROTECTED],  www.wsl.ch/personal_homepages/hoffmann/
Jene, die grundlegende Freiheit aufgeben wuerden, um eine geringe voruebergehende 
Sicherheit zu erwerben, verdienen weder Freiheit noch Sicherheit. - Benjamin 
Franklin


--
Christian W. Hoffmann,
Rigiblickstrasse 15 b, CH-8915Hausen am Albis, Switzerland,
Tel +41-44-7640853, [EMAIL PROTECTED]

__
R-help@r-project.org 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] levels update

2008-12-05 Thread Antje

Hello,

I hope this question is not too stupid. I would like to know how to update 
levels after subsetting data from a data.frame.


df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4))
names(df) - c(X1,X2,X3)

my.sub - subset(df, X1 == a | X1 == b)
levels(my.sub$X1)

# still gives me a,b,c, though the subset does not contain entries with 
c anymore


I guess, the solution is rather simple, but I cannot find it.

Antje

__
R-help@r-project.org 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] Quantile Regression for longitudinal data

2008-12-05 Thread axionator
Hi all,
does anybody know about R implementations for quantile regression for
longitudinal data? I am just aware of a very basic version of R.
Koenker's approach using fixed effects.

Thanks in advance
Armin

__
R-help@r-project.org 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] Comparing survival curves with survdiff strata help

2008-12-05 Thread Richardson, Patrick
ExpeRts,

I'm trying to compare three survival curves using the function survdiff in 
the survival package.  Following is my code and corresponding error message.
 survdiff(Surv(st_months, status) ~ strata(BOR), data=mydata)
Error in survdiff(Surv(st_months, status) ~ strata(BOR), data = mydata) :
  No groups to test

When I check the strata of the variable.  I get . . .
 strata(BOR)
Levels: BOR=PD BOR=PR BOR=SD

So I know there are levels associated with the BOR variable, but I can't seem 
to get the strata statement to work within survdiff.  I checked ?strata and 
(unless I am not understanding) the help, it seems to be working as I get the 
following output
 levels(strata(BOR))
[1] BOR=PD BOR=PR BOR=SD

I can get the survival tables and KM plot with no problem, but I can't seem to 
be able to compare the survival curves.  I can get an overall comparison if I 
remove the strata statement
 survdiff(Surv(st_months, status) ~ BOR, data=mydata)
Call:
survdiff(formula = Surv(st_months, status) ~ BOR, data = mydata)

n=35, 5 observations deleted due to missingness.

N Observed Expected (O-E)^2/E (O-E)^2/V
BOR=PD 13   13 6.51 6.464  8.87
BOR=PR 10   1018.48 3.888 10.59
BOR=SD 12   1210.01 0.395  0.61

 Chisq= 13.5  on 2 degrees of freedom, p= 0.00117

But when I use survdiff(Surv(st_months, status) ~ strata(BOR), data=mydata)  it 
doesn't want to work.  Any suggestions?

Many thanks for your assistance!


_
Patrick Richardson
Biostatistician - Program of Translational Medicine
Van Andel Research Institute - Webb Lab
333 Bostwick Avenue NE
Grand Rapids, MI  49503

This email message, including any attachments, is for th...{{dropped:9}}

__
R-help@r-project.org 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.


Re: [R] levels update

2008-12-05 Thread jim holtman
try this:

 df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4))
 names(df) - c(X1,X2,X3)

 my.sub - subset(df, X1 == a | X1 == b)
 levels(my.sub$X1)
[1] a b c
 my.sub$X1 - factor(my.sub$X1)
 levels(my.sub$X1)
[1] a b



On Fri, Dec 5, 2008 at 7:50 AM, Antje [EMAIL PROTECTED] wrote:
 Hello,

 I hope this question is not too stupid. I would like to know how to update
 levels after subsetting data from a data.frame.

 df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4))
 names(df) - c(X1,X2,X3)

 my.sub - subset(df, X1 == a | X1 == b)
 levels(my.sub$X1)

 # still gives me a,b,c, though the subset does not contain entries
 with c anymore

 I guess, the solution is rather simple, but I cannot find it.

 Antje

 __
 R-help@r-project.org 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org 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.


Re: [R] complex(?) reshaping question

2008-12-05 Thread hadley wickham
 I'm trying to omit NA:s in this DF and produce a reduced DF. The
 problem is that I cannot completely omit NA rows.

 I tried

 library(reshape)
 g - melt(DF, id=c(idvar1, idvar2))
 g - na.omit(g)

You're missing an id variable:

DF$idvar3 - 1:2
g - melt(DF, id=c(idvar1, idvar2, idvar3), na.rm = T)
cast(g, idvar1 + idvar2 + idvar3 ~ variable)

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org 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.


Re: [R] levels update

2008-12-05 Thread Erich Neuwirth
I do the following for a subsetted dataframe:

cleanfactors - function(mydf){
  outdf-mydf
  for (i in 1:dim(mydf)[2]){
if (is.factor(mydf[,i]))
  outdf[,i]-factor(mydf[,i])
  }
outdf
}


Antje wrote:
 Hello,
 
 I hope this question is not too stupid. I would like to know how to
 update levels after subsetting data from a data.frame.
 
 df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8),
 c(9,1,2,3,4))
 names(df) - c(X1,X2,X3)
 
 my.sub - subset(df, X1 == a | X1 == b)
 levels(my.sub$X1)
 
 # still gives me a,b,c, though the subset does not contain entries
 with c anymore
 
 I guess, the solution is rather simple, but I cannot find it.
 
 Antje
 
 __
 R-help@r-project.org 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.
 
 
 
 
 
 No virus found in this incoming message.
 Checked by AVG - http://www.avg.com 
 Version: 8.0.176 / Virus Database: 270.9.14/1831 - Release Date: 12/4/2008 
 9:55 PM
 

-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

__
R-help@r-project.org 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.


Re: [R] How to retrieve a method

2008-12-05 Thread Prof Brian Ripley

On Fri, 5 Dec 2008, Christian Hoffmann wrote:


Hi there,

I am interested in the inner workings of wilcox.test:


wilcox.test

function (x, ...)
UseMethod(wilcox.test)
environment: namespace:stats

how can I get at the code, if it is R-code? For Methods one should be able to 
learn what extension to use, but here default or such do not help.


Is there a wayplot.default to learn which different versions of plot there 
are except trying plot.lm,  ...


methods(wilcox.test)
getS3method(wilcox.test, default)

Uwe Ligges wrote an article in R-News about this in issue 6(4), although 
this particular usage (the most general for S3 methods) seems not to be 
there.


[Note for the cognescenti:  the S3 method for function foo() of class bar 
need not be foo.bar() if no such function is visible and registration was 
used.  I'm not aware of any public package that does that though.]




best

-c

--
Dr. Christian W. Hoffmann,
Swiss Federal Research Institute WSL
Zuercherstrasse 111, CH-8903 Birmensdorf, Switzerland Tel +41-44-7392-277 
(office), -111(exchange), -215  (fax)

[EMAIL PROTECTED],  www.wsl.ch/personal_homepages/hoffmann/
Jene, die grundlegende Freiheit aufgeben wuerden, um eine geringe 
voruebergehende Sicherheit zu erwerben, verdienen weder Freiheit noch 
Sicherheit. - Benjamin Franklin



--
Christian W. Hoffmann,
Rigiblickstrasse 15 b, CH-8915Hausen am Albis, Switzerland,
Tel +41-44-7640853, [EMAIL PROTECTED]


--
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

__
R-help@r-project.org 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.


Re: [R] levels update

2008-12-05 Thread hadley wickham
On Fri, Dec 5, 2008 at 6:50 AM, Antje [EMAIL PROTECTED] wrote:
 Hello,

 I hope this question is not too stupid. I would like to know how to update
 levels after subsetting data from a data.frame.

 df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4))
 names(df) - c(X1,X2,X3)

 my.sub - subset(df, X1 == a | X1 == b)
 levels(my.sub$X1)

 # still gives me a,b,c, though the subset does not contain entries
 with c anymore

 I guess, the solution is rather simple, but I cannot find it.

You might find it easier just to work with character vectors:

options(stringsAsFactors = FALSE)

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org 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.


Re: [R] levels update

2008-12-05 Thread Prof Brian Ripley

On Fri, 5 Dec 2008, jim holtman wrote:


try this:


df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4))
names(df) - c(X1,X2,X3)

my.sub - subset(df, X1 == a | X1 == b)
levels(my.sub$X1)

[1] a b c

my.sub$X1 - factor(my.sub$X1)


I find

my.sub$X1 - my.sub$X1[drop=TRUE]

a lot more self-explanatory.  See ?[.factor.  However, if you find 
yourself wanting to do this, ask why you have a factor (rather than a 
character vector) in the first place.




levels(my.sub$X1)

[1] a b





On Fri, Dec 5, 2008 at 7:50 AM, Antje [EMAIL PROTECTED] wrote:

Hello,

I hope this question is not too stupid. I would like to know how to update
levels after subsetting data from a data.frame.

df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4))
names(df) - c(X1,X2,X3)

my.sub - subset(df, X1 == a | X1 == b)
levels(my.sub$X1)

# still gives me a,b,c, though the subset does not contain entries
with c anymore

I guess, the solution is rather simple, but I cannot find it.

Antje

__
R-help@r-project.org 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.





--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org 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.



--
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

__
R-help@r-project.org 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.


Re: [R] Logical inconsistency

2008-12-05 Thread Wacek Kusnierczyk
Berwin A Turlach wrote:
 Dear Emma,

 On Fri, 5 Dec 2008 04:23:53 -0800 (PST)
 emma jane [EMAIL PROTECTED] wrote:
  
   
 Please could someone kindly explain the following inconsistencies
 I've discovered__when performing logical calculations in R:

 8.8 - 7.8  1
 
 TRUE
   
 8.3 - 7.3  1
 
 TRUE
   

 Gladly:  FAQ 7.31
 http://cran.at.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

   

well, this answer the question only partially.  this explains why a
system with finite precision arithmetic, such as r, will fail to be
logically correct in certain cases.  it does not explain why r, a
language said to isolate a user from the underlying implementational
choices, would have to fail this way. 

there is, in principle, no problem in having a high-level language
perform the computation in a logically consistent way.  for example, bc
is an arbitrary precision calculator language, and has no problem with
examples as the above:

bc  8.8 - 7.8  1
# 0, meaning 'no'

bc  8.3 - 7.3  1
# 0, meaning 'no'

bc  8.8 - 7.8 == 1
# 1, meaning 'yes'


the fact that r (and many others, including matlab and sage, perhaps not
mathematica) does not perform logically here is a consequence of its
implementation of floating point arithmetic. 

the faq you were pointed to, and its referring to the goldberg's
article, show that r does not successfully isolate a user from details
of the lower-level implementation.

vQ

__
R-help@r-project.org 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] Cartesian Product Of Character Vectors

2008-12-05 Thread Rory.WINSTON
Hi all

(I'm sure this question has been asked before, but I cant find it).

If I have two character vectors:

 x - c(aaa,bbb,ccc)
 y - c(1,2,3)

How can I get the cartesian product of the string values?

 expand.grid(x,y)

Gives me a data frame with separate columns...however, I cant seem to get 
*apply to paste the column values together.

Thanks
Rory

Rory Winston
RBS Global Banking  Markets
280 Bishopsgate, London, EC2M 4RB
Office: +44 20 7085 4476



***
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered 
Office: 36 St Andrew Square, Edinburgh EH2 2YB. 
Authorised and regulated by the Financial Services Authority 

This e-mail message is confidential and for use by the=2...{{dropped:25}}

__
R-help@r-project.org 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] Loop swith String replacement

2008-12-05 Thread Michael Pearmain
Hi All,
I'm trying to split my dataset, into multiple datasets that i'll analyse
later, i wanted to do this dynamically as i might need to rerun the code
later.
I was looking at doing this via a loop, (Are other methods more appropriate?
Would a function be better?)

However i'm not sure in R how do do string replacement within the loop in
order to create unique dataset names based on the number of 'Groups' i have

Many thanks

Mike

my code is as follows:

no.groups -names(table(Conv$Group))
for (i in length(Conv$no.groups))
{
groupi - subset(Conv, Conv$Group == i)
}


  Metal  Secs  cost Income stable Group
1   Chrome   6014  3.3458  1 2
2   Chrome   5110  1.8561  0 1
3   Chrome   2412  0.6304  0 1
4   Chrome   38 8  3.4183  1 2
5   Chrome   2512  2.7852  1 3
6   Chrome   6712  2.3866  1 1
7   Chrome   4012  4.2857  0 1
8   Chrome   5610  9.3205  1 1
9   Chrome   3212  3.8797  1 3
10  Chrome   7516  2.7031  1 3
11  Chrome   4615 11.2307  1 2
12  Chrome   5212  8.6696  1 2
13  Chrome   2212  1.7443  0 2
14  Chrome   6012  0.2253  0 2
15  Chrome   2414  4.3348  1 3




-- 
Michael Pearmain
Senior Analytics Research Specialist


Google UK Ltd
Belgrave House
76 Buckingham Palace Road
London SW1W 9TQ
United Kingdom
t +44 (0) 2032191684
[EMAIL PROTECTED]

If you received this communication by mistake, please don't forward it to
anyone else (it may contain confidential or privileged information), please
erase all copies of it, including all attachments, and please let the sender
know it went to the wrong person. Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Changing order of x factor in interaction plot

2008-12-05 Thread Kota Hattori
Hi all,

I would like to ask one simple question. I wanna know how
you can ask R to change the order of x factor when you draw
interaction plot. I find that R puts factors in an alphabetic
order (e.g., dog, lamb, and monkey etc). But I simply want to
control the order. How can I do this?

Aloha,
Kota

__
R-help@r-project.org 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.


Re: [R] Changing order of x factor in interaction plot

2008-12-05 Thread jim holtman
Check out the 'levels' option on 'factor'

On Fri, Dec 5, 2008 at 8:32 AM, Kota Hattori [EMAIL PROTECTED] wrote:
 Hi all,

 I would like to ask one simple question. I wanna know how
 you can ask R to change the order of x factor when you draw
 interaction plot. I find that R puts factors in an alphabetic
 order (e.g., dog, lamb, and monkey etc). But I simply want to
 control the order. How can I do this?

 Aloha,
 Kota

 __
 R-help@r-project.org 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org 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] legend at fixed distance form the bottom

2008-12-05 Thread Christophe Genolini

Hi the list

I would like to add a legend under a graph but at a fixed distance from 
the graphe. Is it possible ?

More precisely, here is my code :

--- 8 
symboles - c(3,4,5,6)
dn - rbind(matrix(rnorm(20),,5),matrix(rnorm(20,2),,5))
listSymboles - rep(symboles,each=2)
matplot(t(dn),pch=listSymboles,type=b)
legend(bottom, pch = unique(listSymboles), legend = c(ane, cheval, 
poney, mule), inset = c(0,-0.175), horiz = TRUE, xpd = NA)

--- 8 

But when I change the size of the graph, the legend is misplaced.

Instead, I try to put some text in xlab, but I do not know how to get 
the +, x , V and other symbol.

Does anyone got a solution ?

Thanks a lot.

Christophe

__
R-help@r-project.org 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.


Re: [R] How to get Greenhouse-Geisser epsilons from anova?

2008-12-05 Thread Skotara

Dear Mr. Daalgard.

thank you very much for your reply, it helped me to progress a bit.

The following works fine:
dd - expand.grid(C = 1:7, B= c(r, l), A= c(c, f))
myma - as.matrix(myma) #myma is a 12 by 28 list
mlmfit - lm(myma~1)
mlmfit0 - update(mlmfit, ~0)
anova(mlmfit, mlmfit0, X= ~C+B, M = ~A+C+B, idata = dd,  
test=Spherical), which tests the main effect of A.
anova(mlmfit, mlmfit0, X= ~A+C,  M = ~A+C+B, idata = dd,  
test=Spherical), which tests the main effect of B.



However, I can not figure out how this works for the other effects.
If I try:
anova(mlmfit, mlmfit0, X= ~A+B,  M = ~A+C+B, idata = dd,  test=Spherical)

I get:
Fehler in function (object, ..., test = c(Pillai, Wilks, 
Hotelling-Lawley,  :

   residuals have rank 1  4

I also don't know how I can calculate the various interactions..
My read is I should change the second argument mlmfit0, too, but I can't 
figure out how...


Do you know what to do?
Thank you very much!



Peter Dalgaard schrieb:

Skotara wrote:

Dear all,

I apologize for my basic question.
I try to calculate an anova for repeated measurements with 3 factors 
(A,B,C) having 2, 2, and 7 levels.

or with an additional fourth between subjects factor D.
Everything works fine using
aov(val ~ A*B*C  + Error(subject/ (A*B*C) ) )  or
aov(val ~ (D*A*B*C)  + Error(subject/(A*B*C)) + D )
val, A, B, C, D and subject are columns in a data.frame.

How can I get the estimated Greenhouse-Geisser and Huynh-Feldt epsilons?
I know Peter Dalgaard described it in R-News Vol. 7/2, October 2007. 
However, unfortunately I am not able to apply that using my data...


Why? It is supposed to work. You just need to work out the X and M 
specification for the relevant error strata and set test=Spherical 
for anova.mlm, or work out the T contrast matrix explicitly if that 
suits your temper better.


Furthermore, I am still confused of how SPSS calculates the epsilons 
since it is mentioned that perhaps there are any errors in SPSS??


I would be glad if anyone could help me!
I am looking forward to hearing from you!

Thank you!
Nils

__
R-help@r-project.org 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-help@r-project.org 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] applying a function several times

2008-12-05 Thread Carlos Cuartas
I am sorry. I am not sure if the mail a send before to this list was rejected 
because of header (subject).
I've changed it. The first maybe was not appropriate.

I did a function (sec_conop) whose arguments are syndic,
well and wellconop. 

sec_conop(syndic='01syndic.txt',well='well-1.csv',wellconop='well-1.dat');closeAllConnections()

This function takes “well” and “syndic”, matching between
them and then it does some transformations. The result is exported to
“wellconop”.

I will apply this function to one hundred different “wells”.
Therefore, for each well I use, the “wellconop argument will change too.
For intance if “well” is now well-2.csv, the function will be 

sec_conop(syndic='01syndic.txt',well='well-2.csv',wellconop='well-2.dat');closeAllConnections()

I am trying to apply this function automatically to all
“well” I have, but I do not find the way.
The last I tried, for three different “wells”, was :

wells-data.frame(funct=rep('sec_conop(',3),syndic=c('01syndic.txt','01syndic.txt','01syndic.txt'),well=c('well-1.csv','well-2.csv','well-3-1.csv'),wellconop=c('well-1.dat','well-2.dat','well-3.dat'))

funct_3wells-paste(wells$funct,',wells$syndic,', ,
,', wells$well,',
, , ' ,wells$wellconop,',),;,closeAllConnections(),sep='')

lapply(funct_3wells,as.formula)

This way works partially because the results in “wellconop”
are truncated. 
Has anyone any suggestion?

Thanks in advance

Carlos


  
__
R-help@r-project.org 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.



  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Legend and Main Title positioning

2008-12-05 Thread Richard . Cotton
 layout(matrix(c(1,2,3,4), nrow = 2, byrow = TRUE))
 plot(rnorm(100))
 plot(rnorm(200))
 plot(rnorm(300))
 plot(rnorm(400))
 
 Now, I'd like to create a legend below each plot and generate a common 
title.
 How can I do that?

If you are laying plots out in grids like this then lattice graphics are 
generally the way to go, but here's a solution based upon base graphics. 
The trick is to include extra potting space in your layout for the 
legends.  The code is messy, since it requires you to manually specify 
which cell of the layout to plot into, but I'm sure guven some thought you 
can automate this.

#4 space for plots, 4 for legends
layout(matrix(1:8, nrow = 4, byrow = TRUE), heights=rep(c(3,1),4))

#Check the layout looks suitable
layout.show(8)

#Avoid clipping problems, and create space for your title
par(xpd=TRUE, oma=c(0,0,2,0))

#First plot
plot(rnorm(100))

#Move down and plot the first legend
par(mfg=c(2,1))
legend(0,0, legend=foo, pch=1)

#Repeat for the other plots and legends
par(mfg=c(1,2))
plot(rnorm(200))
par(mfg=c(2,2))
legend(0,0, legend=bar, pch=1)

par(mfg=c(3,1))
plot(rnorm(300))
par(mfg=c(4,1))
legend(0,0, legend=baz, pch=1)

par(mfg=c(3,2))
plot(rnorm(400))
par(mfg=c(4,2))
legend(0,0, legend=quux, pch=1)

#Title for all the plots
title(main=4 plots, outer=TRUE)


Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
R-help@r-project.org 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.


Re: [R] comparing SAS and R survival analysis with time-dependent covariates

2008-12-05 Thread Terry Therneau
  This query of why do SAS and S give different answers for Cox models comes 
up every so often.  The two most common reasons are that
a. they are using different options for the ties
b. the SAS and S data sets are slightly different.
You have both errors.

First, make sure I have the same data set by reading a common file, and then
compare the results.

tmt54% more sdata.txt
 1   0.0  0.5 0   0
 1   0.5  3.0 1   1
 2   0.0  1.0 0   0
 2   1.0  1.5 1   1
 3   0.0  6.0 0   0
 4   0.0  8.0 0   1
 5   0.0  1.0 0   0
 5   1.0  8.0 1   0
 6   0.0 21.0 0   1
 7   0.0  3.0 0   0
 7   3.0 11.0 1   1

tmt55% more test.sas
options linesize=80;

data trythis;
infile 'sdata.txt';
input id start end delir outcome;

proc phreg data=trythis;
  model (start, end)*outcome(0)=delir/ ties=discrete;

proc phreg data=trythis;
  model (start, end)*outcome(0)=delir/ ties=efron;


tmt56% more test.r
trythis - read.table('sdata.txt',
  col.names=c(id, start, end, delir, outcome))

coxph(Surv(start, end, outcome) ~ delir, data=trythis, ties='exact')
coxph(Surv(start, end, outcome) ~ delir, data=trythis, ties='efron')

-
 I now get comparable answers.  Note that Cox's exact partial likelihood is 
the correct form to use for discrete time data.  I labeled this as the 'exact' 
method and SAS as the 'discrete' method.  The exact marginal likelihood of 
Prentice et al, which SAS calls the 'exact' method is not implemented in S.
 
  As to which package is more reliable, I can only point to a set of formal 
test 
cases that are found in Appendix E of the book by Therneau and Grambsch.  These 
are small data sets where the coefficients, log-likelihood, residuals, etc have 
all been worked out exactly in closed form.  R gets all of these test cases 
right, SAS gets almost all.
 
Terry Therneau

-
Svetlan Eden wrote
Dear R-help,

I was comparing SAS (I do not know what version it is) and R (version 
2.6.0 (2007-10-03) on Linux) survival analyses with time-dependent 
covariates. The results differed significantly so I tried to understand 
on a short example where I went wrong. The following example shows that 
even when argument 'method' in R function coxph and argument 'ties' in 
SAS procedure phreg are the same, the results of Cox regr.  are 
different. This seems to happen when there are ties in the 
events/covariates times.

My question is what software, R or SAS, is more reliable for the 
survival analysis with time-dependent covariates or if you could point 
out a problem in the following example.

 ...

__
R-help@r-project.org 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.


Re: [R] Plotting a kriging on a map

2008-12-05 Thread Jon Loehrke
Rodrigo,

This is an old and quite basic Krig, my data was continuous  
measurements in lat, long so binned first.

library(geoR)

counts-bins2d(long, lat,bin=c(0.1,0.1),plot=FALSE, nlevels=15,  
color.palette=heat.colors, xaxs='i', yaxs='i', las=1, main='')
countsgeo-as.geodata(counts)
xrange-seq(range(countsgeo$coords[,1])[1],range(countsgeo$coords[,1]) 
[2], by=bin[1])
yrange-seq(range(countsgeo$coords[,2])[1],range(countsgeo$coords[,2]) 
[2], by=bin[2])

loci-expand.grid(x=range(counts,y=yrange) #krig grid

kc - krige.conv(countsgeo, loc=loci,
  krige=krige.control(cov.pars=c(1, .25))) #can fine  
tune

color.palette-rainbow #use heat etc.
contour(kc,asp=1, col=col- 
c(#F,color.palette(length(levels)-1)) , add=TRUE) #makes 0  
counts white



You could also use image or other 3d graphics.

Hope that Helps,

Jon Loehrke
Graduate Research Assistant
Department of Fisheries Oceanography
School for Marine Science and Technology
University of Massachusetts
200 Mill Road, Suite 325
Fairhaven, MA 02719
[EMAIL PROTECTED]


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] determine assortative mixing in networks (igraph-library)

2008-12-05 Thread Rainer Tischler
Dear all,

I'm looking for a method to quantify assortative mixing in undirected graphs, 
preferably something that is compatible with the igraph-library for network 
analysis. Is anybody aware of an already existing function/library for this or 
an easy way to implement this functionality in R?

Many thanks,
Rainer

WikipediaWictionaryChambers (UK)Google imagesGoogle defineThe Free 
DictionaryJoin exampleWordNetGoogleUrban 
DictionaryAnswers.comrhymezone.comMerriam-Webster0
wvcidfjoguarm




__
R-help@r-project.org 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.


Re: [R] Cartesian Product Of Character Vectors

2008-12-05 Thread David Winsemius

Does this satisfy?

levels(interaction(x,y))
[1] aaa.1 bbb.1 ccc.1 aaa.2 bbb.2 ccc.2 aaa.3 bbb.3  
ccc.3


--
David Winsemius


On Dec 5, 2008, at 8:12 AM, [EMAIL PROTECTED]  
[EMAIL PROTECTED] wrote:



Hi all

(I'm sure this question has been asked before, but I cant find it).

If I have two character vectors:


x - c(aaa,bbb,ccc)
y - c(1,2,3)


How can I get the cartesian product of the string values?


expand.grid(x,y)


Gives me a data frame with separate columns...however, I cant seem  
to get *apply to paste the column values together.


Thanks
Rory

Rory Winston
RBS Global Banking  Markets
280 Bishopsgate, London, EC2M 4RB
Office: +44 20 7085 4476



***
The Royal Bank of Scotland plc. Registered in Scotland No 90312.  
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.

Authorised and regulated by the Financial Services Authority

This e-mail message is confidential and for use by the=2...{{dropped: 
25}}


__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Cartesian Product Of Character Vectors

2008-12-05 Thread Rory.WINSTON
Hi David

Perfect - if I specify sep=, it gives me exactly what I need.

Cheers



Rory Winston
RBS Global Banking  Markets
Office: +44 20 7085 4476

-Original Message-
From: David Winsemius [mailto:[EMAIL PROTECTED]
Sent: 05 December 2008 14:16
To: WINSTON, Rory, GBM
Cc: r-help@r-project.org
Subject: Re: [R] Cartesian Product Of Character Vectors

Does this satisfy?

levels(interaction(x,y))
[1] aaa.1 bbb.1 ccc.1 aaa.2 bbb.2 ccc.2 aaa.3 bbb.3
ccc.3

--
David Winsemius


On Dec 5, 2008, at 8:12 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi all

 (I'm sure this question has been asked before, but I cant find it).

 If I have two character vectors:

 x - c(aaa,bbb,ccc)
 y - c(1,2,3)

 How can I get the cartesian product of the string values?

 expand.grid(x,y)

 Gives me a data frame with separate columns...however, I cant seem to
 get *apply to paste the column values together.

 Thanks
 Rory

 Rory Winston
 RBS Global Banking  Markets
 280 Bishopsgate, London, EC2M 4RB
 Office: +44 20 7085 4476



 **
 * The Royal Bank of Scotland plc. Registered in Scotland
 No 90312.
 Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
 Authorised and regulated by the Financial Services Authority

 This e-mail message is confidential and for use by the=2...{{dropped:
 25}}

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Cartesian Product Of Character Vectors

2008-12-05 Thread Rory.WINSTON
Sorry, I spoke too soon...

interaction() only works for sequences of equal length. Anyone know a method 
that works with unequal-length vectors?


Rory Winston
RBS Global Banking  Markets
Office: +44 20 7085 4476

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of WINSTON, Rory, 
GBM
Sent: 05 December 2008 14:20
To: [EMAIL PROTECTED]
Cc: r-help@r-project.org
Subject: Re: [R] Cartesian Product Of Character Vectors

Hi David

Perfect - if I specify sep=, it gives me exactly what I need.

Cheers



Rory Winston
RBS Global Banking  Markets
Office: +44 20 7085 4476

-Original Message-
From: David Winsemius [mailto:[EMAIL PROTECTED]
Sent: 05 December 2008 14:16
To: WINSTON, Rory, GBM
Cc: r-help@r-project.org
Subject: Re: [R] Cartesian Product Of Character Vectors

Does this satisfy?

levels(interaction(x,y))
[1] aaa.1 bbb.1 ccc.1 aaa.2 bbb.2 ccc.2 aaa.3 bbb.3
ccc.3

--
David Winsemius


On Dec 5, 2008, at 8:12 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi all

 (I'm sure this question has been asked before, but I cant find it).

 If I have two character vectors:

 x - c(aaa,bbb,ccc)
 y - c(1,2,3)

 How can I get the cartesian product of the string values?

 expand.grid(x,y)

 Gives me a data frame with separate columns...however, I cant seem to
 get *apply to paste the column values together.

 Thanks
 Rory

 Rory Winston
 RBS Global Banking  Markets
 280 Bishopsgate, London, EC2M 4RB
 Office: +44 20 7085 4476



 **
 * The Royal Bank of Scotland plc. Registered in Scotland
 No 90312.
 Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
 Authorised and regulated by the Financial Services Authority

 This e-mail message is confidential and for use by the=2...{{dropped:
 25}}

 __
 R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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] read.gal3.R

2008-12-05 Thread Annachiara Saguatti
Hello everybody,

I'm trying to perform a ESDA on some data about per capita GDP among
European regions and I'm trying to learn how to make R and GeoDa interact.
I'm reading that in order to import a GAL file from GeoDa to R it's best to
source into R the read.gal3.R file. But where can I get it from?

Thank you,
Annachiara Saguatti

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] levels update

2008-12-05 Thread Antje

Thanks a lot!!!
the drop thing was exactly what I was looking for (I already used it some 
time ago but forgot about it).


Thanks to everybody else too.

Antje


Prof Brian Ripley schrieb:

On Fri, 5 Dec 2008, jim holtman wrote:


try this:

df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), 
c(9,1,2,3,4))

names(df) - c(X1,X2,X3)

my.sub - subset(df, X1 == a | X1 == b)
levels(my.sub$X1)

[1] a b c

my.sub$X1 - factor(my.sub$X1)


I find

my.sub$X1 - my.sub$X1[drop=TRUE]

a lot more self-explanatory.  See ?[.factor.  However, if you find 
yourself wanting to do this, ask why you have a factor (rather than a 
character vector) in the first place.




levels(my.sub$X1)

[1] a b





On Fri, Dec 5, 2008 at 7:50 AM, Antje [EMAIL PROTECTED] wrote:

Hello,

I hope this question is not too stupid. I would like to know how to 
update

levels after subsetting data from a data.frame.

df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), 
c(9,1,2,3,4))

names(df) - c(X1,X2,X3)

my.sub - subset(df, X1 == a | X1 == b)
levels(my.sub$X1)

# still gives me a,b,c, though the subset does not contain entries
with c anymore

I guess, the solution is rather simple, but I cannot find it.

Antje

__
R-help@r-project.org 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.





--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] levels update

2008-12-05 Thread Richard . Cotton
 I hope this question is not too stupid. I would like to know how to 
update 
 levels after subsetting data from a data.frame.
 
 df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), 
c(9,1,2,3,4))
 names(df) - c(X1,X2,X3)
 
 my.sub - subset(df, X1 == a | X1 == b)
 levels(my.sub$X1)
 
 # still gives me a,b,c, though the subset does not contain entries 
with 
 c anymore

Two questions in one afternon; aren't I good to you!

levels(my.sub$X1[,drop=TRUE])
[1] a b
levels(factor(my.sub$X1))
[1] a b

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
R-help@r-project.org 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.


Re: [R] setwd and list.files / linux

2008-12-05 Thread Marc Schwartz
Hi Lars,

I am having trouble replicating this problem, using the default
file/folder permissions on my Fedora 10 system.

When creating a new folder, I get:

mkdir Test

drwxrwxr-x  2 marcs marcs   4096 2008-12-05 08:17 Test


When creating a new file, I get:

touch Test.txt

-rw-rw-r-- 1 marcs marcs 0 2008-12-05 08:17 Test.txt


Even when modifying the file permissions to be similar to yours:

chmod 644 Test.txt

-rw-r--r-- 1 marcs marcs 0 2008-12-05 08:17 Test.txt


I can still read the file from a different folder.  It is likely that
your 'umask', which defines the default file/folder permissions on your
system is different than mine. For me, as a regular user, it is 002.
This value is usually defined in /etc/bashrc:

$ grep umask /etc/bashrc
umask 002
umask 022

The first value is for a regular user, the second for 'root'.

It is likely that your umask is 022 based upon the file permissions that
you list, as that would result in a default permission of 644. This
might mean that the default umask on RHEL is different than on Fedora,
or perhaps your default umask has been changed in ~/.bashrc.

I suspect that you might have a folder permission issue, rather than a
file permission issue and I think that would be consistent with the
behavior that you are observing.

I would check the permissions on each folder in the path that you are
trying to access to see if something is amiss there. Perhaps try using
setwd() on each folder in the datapath tree, starting at 'the top',
adding a new lower level folder each time, until it fails. That might
provide some guidance.

HTH,

Marc


on 12/05/2008 02:46 AM Lars Beckmann wrote:
 Hey Marc,
 
 sorry I forgot to mention it. I am the owner of the path, which is in my home 
 directory. I can change the read/write/execute privileges.  All users have - 
 at least - read privileges for all files and the directory:
 
 hpc36 40: ls -la *.tped
 -rw-r--r--  1 cremer C020 205487231 Dec  3 17:35 chr10.tped
 -rw-r--r--  1 cremer C020 192067641 Dec  3 17:37 chr11.tped
 -rw-r--r--  1 cremer C020 192243483 Dec  3 17:38 chr12.tped
 
 etc
  
 A workaround I found now is to start R in the respective directory from the 
 command line, which will set working directory to current directory. 
 list.files will work then too:
 
 list.file(.,pattern=\\.tped)
 
 The problem now is to start a script via R CMD BATCH from a different 
 directory, because setwd() will not work:
 
 datapath-'/nfs/home/m/cremer/gaw/data/traws_chrs/'

 getwd()
 [1] /nfs/home/m/cremer/gaw/code/plink
 setwd(datapath)
 Error in setwd(datapath) : cannot change working directory
 Execution halted

 Lars
 
  Original-Nachricht 
 Datum: Thu, 04 Dec 2008 10:58:16 -0600
 Von: Marc Schwartz [EMAIL PROTECTED]
 An: Lars Beckmann [EMAIL PROTECTED]
 CC: r-help@r-project.org
 Betreff: Re: [R] setwd and list.files / linux
 
 on 12/04/2008 10:38 AM Lars Beckmann wrote:
 Hey,

 two questions regarding setwd and list.files:

 I try to use the function list.files:

 datapath-'/nfs/home/m/cremer/gaw/data/traws_chrs'
 fl-list.files(datapath, pattern=\\.tped)
 but I get the following error message:

 Warning message:
 In list.files(datapath, pattern = \\.tped) :
   list.files: '/nfs/home/m/cremer/gaw/data/traws_chrs/' is not a
 readable directory
 fl
 character(0)

 The use of setwd also does not work:

 setwd(datapath)
 Error in setwd(datapath) : cannot change working directory


 datapath exists and it doesn't matter whether I use single quotes ' or
 double quotes 
 Any help?

 Lars
 You do not have read privileges to the path in question. Either you or
 your SysAdmin will have to grant the appropriate privileges so that you
 can read the files in the path.

 HTH,

 Marc Schwartz


__
R-help@r-project.org 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.


Re: [R] Cartesian Product Of Character Vectors

2008-12-05 Thread Rory.WINSTON
Got it...I completely overlooked the collapse argument to paste():

apply(expand.grid(x,y),1,function(x) paste(x,collapse=))



Rory Winston
RBS Global Banking  Markets
Office: +44 20 7085 4476

-Original Message-
From: WINSTON, Rory, GBM
Sent: 05 December 2008 14:30
To: WINSTON, Rory, GBM; [EMAIL PROTECTED]
Cc: r-help@r-project.org
Subject: RE: [R] Cartesian Product Of Character Vectors

Sorry, I spoke too soon...

interaction() only works for sequences of equal length. Anyone know a method 
that works with unequal-length vectors?


Rory Winston
RBS Global Banking  Markets
Office: +44 20 7085 4476

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of WINSTON, Rory, 
GBM
Sent: 05 December 2008 14:20
To: [EMAIL PROTECTED]
Cc: r-help@r-project.org
Subject: Re: [R] Cartesian Product Of Character Vectors

Hi David

Perfect - if I specify sep=, it gives me exactly what I need.

Cheers



Rory Winston
RBS Global Banking  Markets
Office: +44 20 7085 4476

-Original Message-
From: David Winsemius [mailto:[EMAIL PROTECTED]
Sent: 05 December 2008 14:16
To: WINSTON, Rory, GBM
Cc: r-help@r-project.org
Subject: Re: [R] Cartesian Product Of Character Vectors

Does this satisfy?

levels(interaction(x,y))
[1] aaa.1 bbb.1 ccc.1 aaa.2 bbb.2 ccc.2 aaa.3 bbb.3
ccc.3

--
David Winsemius


On Dec 5, 2008, at 8:12 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi all

 (I'm sure this question has been asked before, but I cant find it).

 If I have two character vectors:

 x - c(aaa,bbb,ccc)
 y - c(1,2,3)

 How can I get the cartesian product of the string values?

 expand.grid(x,y)

 Gives me a data frame with separate columns...however, I cant seem to
 get *apply to paste the column values together.

 Thanks
 Rory

 Rory Winston
 RBS Global Banking  Markets
 280 Bishopsgate, London, EC2M 4RB
 Office: +44 20 7085 4476



 **
 * The Royal Bank of Scotland plc. Registered in Scotland
 No 90312.
 Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
 Authorised and regulated by the Financial Services Authority

 This e-mail message is confidential and for use by the=2...{{dropped:
 25}}

 __
 R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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] Sink does not send graphs to sink file

2008-12-05 Thread John Sorkin
Wiindows XP
R 2.7
I am using sink() to send the results of my analyses to a text file. 
Unfortunately my graphs do not become part of the file. Is there anyway that I 
can have both the text and graphic output of my analyses appear in a file?
Thanks,
John

John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}

__
R-help@r-project.org 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.


Re: [R] How to get Greenhouse-Geisser epsilons from anova?

2008-12-05 Thread John Fox
Dear Nils,

You might also take a look at the Anova() function in the car package, which
though less flexible than anova() should get you the tests that you want
more simply. ?Anova has an example of a repeated-measures ANOVA with two
within-subject and two between-subject factors.

I hope that this helps,
 John

--
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On
 Behalf Of Skotara
 Sent: December-05-08 8:40 AM
 To: Peter Dalgaard; r-help@r-project.org
 Subject: Re: [R] How to get Greenhouse-Geisser epsilons from anova?
 
 Dear Mr. Daalgard.
 
 thank you very much for your reply, it helped me to progress a bit.
 
 The following works fine:
 dd - expand.grid(C = 1:7, B= c(r, l), A= c(c, f))
 myma - as.matrix(myma) #myma is a 12 by 28 list
 mlmfit - lm(myma~1)
 mlmfit0 - update(mlmfit, ~0)
 anova(mlmfit, mlmfit0, X= ~C+B, M = ~A+C+B, idata = dd,
 test=Spherical), which tests the main effect of A.
 anova(mlmfit, mlmfit0, X= ~A+C,  M = ~A+C+B, idata = dd,
 test=Spherical), which tests the main effect of B.
 
 
 However, I can not figure out how this works for the other effects.
 If I try:
 anova(mlmfit, mlmfit0, X= ~A+B,  M = ~A+C+B, idata = dd,
test=Spherical)
 
 I get:
 Fehler in function (object, ..., test = c(Pillai, Wilks,
 Hotelling-Lawley,  :
 residuals have rank 1  4
 
 I also don't know how I can calculate the various interactions..
 My read is I should change the second argument mlmfit0, too, but I can't
 figure out how...
 
 Do you know what to do?
 Thank you very much!
 
 
 
 Peter Dalgaard schrieb:
  Skotara wrote:
  Dear all,
 
  I apologize for my basic question.
  I try to calculate an anova for repeated measurements with 3 factors
  (A,B,C) having 2, 2, and 7 levels.
  or with an additional fourth between subjects factor D.
  Everything works fine using
  aov(val ~ A*B*C  + Error(subject/ (A*B*C) ) )  or
  aov(val ~ (D*A*B*C)  + Error(subject/(A*B*C)) + D )
  val, A, B, C, D and subject are columns in a data.frame.
 
  How can I get the estimated Greenhouse-Geisser and Huynh-Feldt
epsilons?
  I know Peter Dalgaard described it in R-News Vol. 7/2, October 2007.
  However, unfortunately I am not able to apply that using my data...
 
  Why? It is supposed to work. You just need to work out the X and M
  specification for the relevant error strata and set test=Spherical
  for anova.mlm, or work out the T contrast matrix explicitly if that
  suits your temper better.
 
  Furthermore, I am still confused of how SPSS calculates the epsilons
  since it is mentioned that perhaps there are any errors in SPSS??
 
  I would be glad if anyone could help me!
  I am looking forward to hearing from you!
 
  Thank you!
  Nils
 
  __
  R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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.


Re: [R] Cartesian Product Of Character Vectors

2008-12-05 Thread Henrique Dallazuanna
Try this also:

with(expand.grid(x,y), paste(Var1, Var2, sep = ))

On Fri, Dec 5, 2008 at 1:08 PM, [EMAIL PROTECTED] wrote:

 Got it...I completely overlooked the collapse argument to paste():

 apply(expand.grid(x,y),1,function(x) paste(x,collapse=))



 Rory Winston
 RBS Global Banking  Markets
 Office: +44 20 7085 4476

 -Original Message-
 From: WINSTON, Rory, GBM
 Sent: 05 December 2008 14:30
 To: WINSTON, Rory, GBM; [EMAIL PROTECTED]
 Cc: r-help@r-project.org
 Subject: RE: [R] Cartesian Product Of Character Vectors

 Sorry, I spoke too soon...

 interaction() only works for sequences of equal length. Anyone know a
 method that works with unequal-length vectors?


 Rory Winston
 RBS Global Banking  Markets
 Office: +44 20 7085 4476

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 On Behalf Of WINSTON, Rory, GBM
 Sent: 05 December 2008 14:20
 To: [EMAIL PROTECTED]
 Cc: r-help@r-project.org
 Subject: Re: [R] Cartesian Product Of Character Vectors

 Hi David

 Perfect - if I specify sep=, it gives me exactly what I need.

 Cheers



 Rory Winston
 RBS Global Banking  Markets
 Office: +44 20 7085 4476

 -Original Message-
 From: David Winsemius [mailto:[EMAIL PROTECTED]
 Sent: 05 December 2008 14:16
 To: WINSTON, Rory, GBM
 Cc: r-help@r-project.org
 Subject: Re: [R] Cartesian Product Of Character Vectors

 Does this satisfy?

 levels(interaction(x,y))
 [1] aaa.1 bbb.1 ccc.1 aaa.2 bbb.2 ccc.2 aaa.3 bbb.3
 ccc.3

 --
 David Winsemius


 On Dec 5, 2008, at 8:12 AM, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:

  Hi all
 
  (I'm sure this question has been asked before, but I cant find it).
 
  If I have two character vectors:
 
  x - c(aaa,bbb,ccc)
  y - c(1,2,3)
 
  How can I get the cartesian product of the string values?
 
  expand.grid(x,y)
 
  Gives me a data frame with separate columns...however, I cant seem to
  get *apply to paste the column values together.
 
  Thanks
  Rory
 
  Rory Winston
  RBS Global Banking  Markets
  280 Bishopsgate, London, EC2M 4RB
  Office: +44 20 7085 4476
 
 
 
  **
  * The Royal Bank of Scotland plc. Registered in Scotland
  No 90312.
  Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
  Authorised and regulated by the Financial Services Authority
 
  This e-mail message is confidential and for use by the=2...{{dropped:
  25}}
 
  __
  R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Sink does not send graphs to sink file

2008-12-05 Thread Richard . Cotton
 I am using sink() to send the results of my analyses to a text file.
 Unfortunately my graphs do not become part of the file. Is there 
 anyway that I can have both the text and graphic output of my 
 analyses appear in a file?

You can create a latex document with text, graphs and R-code using 
?Sweave.  If you prefer to write to Open document format , there is an 
Odfweave package.

The other alternative is simply writing your graphs to files (or one file 
with all the graphs), e.g.
pdf(test.pdf)
plot(1:10)
hist(rnorm(100))
dev.off()

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
R-help@r-project.org 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] systematically matching the numbers in two sequences

2008-12-05 Thread emj83

I am having trouble writing a code for matching two pairs of sequences with
differing lengths:

for example sequence1= 1,2,3,4,5,6,7 sequence2=1,2,3,4,5,6,7,8,9,10

I want to create several new pairs of sequences in several dataframes such
that:
1st dataframe is 1,10 (start of sequence1, end of sequence 2)
2nd dataframe is 1, 9
 2, 10

3rd dataframe is 1, 8
2, 9
3, 10

etc etc.

I realise this may involve a complicated loop and am really struggling to
make a start on it.
-- 
View this message in context: 
http://www.nabble.com/systematically-matching-the-numbers-in-two-sequences-tp20856673p20856673.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Sink does not send graphs to sink file

2008-12-05 Thread Philipp Pagel
 I am using sink() to send the results of my analyses to a text
 file. Unfortunately my graphs do not become part of the file.
 Is there anyway that I can have both the text and graphic
 output of my analyses appear in a file?

Well, how would you expect the graphs to be represented in a text
file? So the short answer is no you can't do that.

The longer and probably more helpful answer is: Have a look at
Sweave(). Sweave is a system which allows you to integrate R-code
with LaTeX formatting -- including the possibility to insert
graphs.

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@r-project.org 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.


Re: [R] 2D density tophat

2008-12-05 Thread Aaron Robotham
In case anyone other than me was interested, a pretty efficient  
circular tophat can be made using the fields function fields.rdist.near:


CircHat=function (x, y, h=1, gridres = c((max(x)-min(x))/25,(max(y)- 
min(y))/25), lims = c(range(x), range(y)),density=FALSE)

{
require(fields)
nx - length(x)
ny - length(y)
n=c(1+(lims[2]-lims[1])/gridres[1],1+(lims[4]-lims[3])/gridres[2])
if (length(y) != nx)
stop(data vectors must be the same length)
if (any(!is.finite(x)) || any(!is.finite(y)))
stop(missing or infinite values in the data are not allowed)
if (any(!is.finite(lims)))
stop(only finite values are allowed in 'lims')
gx - seq(lims[1], lims[2], by = gridres[1])
gy - seq(lims[3], lims[4], by = gridres[2])
fullgrid=expand.grid(gx,gy)

if (missing(h))
h - c(bandwidth.nrd(x), bandwidth.nrd(y))

temp 
= 
table 
(fields 
.rdist 
.near 
(as 
.matrix 
(fullgrid 
),as.matrix(cbind(x,y)),mean.neighbor=ceiling(length(x)*pi*h^2/ 
((lims[2]-lims[1])*(lims[4]-lims[3]))),delta=h)$ind[,1])


pad=rep(0,length(gx)*length(gy))
pad[as.numeric(names(temp))]=as.numeric(temp)

z - matrix(pad, length(gx), length(gy))

if(density){z=z/(nx*pi*h^2)}

return=list(x = gx, y = gy, z = z)

}

It works in more or less the same way as kde2d, but by default it  
returns counts not densities


Aaron

On 1 Dec 2008, at  11:46, Aaron Robotham wrote:


Hello R users,

I have successfully created a square (or more generally, rectangular)
tophat smoothing routine based on altering the already available
KDE2D. I would be keen to implement a circular tophat routine also,
however this appears to be much more difficult to write efficiently (I
have a routine, but it's very slow). I tried to create one based on
using crossdist (in spatstat) to create a distance matrix between my
data and the sampling grid, but it doesn't take a particularly large
amount of data (or hi-res grid) for memory to be a big problem. The 2D
density routines I have been able to find either don't support a
simple tophat, or don't use the absolute distances between the
sampling grid and the data. Should anyone know of more general 2D
density routines that might support circular tophats, or know of a
simple and efficient method for creating them, I would be very  
grateful.


Thanks for your time,

Aaron

PS: I tried sending this on Friday originally, but as far as I know
that didn't work, so should another post appear from me asking the
same thing I apologise in advance.
[[alternative HTML version deleted]]

__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] systematically matching the numbers in two sequences

2008-12-05 Thread Henrique Dallazuanna
Try this:

s1 - 1:7
s2 - 1:10

lapply(seq(length(s1)), function(i)cbind(head(s1, i), tail(s2, i)))



On Fri, Dec 5, 2008 at 1:44 PM, emj83 [EMAIL PROTECTED] wrote:


 I am having trouble writing a code for matching two pairs of sequences with
 differing lengths:

 for example sequence1= 1,2,3,4,5,6,7 sequence2=1,2,3,4,5,6,7,8,9,10

 I want to create several new pairs of sequences in several dataframes such
 that:
 1st dataframe is 1,10 (start of sequence1, end of sequence 2)
 2nd dataframe is 1, 9
 2, 10

 3rd dataframe is 1, 8
2, 9
3, 10

 etc etc.

 I realise this may involve a complicated loop and am really struggling to
 make a start on it.
 --
 View this message in context:
 http://www.nabble.com/systematically-matching-the-numbers-in-two-sequences-tp20856673p20856673.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] How to calculate the distance between two density functions

2008-12-05 Thread Chang Jia-Ming
Dear all,

  I wrote the following code to calculate the density functions for two data
sets, respectively.

  den_str -density(str_data$Similarity);
  den_non_str -density(nonstr_data$Similarity);

  However, I would like to knowing the difference between den_str and
den_non_str, that is, the difference between the region under the curve of
the den_str and the region under the curve of the den_non_str.

 How to do?

 Thank you for help.

Jia-Ming

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] systematically matching the numbers in two sequences

2008-12-05 Thread emj83

I am having trouble writing a code for matching two pairs of sequences with
differing lengths:

for example sequence1= 1,2,3,4,5,6,7 sequence2=1,2,3,4,5,6,7,8,9,10

I want to create several new pairs of sequences in several dataframes such
that:
1st dataframe is 1,10 (start of sequence1, end of sequence 2)
2nd dataframe is 1, 9
 2, 10

3rd dataframe is 1, 8
2, 9
3, 10

etc etc.

I realise this may involve a complicated loop and am really struggling to
make a start on it. 
-- 
View this message in context: 
http://www.nabble.com/systematically-matching-the-numbers-in-two-sequences-tp20855728p20855728.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Problems with lattice-histograms or png within loops

2008-12-05 Thread Mark Heckmann
Dear R-users,

I have a question concerning the use of lattice plots within for-loops.
I want to create a png file containing a lattice histogram which works out
fine (part 1).
When I loop the whole code, the graphic file does not contain anything (part
2). 
I can fix it by wrapping the histogram function into a print command (part
3).
Why is that so? Why can I not loop it directly? 

TIA,
Mark

attach(iris)

### part 1
png(filename = graphic_1.png)
  histogram( ~ Sepal.Length | Species, data = iris)
dev.off()

### part 2
for (i in c(1))
{
png(filename = graphic_2.png)
  histogram( ~ Sepal.Length | Species, data = iris)
dev.off()
}

### part 3
for (i in c(1))
{
png(filename = graphic_3.png)
  print(histogram( ~ Sepal.Length | Species, data = iris))
dev.off()
}

__
R-help@r-project.org 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.


Re: [R] Strplit code

2008-12-05 Thread William Dunlap
   [R] Strplit code
   pomchip at free.fr pomchip at free.fr
   Wed Dec 3 20:52:21 CET 2008
   
   Dear R-users,

   The strsplit function does not exist in S-plus and I would like to
use it. How
   could I reproduce the function in Splus or access to its source code?

   Thank you in advance,

   Sebastien

strsplit() was added to S+ 8.0 (May 2007).  At the same time
we changed the default regular expression style from 'basic'
(a.k.a. 'obsolete') to 'extended' and we added the string functions
sub(), gsub(), and sprintf().

S+ 8.1 is now available (as of November 2008).  

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

__
R-help@r-project.org 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.


Re: [R] Problems with lattice-histograms or png within loops

2008-12-05 Thread Richard . Cotton
 I have a question concerning the use of lattice plots within for-loops.
 I want to create a png file containing a lattice histogram which works 
out
 fine (part 1).
 When I loop the whole code, the graphic file does not contain anything 
(part
 2). 
 I can fix it by wrapping the histogram function into a print command 
(part
 3).
 Why is that so? Why can I not loop it directly? 
 
 TIA,
 Mark
 
 attach(iris)
 
 ### part 1
 png(filename = graphic_1.png)
   histogram( ~ Sepal.Length | Species, data = iris)
 dev.off()
 
 ### part 2
 for (i in c(1))
 {
 png(filename = graphic_2.png)
   histogram( ~ Sepal.Length | Species, data = iris)
 dev.off()
 }
 
 ### part 3
 for (i in c(1))
 {
 png(filename = graphic_3.png)
   print(histogram( ~ Sepal.Length | Species, data = iris))
 dev.off()
 }

This is FAQ 7.22:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

The help page on ?histogram also mentions that the function returns an 
object of class 'trellis' and the 'print' method (usually called by 
default) will plot it on an appropriate plotting device

It's a good idea to get into the habit of calling print any time you 
create a lattice graph.  If you reorder your code like

h1 - histogram( ~ Sepal.Length | Species, data = iris)
png(filename = graphic_h1.png)
  print(h1)
dev.off()

then you won't end up with an open device if drawing the plot fails.

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
R-help@r-project.org 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.


Re: [R] comparing SAS and R survival analysis with time-dependent covariates

2008-12-05 Thread Svetlana Eden


Thank you so much, this was very helpful.

Svetlana

Terry Therneau wrote:
  This query of why do SAS and S give different answers for Cox models comes 
up every so often.  The two most common reasons are that

a. they are using different options for the ties
b. the SAS and S data sets are slightly different.
You have both errors.

First, make sure I have the same data set by reading a common file, and then
compare the results.

tmt54% more sdata.txt
 1   0.0  0.5 0   0
 1   0.5  3.0 1   1
 2   0.0  1.0 0   0
 2   1.0  1.5 1   1
 3   0.0  6.0 0   0
 4   0.0  8.0 0   1
 5   0.0  1.0 0   0
 5   1.0  8.0 1   0
 6   0.0 21.0 0   1
 7   0.0  3.0 0   0
 7   3.0 11.0 1   1

tmt55% more test.sas
options linesize=80;

data trythis;
infile 'sdata.txt';
input id start end delir outcome;

proc phreg data=trythis;
  model (start, end)*outcome(0)=delir/ ties=discrete;

proc phreg data=trythis;
  model (start, end)*outcome(0)=delir/ ties=efron;


tmt56% more test.r
trythis - read.table('sdata.txt',
  col.names=c(id, start, end, delir, outcome))

coxph(Surv(start, end, outcome) ~ delir, data=trythis, ties='exact')
coxph(Surv(start, end, outcome) ~ delir, data=trythis, ties='efron')

-
 I now get comparable answers.  Note that Cox's exact partial likelihood is 
the correct form to use for discrete time data.  I labeled this as the 'exact' 
method and SAS as the 'discrete' method.  The exact marginal likelihood of 
Prentice et al, which SAS calls the 'exact' method is not implemented in S.
 
  As to which package is more reliable, I can only point to a set of formal test 
cases that are found in Appendix E of the book by Therneau and Grambsch.  These 
are small data sets where the coefficients, log-likelihood, residuals, etc have 
all been worked out exactly in closed form.  R gets all of these test cases 
right, SAS gets almost all.
 
 	Terry Therneau


-
Svetlan Eden wrote
Dear R-help,

I was comparing SAS (I do not know what version it is) and R (version 
2.6.0 (2007-10-03) on Linux) survival analyses with time-dependent 
covariates. The results differed significantly so I tried to understand 
on a short example where I went wrong. The following example shows that 
even when argument 'method' in R function coxph and argument 'ties' in 
SAS procedure phreg are the same, the results of Cox regr.  are 
different. This seems to happen when there are ties in the 
events/covariates times.


My question is what software, R or SAS, is more reliable for the 
survival analysis with time-dependent covariates or if you could point 
out a problem in the following example.


 ...
 






__
R-help@r-project.org 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.


Re: [R] legend at fixed distance form the bottom

2008-12-05 Thread Greg Snow
It is best to create the graphics device at the final size desired, then do the 
plotting and add the legend.  For getting a fixed distance, look at the 
function grconvertY for one possibility.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 project.org] On Behalf Of Christophe Genolini
 Sent: Friday, December 05, 2008 6:40 AM
 To: r-help@r-project.org
 Subject: [R] legend at fixed distance form the bottom

 Hi the list

 I would like to add a legend under a graph but at a fixed distance from
 the graphe. Is it possible ?
 More precisely, here is my code :

 --- 8 
 symboles - c(3,4,5,6)
 dn - rbind(matrix(rnorm(20),,5),matrix(rnorm(20,2),,5))
 listSymboles - rep(symboles,each=2)
 matplot(t(dn),pch=listSymboles,type=b)
 legend(bottom, pch = unique(listSymboles), legend = c(ane,
 cheval,
 poney, mule), inset = c(0,-0.175), horiz = TRUE, xpd = NA)
 --- 8 

 But when I change the size of the graph, the legend is misplaced.

 Instead, I try to put some text in xlab, but I do not know how to get
 the +, x , V and other symbol.
 Does anyone got a solution ?

 Thanks a lot.

 Christophe

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] How to calculate the distance between two density functions

2008-12-05 Thread David Winsemius

A similar question was posed and answered:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/119793.html

Two aspects needed to be addressed ... specifying the same domain, and  
getting the x-values to line up prior to the subtraction (or  
whatever function is desired).


What are you going to do when the two functions cross?

 d1 - dnorm(seq(-2,2,by=.1))
 d2 - dnorm(seq(-2,2,by=.1), mean=2)
 plot(seq(-2,2,by=.1),d1)
 lines(seq(-2,2,by=.1),d2)

 or

 d4 - dnorm(seq(-4,4,by=.1))
 d5 - dnorm(seq(-4,4,by=.1), sd=5)
 plot(seq(-4,4,by=.1),d4)
 lines(seq(-4,4,by=.1),d5)

--
David Winsemius
On Dec 5, 2008, at 8:59 AM, Chang Jia-Ming wrote:


Dear all,

 I wrote the following code to calculate the density functions for  
two data

sets, respectively.

 den_str -density(str_data$Similarity);
 den_non_str -density(nonstr_data$Similarity);

 However, I would like to knowing the difference between den_str and
den_non_str, that is, the difference between the region under the  
curve of

the den_str and the region under the curve of the den_non_str.

How to do?

Thank you for help.

Jia-Ming

[[alternative HTML version deleted]]

__
R-help@r-project.org 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-help@r-project.org 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] Help with wavCWTPeaks

2008-12-05 Thread mauede
I cannot understand the following error printed out when I try to get the 
extrema of my time series.
I would appreciate some suggestion as I really cannot interpret the error. I 
might not be using a proper
set of parameters in calling such functions. I am learning by doing ...

 aa.peak - wavCWTPeaks (aa.tree)  
Error in `row.names-.data.frame`(`*tmp*`, value = c(1, 0)) :
  invalid 'row.names' length

My data vector is as follows:
 aa
  [1] -0.852625404 -0.886941142 -0.920699269 -0.953858240 -0.986377090
  [6] -1.018215725 -1.049335086 -1.079697274 -1.109265628 -1.138004782
 [11] -1.165880733 -1.192860894 -1.218914146 -1.244010899 -1.268123116
 [16] -1.291224432 -1.313290096 -1.334297111 -1.354224193 -1.373051833
 [21] -1.390762317 -1.407339716 -1.422769965 -1.437040775 -1.450141701
 [26] -1.462064157 -1.472801336 -1.482348272 -1.490701780 -1.497860461
 [31] -1.503824640 -1.508596384 -1.512179425 -1.514579128 -1.515802478
 [36] -1.515858035 -1.514755845 -1.512507449 -1.509125815 -1.504625250
 [41] -1.499021421 -1.492331231 -1.484572809 -1.475765432 -1.465929450
 [46] -1.455086269 -1.443258266 -1.430468724 -1.416741774 -1.402102340
 [51] -1.386576077 -1.370189287 -1.352968891 -1.334942359 -1.316137624
 [56] -1.296583049 -1.276307350 -1.255339556 -1.233708931 -1.211444912
 [61] -1.188577082 -1.165135088 -1.141148591 -1.116647219 -1.091660532
 [66] -1.066217945 -1.040348675 -1.014081694 -0.987445689 -0.960469010
 [71] -0.933179631 -0.905605109 -0.82541 -0.849708278 -0.821438088
 [76] -0.792987122 -0.764379898 -0.735640266 -0.706791393 -0.677855738
 [81] -0.648855033 -0.619810274 -0.590741693 -0.561668758 -0.532610156
 [86] -0.503583784 -0.474606745 -0.445695338 -0.416865062 -0.388130609
 [91] -0.359505865 -0.331003918 -0.302637056 -0.274416782 -0.246353810
 [96] -0.218458088 -0.190738802 -0.163204394 -0.135862573 -0.108720337
[101] -0.081783987 -0.055059152 -0.028550808 -0.002263304  0.023799613
[106]  0.049634774  0.075239551  0.100611836  0.125750005  0.150652886
[111]  0.175319722  0.199750141  0.223944116  0.247901927  0.271624125
[116]  0.295111492  0.318365000  0.341385774  0.364175049  0.386734130
[121]  0.409064353  0.431167045  0.453043480  0.474694850  0.496122212
[126]  0.517326465  0.538308303  0.559068185  0.579606300  0.599922532
[131]  0.620016432  0.639887183  0.659533578  0.678953988  0.698146340
[136]  0.716367156  0.734459833  0.752428741  0.770277372  0.788008310
[141]  0.805623188  0.823122667  0.840506396  0.857773019  0.874920094
[146]  0.891944162  0.908840641  0.925603903  0.942227205  0.958702728
[151]  0.975021541  0.991173645  1.007147946  1.022932278  1.038513449
[156]  1.053877190  1.069008243  1.083890313  1.098506181  1.112837647
[161]  1.126865608  1.140570088  1.153930270  1.166924526  1.179530477
[166]  1.191725035  1.203484451  1.214784382  1.225599912  1.235905642
[171]  1.245675755  1.254884072  1.263504095  1.271509107  1.278872248
[176]  1.285566555  1.291565077  1.296840902  1.301367293  1.305117743
[181]  1.308066011  1.310186290  1.311453212  1.311841963  1.311328350
[186]  1.309888930  1.307500999  1.304142758  1.299793348  1.294432925
[191]  1.288042752  1.280605267  1.272104143  1.262524364  1.251852272
[196]  1.240075658  1.227183764  1.213167403  1.198018950  1.181732402
[201]  1.164303440  1.145729407  1.126009401  1.105144212  1.083136426
[206]  1.059990384  1.035712188  1.010309729  0.983792617  0.956172242
[211]  0.927461713  0.897675875  0.866831225  0.834945955  0.802039881
[216]  0.768134393  0.733252445  0.697418506  0.660658502  0.622999781
[221]  0.584471057  0.545102363  0.504924994  0.463971453  0.422275398
[226]  0.379871580  0.336795792  0.293084805  0.248776314  0.203908880
[231]  0.158521870  0.112655403  0.066350293  0.019647991 -0.027409468
[236] -0.074779520 -0.122419124 -0.170284817 -0.218332766 -0.266518818
[241] -0.314798550

I convert it into a time series and then I get the CWT coefficients. Then I 
build the tree
that exhibits only 3 branches (see attached plot)

 aats - ts (aa, deltat =1/30, start = 0.0)  
 aa.cwt -  wavCWT(aats)  
 aa.tree - wavCWTTree (aa.cwt)  

I can get the data for each of the 3 branches:
 aa.tree[[1]]
$itime
 [1] 135 135 134 133 132 130 128 126 123 122 122 122 122 123 126

$iscale
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

$time
 [1] 4.47 4.47 4.43 4.40 4.37 4.30 4.23 4.17
 [9] 4.07 4.03 4.03 4.03 4.03 4.07 4.17

$scale
 [1] 0.0333 0.0667 0.1000 0.1333 0.1667 0.2000
 [7] 0.2333 0.2667 0.3000 0. 0.3667 0.4000
[13] 0.4333 0.4667 0.5000

$extrema
 [1] 0.001143350 0.004153357 0.009778222 0.018315375 0.030294895 0.046225772
 [7] 0.066645451 0.092064228 0.122788334 0.158757578 0.199797960 0.245925327
[13] 0.297235272 0.354056031 0.417519487

 aa.tree[[2]]
$itime
 [1] 202 202 202 202 202 202 202 202 202 202 205

$iscale
 [1]  1  2  3  4  5  6  7  8  9 10 11


Re: [R] Sink does not send graphs to sink file

2008-12-05 Thread Barry Rowlingson
2008/12/5 Philipp Pagel [EMAIL PROTECTED]:
 I am using sink() to send the results of my analyses to a text
 file. Unfortunately my graphs do not become part of the file.
 Is there anyway that I can have both the text and graphic
 output of my analyses appear in a file?

 Well, how would you expect the graphs to be represented in a text
 file? So the short answer is no you can't do that.

Splus used to have (does it still?) an ascii-text based graphics
device. Fine for simple things, I'm not sure how well fancy lattice
graphics would work on it.

 If someone has a few hours to waste, they might be able to build
something similar for R using aalib:

 http://aa-project.sourceforge.net/aalib/

Barry

__
R-help@r-project.org 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.


Re: [R] Sink does not send graphs to sink file

2008-12-05 Thread Bert Gunter
I think Sweave and/or odfWeave are the real answer, though. Obviously, a
bigger and more elaborate kettle of fish.

-- Bert Gunter 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Barry Rowlingson
Sent: Friday, December 05, 2008 9:21 AM
To: Philipp Pagel
Cc: r-help@r-project.org
Subject: Re: [R] Sink does not send graphs to sink file

2008/12/5 Philipp Pagel [EMAIL PROTECTED]:
 I am using sink() to send the results of my analyses to a text
 file. Unfortunately my graphs do not become part of the file.
 Is there anyway that I can have both the text and graphic
 output of my analyses appear in a file?

 Well, how would you expect the graphs to be represented in a text
 file? So the short answer is no you can't do that.

Splus used to have (does it still?) an ascii-text based graphics
device. Fine for simple things, I'm not sure how well fancy lattice
graphics would work on it.

 If someone has a few hours to waste, they might be able to build
something similar for R using aalib:

 http://aa-project.sourceforge.net/aalib/

Barry

__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Sink does not send graphs to sink file

2008-12-05 Thread Greg Snow
Others mentioned Sweave, which is the best way to go if you have a planned set 
of routines to do.  If you are more just playing and want a transcript of what 
you are doing (unpreplanned) that includes graphics in the final version, then 
look at etxtStart from the TeachingDemos package.  You will need to 
postproccess the file using enscript (and optionally ps2pdf), but then you will 
end up with a file including both the text and the graphics.

Note: using the current version (new one due soon) with R2.8 generates some 
warnings that can be ignored.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 project.org] On Behalf Of John Sorkin
 Sent: Friday, December 05, 2008 8:15 AM
 To: r-help@r-project.org
 Subject: [R] Sink does not send graphs to sink file

 Wiindows XP
 R 2.7
 I am using sink() to send the results of my analyses to a text file.
 Unfortunately my graphs do not become part of the file. Is there anyway
 that I can have both the text and graphic output of my analyses appear
 in a file?
 Thanks,
 John

 John David Sorkin M.D., Ph.D.
 Chief, Biostatistics and Informatics
 University of Maryland School of Medicine Division of Gerontology
 Baltimore VA Medical Center
 10 North Greene Street
 GRECC (BT/18/GR)
 Baltimore, MD 21201-1524
 (Phone) 410-605-7119
 (Fax) 410-605-7913 (Please call phone number above prior to faxing)

 Confidentiality Statement:
 This email message, including any attachments, is for
 th...{{dropped:6}}

 __
 R-help@r-project.org 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-help@r-project.org 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] Running R Script on a Sequence of Files

2008-12-05 Thread Chris Poliquin

Hi,

I have about 900 files that I need to run the same R script on.  I  
looked over the R Data Import/Export Manual and  couldn't come up with  
a way to read in a sequence of files.


The files all have unique names and are in the same directory.  What I  
want to do is:
1) Create a list of the file names in the directory (this is really  
what I need help with)

2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
3) Next File

My initial instinct is to use Python to rename all the files with  
numbers 1:900 and then read them all, but the file names contain some  
information that I would like to keep intact and having to keep a  
separate database of original names and numbers seems inefficient.  Is  
there a way to have R read all the files in a directory one at a time?


- Chris

__
R-help@r-project.org 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] [R-pkgs] RMySQL 0.7-2 now available on CRAN

2008-12-05 Thread Jeffrey Horner

Dear R users,

RMySQL 0.7-2 is now available on CRAN:

http://cran.r-project.org/web/packages/RMySQL/index.html

From the NEWS file:

* New maintainer is Jeffrey Horner [EMAIL PROTECTED].

* We no longer distribute libmysql.dll. This library is now found
 either by reading the MYSQL_HOME environment variable or by reading
 the windows registry entries.

* Removed dependence on MySQL C function load_defaults() as it was
 meant for command-line tools, not for (re)connecting to a database.

* Fixed \r issue with dbWriteTable().

* Tests have been added and depend on proper values set in the
 environment variables MYSQL_DATABASE, MYSQL_USER, and
 MYSQL_PASSWD.

Best,

Jeff

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Kyle.
Have you thought about using one of the Python/R interface modules?

http://www.omegahat.org/RSPython/
http://rpy.sourceforge.net/

Admittedly, I have not had much success in getting these to work on my
machine, but I know others who have.



Kyle H. Ambert
Graduate Student
Department of Medical Informatics  Clinical Epidemiology
Oregon Health  Science University
[EMAIL PROTECTED]

On Fri, Dec 5, 2008 at 10:01 AM, Chris Poliquin [EMAIL PROTECTED]wrote:

 Hi,

 I have about 900 files that I need to run the same R script on.  I looked
 over the R Data Import/Export Manual and  couldn't come up with a way to
 read in a sequence of files.

 The files all have unique names and are in the same directory.  What I want
 to do is:
 1) Create a list of the file names in the directory (this is really what I
 need help with)
 2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
 3) Next File

 My initial instinct is to use Python to rename all the files with numbers
 1:900 and then read them all, but the file names contain some information
 that I would like to keep intact and having to keep a separate database of
 original names and numbers seems inefficient.  Is there a way to have R read
 all the files in a directory one at a time?

 - Chris

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Ajay ohri
This is almost a macro problem. It could be done in SAS language using the
WPS product (660 USD) I think.
It is a familiar problem and I would be quite interested in the result.

Is there any concept of Macros in R or a package to do the same.

Regards,

Ajay

On Fri, Dec 5, 2008 at 11:31 PM, Chris Poliquin [EMAIL PROTECTED]wrote:

 Hi,

 I have about 900 files that I need to run the same R script on.  I looked
 over the R Data Import/Export Manual and  couldn't come up with a way to
 read in a sequence of files.

 The files all have unique names and are in the same directory.  What I want
 to do is:
 1) Create a list of the file names in the directory (this is really what I
 need help with)
 2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
 3) Next File

 My initial instinct is to use Python to rename all the files with numbers
 1:900 and then read them all, but the file names contain some information
 that I would like to keep intact and having to keep a separate database of
 original names and numbers seems inefficient.  Is there a way to have R read
 all the files in a directory one at a time?

 - Chris

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Barry Rowlingson
2008/12/5 Chris Poliquin [EMAIL PROTECTED]:
 Hi,

 I have about 900 files that I need to run the same R script on.  I looked
 over the R Data Import/Export Manual and  couldn't come up with a way to
 read in a sequence of files.

 The files all have unique names and are in the same directory.  What I want
 to do is:
 1) Create a list of the file names in the directory (this is really what I
 need help with)
 2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
 3) Next File

 My initial instinct is to use Python to rename all the files with numbers
 1:900 and then read them all, but the file names contain some information
 that I would like to keep intact and having to keep a separate database of
 original names and numbers seems inefficient.  Is there a way to have R read
 all the files in a directory one at a time?

 I can't believe the two 'solutions' already posted. It's easy:

 ?list.files

Barry

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Bert Gunter
 R has quite a few functions to get and manipulate filenames to facilitate
exactly what you want to do. See ?files and especially the links at the end
to the file name manipulation functions.

e.g. dir(pathname) lists all file names in the directory pathname.
?list.files gives details.

-- Bert Gunter

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Chris Poliquin
Sent: Friday, December 05, 2008 10:02 AM
To: r-help@r-project.org
Subject: [R] Running R Script on a Sequence of Files

Hi,

I have about 900 files that I need to run the same R script on.  I  
looked over the R Data Import/Export Manual and  couldn't come up with  
a way to read in a sequence of files.

The files all have unique names and are in the same directory.  What I  
want to do is:
1) Create a list of the file names in the directory (this is really  
what I need help with)
2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
3) Next File

My initial instinct is to use Python to rename all the files with  
numbers 1:900 and then read them all, but the file names contain some  
information that I would like to keep intact and having to keep a  
separate database of original names and numbers seems inefficient.  Is  
there a way to have R read all the files in a directory one at a time?

- Chris

__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Help with wavCWTPeaks

2008-12-05 Thread stephen sefick
#my suggestion would be to use the morlet wavelet as opposed to the
mexican hat wavelet (default).

aa - (structure(list(X.0.85 = c(-1.02, -1.17, -1.29, -1.39, -1.46,
-1.5, -1.52, -1.5, -1.46, -1.39, -1.3, -1.19, -1.07, -0.93, -0.79,
-0.65, -0.5, -0.36, -0.22, -0.08, 0.05, 0.18, 0.3, 0.41, 0.52,
0.62, 0.72, 0.81, 0.89, 0.98, 1.05, 1.13, 1.19, 1.25, 1.29, 1.31,
1.31, 1.29, 1.24, 1.16, 1.06, 0.93, 0.77, 0.58, 0.38, 0.16, -0.07,
-0.31, -0.89, -1.05, -1.19, -1.31, -1.41, -1.47, -1.51, -1.51,
-1.49, -1.44, -1.37, -1.28, -1.17, -1.04, -0.91, -0.76, -0.62,
-0.47, -0.33, -0.19, -0.06, 0.08, 0.2, 0.32, 0.43, 0.54, 0.64,
0.73, 0.82, 0.91, 0.99, 1.07, 1.14, 1.2, 1.25, 1.29, 1.31, 1.31,
1.28, 1.23, 1.15, 1.04, 0.9, 0.73, 0.55, 0.34, 0.11, -0.12, -0.92,
-1.08, -1.22, -1.33, -1.42, -1.48, -1.51, -1.51, -1.48, -1.43,
-1.35, -1.26, -1.14, -1.01, -0.88, -0.74, -0.59, -0.45, -0.3,
-0.16, -0.03, 0.1, 0.22, 0.34, 0.45, 0.56, 0.66, 0.75, 0.84,
0.93, 1.01, 1.08, 1.15, 1.21, 1.26, 1.3, 1.31, 1.3, 1.27, 1.21,
1.13, 1.01, 0.87, 0.7, 0.5, 0.29, 0.07, -0.17, -0.95, -1.11,
-1.24, -1.35, -1.44, -1.49, -1.51, -1.51, -1.48, -1.42, -1.33,
-1.23, -1.12, -0.99, -0.85, -0.71, -0.56, -0.42, -0.27, -0.14,
0, 0.13, 0.25, 0.36, 0.47, 0.58, 0.68, 0.77, 0.86, 0.94, 1.02,
1.1, 1.17, 1.23, 1.27, 1.3, 1.31, 1.3, 1.26, 1.2, 1.11, 0.98,
0.83, 0.66, 0.46, 0.25, 0.02, -0.22, -0.99, -1.14, -1.27, -1.37,
-1.45, -1.5, -1.52, -1.5, -1.47, -1.4, -1.32, -1.21, -1.09, -0.96,
-0.82, -0.68, -0.53, -0.39, -0.25, -0.11, 0.02, 0.15, 0.27, 0.39,
0.5, 0.6, 0.7, 0.79, 0.87, 0.96, 1.04, 1.11, 1.18, 1.24, 1.28,
1.31, 1.31, 1.29, 1.25, 1.18, 1.08, 0.96, 0.8, 0.62, 0.42, 0.2,
-0.03, -0.27)), .Names = X.0.85, class = data.frame, row.names = c(NA,
-240L)))
library(wmtsa)
library(fields)
aats - ts (aa, deltat =1/30, start = 0.0)
aa.cwt -  wavCWT(aats, wavelet=morlet, col=tim.colors(100))
aa.tree - wavCWTTree (aa.cwt)

On Fri, Dec 5, 2008 at 12:15 PM,  [EMAIL PROTECTED] wrote:
 I cannot understand the following error printed out when I try to get the
 extrema of my time series.
 I would appreciate some suggestion as I really cannot interpret the error. I
 might not be using a proper
 set of parameters in calling such functions. I am learning by doing ...

 aa.peak - wavCWTPeaks (aa.tree)
 Error in `row.names-.data.frame`(`*tmp*`, value = c(1, 0)) :
   invalid 'row.names' length

 My data vector is as follows:
 aa
   [1] -0.852625404 -0.886941142 -0.920699269 -0.953858240 -0.986377090
   [6] -1.018215725 -1.049335086 -1.079697274 -1.109265628 -1.138004782
  [11] -1.165880733 -1.192860894 -1.218914146 -1.244010899 -1.268123116
  [16] -1.291224432 -1.313290096 -1.334297111 -1.354224193 -1.373051833
  [21] -1.390762317 -1.407339716 -1.422769965 -1.437040775 -1.450141701
  [26] -1.462064157 -1.472801336 -1.482348272 -1.490701780 -1.497860461
  [31] -1.503824640 -1.508596384 -1.512179425 -1.514579128 -1.515802478
  [36] -1.515858035 -1.514755845 -1.512507449 -1.509125815 -1.504625250
  [41] -1.499021421 -1.492331231 -1.484572809 -1.475765432 -1.465929450
  [46] -1.455086269 -1.443258266 -1.430468724 -1.416741774 -1.402102340
  [51] -1.386576077 -1.370189287 -1.352968891 -1.334942359 -1.316137624
  [56] -1.296583049 -1.276307350 -1.255339556 -1.233708931 -1.211444912
  [61] -1.188577082 -1.165135088 -1.141148591 -1.116647219 -1.091660532
  [66] -1.066217945 -1.040348675 -1.014081694 -0.987445689 -0.960469010
  [71] -0.933179631 -0.905605109 -0.82541 -0.849708278 -0.821438088
  [76] -0.792987122 -0.764379898 -0.735640266 -0.706791393 -0.677855738
  [81] -0.648855033 -0.619810274 -0.590741693 -0.561668758 -0.532610156
  [86] -0.503583784 -0.474606745 -0.445695338 -0.416865062 -0.388130609
  [91] -0.359505865 -0.331003918 -0.302637056 -0.274416782 -0.246353810
  [96] -0.218458088 -0.190738802 -0.163204394 -0.135862573 -0.108720337
 [101] -0.081783987 -0.055059152 -0.028550808 -0.002263304  0.023799613
 [106]  0.049634774  0.075239551  0.100611836  0.125750005  0.150652886
 [111]  0.175319722  0.199750141  0.223944116  0.247901927  0.271624125
 [116]  0.295111492  0.318365000  0.341385774  0.364175049  0.386734130
 [121]  0.409064353  0.431167045  0.453043480  0.474694850  0.496122212
 [126]  0.517326465  0.538308303  0.559068185  0.579606300  0.599922532
 [131]  0.620016432  0.639887183  0.659533578  0.678953988  0.698146340
 [136]  0.716367156  0.734459833  0.752428741  0.770277372  0.788008310
 [141]  0.805623188  0.823122667  0.840506396  0.857773019  0.874920094
 [146]  0.891944162  0.908840641  0.925603903  0.942227205  0.958702728
 [151]  0.975021541  0.991173645  1.007147946  1.022932278  1.038513449
 [156]  1.053877190  1.069008243  1.083890313  1.098506181  1.112837647
 [161]  1.126865608  1.140570088  1.153930270  1.166924526  1.179530477
 [166]  1.191725035  1.203484451  1.214784382  1.225599912  1.235905642
 [171]  1.245675755  1.254884072  1.263504095  1.271509107  1.278872248
 [176]  1.285566555  1.291565077  1.296840902  1.301367293  1.305117743
 [181]  1.308066011  

Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Kyle.
Thanks, Barry. I'll use that in the future.


---Kyle.

On Fri, Dec 5, 2008 at 11:01 AM, Barry Rowlingson 
[EMAIL PROTECTED] wrote:

 2008/12/5 Chris Poliquin [EMAIL PROTECTED]:
  Hi,
 
  I have about 900 files that I need to run the same R script on.  I looked
  over the R Data Import/Export Manual and  couldn't come up with a way to
  read in a sequence of files.
 
  The files all have unique names and are in the same directory.  What I
 want
  to do is:
  1) Create a list of the file names in the directory (this is really what
 I
  need help with)
  2) For each item in the list...
 a) open the file with read.table
 b) perform some analysis
 c) append some results to an array or save them to another file
  3) Next File
 
  My initial instinct is to use Python to rename all the files with numbers
  1:900 and then read them all, but the file names contain some information
  that I would like to keep intact and having to keep a separate database
 of
  original names and numbers seems inefficient.  Is there a way to have R
 read
  all the files in a directory one at a time?

  I can't believe the two 'solutions' already posted. It's easy:

  ?list.files

 Barry

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Gabor Grothendieck
Use dir to get the names and then lapply over them with a
custom anonymous function where L is a list of the returned
values:

# assumes file names are those in
# current directory that end in .dat
filenames - dir(pattern = \\.dat$)

L - lapply(filenames, function(x) {
  DF - read.table(x, ...whatever...)
  somefunction(DF)
})

Now L is a list of the returned 900 values.  Alternately you could use
a loop.


On Fri, Dec 5, 2008 at 1:01 PM, Chris Poliquin [EMAIL PROTECTED] wrote:
 Hi,

 I have about 900 files that I need to run the same R script on.  I looked
 over the R Data Import/Export Manual and  couldn't come up with a way to
 read in a sequence of files.

 The files all have unique names and are in the same directory.  What I want
 to do is:
 1) Create a list of the file names in the directory (this is really what I
 need help with)
 2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
 3) Next File

 My initial instinct is to use Python to rename all the files with numbers
 1:900 and then read them all, but the file names contain some information
 that I would like to keep intact and having to keep a separate database of
 original names and numbers seems inefficient.  Is there a way to have R read
 all the files in a directory one at a time?

 - Chris

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Philipp Pagel
  I can't believe the two 'solutions' already posted. It's easy:

Me neither.
 
  ?list.files

That's what I would use, too. If the OP is on a UNIX platform,
run the R-script in a loop in the shell is an alternative.
Something like this (bourne shell syntax):

for datafile in *.csv ; do
Rscript analyze.R $datafile
done

The R script (analyze.R) can use commandArgs() to read the filename
argument.

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Gustavo Carvalho
Is there a way to list only the files in a given directory without
passing pattern=... to list.files()?

On Fri, Dec 5, 2008 at 5:10 PM, Kyle. [EMAIL PROTECTED] wrote:
 Thanks, Barry. I'll use that in the future.


 ---Kyle.

 On Fri, Dec 5, 2008 at 11:01 AM, Barry Rowlingson 
 [EMAIL PROTECTED] wrote:

 2008/12/5 Chris Poliquin [EMAIL PROTECTED]:
  Hi,
 
  I have about 900 files that I need to run the same R script on.  I looked
  over the R Data Import/Export Manual and  couldn't come up with a way to
  read in a sequence of files.
 
  The files all have unique names and are in the same directory.  What I
 want
  to do is:
  1) Create a list of the file names in the directory (this is really what
 I
  need help with)
  2) For each item in the list...
 a) open the file with read.table
 b) perform some analysis
 c) append some results to an array or save them to another file
  3) Next File
 
  My initial instinct is to use Python to rename all the files with numbers
  1:900 and then read them all, but the file names contain some information
  that I would like to keep intact and having to keep a separate database
 of
  original names and numbers seems inefficient.  Is there a way to have R
 read
  all the files in a directory one at a time?

  I can't believe the two 'solutions' already posted. It's easy:

  ?list.files

 Barry

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Gabor Grothendieck
Try this:

dir()[!file.info(dir())$isdir]


On Fri, Dec 5, 2008 at 2:30 PM, Gustavo Carvalho
[EMAIL PROTECTED] wrote:
 Is there a way to list only the files in a given directory without
 passing pattern=... to list.files()?

 On Fri, Dec 5, 2008 at 5:10 PM, Kyle. [EMAIL PROTECTED] wrote:
 Thanks, Barry. I'll use that in the future.


 ---Kyle.

 On Fri, Dec 5, 2008 at 11:01 AM, Barry Rowlingson 
 [EMAIL PROTECTED] wrote:

 2008/12/5 Chris Poliquin [EMAIL PROTECTED]:
  Hi,
 
  I have about 900 files that I need to run the same R script on.  I looked
  over the R Data Import/Export Manual and  couldn't come up with a way to
  read in a sequence of files.
 
  The files all have unique names and are in the same directory.  What I
 want
  to do is:
  1) Create a list of the file names in the directory (this is really what
 I
  need help with)
  2) For each item in the list...
 a) open the file with read.table
 b) perform some analysis
 c) append some results to an array or save them to another file
  3) Next File
 
  My initial instinct is to use Python to rename all the files with numbers
  1:900 and then read them all, but the file names contain some information
  that I would like to keep intact and having to keep a separate database
 of
  original names and numbers seems inefficient.  Is there a way to have R
 read
  all the files in a directory one at a time?

  I can't believe the two 'solutions' already posted. It's easy:

  ?list.files

 Barry

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Jagat.K.Sheth
This is almost a macro problem. It could be done in SAS language using
the WPS product (660 USD) I think. ... 

OUCH! Why do it the complicated way??? Check out ?dir, ?list.files, and
then ?lapply for a simple start.

Don't give up so soon! When it comes to R there is no need to punt - you
can always keep possession of the ball ... :-)

Cheers,
Jagat

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ajay ohri
Sent: Friday, December 05, 2008 12:59 PM
To: Chris Poliquin
Cc: r-help@r-project.org
Subject: Re: [R] Running R Script on a Sequence of Files

This is almost a macro problem. It could be done in SAS language using
the
WPS product (660 USD) I think.
It is a familiar problem and I would be quite interested in the result.

Is there any concept of Macros in R or a package to do the same.

Regards,

Ajay

On Fri, Dec 5, 2008 at 11:31 PM, Chris Poliquin
[EMAIL PROTECTED]wrote:

 Hi,

 I have about 900 files that I need to run the same R script on.  I
looked
 over the R Data Import/Export Manual and  couldn't come up with a way
to
 read in a sequence of files.

 The files all have unique names and are in the same directory.  What I
want
 to do is:
 1) Create a list of the file names in the directory (this is really
what I
 need help with)
 2) For each item in the list...
a) open the file with read.table
b) perform some analysis
c) append some results to an array or save them to another file
 3) Next File

 My initial instinct is to use Python to rename all the files with
numbers
 1:900 and then read them all, but the file names contain some
information
 that I would like to keep intact and having to keep a separate
database of
 original names and numbers seems inefficient.  Is there a way to have
R read
 all the files in a directory one at a time?

 - Chris

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Ajay ohri
Thanks for the solution . I especially liked the analogy along with the code
of course.
Regards,

Ajay

www.decisionstats.com

On Sat, Dec 6, 2008 at 1:23 AM, [EMAIL PROTECTED] wrote:

 This is almost a macro problem. It could be done in SAS language using
 the WPS product (660 USD) I think. ...

 OUCH! Why do it the complicated way??? Check out ?dir, ?list.files, and
 then ?lapply for a simple start.

 Don't give up so soon! When it comes to R there is no need to punt - you
 can always keep possession of the ball ... :-)

 Cheers,
 Jagat

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 On Behalf Of Ajay ohri
 Sent: Friday, December 05, 2008 12:59 PM
 To: Chris Poliquin
 Cc: r-help@r-project.org
 Subject: Re: [R] Running R Script on a Sequence of Files

 This is almost a macro problem. It could be done in SAS language using
 the
 WPS product (660 USD) I think.
 It is a familiar problem and I would be quite interested in the result.

 Is there any concept of Macros in R or a package to do the same.

 Regards,

 Ajay

 On Fri, Dec 5, 2008 at 11:31 PM, Chris Poliquin
 [EMAIL PROTECTED]wrote:

  Hi,
 
  I have about 900 files that I need to run the same R script on.  I
 looked
  over the R Data Import/Export Manual and  couldn't come up with a way
 to
  read in a sequence of files.
 
  The files all have unique names and are in the same directory.  What I
 want
  to do is:
  1) Create a list of the file names in the directory (this is really
 what I
  need help with)
  2) For each item in the list...
 a) open the file with read.table
 b) perform some analysis
 c) append some results to an array or save them to another file
  3) Next File
 
  My initial instinct is to use Python to rename all the files with
 numbers
  1:900 and then read them all, but the file names contain some
 information
  that I would like to keep intact and having to keep a separate
 database of
  original names and numbers seems inefficient.  Is there a way to have
 R read
  all the files in a directory one at a time?
 
  - Chris
 
  __
  R-help@r-project.org 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.
 

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org 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.



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Running R Script on a Sequence of Files

2008-12-05 Thread Steve_Friedman
It seems that you have 900 files with the same parameters in each file (I
might be reading more between the lines here than you inferred). However if
this is the case, why not import each of the files into a common database
and then link the database using ODBC connectivity options.  If that is
practical, you could then code a series of subsetting options to select the
data you need for specific analysis, write reports, and then iteratively
select the next set of records.

I may be suggesting a very simple solution, so forgive me if this
trivializes your problem too greatly.

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

[EMAIL PROTECTED]
Office (305) 224 - 4282
Fax (305) 224 - 4147


   
 Chris Poliquin
 [EMAIL PROTECTED] 
 nn.eduTo 
 Sent by:  r-help@r-project.org
 [EMAIL PROTECTED]  cc 
 project.org   
   Subject 
   [R] Running R Script on a Sequence  
 12/05/2008 01:01  of Files
 PM EST
   
   
   
   
   




Hi,

I have about 900 files that I need to run the same R script on.  I
looked over the R Data Import/Export Manual and  couldn't come up with
a way to read in a sequence of files.

The files all have unique names and are in the same directory.  What I
want to do is:
1) Create a list of the file names in the directory (this is really
what I need help with)
2) For each item in the list...
 a) open the file with read.table
 b) perform some analysis
 c) append some results to an array or save them to another
file
3) Next File

My initial instinct is to use Python to rename all the files with
numbers 1:900 and then read them all, but the file names contain some
information that I would like to keep intact and having to keep a
separate database of original names and numbers seems inefficient.  Is
there a way to have R read all the files in a directory one at a time?

- Chris

__
R-help@r-project.org 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-help@r-project.org 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] adding rows as arithmatic calculation on original rows

2008-12-05 Thread Ferry
Dear R users,

Suppose I have the following data.frame:

myID myType myNum1 myNum2 myNum3
a   Single   10  11   12
b   Single   15  25   35
c   Double  22  33   44
d   Double4   6 8

and I want to have new records:

myID myType myNum1 myNum2 myNum3
e  Single   12.5   18   23.5
f   Double  13  19.5 28

where record e got its myNum1-3 as the average from record a and b, and
record f got its myNum1-3 as the average from record c and d.

and the final data.frame should be like the following:

myID myType myNum1 myNum2 myNum3
a   Single   10  11   12
b   Single   15  25   35
e   Single   12.5   18   43.5
c   Double  22  33   44
d   Double4   6 8
fDouble  13  19.5 28

Any idea is appreciated. Thanks beforehand.

Ferry

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] How to calculate the distance between two density functions

2008-12-05 Thread Lucke, Joseph F
In general, comparing two continuous densities is difficult because they
can differ on a set of measure 0 (i.e., at a single point) and yet have
the same distribution function. 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Chang Jia-Ming
Sent: Friday, December 05, 2008 8:00 AM
To: r-help@r-project.org
Subject: [R] How to calculate the distance between two density functions

Dear all,

  I wrote the following code to calculate the density functions for two
data sets, respectively.

  den_str -density(str_data$Similarity);
  den_non_str -density(nonstr_data$Similarity);

  However, I would like to knowing the difference between den_str and
den_non_str, that is, the difference between the region under the curve
of the den_str and the region under the curve of the den_non_str.

 How to do?

 Thank you for help.

Jia-Ming

[[alternative HTML version deleted]]

__
R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Random Forest weighting

2008-12-05 Thread Raghu Naik
Andy,

Thanks for your email.

I understand that by default, the sampsize variable will use the behavior
variable that we are classifying as the strata variable.

Then, I could set sampsize=c(no=89, yes=11). I implemented that but I got
99% classification error rate on the yes value. When I oversample on the yes
values by taking sampsize=c(50,50) I get more or less equal classification
error rate of 50% for both the yes and no values.

Is there some science to what extent we should oversample on the imbalanced
level?

Thanks for your reply and all your help.

Raghu


On 12/4/08, Liaw, Andy [EMAIL PROTECTED] wrote:

 If I understand your situation correctly, you may be able to make use of
 the strata and sampsize arguments in randomForest() to get bootstrap
 samples that resemble the original data distribution.  They allow you to
 specify stratified samples using the strata variable.

 Best,
 Andy

 From: Raghu Naik
 
  Folks,
 
  I have a query around weighting in Random Forest (RF). I know
  that several
  earlier emails in this group have raised this issue, but I
  did not find an
  answer to my query.
 
  I am working on a dataset (dataset1) that consists of 4
  million records that
  can be reduced to a dataset (dataset2) of approximately 1500
  unique records
  with frequency counts that add up to the 4 million records
  number as above.
  Because of size issues, I cannot work with dataset1 in R and
  therefore, I am
  working with dataset2 .
 
  Each record consists of whether or not a patient chose a
  particular drug
  based on 14 comorbidity (Yes / No) variables; I am using RF
  to understand
  the comorbidity drivers of drug adoption (yes/no) classification.
 
  At full dataset level (dataset1), the drug adoption incidence
  is ~11%. At
  the reduced dataset dataset2 level, the drug adoption
  incidence increases to
  ~38%.
 
  My question is that, if am using the reduced dataset
  (dataset2), how should
  I inform RF that the adoption incidence at the full dataset
  level was 11%.
  Should that be used as a classwt prior with
  classwt=c(Yes=.11, No=.89)? My
  understanding is that RF does not allow case weighting.
  Or can this be handled with the sampsize arguement through
  oversampling?
  What proportions should one use for this (e.g., sampsize=c(Yes=100,
  No=100))?
 
 
 
  I would appreciate any feedback or pointers to any earlier
  thread that I may
  have overlooked.
 
  Regards,
 
  Raghu
 Notice:  This e-mail message, together with any attach...{{dropped:17}}

__
R-help@r-project.org 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.


Re: [R] alternative way to replicate()

2008-12-05 Thread Johannes Hüsing

Am 03.12.2008 um 09:06 schrieb Liviu Andronic:


Dear all,

I'm looking for an alternative way to replicate the 2, string for an
x number of times, and end up with one string containing 2, x times.
I can partly achieve this using replicate().

y - rep(2,, times=3)
y



JFTR: replicate() is a different function from rep(). See ?rep and 
?replicate.


__
R-help@r-project.org 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] lme4, error in mer_finalize(ans)

2008-12-05 Thread B. Meijering
Using lmer() on my data results in an error. The problem, 
I think, is my model specification. However, lm() works 
ok.
I recreated this error with a more simple dataset. (See 
code below.)


# word and letter recognition data
# two within factors:
# word length: 4, 5, 6 letters
# letter position: 1-4 (in 4-letter words), 1-5 (in 
5-letter words), 1-6 (in 6-letter words)

# one dependent variable:
# reaction time

# make artificial data
length - c(rep(4,4), rep(5,5), rep(6,6)) # independent 
variable word length

length - factor(c(rep(length, 2)))
pos - c(1:4, 1:5, 1:6) # independent variable letter 
position

pos - factor(c(rep(pos, 2)))
rt - c(rnorm(15, 200, sd=10), rnorm(15, 300, sd=15)) # 
dependent variable reaction time
df - data.frame(subj=factor(c(rep(1:2, each=15))), 
length=length, pos=pos, rt=rt)


# to use lmer from lme4 package
library(lme4)

# first fit a linear model with letter position nested in 
word length

lm(rt ~ length + length:pos, data=df)

# fit a mixed effects model, with subj (participant) as 
random effect

lmer(rt ~ length + length:pos + (1 | subj), data=df)

Using lmer() results in an error: Error in 
mer_finalize(ans) : Downdated X'X is not positive 
definite, 13. I don't experience any problems using lm(). 
Does anyone know where things go wrong?


~ Ben Meijering

__
R-help@r-project.org 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.


Re: [R] adding rows as arithmatic calculation on original rows

2008-12-05 Thread jim holtman
This should get you close:

 x - read.table(textConnection(myID myType myNum1 myNum2 myNum3
+ a   Single   10  11   12
+ b   Single   15  25   35
+ c   Double  22  33   44
+ d   Double4   6 8), header=TRUE)
 closeAllConnections()
 y - lapply(split(x, x$myType), function(.type){
+ .means - colMeans(.type[,3:5])
+ # create the new line for the data frame
+ .df - data.frame(myID='', myType=.type$myType[1], myNum1=.means[1],
+ myNum2=.means[2], myNum3=.means[3])
+ rbind(.type, .df) # append the line to the original dataframe
+ })
 do.call(rbind, y)  # you can add the names your want
  myID myType myNum1 myNum2 myNum3
Double.3 c Double   22.0   33.0   44.0
Double.4 d Double4.06.08.0
Double.myNum1  Double   13.0   19.5   26.0
Single.1 a Single   10.0   11.0   12.0
Single.2 b Single   15.0   25.0   35.0
Single.myNum1  Single   12.5   18.0   23.5


On Fri, Dec 5, 2008 at 3:21 PM, Ferry [EMAIL PROTECTED] wrote:
 Dear R users,

 Suppose I have the following data.frame:

 myID myType myNum1 myNum2 myNum3
 a   Single   10  11   12
 b   Single   15  25   35
 c   Double  22  33   44
 d   Double4   6 8

 and I want to have new records:

 myID myType myNum1 myNum2 myNum3
 e  Single   12.5   18   23.5
 f   Double  13  19.5 28

 where record e got its myNum1-3 as the average from record a and b, and
 record f got its myNum1-3 as the average from record c and d.

 and the final data.frame should be like the following:

 myID myType myNum1 myNum2 myNum3
 a   Single   10  11   12
 b   Single   15  25   35
 e   Single   12.5   18   43.5
 c   Double  22  33   44
 d   Double4   6 8
 fDouble  13  19.5 28

 Any idea is appreciated. Thanks beforehand.

 Ferry

[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org 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.


Re: [R] lme4, error in mer_finalize(ans)

2008-12-05 Thread Douglas Bates
On Fri, Dec 5, 2008 at 3:44 PM, B. Meijering [EMAIL PROTECTED] wrote:
 Using lmer() on my data results in an error. The problem, I think, is my
 model specification. However, lm() works ok.
 I recreated this error with a more simple dataset. (See code below.)

 # word and letter recognition data
 # two within factors:
 # word length: 4, 5, 6 letters
 # letter position: 1-4 (in 4-letter words), 1-5 (in 5-letter words), 1-6 (in
 6-letter words)
 # one dependent variable:
 # reaction time



 # first fit a linear model with letter position nested in word length
 lm(rt ~ length + length:pos, data=df)

 # fit a mixed effects model, with subj (participant) as random effect
 lmer(rt ~ length + length:pos + (1 | subj), data=df)

 Using lmer() results in an error: Error in mer_finalize(ans) : Downdated X'X
 is not positive definite, 13. I don't experience any problems using lm().
 Does anyone know where things go wrong?

That, admittedly obscure, error message relates to the fixed-effects
specification rt ~ length + length:pos being rank deficient.  If you
look at the summary of the linear model fit you will see that there
are 3 coefficients that are not determined because of singularities.
The lm function detects the singularities and fits a lower-rank model.
 The lmer function is not as sophisticated.  It just detects the
singularities and quits.

The length and the position are confounded.

 xtabs(~ len + pos, df)
   pos
len 1 2 3 4 5 6
  4 2 2 2 2 0 0
  5 2 2 2 2 2 0
  6 2 2 2 2 2 2

(By the way, I changed the name of the length variable to len as
typing length makes me expect the function called length.)

Even when you remove this confounding by creating the len:pos
interaction separately as a factor, you will still get singularities
because there is only one len:pos combination for len = 6.

You will need to think of a way of parameterizing the fixed effects
without the singularities.  You can check for singularities in the
summary of the lm fit.

__
R-help@r-project.org 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.


Re: [R] adding rows as arithmatic calculation on original rows

2008-12-05 Thread Ferry
Thanks much Jim.

On Fri, Dec 5, 2008 at 2:05 PM, jim holtman [EMAIL PROTECTED] wrote:

 This should get you close:

  x - read.table(textConnection(myID myType myNum1 myNum2 myNum3
 + a   Single   10  11   12
 + b   Single   15  25   35
 + c   Double  22  33   44
 + d   Double4   6 8), header=TRUE)
  closeAllConnections()
  y - lapply(split(x, x$myType), function(.type){
 + .means - colMeans(.type[,3:5])
 + # create the new line for the data frame
 + .df - data.frame(myID='', myType=.type$myType[1], myNum1=.means[1],
 + myNum2=.means[2], myNum3=.means[3])
 + rbind(.type, .df) # append the line to the original dataframe
 + })
  do.call(rbind, y)  # you can add the names your want
   myID myType myNum1 myNum2 myNum3
 Double.3 c Double   22.0   33.0   44.0
 Double.4 d Double4.06.08.0
 Double.myNum1  Double   13.0   19.5   26.0
 Single.1 a Single   10.0   11.0   12.0
 Single.2 b Single   15.0   25.0   35.0
 Single.myNum1  Single   12.5   18.0   23.5


 On Fri, Dec 5, 2008 at 3:21 PM, Ferry [EMAIL PROTECTED] wrote:
  Dear R users,
 
  Suppose I have the following data.frame:
 
  myID myType myNum1 myNum2 myNum3
  a   Single   10  11   12
  b   Single   15  25   35
  c   Double  22  33   44
  d   Double4   6 8
 
  and I want to have new records:
 
  myID myType myNum1 myNum2 myNum3
  e  Single   12.5   18   23.5
  f   Double  13  19.5 28
 
  where record e got its myNum1-3 as the average from record a and b, and
  record f got its myNum1-3 as the average from record c and d.
 
  and the final data.frame should be like the following:
 
  myID myType myNum1 myNum2 myNum3
  a   Single   10  11   12
  b   Single   15  25   35
  e   Single   12.5   18   43.5
  c   Double  22  33   44
  d   Double4   6 8
  fDouble  13  19.5 28
 
  Any idea is appreciated. Thanks beforehand.
 
  Ferry
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org 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.
 



 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Cartesian Product Of Character Vectors

2008-12-05 Thread Ben Bolker
 Rory.WINSTON at rbs.com writes:

 
 Sorry, I spoke too soon...
 
 interaction() only works for sequences of equal length. Anyone know a method
that works with
 unequal-length vectors?
 

  Something like

 c(outer(vec1,vec2,paste,sep=))  ?

  (totally untested)

  Ben Bolker

__
R-help@r-project.org 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.


Re: [R] Question about lrandom effects specification in lme4

2008-12-05 Thread Douglas Bates
On Thu, Dec 4, 2008 at 6:21 PM, Bert Gunter [EMAIL PROTECTED] wrote:

 Folks:

 Suppose I have 3 random effects, A,B, and C. Using the older lme() function
 (in nlme) it was possible (using the pdMat classes) to specify that they are
 uncorrelated with identical variances. Is it possible to do this with lmer?
 My understanding is that if I specify them as

 lmer( y ~ ... + (A|Grp) + (B|Grp) + (C|Grp))

 then they are uncorrelated but have different variances.

That's correct.

At present there isn't an easy way to do what you want to do but I am
working on modifications that would allow such changes.  You would
need to define a new reCovFac (random-effects covariance factor)
class.  In this case it would be straightforward because the
covariance factor for the combined terms is a multiple of the
identity.

If you are feeling adventurous contact me off-list and I will describe
how I think this could be done using the code in the allcoef branch
of the SVN tree at R-forge.  Installing that branch is not for the
faint of heart.  It is seriously broken right now but I'm confident
I'll get it all back together in the not-too-distant future.

 Motivation: I'd like to use lmer instead of lme for fitting smoothing
 splines to longitudinal data.

 Cheers,
 Bert Gunter
 Genentech

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] adding rows as arithmatic calculation on original rows

2008-12-05 Thread Gabor Grothendieck
Here is a solution using sqldf



library(sqldf)

DF2 -
structure(list(myID = structure(1:4, .Label = c(a, b, c,
d), class = factor), myType = structure(c(2L, 2L, 1L, 1L), .Label
= c(Double,
Single), class = factor), myNum1 = c(10, 15, 22, 4), myNum2 = c(11,
25, 33, 6), myNum3 = c(12, 35, 44, 8)), .Names = c(myID, myType,
myNum1, myNum2, myNum3), row.names = c(NA, -4L), class = data.frame)

sqldf(select 1 TotalLevel, '+' myID, myType, avg(myNum1) myNum1,
avg(myNum2) myNum2, avg(myNum3) myNum3
  from DF2
  group by myType
union
  select 0 TotalLevel, *
 from DF2
order by myType, TotalLevel, myID,
method = raw)[-1]

The output is (display in fixed font):

  myID myType myNum1 myNum2 myNum3
1c Double   22.0   33.0   44.0
2d Double4.06.08.0
3+ Double   13.0   19.5   26.0
4a Single   10.0   11.0   12.0
5b Single   15.0   25.0   35.0
6+ Single   12.5   18.0   23.5



On Fri, Dec 5, 2008 at 3:21 PM, Ferry [EMAIL PROTECTED] wrote:
 Dear R users,

 Suppose I have the following data.frame:

 myID myType myNum1 myNum2 myNum3
 a   Single   10  11   12
 b   Single   15  25   35
 c   Double  22  33   44
 d   Double4   6 8

 and I want to have new records:

 myID myType myNum1 myNum2 myNum3
 e  Single   12.5   18   23.5
 f   Double  13  19.5 28

 where record e got its myNum1-3 as the average from record a and b, and
 record f got its myNum1-3 as the average from record c and d.

 and the final data.frame should be like the following:

 myID myType myNum1 myNum2 myNum3
 a   Single   10  11   12
 b   Single   15  25   35
 e   Single   12.5   18   43.5
 c   Double  22  33   44
 d   Double4   6 8
 fDouble  13  19.5 28

 Any idea is appreciated. Thanks beforehand.

 Ferry

[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] How to get Greenhouse-Geisser epsilons from anova?

2008-12-05 Thread Peter Dalgaard

Skotara wrote:

Dear Mr. Daalgard.

thank you very much for your reply, it helped me to progress a bit.

The following works fine:
dd - expand.grid(C = 1:7, B= c(r, l), A= c(c, f))
myma - as.matrix(myma) #myma is a 12 by 28 list
mlmfit - lm(myma~1)
mlmfit0 - update(mlmfit, ~0)
anova(mlmfit, mlmfit0, X= ~C+B, M = ~A+C+B, idata = dd,  
test=Spherical), which tests the main effect of A.
anova(mlmfit, mlmfit0, X= ~A+C,  M = ~A+C+B, idata = dd,  
test=Spherical), which tests the main effect of B.



However, I can not figure out how this works for the other effects.
If I try:
anova(mlmfit, mlmfit0, X= ~A+B,  M = ~A+C+B, idata = dd,  test=Spherical)

I get:
Fehler in function (object, ..., test = c(Pillai, Wilks, 
Hotelling-Lawley,  :

   residuals have rank 1  4


dd$C is not a factor with that construction. It works for me after

dd$C - factor(dd$C)

(The other message is nasty, though. It's slightly different in R-patched:

 anova(mlmfit, mlmfit0, X= ~A+B, M = ~A+C+B, idata = dd, 
test=Spherical)

Error in solve.default(Psi, B) :
  system is computationally singular: reciprocal condition number = 
2.17955e-34


but it shouldn't happen...
Looks like it is a failure of the internal Thin.row function. Ick!
)


I also don't know how I can calculate the various interactions..
My read is I should change the second argument mlmfit0, too, but I can't 
figure out how...



The within interactions should be straightforward, e.g.

M=~A*B*C
X=~A*B*C-A:B:C

etc.

The within/between interactions are otained from the similar tests of 
the between factor(s)


e.g.

mlmfitD - lm(myma~D)

and then

anova(mlmfitD, mlmfit,)





Do you know what to do?
Thank you very much!



Peter Dalgaard schrieb:

Skotara wrote:

Dear all,

I apologize for my basic question.
I try to calculate an anova for repeated measurements with 3 factors 
(A,B,C) having 2, 2, and 7 levels.

or with an additional fourth between subjects factor D.
Everything works fine using
aov(val ~ A*B*C  + Error(subject/ (A*B*C) ) )  or
aov(val ~ (D*A*B*C)  + Error(subject/(A*B*C)) + D )
val, A, B, C, D and subject are columns in a data.frame.

How can I get the estimated Greenhouse-Geisser and Huynh-Feldt epsilons?
I know Peter Dalgaard described it in R-News Vol. 7/2, October 2007. 
However, unfortunately I am not able to apply that using my data...


Why? It is supposed to work. You just need to work out the X and M 
specification for the relevant error strata and set test=Spherical 
for anova.mlm, or work out the T contrast matrix explicitly if that 
suits your temper better.


Furthermore, I am still confused of how SPSS calculates the epsilons 
since it is mentioned that perhaps there are any errors in SPSS??


I would be glad if anyone could help me!
I am looking forward to hearing from you!

Thank you!
Nils

__
R-help@r-project.org 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.






--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org 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.


Re: [R] adding rows as arithmatic calculation on original rows

2008-12-05 Thread rmailbox

Here is a solution using doBy and Gabor's DF2 created below:

library( doBy )
newrows - summaryBy ( myNum1 + myNum2 + myNum3  ~ myType , DF2, keep.names = 
TRUE )
newrows[,myID] - + 
rbind ( DF2, newrows)





- Original message -
From: Gabor Grothendieck [EMAIL PROTECTED]
To: Ferry [EMAIL PROTECTED]
Cc: r-help@r-project.org
Date: Fri, 5 Dec 2008 17:50:42 -0500
Subject: Re: [R] adding rows as arithmatic calculation on original rows

Here is a solution using sqldf



library(sqldf)

DF2 -
structure(list(myID = structure(1:4, .Label = c(a, b, c,
d), class = factor), myType = structure(c(2L, 2L, 1L, 1L), .Label
= c(Double,
Single), class = factor), myNum1 = c(10, 15, 22, 4), myNum2 = c(11,
25, 33, 6), myNum3 = c(12, 35, 44, 8)), .Names = c(myID, myType,
myNum1, myNum2, myNum3), row.names = c(NA, -4L), class = data.frame)

sqldf(select 1 TotalLevel, '+' myID, myType, avg(myNum1) myNum1,
avg(myNum2) myNum2, avg(myNum3) myNum3
  from DF2
  group by myType
union
  select 0 TotalLevel, *
 from DF2
order by myType, TotalLevel, myID,
method = raw)[-1]

The output is (display in fixed font):

  myID myType myNum1 myNum2 myNum3
1c Double   22.0   33.0   44.0
2d Double4.06.08.0
3+ Double   13.0   19.5   26.0
4a Single   10.0   11.0   12.0
5b Single   15.0   25.0   35.0
6+ Single   12.5   18.0   23.5



On Fri, Dec 5, 2008 at 3:21 PM, Ferry [EMAIL PROTECTED] wrote:
 Dear R users,

 Suppose I have the following data.frame:

 myID myType myNum1 myNum2 myNum3
 a   Single   10  11   12
 b   Single   15  25   35
 c   Double  22  33   44
 d   Double4   6 8

 and I want to have new records:

 myID myType myNum1 myNum2 myNum3
 e  Single   12.5   18   23.5
 f   Double  13  19.5 28

 where record e got its myNum1-3 as the average from record a and b, and
 record f got its myNum1-3 as the average from record c and d.

 and the final data.frame should be like the following:

 myID myType myNum1 myNum2 myNum3
 a   Single   10  11   12
 b   Single   15  25   35
 e   Single   12.5   18   43.5
 c   Double  22  33   44
 d   Double4   6 8
 fDouble  13  19.5 28

 Any idea is appreciated. Thanks beforehand.

 Ferry

[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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.


Re: [R] adding rows as arithmatic calculation on original rows

2008-12-05 Thread Ferry
thanks Gabor, and rmailbox.

On Fri, Dec 5, 2008 at 3:32 PM, [EMAIL PROTECTED] wrote:


 Here is a solution using doBy and Gabor's DF2 created below:

 library( doBy )
 newrows - summaryBy ( myNum1 + myNum2 + myNum3  ~ myType , DF2, keep.names
 = TRUE )
 newrows[,myID] - +
 rbind ( DF2, newrows)





 - Original message -
 From: Gabor Grothendieck [EMAIL PROTECTED]
 To: Ferry [EMAIL PROTECTED]
 Cc: r-help@r-project.org
 Date: Fri, 5 Dec 2008 17:50:42 -0500
 Subject: Re: [R] adding rows as arithmatic calculation on original rows

 Here is a solution using sqldf



 library(sqldf)

 DF2 -
 structure(list(myID = structure(1:4, .Label = c(a, b, c,
 d), class = factor), myType = structure(c(2L, 2L, 1L, 1L), .Label
 = c(Double,
 Single), class = factor), myNum1 = c(10, 15, 22, 4), myNum2 = c(11,
 25, 33, 6), myNum3 = c(12, 35, 44, 8)), .Names = c(myID, myType,
 myNum1, myNum2, myNum3), row.names = c(NA, -4L), class =
 data.frame)

 sqldf(select 1 TotalLevel, '+' myID, myType, avg(myNum1) myNum1,
 avg(myNum2) myNum2, avg(myNum3) myNum3
  from DF2
  group by myType
 union
  select 0 TotalLevel, *
 from DF2
 order by myType, TotalLevel, myID,
 method = raw)[-1]

 The output is (display in fixed font):

  myID myType myNum1 myNum2 myNum3
 1c Double   22.0   33.0   44.0
 2d Double4.06.08.0
 3+ Double   13.0   19.5   26.0
 4a Single   10.0   11.0   12.0
 5b Single   15.0   25.0   35.0
 6+ Single   12.5   18.0   23.5



 On Fri, Dec 5, 2008 at 3:21 PM, Ferry [EMAIL PROTECTED] wrote:
  Dear R users,
 
  Suppose I have the following data.frame:
 
  myID myType myNum1 myNum2 myNum3
  a   Single   10  11   12
  b   Single   15  25   35
  c   Double  22  33   44
  d   Double4   6 8
 
  and I want to have new records:
 
  myID myType myNum1 myNum2 myNum3
  e  Single   12.5   18   23.5
  f   Double  13  19.5 28
 
  where record e got its myNum1-3 as the average from record a and b, and
  record f got its myNum1-3 as the average from record c and d.
 
  and the final data.frame should be like the following:
 
  myID myType myNum1 myNum2 myNum3
  a   Single   10  11   12
  b   Single   15  25   35
  e   Single   12.5   18   43.5
  c   Double  22  33   44
  d   Double4   6 8
  fDouble  13  19.5 28
 
  Any idea is appreciated. Thanks beforehand.
 
  Ferry
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org 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-help@r-project.org 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-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Kaplan-Meier function from survfit

2008-12-05 Thread Ritwik Sinha
Hi All,

Please pardon me if I am missing something obvious here. How do I get
the Kaplan-Meier estimate function that is created by survfit and
plotted by the code.

fit - survfit(Surv(time, status) , data=aml)
plot(fit)

That is, I need a function that will give me the survival estimate at
a given time: \hat{S}(t).

Thanks in advance.

Ritwik Sinha
[EMAIL PROTECTED] | +12033042111 | http://ritwik.sinha.googlepages.com/

__
R-help@r-project.org 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.


Re: [R] Kaplan-Meier function from survfit

2008-12-05 Thread Marc Schwartz
on 12/05/2008 09:10 PM Ritwik Sinha wrote:
 Hi All,
 
 Please pardon me if I am missing something obvious here. How do I get
 the Kaplan-Meier estimate function that is created by survfit and
 plotted by the code.
 
 fit - survfit(Surv(time, status) , data=aml)
 plot(fit)
 
 That is, I need a function that will give me the survival estimate at
 a given time: \hat{S}(t).
 
 Thanks in advance.
 
 Ritwik Sinha


See:

library(survival)
?summary.survfit

and note the 'times' argument.

fit - survfit(Surv(time, status) , data = aml)

 summary(fit)
Call: survfit(formula = Surv(time, status), data = aml)

 time n.risk n.event survival std.err lower 95% CI upper 95% CI
5 23   2   0.9130  0.0588   0.80491.000
8 21   2   0.8261  0.0790   0.68480.996
9 19   1   0.7826  0.0860   0.63100.971
   12 18   1   0.7391  0.0916   0.57980.942
   13 17   1   0.6957  0.0959   0.53090.912
   18 14   1   0.6460  0.1011   0.47530.878
   23 13   2   0.5466  0.1073   0.37210.803
   27 11   1   0.4969  0.1084   0.32400.762
   30  9   1   0.4417  0.1095   0.27170.718
   31  8   1   0.3865  0.1089   0.22250.671
   33  7   1   0.3313  0.1064   0.17650.622
   34  6   1   0.2761  0.1020   0.13380.569
   43  5   1   0.2208  0.0954   0.09470.515
   45  4   1   0.1656  0.0860   0.05980.458
   48  2   1   0.0828  0.0727   0.01480.462


 summary(fit, times = seq(0, 48, 6))
Call: survfit(formula = Surv(time, status), data = aml)

 time n.risk n.event survival std.err lower 95% CI upper 95% CI
0 23   0   1.  0.   1.1.000
6 21   2   0.9130  0.0588   0.80491.000
   12 18   4   0.7391  0.0916   0.57980.942
   18 14   2   0.6460  0.1011   0.47530.878
   24 11   2   0.5466  0.1073   0.37210.803
   30  9   2   0.4417  0.1095   0.27170.718
   36  5   3   0.2761  0.1020   0.13380.569
   42  5   0   0.2761  0.1020   0.13380.569
   48  2   3   0.0828  0.0727   0.01480.462


HTH,

Marc Schwartz

__
R-help@r-project.org 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.


Re: [R] Spectral Analysis of Time Series in R

2008-12-05 Thread David Stoffer

You can do (1) and (2) [with some additional coding] using mvspec.R, which
you can download from http://www.stat.pitt.edu/stoffer/tsa2/chap7.htm ...
scroll down to the Spectral Envelope section and you'll find it there.  You
can look at the top part of the examples to get an idea of how to use
mvspec.R ... once you have the  spectral matrix estimate, you can code up
the extraction of the partial coherence and so on.





Alexander Schnebel wrote:
 
 Dear R Community,
 
 I am currently student at the Vienna University of Technology writing my 
 Diploma thesis on causality in time series and doing some analyses of 
 time series in R. I have the following questions:
 
 (1) Is there a function in R to estimate the PARTIAL spectral coherence 
 of a multivariate time series? If yes, how does this work? Is there an 
 test in R if the partial spectral coherence between two variables is 
 zero? The functions I know (spectrum, etc.) only work to estimate the 
 spectral coherence.
 
 (2) For some causality analysis I need an estimate of the inverse of the 
 spectral density matrix of a multivariate time series. Is there any 
 possibility in R to get this? Actually, I would be happy if I could at 
 least get a functional estimate of the spectral density matrix. I guess 
 this should work because R can plot the kernel density estimator of the 
 spectral density, so it should be possible to extract the underlying 
 function estimate.
 
 (3) Is there any possibility to do Granger Causality in R? That means 
 fitting an VAR model and testing if some coefficients are zero.
 
 Thank you very much in advance!
 
 Best Regards,
 Alexander
 T
 
 __
 R-help@r-project.org 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.
 
 


-
The power of accurate observation is commonly called cynicism 
by those who have not got it.  George Bernard Shaw
-- 
View this message in context: 
http://www.nabble.com/Spectral-Analysis-of-Time-Series-in-R-tp20814256p20866634.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


  1   2   >