Re: [R] OT(slightly) - Tracking extended projects

2007-07-24 Thread Heinz Tuechler
At 22:36 23.07.2007 +, D L McArthur wrote:
James MacDonald jmacdon at med.umich.edu writes:

 
 Hi all,
 
 Most of the analyses I do are short little once-and-done type things
that are 
easily encapsulated in a .Rnw
 file. However, I sometimes end up with projects that take an extended
amount 
of time. Usually these
 projects are not easily encapsulated in an .Rnw file, so I have been
using a 
single .R file with lots of comments.
 
 The problem with this approach is keeping track of what you have done and 
what the results were. Once the .R
 file gets to be a certain size, the comments aren't as useful, and I
find it 
easy to get lost. I have to assume
 that others have encountered this problem and hopefully have come up with 
something more elegant.
 
 Any suggestions?
 
 Best,
 
 Jim
 
One possible choice is the intuitively structured approach of Projects in 
Tinn-R (see http://www.sciviews.org/Tinn-R/).
 -- D L McArthur  dmca at ucla.edu


Or, in case you use emacs and ESS you could find some hints at the ESS help
list ([EMAIL PROTECTED]). Look for [ESS] hide function bodies
and [ESS] outline-minor-mode.

Heinz

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


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


[R] How to check for existence url from within a function?

2007-05-26 Thread Heinz Tuechler
Dear All,

To check if an url exists, I can use try(). This works, as I expected, if I
do it directly, as in the first part of the following example, but I could
not find a way to do it from within a function, as in the second part.

Where could I find information on how to do this?

Thanks,
Heinz


## set nonexisting url
url.string - 'http://www.google.at/nonexist.html'

## first part
1 # to start with defined .Last.value
try(con.url - url(url.string, open='rb'))
class.try.res - class(.Last.value)
try.error - class.try.res== 'try-error'
print(try.error)  # TRUE
try(close(con.url))

## try() within a function
url.error - function(url.string) {
  1 # to start with defined .Last.value
  try(con.url - url(url.string, open='rb'))
  class.try.res - class(.Last.value)
  try.error - class.try.res== 'try-error'
  print(try.error)
  try(close(con.url))
  invisible(try.error)
}

## call the function
url.error(url.string)   # result - FALSE

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


Re: [R] How to check for existence url from within a function?

2007-05-26 Thread Heinz Tuechler
Thank you, Duncan, especially for the hint concerning inherits.

Heinz

At 08:02 26.05.2007 -0400, Duncan Murdoch wrote:
On 26/05/2007 7:13 AM, Heinz Tuechler wrote:
 Dear All,
 
 To check if an url exists, I can use try(). This works, as I expected, if I
 do it directly, as in the first part of the following example, but I could
 not find a way to do it from within a function, as in the second part.
 
 Where could I find information on how to do this?
 
 Thanks,
 Heinz
 
 
 ## set nonexisting url
 url.string - 'http://www.google.at/nonexist.html'
 
 ## first part
 1 # to start with defined .Last.value
 try(con.url - url(url.string, open='rb'))
 class.try.res - class(.Last.value)
 try.error - class.try.res== 'try-error'
 print(try.error)  # TRUE
 try(close(con.url))
 
 ## try() within a function
 url.error - function(url.string) {
   1 # to start with defined .Last.value
   try(con.url - url(url.string, open='rb'))
   class.try.res - class(.Last.value)
   try.error - class.try.res== 'try-error'

.Last.value isn't set until your function returns.  You should write this as

con.url - try(url(url.string, open='rb'))
try.error - inherits(con.url, try-error)

Notice that I used inherits, rather than testing for equality.  It's 
documented that the result of try() will be of class 'try-error' if an 
error occurs, but there may be circumstances (in the future?) where 
different types of errors are signalled by using a more complicated class.

Duncan Murdoch

   print(try.error)
   try(close(con.url))
   invisible(try.error)
 }
 
 ## call the function
 url.error(url.string)   # result - FALSE
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] factor documentation issue

2007-02-28 Thread Heinz Tuechler
At 09:41 28.02.2007 +1030, Geoff Russell wrote:
There is a warning in the documentation for ?factor  (R version 2.3.0)
as follows:

 The interpretation of a factor depends on both the codes and the
  'levels' attribute.  Be careful only to compare factors with the
  same set of levels (in the same order).  In particular,
  'as.numeric' applied to a factor is meaningless, and may happen by
  implicit coercion.  To revert a factor 'f' to its original
  numeric values, 'as.numeric(levels(f))[f]' is recommended and
  slightly more efficient than 'as.numeric(as.character(f))'.


But as.numeric seems to work fine whereas as.numeric(levels(f))[f] doesn't
always do anything useful.

For example:

 f-factor(1:3,labels=c(A,B,C))
 f
[1] A B C
Levels: A B C
 as.numeric(f)
[1] 1 2 3
 as.numeric(levels(f))[f]
[1] NA NA NA
Warning message:
NAs introduced by coercion

And also,

 f-factor(1:3,labels=c(1,5,6))
 f
[1] 1 5 6
Levels: 1 5 6
 as.numeric(f)
[1] 1 2 3
 as.numeric(levels(f))[f]
[1] 1 5 6

Is the documentation wrong, or is the code wrong, or have I missed
something?

Cheers,
Geoff Russell

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

From R Language Definition

2.3.1 Factors

Factors are used to describe items that can have a finite number of values
(gender, social class, etc.). 
...
Factors are currently implemented using an integer array to specify the
actual levels and a second array of names that are mapped to the integers.
Rather unfortunately users often make use of the implementation in order to
make some calculations easier. This, however, is an implementation issue
and is not guaranteed to hold in all implementations of R.

In my view factors are (miss)used in different, not necessarily connected
ways.
A factor may represent a statistical concept i.e. a categorical variable.
Further it may be an (internal) way of data reduction or some method for
labelling values.
In my view these concepts should not be mixed up and would I recommend to
avoid factors for data reduction and labelling.

Heinz

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


[R] convenient way to combine Surv objects?

2006-12-09 Thread Heinz Tuechler
Dear All,

is there a convenient way to combine Surv objects?
Imagine two Surv objects as in the following example.
Is it possible to combine them into one _Surv_ object?
I tried rbind(), cbind(), c(), merge(), but none of these function does,
what I would like.
So I drafted a method for rbind.Surv (see below), but I would be happy
about a better solution.

Ideas? Comments?

Thanks,
Heinz

R version 2.4.0 Patched (2006-11-03 r39792)
Windows XP

library(survival)
## create example data
so1 - Surv(1:5, c(0, 0, 1, 0, 1))
so2 - Surv(6:8, c(1, 0, 0))
### combinefunction(so1, so2)
## desired result:
[1] 1+ 2+ 3  4+ 5  6  7+ 8+

### Surv method for rbind - untested  
rbind.Surv - function(..., deparse.level = 1)
{
  so - list(...)
  ## check objects for number of columns
  so.dims - sapply(so, dim)[2, ] # colums of each so
  min.so.cols - min(so.dims)
  max.so.cols - max(so.dims)
  ## if max range == 3 insert zero column in so with only 2 columns
  if (min.so.cols == 2  max.so.cols == 3)
for (i in seq(along=so)) {
  if (dim(so[[i]])[2] == 2) so[[i]] - cbind(0, so[[i]])
}
  ## function to get column in list element
  elco - function(element,column) {element[,column]}
  if (max.so.cols == 2)
return(Surv(unlist(sapply(so, elco, 1)), unlist(sapply(so, elco, 2
  else
return(Surv(unlist(sapply(so, elco, 1)), unlist(sapply(so, elco, 2)),
unlist(sapply(so, elco, 3
}

rbind(so1, so2)

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


[R] How to join data.frames containing Surv objects?

2006-12-05 Thread Heinz Tuechler
Dear All,

Trying to combine two data frames with identical structure by rbind() or
merge() I cannot find a way to preserve the class of a Surv object (see
example).
Reading the help page for rbind, I an uncertain if I could expect that a
Surf oject retains it's class, but I would wish it did.

Thanks

Heinz Tüchler

R version 2.4.0 Patched (2006-11-03 r39792)
Windows XP

library(survival)
## create example data
starttime - rep(0,5)
stoptime  - 1:5
event - c(1,0,1,1,1)
group - c(1,1,1,2,2)

## build Surv object
survobj - Surv(starttime, stoptime, event)

## build data.frame with Surv object
df.test - data.frame(survobj, group); df.test; str(df.test)
## split in two data frames
dft1 - df.test[1:3,]; dft1; str(dft1); class(dft1$survobj)  # class is Surv
dft2 - df.test[4:5,]; dft2; str(dft2); class(dft2$survobj)  # class is Surv
## rbind in one data.frame
dft12 - rbind(dft1, dft2); dft12; str(dft12); class(dft12$survobj)  #
class is matrix

## merge in one data.frame
dft12merge - merge(dft1, dft2, all=TRUE, sort=FALSE)
dft12merge; str(dft12merge); class(dft12merge$survobj)  # class is matrix

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


Re: [R] Netiquette, was Re: ... gfortran and gcc...

2006-08-08 Thread Heinz Tuechler
What could be the reason, to respond not only to the list? I did not see an
advantage, to receive a response twice, once directly, once by the list.
Is it wrong, to assume that someone who writes to the list, does also
receive all the postings on the list?

Heinz

At 08:09 08.08.2006 -0500, Mike wrote:
Thank you both.

I would prefer to communicate through the list only.

Mike.

On Tue August 8 2006 04:47, Prof Brian Ripley wrote:
 On Tue, 8 Aug 2006, Peter Dalgaard wrote:
  Prof Brian Ripley [EMAIL PROTECTED] writes:
   First, you replied to the list and not to me, which was discourteous.
 
  You mean that he replied to the list *only*, I hope.

 Yes, and it was written as if to me, and was a reply to an email from me.

  I usually consider it offensive when people reply to me and not the
  list (reasons including: It feels like being grabbed by the sleeve, I
  might not actually be the best source for the answer, and it's
  withholding the answer from the rest of the subscribers.)

 We do ask people to copy to the list.

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



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


Re: [R] Summary method needed?

2006-08-03 Thread Heinz Tuechler
At 21:04 02.08.2006 +0100, Prof Brian Ripley wrote:
On Wed, 2 Aug 2006, Christian Hennig wrote:

 Thank you Brian!
 
   I'm updating my fpc package at the moment and will add some new
functions.
   I learned that there should be print and summary methods for the key
   functions.
 
  for 'classes', I think.
 
 Yes.
 
   But in some cases the print method will make use of more or less all
the
   output information of the function. Is there any reason to implement a
   summary method in these cases?
 
  Would a more concise print() method be useful?  If so the existing
print()
  could become summary().
 
 :-)
 What I initially did some years ago was to write summary methods to
print out
 the required informations. Then M. Maechler told me that this is not the
 purpose of a summary method and I should write a print.summary method for
 this. Now I realise that I actually just want to print, and I don't really
 need the extra synopsis to be done by summary().
 
 Now is there any recommendation on this? My intuition would be to write a
 print, but not a summary method.

That sounds fine for your purposes.


Maybe I am wrong, but as far as I see, print() has the disadvantage that it
has to return x and must not return the summarized results as an object.
You remember the difficulties with print.survfit.
Instead it seems to be allowed that summary does not only print but also
return summarized results.
Is that right?

Greetings,
Heinz

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



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


[R] Default first argument in assignment function possible?

2006-08-03 Thread Heinz Tuechler
Dear All,

is there a possibility to provide a default for the first argument in an
assignment function?
I could not find out if and how. You see in the example below that not
explicitly stating the first argument leads to errors.

Thanks,
Heinz Tüchler

### example of assignment function
'testfun-' - function(x=a, y=b, value)
  { x - x+ y+ value
print(x)
x }

a - 0; b - 1; c - 2
testfun(c, 2) - 2  # result: 6
c - 2
testfun(c   ) - 2  # result: 5
testfun( , 2) - 2  # Error: argument is missing, with no default
testfun(y=2) - 2   # Error: target of assignment expands to non-language
object
testfun() - 2  # Error: invalid (NULL) left side of assignment

   _
platform   i386-pc-mingw32  
arch   i386 
os mingw32  
system i386, mingw32
status Patched  
major  2
minor  3.1  
year   2006 
month  07   
day23   
svn rev38687
language   R
version.string Version 2.3.1 Patched (2006-07-23 r38687)

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


[R] get() in sapply() in with()

2006-08-03 Thread Heinz Tuechler
Dear All,

applying some function within a with() function I wanted to use also
sapply() and get() to form a data.frame, but did not succede.
Below is a simplified example.
It is possible to use sapply() within a with() function, it is also
possible to use get() within a with() function, but when I try to use get
within sapply within with I arrive at Error in get(x, envir, mode,
inherits) : variable v5 was not found.
Is there a solution?

Thanks,
Heinz Tüchler


## example
df1 - data.frame(v5=16:20, v6=21:25, v7=I(letters[16:20]), v8=letters[16:20])

with(df1, sapply(c('v5', 'v6'), get) ) ## Error, see next line
## Error in get(x, envir, mode, inherits) : variable v5 was not found

with(df1, sapply(list(v5, v6), mean) ) # does work
with(df1, get('v5') ) # does work

platform   i386-pc-mingw32  
arch   i386 
os mingw32  
system i386, mingw32
status Patched  
major  2
minor  3.1  
year   2006 
month  07   
day23   
svn rev38687
language   R
version.string Version 2.3.1 Patched (2006-07-23 r38687)

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


Re: [R] get() in sapply() in with()

2006-08-03 Thread Heinz Tuechler
Thank you, Thomas!
It helps a lot to know that something is impossible and that I have to look
for a different kind of solution.
Heinz

At 07:33 03.08.2006 -0700, Thomas Lumley wrote:
On Thu, 3 Aug 2006, Heinz Tuechler wrote:

 Dear All,

 applying some function within a with() function I wanted to use also
 sapply() and get() to form a data.frame, but did not succede.
 Below is a simplified example.
 It is possible to use sapply() within a with() function, it is also
 possible to use get() within a with() function, but when I try to use get
 within sapply within with I arrive at Error in get(x, envir, mode,
 inherits) : variable v5 was not found.
 Is there a solution?

This isn't what you want to hear, but the solution is probably to not use 
get(). How to not use get() will depend on what your problem really is.


 ## example
 df1 - data.frame(v5=16:20, v6=21:25, v7=I(letters[16:20]),
v8=letters[16:20])

 with(df1, sapply(c('v5', 'v6'), get) ) ## Error, see next line
 ## Error in get(x, envir, mode, inherits) : variable v5 was not found

get() looks in the environment it was called from, which is the 
environment inside lapply(), whose parent is the environment of 
the base package. There is no v5 there.

 with(df1, sapply(list(v5, v6), mean) ) # does work

This works because list(v5,v6) is evaluated in df1.

 with(df1, get('v5') ) # does work

This works because get() looks in the environment it was called from, 
which is df1.


   -thomas

Thomas Lumley  Assoc. Professor, Biostatistics
[EMAIL PROTECTED]  University of Washington, Seattle



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


[R] How to get the name of the first argument in an assignment function?

2006-07-27 Thread Heinz Tuechler
Dear All!

If I pass an object to an assignment function I cannot get it's name by 
deparse(substitute(argument)), but I get *tmp* and I found no way to get
the original name, in the example below it should be va1.
Is there a way?

Thanks,

Heinz

## example
'fu1-' - function(var, value) {
print(c(name.of.var=deparse(substitute(var}
fu1(va1) - 3

name.of.var 
*tmp* 

## desired result:
## name.of.var 
##va1 



version
   _
platform   i386-pc-mingw32  
arch   i386 
os mingw32  
system i386, mingw32
status Patched  
major  2
minor  3.1  
year   2006 
month  07   
day23   
svn rev38687
language   R
version.string Version 2.3.1 Patched (2006-07-23 r38687)

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


Re: [R] How to get the name of the first argument in an assignment function?

2006-07-27 Thread Heinz Tuechler
At 06:10 27.07.2006 -0400, Gabor Grothendieck wrote:
If you are willing to write fu2[Var] - 3 instead of fu2(Var) - 3
then this workaround may suffice:

fu2 - structure(NA, class = fu2)
[-.fu2 - function(x, ..., value) { print(match.call()[[3]]); fu2 }

# test
fu2[Var] - 3  # prints Var


Thank you, Gabor for your response. My example was very reduced, just to
show the point, but in the way I would like to use it, probably your
solution may be difficult to apply. Seems, I have to accept that I cannot
solve it.

Thanks again,
Heinz

On 7/27/06, Heinz Tuechler [EMAIL PROTECTED] wrote:
 Dear All!

 If I pass an object to an assignment function I cannot get it's name by
 deparse(substitute(argument)), but I get *tmp* and I found no way to get
 the original name, in the example below it should be va1.
 Is there a way?

 Thanks,

 Heinz

 ## example
 'fu1-' - function(var, value) {
 print(c(name.of.var=deparse(substitute(var}
 fu1(va1) - 3

 name.of.var
*tmp*

 ## desired result:
 ## name.of.var
 ##va1



 version
   _
 platform   i386-pc-mingw32
 arch   i386
 os mingw32
 system i386, mingw32
 status Patched
 major  2
 minor  3.1
 year   2006
 month  07
 day23
 svn rev38687
 language   R
 version.string Version 2.3.1 Patched (2006-07-23 r38687)

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




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


Re: [R] Keep value lables with data frame manipulation

2006-07-17 Thread Heinz Tuechler
At 20:39 14.07.2006 -0500, Frank E Harrell Jr wrote:
Heinz Tuechler wrote:
 At 11:02 13.07.2006 -0500, Frank E Harrell Jr wrote:
 Heinz Tuechler wrote:
 At 08:11 13.07.2006 -0500, Frank E Harrell Jr wrote:
 Heinz Tuechler wrote:
 At 13:14 12.07.2006 -0500, Marc Schwartz (via MN) wrote:
 On Wed, 2006-07-12 at 17:41 +0100, Jol, Arne wrote:
 Dear R,

 I import data from spss into a R data.frame. On this rawdata I do
some
 data processing (selection of observations, normalization,
recoding of
 variables etc..). The result is stored in a new data.frame,
however, in
 this new data.frame the value labels are lost.

 Example of what I do in code:

 # read raw data from spss
 rawdata - read.spss(./data/T50937.SAV,
use.value.labels=FALSE,to.data.frame=TRUE)

 # select the observations that we need
 diarydata - rawdata[rawdata$D22==2 | rawdata$D22==3 |
 rawdata$D22==17 |
 rawdata$D22==18 | rawdata$D22==20 | rawdata$D22==22 |
rawdata$D22==24 | rawdata$D22==33,]

 The result is that rawdata$D22 has value labels and that
diarydata$D22
 is numeric without value labels.

 Question: How can I prevent this from happening?

 Thanks in advance!
 Groeten,
 Arne
 Two things:

 1. With respect to your subsetting, your lengthy code can be replaced
 with the following:

  diarydata - subset(rawdata, D22 %in% c(2, 3, 17, 18, 20, 22, 24,
33))

 See ?subset and ?%in% for more information.


 2. With respect to keeping the label related attributes, the
 'value.labels' attribute and the 'variable.labels' attribute will
not by
 default survive the use of [.data.frame in R (see ?Extract
 and ?[.data.frame).

 On the other hand, based upon my review of ?read.spss, the SPSS value
 labels should be converted to the factor levels of the respective
 columns when 'use.value.labels = TRUE' and these would survive a
 subsetting.

 If you want to consider a solution to the attribute subsetting issue,
 you might want to review the following post by Gabor Grothendieck in
 May, which provides a possible solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106308.html

 and this post by me, for an explanation of what is happening in
Gabor's
 solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106351.html

 HTH,

 Marc Schwartz

 Hello Mark and Arne,

 I worked on the suggestions of Gabor and Mark and programmed some
 functions
 in this way, but they are very, very preliminary (see below).
 In my view there is a lack of convenient possibilities in R to document
 empirical data by variable labels, value labels, etc. I would prefer to
 have these possibilities in the standard configuration.
 So I sketched a concept, but in my view it would only be useful, if
there
 was some acceptance by the core developers of R.

 The concept would be to define a class. For now I call it
source.data.
 To design it more flexible than the Hmisc class labelled I would
 define a
 related option source.data.attributes with default c('value.labels',
 'variable.name', 'label')). This option contains all attributes that
 should
 persist in subsetting/indexing.

 I made only some very, very preliminary tests with these functions,
 mainly
 because I am not happy with defining a new class. Instead I would
prefer,
 if this functionality could be integrated in the Hmisc class
labelled,
 since this is in my view the best known starting point for data
 documentation in R.

 I would be happy, if there were some discussion about the
wishes/needs of
 other Rusers concerning data documentation.

 Greetings,

 Heinz
 I feel that separating variable labels and value labels and just using 
 factors for value labels works fine, and I would urge you not to create 
 a new system that will not benefit from the many Hmisc functions that 
 use variable labels and units.  [.data.frame in Hmisc keeps all
 attributes.
 Frank

 Frank,

 of course I aggree with you about the importance of Hmisc and as I
said, I
 do not want to define a new class, but in my view factors are no good
 substitute for value labels.
 As the language definition (version 2.3.1 (2006-06-05) Draft, page 7)
says:
 Factors are currently implemented using an integer array to specify the
 actual levels and a second array of names that are mapped to the
integers.
 Rather unfortunately users often make use of the implementation in
order to
 make some calculations easier. 
 So, in my view, the levels represent the values of the factor.
 This has inconveniencies if you want to use value labels in different
 languages. Further I do not see a simple method to label numerical
 variables. I often encounter discrete, but still metric data, as e.g.
risk
 scores. Usually it would be nice to use them in their original coding,
 which may include zero or decimal places and to label them at the same
 time.
 Personally at the moment I try to solve this problem by following a
 suggestion of Martin, Dimitis and others to use names instead. I doubt,
 however, that this is a good solution, but at least

Re: [R] Keep value lables with data frame manipulation

2006-07-14 Thread Heinz Tuechler
At 11:02 13.07.2006 -0500, Frank E Harrell Jr wrote:
Heinz Tuechler wrote:
 At 08:11 13.07.2006 -0500, Frank E Harrell Jr wrote:
 Heinz Tuechler wrote:
 At 13:14 12.07.2006 -0500, Marc Schwartz (via MN) wrote:
 On Wed, 2006-07-12 at 17:41 +0100, Jol, Arne wrote:
 Dear R,

 I import data from spss into a R data.frame. On this rawdata I do some
 data processing (selection of observations, normalization, recoding of
 variables etc..). The result is stored in a new data.frame, however, in
 this new data.frame the value labels are lost.

 Example of what I do in code:

 # read raw data from spss
 rawdata - read.spss(./data/T50937.SAV,
  use.value.labels=FALSE,to.data.frame=TRUE)

 # select the observations that we need
 diarydata - rawdata[rawdata$D22==2 | rawdata$D22==3 |
rawdata$D22==17 |
 rawdata$D22==18 | rawdata$D22==20 | rawdata$D22==22 |
  rawdata$D22==24 | rawdata$D22==33,]

 The result is that rawdata$D22 has value labels and that diarydata$D22
 is numeric without value labels.

 Question: How can I prevent this from happening?

 Thanks in advance!
 Groeten,
 Arne
 Two things:

 1. With respect to your subsetting, your lengthy code can be replaced
 with the following:

  diarydata - subset(rawdata, D22 %in% c(2, 3, 17, 18, 20, 22, 24, 33))

 See ?subset and ?%in% for more information.


 2. With respect to keeping the label related attributes, the
 'value.labels' attribute and the 'variable.labels' attribute will not by
 default survive the use of [.data.frame in R (see ?Extract
 and ?[.data.frame).

 On the other hand, based upon my review of ?read.spss, the SPSS value
 labels should be converted to the factor levels of the respective
 columns when 'use.value.labels = TRUE' and these would survive a
 subsetting.

 If you want to consider a solution to the attribute subsetting issue,
 you might want to review the following post by Gabor Grothendieck in
 May, which provides a possible solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106308.html

 and this post by me, for an explanation of what is happening in Gabor's
 solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106351.html

 HTH,

 Marc Schwartz

 Hello Mark and Arne,

 I worked on the suggestions of Gabor and Mark and programmed some
functions
 in this way, but they are very, very preliminary (see below).
 In my view there is a lack of convenient possibilities in R to document
 empirical data by variable labels, value labels, etc. I would prefer to
 have these possibilities in the standard configuration.
 So I sketched a concept, but in my view it would only be useful, if there
 was some acceptance by the core developers of R.

 The concept would be to define a class. For now I call it source.data.
 To design it more flexible than the Hmisc class labelled I would
define a
 related option source.data.attributes with default c('value.labels',
 'variable.name', 'label')). This option contains all attributes that
should
 persist in subsetting/indexing.

 I made only some very, very preliminary tests with these functions,
mainly
 because I am not happy with defining a new class. Instead I would prefer,
 if this functionality could be integrated in the Hmisc class labelled,
 since this is in my view the best known starting point for data
 documentation in R.

 I would be happy, if there were some discussion about the wishes/needs of
 other Rusers concerning data documentation.

 Greetings,

 Heinz
 I feel that separating variable labels and value labels and just using 
 factors for value labels works fine, and I would urge you not to create 
 a new system that will not benefit from the many Hmisc functions that 
 use variable labels and units.  [.data.frame in Hmisc keeps all
attributes.

 Frank

 
 Frank,
 
 of course I aggree with you about the importance of Hmisc and as I said, I
 do not want to define a new class, but in my view factors are no good
 substitute for value labels.
 As the language definition (version 2.3.1 (2006-06-05) Draft, page 7) says:
 Factors are currently implemented using an integer array to specify the
 actual levels and a second array of names that are mapped to the integers.
 Rather unfortunately users often make use of the implementation in order to
 make some calculations easier. 
 So, in my view, the levels represent the values of the factor.
 This has inconveniencies if you want to use value labels in different
 languages. Further I do not see a simple method to label numerical
 variables. I often encounter discrete, but still metric data, as e.g. risk
 scores. Usually it would be nice to use them in their original coding,
 which may include zero or decimal places and to label them at the same
time.
 Personally at the moment I try to solve this problem by following a
 suggestion of Martin, Dimitis and others to use names instead. I doubt,
 however, that this is a good solution, but at least it makes it possible to
 have the source data numerically coded and in this sense

Re: [R] Keep value lables with data frame manipulation

2006-07-13 Thread Heinz Tuechler
At 13:14 12.07.2006 -0500, Marc Schwartz (via MN) wrote:
On Wed, 2006-07-12 at 17:41 +0100, Jol, Arne wrote:
 Dear R,
 
 I import data from spss into a R data.frame. On this rawdata I do some
 data processing (selection of observations, normalization, recoding of
 variables etc..). The result is stored in a new data.frame, however, in
 this new data.frame the value labels are lost.
 
 Example of what I do in code:
 
 # read raw data from spss
 rawdata - read.spss(./data/T50937.SAV,
  use.value.labels=FALSE,to.data.frame=TRUE)
 
 # select the observations that we need
 diarydata - rawdata[rawdata$D22==2 | rawdata$D22==3 | rawdata$D22==17 |
 rawdata$D22==18 | rawdata$D22==20 | rawdata$D22==22 |
  rawdata$D22==24 | rawdata$D22==33,]
 
 The result is that rawdata$D22 has value labels and that diarydata$D22
 is numeric without value labels.
 
 Question: How can I prevent this from happening?
 
 Thanks in advance!
 Groeten,
 Arne

Two things:

1. With respect to your subsetting, your lengthy code can be replaced
with the following:

  diarydata - subset(rawdata, D22 %in% c(2, 3, 17, 18, 20, 22, 24, 33))

See ?subset and ?%in% for more information.


2. With respect to keeping the label related attributes, the
'value.labels' attribute and the 'variable.labels' attribute will not by
default survive the use of [.data.frame in R (see ?Extract
and ?[.data.frame).

On the other hand, based upon my review of ?read.spss, the SPSS value
labels should be converted to the factor levels of the respective
columns when 'use.value.labels = TRUE' and these would survive a
subsetting.

If you want to consider a solution to the attribute subsetting issue,
you might want to review the following post by Gabor Grothendieck in
May, which provides a possible solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106308.html

and this post by me, for an explanation of what is happening in Gabor's
solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106351.html

HTH,

Marc Schwartz

Hello Mark and Arne,

I worked on the suggestions of Gabor and Mark and programmed some functions
in this way, but they are very, very preliminary (see below).
In my view there is a lack of convenient possibilities in R to document
empirical data by variable labels, value labels, etc. I would prefer to
have these possibilities in the standard configuration.
So I sketched a concept, but in my view it would only be useful, if there
was some acceptance by the core developers of R.

The concept would be to define a class. For now I call it source.data.
To design it more flexible than the Hmisc class labelled I would define a
related option source.data.attributes with default c('value.labels',
'variable.name', 'label')). This option contains all attributes that should
persist in subsetting/indexing.

I made only some very, very preliminary tests with these functions, mainly
because I am not happy with defining a new class. Instead I would prefer,
if this functionality could be integrated in the Hmisc class labelled,
since this is in my view the best known starting point for data
documentation in R.

I would be happy, if there were some discussion about the wishes/needs of
other Rusers concerning data documentation.

Greetings,

Heinz


### intention and concept
#   There should be a convenient possibility to keep source data numerical
#   coded and at the same time have labelled categories.
#   Such labelled categorical numerical data should be easily converted
#   to factors.
#   Indexing/subsetting should preserve the concerned attributes of this data.

### description of (intended!!!) functionality
#   - a class source.data is defined. It is intended only for atomic objects.
#   - option source.data.attributes defines which attributes will be copied
# in indexing/subsetting objects of class source.data
#   - option source.data.is.ordered sets defining factors as ordered, when
# built from objects of class source.data by the function factsd
#   - function 'value.labels-' assigns an attribute value.labels and sets
# class source.data
#   - function value.labels reads the attribute value.labels
#   - the indexing method '[.source.data' defines indexing for source.data
#   - the print method print.source.data ignores source.data.attributes in
# printing
#   - the as.data.frame method as.data.frame.source.data enables inclusion
# of objects of class source.data in data.frames
#   - function factsd should in general behave as function factor but should
# in case of an object of class source.data by default use the
value.labels
# as levels and the names(value.labels) as the labels of the new built
# factor.
# If the parameter ordered is NULL it should create ordered factors
# according to the option source.data.is.ordered.

### set option for source.data.attributes
options(source.data.attributes=c('value.labels', 'variable.name', 'label'))
### set option for converting source.data class in 

Re: [R] Keep value lables with data frame manipulation

2006-07-13 Thread Heinz Tuechler
At 08:11 13.07.2006 -0500, Frank E Harrell Jr wrote:
Heinz Tuechler wrote:
 At 13:14 12.07.2006 -0500, Marc Schwartz (via MN) wrote:
 On Wed, 2006-07-12 at 17:41 +0100, Jol, Arne wrote:
 Dear R,

 I import data from spss into a R data.frame. On this rawdata I do some
 data processing (selection of observations, normalization, recoding of
 variables etc..). The result is stored in a new data.frame, however, in
 this new data.frame the value labels are lost.

 Example of what I do in code:

 # read raw data from spss
 rawdata - read.spss(./data/T50937.SAV,
use.value.labels=FALSE,to.data.frame=TRUE)

 # select the observations that we need
 diarydata - rawdata[rawdata$D22==2 | rawdata$D22==3 | rawdata$D22==17 |
 rawdata$D22==18 | rawdata$D22==20 | rawdata$D22==22 |
rawdata$D22==24 | rawdata$D22==33,]

 The result is that rawdata$D22 has value labels and that diarydata$D22
 is numeric without value labels.

 Question: How can I prevent this from happening?

 Thanks in advance!
 Groeten,
 Arne
 Two things:

 1. With respect to your subsetting, your lengthy code can be replaced
 with the following:

  diarydata - subset(rawdata, D22 %in% c(2, 3, 17, 18, 20, 22, 24, 33))

 See ?subset and ?%in% for more information.


 2. With respect to keeping the label related attributes, the
 'value.labels' attribute and the 'variable.labels' attribute will not by
 default survive the use of [.data.frame in R (see ?Extract
 and ?[.data.frame).

 On the other hand, based upon my review of ?read.spss, the SPSS value
 labels should be converted to the factor levels of the respective
 columns when 'use.value.labels = TRUE' and these would survive a
 subsetting.

 If you want to consider a solution to the attribute subsetting issue,
 you might want to review the following post by Gabor Grothendieck in
 May, which provides a possible solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106308.html

 and this post by me, for an explanation of what is happening in Gabor's
 solution:

  https://stat.ethz.ch/pipermail/r-help/2006-May/106351.html

 HTH,

 Marc Schwartz

 Hello Mark and Arne,
 
 I worked on the suggestions of Gabor and Mark and programmed some functions
 in this way, but they are very, very preliminary (see below).
 In my view there is a lack of convenient possibilities in R to document
 empirical data by variable labels, value labels, etc. I would prefer to
 have these possibilities in the standard configuration.
 So I sketched a concept, but in my view it would only be useful, if there
 was some acceptance by the core developers of R.
 
 The concept would be to define a class. For now I call it source.data.
 To design it more flexible than the Hmisc class labelled I would define a
 related option source.data.attributes with default c('value.labels',
 'variable.name', 'label')). This option contains all attributes that should
 persist in subsetting/indexing.
 
 I made only some very, very preliminary tests with these functions, mainly
 because I am not happy with defining a new class. Instead I would prefer,
 if this functionality could be integrated in the Hmisc class labelled,
 since this is in my view the best known starting point for data
 documentation in R.
 
 I would be happy, if there were some discussion about the wishes/needs of
 other Rusers concerning data documentation.
 
 Greetings,
 
 Heinz

I feel that separating variable labels and value labels and just using 
factors for value labels works fine, and I would urge you not to create 
a new system that will not benefit from the many Hmisc functions that 
use variable labels and units.  [.data.frame in Hmisc keeps all attributes.

Frank


Frank,

of course I aggree with you about the importance of Hmisc and as I said, I
do not want to define a new class, but in my view factors are no good
substitute for value labels.
As the language definition (version 2.3.1 (2006-06-05) Draft, page 7) says:
Factors are currently implemented using an integer array to specify the
actual levels and a second array of names that are mapped to the integers.
Rather unfortunately users often make use of the implementation in order to
make some calculations easier. 
So, in my view, the levels represent the values of the factor.
This has inconveniencies if you want to use value labels in different
languages. Further I do not see a simple method to label numerical
variables. I often encounter discrete, but still metric data, as e.g. risk
scores. Usually it would be nice to use them in their original coding,
which may include zero or decimal places and to label them at the same time.
Personally at the moment I try to solve this problem by following a
suggestion of Martin, Dimitis and others to use names instead. I doubt,
however, that this is a good solution, but at least it makes it possible to
have the source data numerically coded and in this sense language free
(see first attempts of functions below).

Heinz


### These are very preliminary

Re: [R] Keep value lables with data frame manipulation

2006-07-13 Thread Heinz Tuechler
At 12:36 13.07.2006 -0400, Richard M. Heiberger wrote:
 Further I do not see a simple method to label numerical
 variables. I often encounter discrete, but still metric data, as e.g. risk
 scores. Usually it would be nice to use them in their original coding,
 which may include zero or decimal places and to label them at the same
time.

## For this specific case, I use a position attribute.


tmp - data.frame(y=rnorm(30), x=factor(rep(c(0,1,2,4,8), 6)))
attr(tmp$x, position) - as.numeric(as.character(tmp$x))

tmp
as.numeric(tmp$x)
attr(tmp$x, position)

bwplot(y ~ x, data=tmp)

panel.bwplot.position - function(x, y, ..., x.at) {
 for (x.i in x.at) {
   y.i - y[x.i==x]
   panel.bwplot(rep(x.i, length(y.i)), y.i, ...)
 }
   }

bwplot.position - function(formula, data, ..., x.at) {
  if (missing(x.at)) {
x.name - dimnames(attr(terms(formula),factors))[[2]]
x.at - attr(data[[x.name]], position)
  }
  bwplot(formula, data, ...,
 x.at=x.at,
 panel=panel.bwplot.position,
 scales=list(x=list(at=x.at, limits=x.at+c(-1,1
}

bwplot.position(y ~ x, data=tmp)


## The above is a simplified version of
## panel.bwplot.intermediate.hh
## in the online files for
## Statistical Analysis and Data Display
## Richard M. Heiberger and Burt Holland
##http://springeronline.com/0-387-40270-5
## 
## An example of a boxplot with both placement and color of the boxes
## under user control is in
## 
## http://astro.ocis.temple.edu/~rmh/HH/bwplot-color.pdf

Richard, 

I recognized your solution already last time you mentioned it and I am
thinking about a similar one, (ab)using the names attribute.
In principle it seems easy to solve this kind of problems with additional
attributes, but without defining a new class and corresponding methods
additional attributes get easily lost when indexing/subsetting.
The names attribute seems to be rather resistent. As far as I see, it
survives indexing/subsetting and even sorting and this seems to be true
also for factors.

Greetings,

Heinz

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


Re: [R] Coxph

2006-07-11 Thread Heinz Tuechler
From the help page of Surv:
Although unusual, the event indicator can be omitted, in which case all
subjects are assumed to have an event.

That means, you can use coxph that way, _but_ it depends on your model.
Do you really want to model the time on study regardless of the kind of event?

Greetings,
Heinz Tüchler

At 12:22 11.07.2006 +0200, [EMAIL PROTECTED] wrote:


Dear all,



My question is:

In the Surv object you have two arguments, time and event. I have
two events, namely withdrawn and success. 
I use no event or status argument in Surv because all my objects die
in my data set.

Does coxph function calculate the coefficients correctly when you put no
event argument into the Surv object?

Thus:

Coxph(Surv(duration)~covariates,data=data) duration=duration of the deal

Duration: is the time till one subject fails or succeed in my research.

Can somebody help me?


Best regards,


Sharon Mazurel


-
ATTENTION:
The information in this electronic mail message is private and
confidential, and only intended for the addressee. Should you
receive this message by mistake, you are hereby notified that
any disclosure, reproduction, distribution or use of this
message is strictly prohibited. Please inform the sender by
reply transmission and delete the message without copying or
opening it.

Messages and attachments are scanned for all viruses known.
If this message contains password-protected attachments, the
files have NOT been scanned for viruses by the ING mail domain.
Always scan attachments before opening them.
-


   [[alternative HTML version deleted]]

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



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


Re: [R] Proportional Hazard Function and Competing risks

2006-07-11 Thread Heinz Tuechler
Maybe you find that thread helpful:

http://tolstoy.newcastle.edu.au/R/help/00b/1426.html

Heinz

At 12:59 11.07.2006 +0200, [EMAIL PROTECTED] wrote:


How can I model coxph() in combination with competing risks

i.e. I have two events and for event the object will leave the data set.
So :

Coxph(Surv(time,event)~) the event is for all my objects 1.

How can I model this?

Sharon
-
ATTENTION:
The information in this electronic mail message is private and
confidential, and only intended for the addressee. Should you
receive this message by mistake, you are hereby notified that
any disclosure, reproduction, distribution or use of this
message is strictly prohibited. Please inform the sender by
reply transmission and delete the message without copying or
opening it.

Messages and attachments are scanned for all viruses known.
If this message contains password-protected attachments, the
files have NOT been scanned for viruses by the ING mail domain.
Always scan attachments before opening them.
-


   [[alternative HTML version deleted]]

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



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


[R] How to include NA's of a factor in table?

2006-07-10 Thread Heinz Tuechler
Dear All,

Is there a better way to include NA's of a factor in the output of table()
than using as.character()?
Admittedly, I do not understand the help page for table concerning the
exclude argument applied to factors. I tried in different ways, but could
not get NA to be included in the table, if not using as.character() (see
example).

Greetings,
Heinz

## example
fcv - factor(c('a', NA, 'c'))
table(fcv)# shows a, c
table(fcv, exclude='a')   # shows c
table(fcv, exclude=)# shows a, c
table(fcv, exclude=NULL)  # shows a, c
table(as.character(fcv), exclude=NULL) # shows a, c, NA

platform   i386-pc-mingw32  
arch   i386 
os mingw32  
system i386, mingw32
status Patched  
major  2
minor  3.1  
year   2006 
month  07   
day01   
svn rev38471
language   R
version.string Version 2.3.1 Patched (2006-07-01 r38471)

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


Re: [R] How to include NA's of a factor in table?

2006-07-10 Thread Heinz Tuechler
Thank you Jacques and Gabor!

Your solution does work and it led me to try also:

table(factor(fcv, exclude=NULL))  # shows a, c, NA 

Greetings,
Heinz



At 08:34 10.07.2006 -0400, Gabor Grothendieck wrote:
If we specify exclude=NULL in factor then it need not also be
specified in table:

fcv - factor(c('a', NA, 'c'), exclude=NULL)
table(fcv)



On 7/10/06, Jacques VESLOT [EMAIL PROTECTED] wrote:
 fcv - factor(c('a', NA, 'c'), exclude=NULL)
 table(fcv, exclude=NULL)
 ---
 Jacques VESLOT

 CNRS UMR 8090
 I.B.L (2ème étage)
 1 rue du Professeur Calmette
 B.P. 245
 59019 Lille Cedex

 Tel : 33 (0)3.20.87.10.44
 Fax : 33 (0)3.20.87.10.31

 http://www-good.ibl.fr
 ---


 Heinz Tuechler a écrit :
  Dear All,
 
  Is there a better way to include NA's of a factor in the output of
table()
  than using as.character()?
  Admittedly, I do not understand the help page for table concerning the
  exclude argument applied to factors. I tried in different ways, but could
  not get NA to be included in the table, if not using as.character() (see
  example).
 
  Greetings,
  Heinz
 
  ## example
  fcv - factor(c('a', NA, 'c'))
  table(fcv)# shows a, c
  table(fcv, exclude='a')   # shows c
  table(fcv, exclude=)# shows a, c
  table(fcv, exclude=NULL)  # shows a, c
  table(as.character(fcv), exclude=NULL) # shows a, c, NA
 
  platform   i386-pc-mingw32
  arch   i386
  os mingw32
  system i386, mingw32
  status Patched
  major  2
  minor  3.1
  year   2006
  month  07
  day01
  svn rev38471
  language   R
  version.string Version 2.3.1 Patched (2006-07-01 r38471)
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
 

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




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


[R] unique deletes names - intended?

2006-07-04 Thread Heinz Tuechler
Dear All,

as shown in the example, unique() deletes names of vector elements. 
Is this intended?
Of course, one can use indexing by !duplicated() instead.

Greetings,
Heinz

## unique deletes names
v1 - c(a=1, b=2, c=3, e=2, a=4)
unique(v1) # names deleted

v1[!duplicated(v1)] # names preserved


platform   i386-pc-mingw32  
arch   i386 
os mingw32  
system i386, mingw32
status Patched  
major  2
minor  3.1  
year   2006 
month  07   
day01   
svn rev38471
language   R
version.string Version 2.3.1 Patched (2006-07-01 r38471)

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


Re: [R] How to call a value labels attribute?

2006-06-06 Thread Heinz Tuechler
Thank you, Richard. As soon as I find time I will carefully look at your
solution and your book.

Heinz

At 10:01 05.06.2006 -0400, Richard M. Heiberger wrote:
Aha!  Thank you for the more detailed example.

My solution for that situation is an attribute position and function
as.position().  I use this in my book

Statistical Analysis and Data Display
Richard M. Heiberger and Burt Holland

The online files for the book are available at
http://springeronline.com/0-387-40270-5



For this example, you need the function as.position() included in this
email.


### example 
x - ordered(c(1,2,3,2,4,3,1,2,4,3,2,1,3),
 labels=c(small, medium, large, very.large))
x
attr(x, position) - c(1,2,4,8)
x
as.position(x)

y - rnorm(length(x))
y

xyplot(y ~ x)
source(~/h2/library/code/as.position.s)
xyplot(y ~ as.position(x))
xyplot(y ~ as.position(x),
   scale=list(x=list(at=attr(x,position), labels=levels(x
xyplot(y ~ as.position(x),
   scale=list(x=list(at=attr(x,position), labels=levels(x))),
   xlab=x)
### end example 



### as.position.s #
as.position - function(x) {
  if (is.numeric(x))
x
  else {
if (!is.factor(x)) stop(x must be either numeric or factor.)

if (!is.null(attr(x, position)))
  x - attr(x, position)[x]
else {
  lev.x - levels(x)
  if (inherits(x, ordered)) {
on.exit(options(old.warn))
old.warn - options(warn=-1)
if (!any(is.na(as.numeric(lev.x
  x - as.numeric(lev.x)[x]
else
  x - as.numeric(ordered(lev.x, lev.x))[x]
  }
  else
x - as.numeric(x)
}
  }
  x
}


## tmp - ordered(c(c,b,f,f,c,b), c(c,b,f))
## as.numeric(tmp)
## as.position(tmp)
## 
## tmp - factor(c(c,b,f,f,c,b))
## as.numeric(tmp)
## as.position(tmp)
## 
## tmp - factor(c(1,3,5,3,5,1))
## as.numeric(tmp)
## as.position(tmp)
## 
## tmp - ordered(c(1,3,5,3,5,1))
## as.numeric(tmp)
## as.position(tmp)
## 
## tmp - c(1,3,5,3,5,1)
## as.numeric(tmp)
## as.position(tmp)

### end as.position.s #



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


Re: [R] How to call a value labels attribute?

2006-06-05 Thread Heinz Tuechler
Dimitris,

thank you. I have to considere all the responses to this question and then
your functions may prove to be useful.

Heinz

At 17:01 04.06.2006 +0200, Dimitrios Rizopoulos wrote:
maybe you could consider something like the following:

varlabs - function(x){
if (is.null(names(x))) NULL else x[!duplicated(x)]
}
varlabs- - function(x, value){
names(x) - names(value[x])
x
}
###
x - c(1, 2, 3, 3, 2, 3, 1)
x
varlabs(x)
varlabs(x) - c(apple=1, banana=2, NA=3)
x
varlabs(x)
varlabs(x) - c(Apfel=1, Banane=2, Birne=3)
x
varlabs(x)


I hope it helps.

Best,
Dimitris

 
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Heinz Tuechler [EMAIL PROTECTED]:

 At 14:12 03.06.2006 +0200, Martin Maechler wrote:
  Heinz == Heinz Tuechler [EMAIL PROTECTED]
  on Tue, 23 May 2006 01:17:21 +0100 writes:
 
 Heinz Dear All, after searching on CRAN I got the
 Heinz impression that there is no standard way in R to
 Heinz label values of a numerical variable.  
 
 Hmm, there's  names(.)  and  names(.) - ..
 Why are those not sufficient?
 
 x - 1:3
 names(x) - c(apple, banana, NA)
 
 Martin,
 
 I will considere this. For now I am using an attribute value.labels
 and a
 corresponding class to preserve this and other attributes after
 inclusion
 in a data.frame and indexing/subsetting, but using names should do as
 well.
 My idea was more like defining a set of value labels for a variable
 and
 apply it to all the variable, as e.g. in the following _pseudocode_:
 
 ### not run
 ### pseudocode
 x - c(1, 2, 3, 3, 2, 3, 1)
 value.labels(x) - c(apple=1, banana=2, NA=3)
 x
 ### desired result
 apple banana  NA  NA banana NA apple
 1  2   3   3  2  3 1
 
 value.labels(x) - c(Apfel=1, Banane=2, Birne=3) # redefine labels
 x
 ### desired result
 Apfel Banane Birne Birne Banane Birne Apfel
 1  2 3 3  2 3 1
 
 value.labels(x) # inspect labels
 ### desired result
 Apfel Banane Birne
 1  2 3
 
 These value.labels should persist even after inclusion in a
 data.frame and
 after indexing/subsetting.
 I did not yet try your idea concerning these aspects, but I will do
 it. My
 final goal is to do all the data handling on numerically coded
 variables
 and to transform to factors on the fly when needed for statistical
 procedures. Given the presence of value.labels a factor function
 could use
 them for the conversion.
 
 I described my motivation for all this in a previous post, titled:
 How to represent a metric categorical variable?
 There was no response at all and I wonder, if this is such a rare
 problem.
 
 Thanks,
 Heinz
 
 
 
 Heinz Since this
 Heinz would be useful for me I intend to create such an
 Heinz attribute, at the moment for my personal use.  Still
 Heinz I would like to choose a name which does not conflict
 Heinz with names of commonly used attributes.
 
 Heinz Would value.labels or vallabs create conflicts?
 
 Heinz The attribute should be structured as data.frame with
 Heinz two columns, levels (numeric) and labels
 Heinz (character). These could then also be used to
 Heinz transform from numeric to factor. If the attribute is
 Heinz copied to the factor variable it could also serve to
 Heinz retransform the factor to the original numerical
 Heinz variable.
 
 Heinz Comments? Ideas?
 
 Heinz Thanks
 
 Heinz Heinz Tüchler
 
 Heinz __
 Heinz R-help@stat.math.ethz.ch mailing list
 Heinz https://stat.ethz.ch/mailman/listinfo/r-help PLEASE
 Heinz do read the posting guide!
 Heinz http://www.R-project.org/posting-guide.html
 
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 
 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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


Re: [R] How to call a value labels attribute?

2006-06-05 Thread Heinz Tuechler
Richard, Martin,

the example is not ideal, I see. I was strating from the question, how to
represent a metric categorical variable.
By metric categorical variable I intend a variable, which has only few
distinct values and an inherent metric. An example would be a risk score,
which classifies patients in several groups like low, intermediate, high,
extreme with corresponding risk estimates of 0, 1, 2, 5.5.
Other examples could be items in a questionnaire. These items often have
numerical values that may range from -5 to 5.
In some cases, like tables and box-plots these scores/items should be
treated like a factor (with labelled values), in other cases like
cox-regression or when forming an overall score they should be treated like
numeric variables.
I was asking for a convenient way to represent a variable like this, but
there was no response.
The crucial point is that the variables should retain their numerical
values and their value labels.
Without value labels they could be defined as factor and used or directly
or by as.numeric(), because the levels still represent the numerical
values, but as soon as labels are used, the original numerical values get
lost.


Thanks,

Heinz Tüchler

At 12:12 04.06.2006 -0400, Richard M. Heiberger wrote:
How is what you are doing any different from factors?


 x - factor(c(1, 2, 3, 3, 2, 3, 1), labels=c(apple, banana, other))
 x
[1] apple  banana other  other  banana other  apple 
Levels: apple banana other
 as.numeric(x)
[1] 1 2 3 3 2 3 1
 levels(x)[3] - birne
 x
[1] apple  banana birne  birne  banana birne  apple 
Levels: apple banana birne
 


 Original message 
### not run
### pseudocode
x - c(1, 2, 3, 3, 2, 3, 1)
value.labels(x) - c(apple=1, banana=2, NA=3)
x
### desired result
apple banana  NA  NA banana NA apple
1  2   3   3  2  3 1

value.labels(x) - c(Apfel=1, Banane=2, Birne=3) # redefine labels
x
### desired result
Apfel Banane Birne Birne Banane Birne Apfel
1  2 3 3  2 3 1

value.labels(x) # inspect labels
### desired result
Apfel Banane Birne
1  2 3



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


Re: [R] How to call a value labels attribute?

2006-06-04 Thread Heinz Tuechler
At 14:12 03.06.2006 +0200, Martin Maechler wrote:
 Heinz == Heinz Tuechler [EMAIL PROTECTED]
 on Tue, 23 May 2006 01:17:21 +0100 writes:

Heinz Dear All, after searching on CRAN I got the
Heinz impression that there is no standard way in R to
Heinz label values of a numerical variable.  

Hmm, there's  names(.)  and  names(.) - ..
Why are those not sufficient?

x - 1:3
names(x) - c(apple, banana, NA)

Martin,

I will considere this. For now I am using an attribute value.labels and a
corresponding class to preserve this and other attributes after inclusion
in a data.frame and indexing/subsetting, but using names should do as well.
My idea was more like defining a set of value labels for a variable and
apply it to all the variable, as e.g. in the following _pseudocode_:

### not run
### pseudocode
x - c(1, 2, 3, 3, 2, 3, 1)
value.labels(x) - c(apple=1, banana=2, NA=3)
x
### desired result
apple banana  NA  NA banana NA apple
1  2   3   3  2  3 1

value.labels(x) - c(Apfel=1, Banane=2, Birne=3) # redefine labels
x
### desired result
Apfel Banane Birne Birne Banane Birne Apfel
1  2 3 3  2 3 1

value.labels(x) # inspect labels
### desired result
Apfel Banane Birne
1  2 3

These value.labels should persist even after inclusion in a data.frame and
after indexing/subsetting.
I did not yet try your idea concerning these aspects, but I will do it. My
final goal is to do all the data handling on numerically coded variables
and to transform to factors on the fly when needed for statistical
procedures. Given the presence of value.labels a factor function could use
them for the conversion.

I described my motivation for all this in a previous post, titled:
How to represent a metric categorical variable?
There was no response at all and I wonder, if this is such a rare problem.

Thanks,
Heinz



Heinz Since this
Heinz would be useful for me I intend to create such an
Heinz attribute, at the moment for my personal use.  Still
Heinz I would like to choose a name which does not conflict
Heinz with names of commonly used attributes.

Heinz Would value.labels or vallabs create conflicts?

Heinz The attribute should be structured as data.frame with
Heinz two columns, levels (numeric) and labels
Heinz (character). These could then also be used to
Heinz transform from numeric to factor. If the attribute is
Heinz copied to the factor variable it could also serve to
Heinz retransform the factor to the original numerical
Heinz variable.

Heinz Comments? Ideas?

Heinz Thanks

Heinz Heinz Tüchler

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



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


Re: [R] How to make attributes persist after indexing?

2006-05-25 Thread Heinz Tuechler
Thank you Mark, for this helpful explanation. I noted the class labelled
in Hmisc, but did not yet study it well.
My example was just to see if attributes persist, but my main motivation is
to use  value labels for numerical variables and factors to solve my
problem of how to represent a metric categorical variable.
From an other discussion (attributes of a data.frame, Tue 22 Nov 2005) I
understood that there is very little interest in labelling variables, and I
assume even less in labelling variable values.
In my work, however categorical variables with an inherent metric (e.g.
risk scores) occur frequently and I think they could best be treated as
numeric with attached value.labels so that they can be converted easily to
factors if needed for use in a function.
So I have to see how convenient it is to introduce a labelled.labelled
class.

Thanks,

Heinz



At 21:37 24.05.2006 -0500, Marc Schwartz wrote:
On Thu, 2006-05-25 at 00:43 +0100, Heinz Tuechler wrote:
 Thank you for your answer, Gabor. I will see, if I understood it.
 
 Heinz
 
 At 11:31 24.05.2006 -0400, Gabor Grothendieck wrote:
 You could create your own child class with its own [ method.
 
 [.myfactor - function(x, ...) {
attr - attributes(x)
x - NextMethod([)
attributes(x) - attr
x
 }
 
 gx - structure(fx, class = c(myfactor, class(fx)))
 attributes(gx[1])
 

Heinz,

What Gabor has proposed is essentially what Frank Harrell does in the
Hmisc package (which I referenced), though in a more generic fashion
with respect to the attributes that are saved and reset.

By using:

  gx - structure(fx, class = c(myfactor, class(fx)))

you are taking an object 'fx' and adding a child class attribute called
myfactor to it. So it is in effect an object that retains the
attributes of the original class of 'fx', plus the new class attribute
'myfactor'.

As a parallel, for example, consider that a square is a child class of a
rectangle. A square inherits all of the attributes of a rectangle, plus
the additional attribute that all four sides are of equal length. So for
example, if 'x' is a square, you might see:

 x
[1] 4 4 4 4
attr(,class)
[1] squarerectangle

as compared to a rectangle 'y':

 y
[1] 4 2 4 2
attr(,class)
[1] rectangle


Note the two class attributes for 'x', with 'square' preceding
'rectangle' in the order. The order is important, because in R, function
methods are dispatched based upon the class attributes in the order that
they appear in the vector.

So...back to 'gx'.

When the generic [ function is called with gx (ie. gx[1]), the first
class attribute 'myfactor' is picked up from 'gx'. Then, the method that
Gabor has presented, [.myfactor, is dispatched (executed). It is the
generic function [ with the specific class method defined by
.myfactor.

In that function, the first thing that takes place is that the
attributes of the 'x' argument are saved in 'attr'. 

  attr - attributes(x)

This would include any new attributes that you have defined and added,
such as labels and comments.

The next thing that happens is that the generic [ is now called again:

  x - NextMethod([)

but this time, the method dispatched is based upon the Next entry in
the class vector. In this case, whatever the original class of 'fx' was,
which could be an atomic vector, a factor, a matrix or a data frame, for
example.

You can see the methods available for [ by using:

   methods([)

The appropriate method for [ is then executed, resulting in 'x', which
is the subset version of 'gx'. 

Then:

  attributes(x) - attr

restores the original attributes saved in 'attr' to 'x'.

Then, finally, the 'x' object is returned to the calling environment.

So, in effect, you have created a new subset function [ that retains
your new attributes. The great thing about this, is that once the method
is defined in your working environment, all you have to do is to add the
newly associated class attribute to the objects you want to subset and R
does the rest transparently.

Thus:

# Add the new method
[.myfactor - function(x, ...) {
   attr - attributes(x)
   x - NextMethod([)
   attributes(x) - attr
   x
}

# Create fx
fx - factor(1:5, ordered = TRUE)
attr(fx, 'comment') - 'Comment for fx'
attr(fx, 'label') - 'Label for fx'
attr(fx, 'testattribute') - 'just for fun'

 attributes(fx)
$levels
[1] 1 2 3 4 5

$class
[1] ordered factor

$comment
[1] Comment for fx

$label
[1] Label for fx

$testattribute
[1] just for fun


# Create gx, which is identical to fx, with the 
# additional class attribute
gx - structure(fx, class = c(myfactor, class(fx)))

 attributes(gx)
$levels
[1] 1 2 3 4 5

$class
[1] myfactor ordered  factor   # - Note change here

$comment
[1] Comment for fx

$label
[1] Label for fx

$testattribute
[1] just for fun


# Show the structure of fx[1]
# Note that other attributes are lost
 str(fx[1])
 Ord.factor w/ 5 levels 1234..: 1


# Show the structure of gx[1]
# Note that attributes are retained
 str(gx[1

Re: [R] median of a survfit object

2006-05-24 Thread Heinz Tuechler
see: [R] How to access results of survival analysis Xiaochun Li (06 May 2006)

At 15:03 24.05.2006 +0200, David Hajage wrote:
 Hello R users !

Here a survfit object :

library(survival)

essai - aml[aml$x == Maintained,]

calc - survfit(Surv(essai$time, 1 - essai$status))

calc

Call: survfit(formula = Surv(essai$time, 1 - essai$status))

  n  events  median 0.95LCL 0.95UCL
 11   4 103  28 Inf
I would like to get the median of the object calc...
For example,

med - calc$median

But it doesn't work... How can I do this ?

-- 
David


-- 
David

   [[alternative HTML version deleted]]

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



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


[R] How to make attributes persist after indexing?

2006-05-24 Thread Heinz Tuechler
Dear All!

For descriptive purposes I would like to add attributes to objects. These
attributes should be kept, even if by indexing only part of the object is
used.
I noted that some attributes like levels and class of a factor exist also
after indexing, while others, like comment or label vanish.
Is there a way to make an arbitrary attribute to be kept after indexing?
This would be especially useful when indexing a data.frame.

## example for loss of attributes
fx - factor(1:5, ordered=TRUE)
attr(fx, 'comment') - 'Comment for fx'
attr(fx, 'label') - 'Label for fx'
attr(fx, 'testattribute') - 'just for fun'
attributes(fx)  # all attributes are shown
attributes(fx[])# all attributes are shown
attributes(fx[1:5]) # only levels and class are shown
attributes(fx[1])   # only levels and class are shown

Thanks,

Heinz Tüchler

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


Re: [R] How to make attributes persist after indexing?

2006-05-24 Thread Heinz Tuechler
Thank you for your answer, Gabor. I will see, if I understood it.

Heinz

At 11:31 24.05.2006 -0400, Gabor Grothendieck wrote:
You could create your own child class with its own [ method.

[.myfactor - function(x, ...) {
   attr - attributes(x)
   x - NextMethod([)
   attributes(x) - attr
   x
}

gx - structure(fx, class = c(myfactor, class(fx)))
attributes(gx[1])


On 5/24/06, Heinz Tuechler [EMAIL PROTECTED] wrote:
 Dear All!

 For descriptive purposes I would like to add attributes to objects. These
 attributes should be kept, even if by indexing only part of the object is
 used.
 I noted that some attributes like levels and class of a factor exist also
 after indexing, while others, like comment or label vanish.
 Is there a way to make an arbitrary attribute to be kept after indexing?
 This would be especially useful when indexing a data.frame.

 ## example for loss of attributes
 fx - factor(1:5, ordered=TRUE)
 attr(fx, 'comment') - 'Comment for fx'
 attr(fx, 'label') - 'Label for fx'
 attr(fx, 'testattribute') - 'just for fun'
 attributes(fx)  # all attributes are shown
 attributes(fx[])# all attributes are shown
 attributes(fx[1:5]) # only levels and class are shown
 attributes(fx[1])   # only levels and class are shown

 Thanks,

 Heinz Tüchler

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




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


[R] How to call a value labels attribute?

2006-05-22 Thread Heinz Tuechler
Dear All,

after searching on CRAN I got the impression that there is no standard way
in R to label values of a numerical variable.
Since this would be useful for me I intend to create such an attribute, at
the moment for my personal use.
Still I would like to choose a name which does not conflict with names of
commonly used attributes.

Would value.labels or vallabs create conflicts?

The attribute should be structured as data.frame with two columns, levels
(numeric) and labels (character). These could then also be used to
transform from numeric to factor. If the attribute is copied to the factor
variable it could also serve to retransform the factor to the original
numerical variable.

Comments? Ideas?

Thanks

Heinz Tüchler

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


[R] How to represent a metric categorical variable?

2006-05-18 Thread Heinz Tuechler
Dear All,

often I encounter variables, which have only few distinct values and an
inherent metric. An example would be a risk score, which classifies
patients in several groups like low, intermediate, high, extreme with
corresponding risk estimates of 0, 1, 2, 5.5.
In some cases, like tables and box-plots this score should be treated like
a factor, in other cases like cox-regression it should be treated like a
numeric variable.

Is there a convenient way to represent a variable like this?

The crucial point is that the variable should retain its numerical values
and its value labels. Without value labels it could be defined as factor
and used or directly or by as.numeric(), because the levels still represent
the numerical values, but as soon as labels are used, the original
numerical values get lost.

Thanks,

Heinz Tüchler

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


Re: [R] How to access results of survival analysis

2006-05-08 Thread Heinz Tuechler
At 12:55 07.05.2006 +0100, Prof Brian Ripley wrote:
On Sun, 7 May 2006, Heinz Tuechler wrote:

 Hello Xiaochun Li!

 Thank you for submitting the function. At the time I had that problem I
 solved it in a somewhat different way.
 I changed a few lines in the print.survfit method. I introduced a parameter
 ret.res=FALSE set to false to preserve the normal behaviour of print.
 The second last line invisible(x) I changed to:

 if (ret.res)
  invisible(list(x,x1))
 else
  invisible(x)

 So print.survfit returned the results. Of course, Your method has the
 advantage to work as long as the output structure of print.survfit does not
 change. At the end I would prefer the original function to be changed and
 when I find the time I will submit a worked proposal to Thomas Lumley, the
 maintainer of the survival package. In that way it would be available also
 in future versions of survival.

But all print() methods are required to return their first argument 
unchanged, so

foo
print(foo)

do the same thing.  See ?print.

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


I see that my proposal is against the rules.
So what would be a correct solution? Using the (expanded) example from
Xiaochun Li, you see that print(fit1) does not _simply_ print its first
argument, but calculates the median and its confidence interval. 
What would be the correct way to access these values?

# example:

library(survival)

fit1 - survfit(Surv(time, status) ~ 1, data=aml)
print(fit1)

Call: survfit(formula = Surv(time, status) ~ 1, data = aml)

  n  events  median 0.95LCL 0.95UCL 
 23  18  27  18  45 
 

smed - function(x) {
ox - capture.output(print(x))
n - length(ox)
tmp - t(sapply(ox[4:n],  
function(l) strsplit(l, split=' +')[[1]]))
nres - strsplit(ox[3],split=' +')[[1]][2:6]
res - matrix(as.numeric(tmp[,2:6]), ncol=5,
dimnames=list(tmp[,1], nres))
res
}

sf1 - smed(fit1)
sf1

Lacking experience in R-programming, my personal opinion is that
calculations like the median and the confidence interval should not be only
side effects of a print command but accessible result objects of a
corresponding function.

Heinz Tüchler

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


Re: [R] How to access results of survival analysis

2006-05-07 Thread Heinz Tuechler
Hello Xiaochun Li!

Thank you for submitting the function. At the time I had that problem I
solved it in a somewhat different way.
I changed a few lines in the print.survfit method. I introduced a parameter
ret.res=FALSE set to false to preserve the normal behaviour of print.
The second last line invisible(x) I changed to:

if (ret.res)
invisible(list(x,x1))
else
invisible(x)

So print.survfit returned the results. Of course, Your method has the
advantage to work as long as the output structure of print.survfit does not
change. At the end I would prefer the original function to be changed and
when I find the time I will submit a worked proposal to Thomas Lumley, the
maintainer of the survival package. In that way it would be available also
in future versions of survival.

Greetings

Heinz


At 10:40 05.05.2006 -0400, you wrote:
Hi List,

A friend of mine recently asked the same question as Heinz Tüchler.  Since
I've already written the code I'd like to share with the list.

# x is an object returned by survfit;
# smed returns a matrix of 5 columns of
# n, events, median, 0.95LCL, 0.95UCL.
# The matrix returned has rownames as the
# group labels (eg., treatment arms) if any.

smed - function(x) {
ox - capture.output(print(x))
n - length(ox)
tmp - t(sapply(ox[4:n],  
function(l) strsplit(l, split=' +')[[1]]))
nres - strsplit(ox[3],split=' +')[[1]][2:6]
res - matrix(as.numeric(tmp[,2:6]), ncol=5,
dimnames=list(tmp[,1], nres))
res
}


# example:

library(survival)

fit1 - survfit(Surv(time, status) ~ 1, data=aml)   
sf1 - smed(fit1)
sf1


fit - survfit(Surv(time, status) ~ x, data=aml)
sf - smed(fit)
sf

-- 
Xiaochun Li, Ph.D.
Research Scientist
Department of Biostatistics and Computational Biology
Dana Farber Cancer Institute
Harvard School of Public Health

M1B25
(617) 632 3602



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


[R] Surv object in data.frame and Design package

2006-03-16 Thread Heinz Tuechler
Dear All,

there seems to be some strange influence of the Design package on
data.frame. If I build a data.frame containing a Surv object without
loading the package Design, the data frame is usable to coxph. If instead I
just load Design and build a data.frame afterwards, the naming of the Surv
object is different and it does not work with coxph.
(In my real application I loaded Design to use the ie.setup function.)
Even if I detach Design I cannot build a data.frame as before loading
Design. If I include the Surv object with the I() function it seems to
work, but then there appeare the problems discussed in the posting from
yesterday Surv object in data.frame.
The problem is solvable, but I was surprised of the unexpected
difficulties, especially that detaching Design did not solve the problem.

Is it wrong to expect that R works after detaching a package as before
loading it?
Comments?

Thanks

Heinz Tüchler


## example
starttime - c(0, 0, 1.5, 0, 2.5)
stoptime  - c(1, 1.5, 2, 2.5, 3)
event - c(1, 0, 1, 0, 0)
ie.status - c(0, 0, 1, 0, 1)
library(survival)
survobj - Surv(starttime, stoptime, event)
df.nodesign - data.frame(survobj, ie.status) # build df without loading
Design
df.nodesign

library(Design)
df.design - data.frame(survobj, ie.status) # build df after loading Design
df.design
all.equal(df.nodesign, df.design)
detach(package:Design)
detach(package:survival)
df.afterdesign - data.frame(survobj, ie.status) # building df after
detaching Design
df.afterdesign
library(survival)
rm(survobj, ie.status)
coxph(survobj~ie.status, data=df.nodesign) # works
coxph(survobj~ie.status, data=df.design) # doesn't works
coxph(survobj~ie.status, data=df.afterdesign) # doesn't works


Windows98 SE
Version 2.2.0 Patched (2005-10-31 r36100)

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


Re: [R] Surv object in data.frame and Design package

2006-03-16 Thread Heinz Tuechler
At 11:13 16.03.2006 -0800, Thomas Lumley wrote:
On Thu, 16 Mar 2006, Heinz Tuechler wrote:

 Dear All,

 there seems to be some strange influence of the Design package on
 data.frame. If I build a data.frame containing a Surv object without
 loading the package Design, the data frame is usable to coxph. If instead I
 just load Design and build a data.frame afterwards, the naming of the Surv
 object is different and it does not work with coxph.
 (In my real application I loaded Design to use the ie.setup function.)
 Even if I detach Design I cannot build a data.frame as before loading
 Design. If I include the Surv object with the I() function it seems to
 work, but then there appeare the problems discussed in the posting from
 yesterday Surv object in data.frame.
 The problem is solvable, but I was surprised of the unexpected
 difficulties, especially that detaching Design did not solve the problem.

 Is it wrong to expect that R works after detaching a package as before
 loading it?

It's not as strange as all that. The Design package requires the Hmisc 
package, which you did not detach.  Hmisc contains an implementation of 
as.data.frame.Surv that doesn't work with data.frame()

Unfortunately the Hmisc implementation overrides the survival one, 
irrespective of the order in which the packages are loaded (at least from 
the viewpoint of getS3method()).

For code internal to the survival package the namespace system ensures 
that survival:::as.data.frame.Surv is called, but data.frame() is not part 
of the survival package and sees the Hmisc version.

I would have expected that S3 methods registered in NAMESPACE would 
override those based on the function name, but it seems to be the other 
way around.


Also, when you detached Design you also detached survival. If Design 
rather than Hmisc had been the source of the problem this still wouldn't 
have worked as no as.data.frame method for Surv objects would have been 
available.


   -thomas

Thanks a lot for this explanation. I tried all this also with Hmisc and
woundered, why the effect of Hmisc was reversible by detaching it and
that of Design was not. Now I see.

Thanks again

Heinz

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


[R] Surv object in data.frame

2006-03-15 Thread Heinz Tuechler
Dear All,

a Surv object I put in a data frame behaves somehow unexpected (see example).
If I do a Cox regression on the original Surv object it works. If I put it
in a data.frame and do the regression on the data frame it does not work.
Seemingly it has to do with the class attribute, because if I change the
class attribute to let Surv appeare first, again it works.
Is this known? Should I have found information on it?
Any comments?

Thanks

Heinz Tüchler

## example data
starttime - rep(0,5)
stoptime  - 1:5
event - c(1,0,1,1,1)
group - c(1,1,1,2,2)
## Surv object
survobj   - Surv(starttime, stoptime, event)
## Cox-regression
coxph(survobj~group) # this works
## put Surv object in data.frame
df.test - data.frame(survobj=I(survobj), group)
## Cox-regression on data.frame
coxph(survobj~group, data=df.test) # this does not work
attr(df.test$survobj, 'class') # survobject has class AsIs, Surv
attr(df.test$survobj, 'class') - c('Surv', 'AsIs') # put Surv first
attr(df.test$survobj, 'class') # survobject has class Surv, AsIs
coxph(survobj~group, data=df.test) # now it works

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


Re: [R] Surv object in data.frame

2006-03-15 Thread Heinz Tuechler
At 09:23 15.03.2006 -0800, Thomas Lumley wrote:
On Wed, 15 Mar 2006, Heinz Tuechler wrote:

 Dear All,

 a Surv object I put in a data frame behaves somehow unexpected (see
example).
 If I do a Cox regression on the original Surv object it works. If I put it
 in a data.frame and do the regression on the data frame it does not work.
 Seemingly it has to do with the class attribute, because if I change the
 class attribute to let Surv appeare first, again it works.
 Is this known? Should I have found information on it?

Well, this is the sort of thing that happens when you use kludges like 
AsIs.

The problem is with [.AsIs
survobj[,1] is supposed to be a vector of times (that's what [.Surv 
returns), but [.AsIs sticks the original class attribute on to it.

 str(survobj[,1])
  num [1:5] 0 0 0 0 0
 str(I(survobj)[,1])
Classes 'AsIs', 'Surv'  num [1:5] 0 0 0 0 0

The solution is not to use I() -- there's no problem with putting survival 
objects in a data frame
 df.right-data.frame(survobj,group)
 df.right
   survobj group
1  (0,1 ] 1
2  (0,2+] 1
3  (0,3 ] 1
4  (0,4 ] 2
5  (0,5 ] 2


   -thomas

Thank you, Thomas. You are right, it works, but why then I find on the help
page for Surv{survival} the following sentence:
To include a survival object inside a data frame, use the I() function.
Surv objects are implemented as a matrix of 2 or 3 columns.

Heinz

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


Re: [R] Surv object in data.frame

2006-03-15 Thread Heinz Tuechler
At 11:59 15.03.2006 -0600, Robert Baer wrote:
This does work:
coxph(survobj~group, data=df.test[[1]]) # this works like your original

To get insight compare:
str(survobj)
str(df.test)
str(df.test[[1]])

Thank you for your answer. It seems to me that your solution only works, as
long as the original objects are in the search path. If I do rm(survobj,
group) then coxph(survobj~group, data=df.test[[1]]) does not work, because
it is not found in data=df.test[[1]]. As long as the objects are present also
data=data.frame(NULL) works.

## example data
starttime - rep(0,5)
stoptime  - 1:5
event - c(1,0,1,1,1)
group - c(1,1,1,2,2)
## Surv object
survobj   - Surv(starttime, stoptime, event)
## put Surv object in data.frame
df.test - data.frame(survobj=I(survobj), group)

## following Robert Baer
coxph(survobj~group, data=df.test[[1]]) # this works like your original

coxph(survobj~group, data=data.frame(NULL)) # give an empty data frame

## remove objects to verify that df.test is used
rm(starttime, stoptime, event, group, survobj)
coxph(survobj~group, data=df.test[[1]]) # now it doesn't work



Then note the 2nd sentence of the  following from ?coxph
Arguments:

 formula: a formula object, with the response on the left of a '~'
  operator, and the terms on the right.  The response must be a
  survival object as returned by the 'Surv' function.
I know that the response must be a survival object as returned by the
'Surv' function. The following sentence on the help page for Surv{survival}:
To include a survival object inside a data frame, use the I() function.
Surv objects are implemented as a matrix of 2 or 3 columns. gave me the
impression that a survival object retains its class if it is included via
I() in a data frame. I was in error.

Heinz






Robert W. Baer, Ph.D.
Associate Professor
Department of Physiology
A. T. Still University of Health Science
800 W. Jefferson St.
Kirksville, MO 63501-1497 USA


Dear All,

a Surv object I put in a data frame behaves somehow unexpected (see
example).
If I do a Cox regression on the original Surv object it works. If I put it
in a data.frame and do the regression on the data frame it does not work.
Seemingly it has to do with the class attribute, because if I change the
class attribute to let Surv appeare first, again it works.
Is this known? Should I have found information on it?
Any comments?

Thanks

Heinz Tüchler

## example data
starttime - rep(0,5)
stoptime  - 1:5
event - c(1,0,1,1,1)
group - c(1,1,1,2,2)
## Surv object
survobj   - Surv(starttime, stoptime, event)
## Cox-regression
coxph(survobj~group) # this works
## put Surv object in data.frame
df.test - data.frame(survobj=I(survobj), group)
## Cox-regression on data.frame
coxph(survobj~group, data=df.test) # this does not work
attr(df.test$survobj, 'class') # survobject has class AsIs, Surv
attr(df.test$survobj, 'class') - c('Surv', 'AsIs') # put Surv first
attr(df.test$survobj, 'class') # survobject has class Surv, AsIs
coxph(survobj~group, data=df.test) # now it works

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



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


Re: [R] Splitting the list

2006-01-05 Thread Heinz Tuechler
At 11:56 05.01.2006 +1100, John Maindonald wrote:
I've changed the heading because this really is another thread.  I  
think it inevitable that there will, in the course of time, be other  
lists that are devoted, in some shape or form, to the concerns of  
practitioners (at all levels) who are using R.  One development I'd  
not like to see is fracture along application area lines, allowing  
those who are comfortable in coteries whose focus was somewhat  
relevant to standards of use of statistics in that area 15 or 20  
years ago to continue that way.  One of the great things about R, in  
its development to date, has been its role in exposing people from a  
variety of application area communities to statistical traditions  
different from that in which they have been nurtured. I expect it to  
have a continuing role in raising statistical analysis standards, in  
raising the bar.

Another possibility is fracture along geographic boundaries.  This  
has both benefits (one being that its is easier within a smaller  
circle of people who are more likely to know each other for  
contributors to establish a rapport that will make the list really  
effective; also there will be notices and discussion that are of  
local interest) and drawbacks (it risks separating subscribers off  
from important discussions on the official R lists.)  On balance,  
this may be the better way to go. Indeed subscribers to ANZSTAT  
(Australian and NZ statistical list) will know that an R-downunder  
list, hosted at Auckland, is currently in test-drive mode. There  
should be enough subscribers in common between this and the official  
R lists that the south-eastern portion of Gondwana does not, at any  
time in the very near future, float off totally on its own.

There are of course other possibilities, and it may be useful to  
canvass them.


Repeating a comment under the subject Splitting the list:
I would considere to use flags at the beginning of the subject line, like
e.g. BQ for basic question. Of course, also geographic boundaries could
be considered.
This flags should be defined in the posting guide.
This way, every reader/expert can decide on a personal level to split the
list by filtering the messages accordingly.

Heinz Tuechler

John Maindonald email: [EMAIL PROTECTED]
phone : +61 2 (6125)3473fax  : +61 2(6125)5549
Mathematical Sciences Institute, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.



On 4 Jan 2006, at 10:00 PM, [EMAIL PROTECTED] wrote:

 From: Ben Fairbank [EMAIL PROTECTED]
 Date: 4 January 2006 4:42:31 AM
 To: R-help@stat.math.ethz.ch
 Subject: Re: [R] A comment about R:


 One implicit point in Kjetil's message is the difficulty of learning
 enough of R to make its use a natural and desired first choice
 alternative, which I see as the point at which real progress and
 learning commence with any new language.  I agree that the long  
 learning
 curve is a serious problem, and in the past I have discussed, off  
 list,
 with one of the very senior contributors to this list the  
 possibility of
 splitting the list into sections for newcomers and for advanced users.
 He gave some very cogent reasons for not splitting, such as the
 possibility of newcomers' getting bad advice from others only slightly
 more advanced than themselves.  And yet I suspect that a newcomers'
 section would encourage the kind of mutually helpful collegiality  
 among
 newcomers that now characterizes the exchanges of the more experienced
 users on this list.  I know that I have occasionally been reluctant to
 post issues that seem too elementary or trivial to vex the others  
 on the
 list with and so have stumbled around for an hour or so seeking the
 solution to a simple problem.  Had I the counsel of others similarly
 situated progress might have been far faster.  Have other newcomers or
 occasional users had the same experience?

 Is it time to reconsider splitting this list into two sections?
 Certainly the volume of traffic could justify it.

 Ben Fairbank



   [[alternative HTML version deleted]]

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



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


Re: [R] A comment about R:

2006-01-04 Thread Heinz Tuechler
At 13:11 03.01.2006 -0500, Peter Flom wrote:
 Ben Fairbank [EMAIL PROTECTED] 1/3/2006 12:42 pm  wrote

One implicit point in Kjetil's message is the difficulty of learning
enough of R to make its use a natural and desired first choice
alternative, which I see as the point at which real progress and
learning commence with any new language.  I agree that the long
learning
curve is a serious problem, and in the past I have discussed, off
list,
with one of the very senior contributors to this list the possibility
of
splitting the list into sections for newcomers and for advanced users.
He gave some very cogent reasons for not splitting, such as the
possibility of newcomers' getting bad advice from others only slightly
more advanced than themselves.  And yet I suspect that a newcomers'
section would encourage the kind of mutually helpful collegiality
among
newcomers that now characterizes the exchanges of the more experienced
users on this list.  I know that I have occasionally been reluctant to
post issues that seem too elementary or trivial to vex the others on
the
list with and so have stumbled around for an hour or so seeking the
solution to a simple problem.  Had I the counsel of others similarly
situated progress might have been far faster.  Have other newcomers or
occasional users had the same experience?


I, for one, have had this experience.  I am usually hesitant to post
elementary questions here.

My experiences are similar. Since you are expected to search for hours all
available documents before asking a question, I am sometimes inclined to
try for hours to solve a trivial problem that would be solved by an answer
like see FAQ 3.3.3 (my yesterday's problem).
I would be happy, if it was accepted to ask also trivial or very basic
questions, and one way not to bother the experts could be, instead of
splitting the list, simply to flag such questions in the header by some
keyword like basic or BQ. (Starting the subject with the keyword, not
replacing it! It's not too convenient for readers, just to state newbie
question _instead_ of a meaningful subject.)
This keyword should be defined in the posting guide.
This way, every reader/expert can decide on a personal level to split the
list by filtering the messages accordingly.

Heinz

However, I think that the 'cogent reasons' given by 'one of the very
senior contributors' are valid.
I think that  a 'newcomers list' would only really be useful if it
included some experts who could respond,
out of generosity.  I don't think the R community lacks generosity -
obviously not, given all the thousands of 
hours people have spent writing the language and all the packages and
so on.  

But these generous people have different abilities and get pleasure in
different ways.  Some people get a thrill
out of answering complex questions that require them to come up with
novel solutions involving complex code.
Some people get a thrill out of helping newbies over the humps. 
Dividing the lists might help the experts, as much as it helps the
beginners. 


Peter

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



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


[R] survexp ratetables for european contries?

2005-12-15 Thread Heinz Tuechler
Dear All,

Does someone have, or know of survexp ratetables for european contries,
especially Austria and Germany?
I know only about slopop in the package relsurv.

Thanks in advance

Heinz Tüchler

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


Re: [R] survexp ratetables for european contries?

2005-12-15 Thread Heinz Tuechler
At 16:30 15.12.2005 +0100, Robert Chung wrote:
Heinz Tuechler wrote:
 Dear All,

 Does someone have, or know of survexp ratetables for european contries,
 especially Austria and Germany?
 I know only about slopop in the package relsurv.

I'm not sure I understand what you're asking for; slopop contains counts
from the census.

Not exactly, slopop is already a ratetable, although the description says
census data set for the Slovene population.
If I do:
library(relsurv)
 data(slopop)
 class(slopop)
[1] ratetable

I get class ratetable. It is not too difficult to construct a ratetable
from mortality data, but in case one is already available, I would use it.
It would be especially convenient to have one with a factor contry to be
used with international data. 


If you're looking for rates or life tables, check out the Human Mortality
Database:
http://www.mortality.org

Thanks for the link.

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



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


Re: [R] SPSS Dataset

2005-09-09 Thread Heinz Tuechler
At 07:56 09.09.2005 +0200, TEMPL Matthias wrote:
RSiteSearch(read spss data)
--
library(foreign)
?read.spss

Best,
Matthias


or spss.get in Hmisc

Heinz
 -Ursprüngliche Nachricht-
 Von: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] Im Auftrag von ERICK YEGON
 Gesendet: Freitag, 09. September 2005 07:02
 An: R-help@stat.math.ethz.ch
 Betreff: [R] SPSS Dataset
 
 
 How would one read SPSS data sets directly into R
 
 __
 R-help@stat.math.ethz.ch mailing list 
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read 
 the posting guide! http://www.R-project.org/posting-guide.html


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



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


Re: [R] change in read.spss, package foreign?

2005-09-09 Thread Heinz Tuechler
At 12:09 09.09.2005 +0200, Martin Maechler wrote:
 Heinz == Heinz Tuechler [EMAIL PROTECTED]
 on Fri, 09 Sep 2005 01:58:29 +0200 writes:

Heinz Dear All,
Heinz it seems to me that the function read.spss of package
Heinz foreign changed its behaviour regarding factors. I
Heinz noted that in version 0.8-8 variables with value
Heinz labels in SPSS were transformed in factors with the
Heinz labels in alphabetic order.

Heinz In version 0.8-10 they seem to be ordered preserving
Heinz the order corresponding to their numerical codes in
Heinz SPSS.  However I could not find a description of this
Heinz supposed change. Since the different behaviour seems
Heinz to depend on the installed version of the
Heinz foreign-package I don't know how to give a
Heinz reproducible example.  It also affects spss.get of
Heinz the Hmisc-package, which is not surprising.

Heinz I prefer the new behaviour and would like to know, if
Heinz it will persist in future versions.

Yes, it was on purpose.

Note that the development of foreign is also on
svn.R-project.org, and you can easily get at its 'ChangeLog' :

 https://svn.R-project.org/R-packages/trunk/foreign/ChangeLog

where you find the relevant entry at 2005-08-15 .

Regards,
Martin Maechler

Dear Martin, 
Thank you for your answer. As I said, I appreciate this change. The
documentation does not explain precisely, how variables with labels are
treated now. It only tells If SPSS value labels are converted to factors
the underlying numerical codes will not in general be the same as the SPSS
numerical values, since the numerical codes in R are always 1,2,3,
Will now the created factor levels in any case be ordered according to the
order of the original numerical codes in SPSS?

In general I wonder, how I could get to know such critical changes before I
update a package instead of finding it out by chance. Is there a place,
where a responsible R-user should look, when updating the program?
Thanks again,
Heinz Tüchler

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


Re: [R] change in read.spss, package foreign?

2005-09-09 Thread Heinz Tuechler
Dear Thomas,
Thanks a lot for your extensive answer.
Heinz

At 08:53 09.09.2005 -0700, Thomas Lumley wrote:
On Fri, 9 Sep 2005, Heinz Tuechler wrote:
 Dear Martin,
 Thank you for your answer. As I said, I appreciate this change. The
 documentation does not explain precisely, how variables with labels are
 treated now. It only tells If SPSS value labels are converted to factors
 the underlying numerical codes will not in general be the same as the SPSS
 numerical values, since the numerical codes in R are always 1,2,3,
 Will now the created factor levels in any case be ordered according to the
 order of the original numerical codes in SPSS?

We don't know. We think so, based on a reasonable amount of 
experimentation, but the file format isn't documented.  We do know that 
the numerical codes R uses will always be 1,2,3,... so that there is no 
hope for having the same codes as SPSS unless the SPSS codes were also 
1,2,3...

 In general I wonder, how I could get to know such critical changes before I
 update a package instead of finding it out by chance. Is there a place,
 where a responsible R-user should look, when updating the program?

Many packages have a NEWS or ChangeLog file describing changes.  You would 
typically have to look at the source package to find them, since by Unix 
tradition they are usually in the top-level directory and so are not 
included in the binary build.

The foreign package is on svn.r-project.org, so you can see its Changelog 
there. There have been suggestions to extract these files and put them in 
the CRAN listing, but one obstacle is the lack of standardisation.

   -thomas



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


[R] change in read.spss, package foreing?

2005-09-08 Thread Heinz Tuechler
Dear All,

it seems to me that the function read.spss of package foreign changed its
behaviour regarding factors. I noted that in version 0.8-8 variables with
value labels in SPSS were transformed in factors with the labels in
alphabetic order.
In version 0.8-10 they seem to be ordered preserving the order
corresponding to their numerical codes in SPSS.
However I could not find a description of this supposed change. Since the
different behaviour seems to depend on the installed version of the
foreign-package I don't know how to give a reproducible example.
It also affects spss.get of the Hmisc-package, which is not surprising.
I prefer the new behaviour and would like to know, if it will persist in
future versions.

Comments?

Heinz Tüchler

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


Re: [R] stratified Wilcoxon available?

2005-08-29 Thread Heinz Tuechler
At 19:02 28.08.2005 -0700, Thomas Lumley wrote:
On Sun, 28 Aug 2005, Heinz Tuechler wrote:

 Thanks to Peter Dalgaard and Frank Harrell for your answers. Fortunately I
 don't have an urgent need for this test, but it may be in the future.
 Still I would be grateful if someone could comment on my opinion that using
 survdiff and regarding all the measures as events would lead to an
 equivalent test.

In the absence of ties, yes.   In the presence of ties I think survdiff() 
does something slightly different from what would be usual for the 
Wilcoxon test.  This would matter only with many tied observations.

   -thomas


Thank you, Thomas, for this information.

Heinz




 Thanks,

 Heinz Tüchler

 At 15:18 28.08.2005 -0500, Frank E Harrell Jr wrote:
 Peter Dalgaard wrote:
 Heinz Tuechler [EMAIL PROTECTED] writes:


 Dear All,

 is there a stratified version of the Wilcoxon test (also known as van
 Elteren test) available in R?
 I could find it in the survdiff function of the survival package for
 censored data. I think, it should be possible to use this function
creating
 a dummy censoring indicator and setting it to not censored, but may be
 there is a better way to perform the test.


 Not easily, I think. I played with the stratified Kruskal Wallis test
 (which is the same thing for larger values of 2...) with a grad
 student some years ago, but we never got it integrated as an official
 R function.

 It was not massively hard to code, as I recall it. Basically, you
 convert observations to within-stratum ranks, scaled so that the
 scores have similar variance (this is crucial: just adding the
 per-stratum rank sums won't work). You can then get the relevant SSD
 from lm(), by comparing the models r ~ group + strata and r ~
 strata. This SSD can be looked up as a chi-square statistic, possibly
 after applying a scale factor which I have forgotten (I.e. do your
 own math, don't trust me!)


 You might think of such a stratified test as part of a proportional odds
 model with adjustment for strata as main effects.  The Wilcoxon tests is
  a special case of the PO model.  You can fit it with polr or lrm.

 --
 Frank E Harrell Jr   Professor and Chair   School of Medicine
  Department of Biostatistics   Vanderbilt University



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


Thomas Lumley  Assoc. Professor, Biostatistics
[EMAIL PROTECTED]  University of Washington, Seattle

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


[R] stratified Wilcoxon available?

2005-08-28 Thread Heinz Tuechler
Dear All,

is there a stratified version of the Wilcoxon test (also known as van
Elteren test) available in R?
I could find it in the survdiff function of the survival package for
censored data. I think, it should be possible to use this function creating
a dummy censoring indicator and setting it to not censored, but may be
there is a better way to perform the test.

Thanks,

Heinz Tüchler

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


Re: [R] stratified Wilcoxon available?

2005-08-28 Thread Heinz Tuechler
Thanks to Peter Dalgaard and Frank Harrell for your answers. Fortunately I
don't have an urgent need for this test, but it may be in the future.
Still I would be grateful if someone could comment on my opinion that using
survdiff and regarding all the measures as events would lead to an
equivalent test.

Thanks,

Heinz Tüchler

At 15:18 28.08.2005 -0500, Frank E Harrell Jr wrote:
Peter Dalgaard wrote:
 Heinz Tuechler [EMAIL PROTECTED] writes:
 
 
Dear All,

is there a stratified version of the Wilcoxon test (also known as van
Elteren test) available in R?
I could find it in the survdiff function of the survival package for
censored data. I think, it should be possible to use this function creating
a dummy censoring indicator and setting it to not censored, but may be
there is a better way to perform the test.
 
 
 Not easily, I think. I played with the stratified Kruskal Wallis test
 (which is the same thing for larger values of 2...) with a grad
 student some years ago, but we never got it integrated as an official
 R function. 
 
 It was not massively hard to code, as I recall it. Basically, you
 convert observations to within-stratum ranks, scaled so that the
 scores have similar variance (this is crucial: just adding the
 per-stratum rank sums won't work). You can then get the relevant SSD
 from lm(), by comparing the models r ~ group + strata and r ~
 strata. This SSD can be looked up as a chi-square statistic, possibly
 after applying a scale factor which I have forgotten (I.e. do your
 own math, don't trust me!)
 

You might think of such a stratified test as part of a proportional odds 
model with adjustment for strata as main effects.  The Wilcoxon tests is 
  a special case of the PO model.  You can fit it with polr or lrm.

-- 
Frank E Harrell Jr   Professor and Chair   School of Medicine
  Department of Biostatistics   Vanderbilt University



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


[R] how to write assignment form of function

2005-08-10 Thread Heinz Tuechler
Dear All,

where can I find information about how to write an assigment form of a
function?
For curiosity I tried to write a different form of the levels()-function,
since the original method for factor deletes all other attributes of a factor.
Of course, the simple method would be to use instead of levels(x) -
newlevels, attr(x, 'levels') - newlevels.

I tried the following:
## example
x - factor(c(1,1,NA,2,3,4,4,4,1,2)); y - x
attr(x, 'levels') - c('a', 'b', 'c', 'd') # does what I want
x
 [1] aaNA bcdddab   
Levels: a b c d
 
'levels.simple-' - function (x, value) 
 {
  attr(x, 'levels') - value
 }
 
levels.simple(y) - c('a', 'b', 'c', 'd') # does not what I want
y
[1] a b c d
 
Thanks,
Heinz Tüchler

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


Re: [R] how to write assignment form of function

2005-08-10 Thread Heinz Tuechler
At 14:49 10.08.2005 +0200, Dimitris Rizopoulos wrote:
take a look at e.g., get(levels-.factor); you should return x in 
your function, i.e.,

y - x - factor(c(1,1,NA,2,3,4,4,4,1,2))

'levels.simple-' - function(x, value){
  attr(x, 'levels') - value
  x
 }

levels.simple(y) - c('a', 'b', 'c', 'd')
y


I hope it helps.

Best,
Dimitris

Dear Dimitris,

Thank you a lot - it helped. Now it works.

Heinz




Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: Heinz Tuechler [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Wednesday, August 10, 2005 2:24 PM
Subject: [R] how to write assignment form of function


Dear All,

where can I find information about how to write an assigment form of a
function?
For curiosity I tried to write a different form of the 
levels()-function,
since the original method for factor deletes all other attributes of a 
factor.
Of course, the simple method would be to use instead of levels(x) -
newlevels, attr(x, 'levels') - newlevels.

I tried the following:
## example
x - factor(c(1,1,NA,2,3,4,4,4,1,2)); y - x
attr(x, 'levels') - c('a', 'b', 'c', 'd') # does what I want
x
 [1] aaNA bcdddab
Levels: a b c d

'levels.simple-' - function (x, value)
 {
  attr(x, 'levels') - value
 }

levels.simple(y) - c('a', 'b', 'c', 'd') # does not what I want
y
[1] a b c d

Thanks,
Heinz Tüchler

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



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


Re: [R] how to write assignment form of function

2005-08-10 Thread Heinz Tuechler
At 17:44 10.08.2005 +0100, Patrick Burns wrote:
S Poetry may be of use to you in this.

Thank you for the hint and thank you for S Poetry. I like it, I read it,
maybe about a year ago, but I don't remember all of it and with all the
material I collected about R it's not always easy to remember where I read
what.

Heinz Tüchler


Patrick Burns
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and A Guide for the Unwilling S User)

Heinz Tuechler wrote:

Dear All,

where can I find information about how to write an assigment form of a
function?
For curiosity I tried to write a different form of the levels()-function,
since the original method for factor deletes all other attributes of a
factor.
Of course, the simple method would be to use instead of levels(x) -
newlevels, attr(x, 'levels') - newlevels.

I tried the following:
## example
x - factor(c(1,1,NA,2,3,4,4,4,1,2)); y - x
attr(x, 'levels') - c('a', 'b', 'c', 'd') # does what I want
x
 [1] aaNA bcdddab   
Levels: a b c d
 
'levels.simple-' - function (x, value) 
 {
  attr(x, 'levels') - value
 }
 
levels.simple(y) - c('a', 'b', 'c', 'd') # does not what I want
y
[1] a b c d
 
Thanks,
Heinz Tüchler

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



  




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


[R] how to print a data.frame without row.names

2005-08-02 Thread Heinz Tuechler
Dear All,
is there a simple way to print a data.frame without its row.names?

example:
datum - as.Date(c(2004-01-01, 2004-01-06, 2004-04-12))
content - c('Neujahr', 'Hl 3 K.', 'Ostern')
df1 - data.frame(datum, content)
print(df1)

   datum content
1 2004-01-01 Neujahr
2 2004-01-06 Hl 3 K.
3 2004-04-12  Ostern

Can I get this table without 1, 2, 3 ?

Thanks in advance

Heinz Tuechler

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


Re: [R] how to print a data.frame without row.names

2005-08-02 Thread Heinz Tuechler
At 16:05 02.08.2005 +0200, Romain Francois wrote:
Le 02.08.2005 15:45, Heinz Tuechler a écrit :

Dear All,
is there a simple way to print a data.frame without its row.names?

example:
datum - as.Date(c(2004-01-01, 2004-01-06, 2004-04-12))
content - c('Neujahr', 'Hl 3 K.', 'Ostern')
df1 - data.frame(datum, content)
print(df1)

   datum content
1 2004-01-01 Neujahr
2 2004-01-06 Hl 3 K.
3 2004-04-12  Ostern

Can I get this table without 1, 2, 3 ?
  

See write.table and its row.names argument

R write.table(df1, row.names=FALSE)

Romain


write.table(df1, row.names=FALSE, quote=FALSE)
datum content
2004-01-01 Neujahr
2004-01-06 Hl 3 K.
2004-04-12 Ostern

I tried this, but then the column headers and column contents are not aligned.

If you expand the example, you see clearly the difference.

datum - as.Date(c(2004-01-01, 2004-01-06, 2004-04-12))
content - c('Neujahr', 'Hl 3 K.', 'Ostern')
number - c(1, 6, 110)
string - c('a', '', 'c')
df1 - data.frame(datum, content, number, string)
print(df1)
   datum content number string
1 2004-01-01 Neujahr  1  a
2 2004-01-06 Hl 3 K.  6   
3 2004-04-12  Ostern110  c

write.table(df1, row.names=FALSE, quote=FALSE)
datum content number string
2004-01-01 Neujahr 1 a
2004-01-06 Hl 3 K. 6 
2004-04-12 Ostern 110 c

Maybe I missed a function like print.xtable with type=ascii. It seems
that it has to be done with cat.

Thank you

Heinz

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
 ~ 
~~  Romain FRANCOIS - http://addictedtor.free.fr ~~
Etudiant  ISUP - CS3 - Industrie et Services   
~~http://www.isup.cicrp.jussieu.fr/  ~~
   Stagiaire INRIA Futurs - Equipe SELECT  
~~   http://www.inria.fr/recherche/equipes/select.fr.html~~
 ~ 



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


Re: [R] how to print a data.frame without row.names

2005-08-02 Thread Heinz Tuechler
Thanks to all of you for your help.

As far as I see, the solution of Peter Dalgaard works exactly as I want.
All other solutions have limitations.

Heinz

At 19:19 02.08.2005 +0200, Peter Dalgaard wrote:
Martin Maechler [EMAIL PROTECTED] writes:

  Heinz == Heinz Tuechler [EMAIL PROTECTED]
  on Tue, 02 Aug 2005 17:46:07 +0200 writes:
 
   ...
 
 Heinz I tried this, but then the column headers and column
 Heinz contents are not aligned.
 
   
 
 Use the tabulator if you need them aligned :
 
 write.table(USArrests, row.names = FALSE, sep = \t)

Unless a column or a header is 8 chars or wider (and UrbanPop is!).

This seems to do it:

  x - as.matrix(format(USArrests))
  rownames(x) - rep(, nrow(x))
  print(x, quote=FALSE, right=TRUE)

-- 
   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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] levels() deletes other attributes

2005-07-18 Thread Heinz Tuechler
Dear All,

it seems to me that levels() deletes other attributes. See the following
example:

## example with levels
f1 - factor(c('level c','level b','level a','level c'), ordered=TRUE)
attr(f1, 'testattribute') - 'teststring'
attributes(f1)
levels(f1) - c('L-A', 'L-B', 'L-C')
attributes(f1)

If I run it, after assigning new levels, the class is only factor instead
of ordered factor and the $testattribute teststring is gone.

The same happens to the label() attribute of Hmisc.

## example with levels and label
library(Hmisc)
f1 - factor(c('level c','level b','level a','level c'), ordered=TRUE)
label(f1) - 'factor f1'
attr(f1, 'testattribute') - 'teststring'
attributes(f1)
levels(f1) - c('L-A', 'L-B', 'L-C')
attributes(f1)

Should I expect this behaviour?

Thanks

Heinz

# R-Version 2.1.0 Patched (2005-05-30)
# Windows98

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


Re: [R] levels() deletes other attributes

2005-07-18 Thread Heinz Tuechler
At 09:29 18.07.2005 -0500, Frank E Harrell Jr wrote:
Heinz Tuechler wrote:
 Dear All,
 
 it seems to me that levels() deletes other attributes. See the following
 example:
 
 ## example with levels
 f1 - factor(c('level c','level b','level a','level c'), ordered=TRUE)
 attr(f1, 'testattribute') - 'teststring'
 attributes(f1)
 levels(f1) - c('L-A', 'L-B', 'L-C')
 attributes(f1)
 
 If I run it, after assigning new levels, the class is only factor instead
 of ordered factor and the $testattribute teststring is gone.
 
 The same happens to the label() attribute of Hmisc.
 
 ## example with levels and label
 library(Hmisc)
 f1 - factor(c('level c','level b','level a','level c'), ordered=TRUE)
 label(f1) - 'factor f1'
 attr(f1, 'testattribute') - 'teststring'
 attributes(f1)
 levels(f1) - c('L-A', 'L-B', 'L-C')
 attributes(f1)
 
 Should I expect this behaviour?

Does the same thing happen when you do

  attr(f1,'levels') - c('L-A',...)

Frank

No, it does not. With attr(f1,'levels') - c('L-A', 'L-B', 'L-C') only the
levels are changed, all other attributes remain as before.
Heinz

 
 Thanks
 
 Heinz
 
 # R-Version 2.1.0 Patched (2005-05-30)
 # Windows98
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
 


-- 
Frank E Harrell Jr   Professor and Chair   School of Medicine
  Department of Biostatistics   Vanderbilt University



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


Re: [R] levels() deletes other attributes

2005-07-18 Thread Heinz Tuechler
At 16:53 18.07.2005 +0200, Heinz Tuechler wrote:
At 09:29 18.07.2005 -0500, Frank E Harrell Jr wrote:
Heinz Tuechler wrote:
 Dear All,
 
 it seems to me that levels() deletes other attributes. See the following
 example:
 
 ## example with levels
 f1 - factor(c('level c','level b','level a','level c'), ordered=TRUE)
 attr(f1, 'testattribute') - 'teststring'
 attributes(f1)
 levels(f1) - c('L-A', 'L-B', 'L-C')
 attributes(f1)
 
 If I run it, after assigning new levels, the class is only factor
instead
 of ordered factor and the $testattribute teststring is gone.
 
 The same happens to the label() attribute of Hmisc.
 
 ## example with levels and label
 library(Hmisc)
 f1 - factor(c('level c','level b','level a','level c'), ordered=TRUE)
 label(f1) - 'factor f1'
 attr(f1, 'testattribute') - 'teststring'
 attributes(f1)
 levels(f1) - c('L-A', 'L-B', 'L-C')
 attributes(f1)
 
 Should I expect this behaviour?

Does the same thing happen when you do

  attr(f1,'levels') - c('L-A',...)

Frank

No, it does not. With attr(f1,'levels') - c('L-A', 'L-B', 'L-C') only the
levels are changed, all other attributes remain as before.
Heinz

I think, I know why attr(f1,'levels') behaves different from levels(f1) - .
As far as I see, the method of levels for factor does not use attr() but
factor().
Heinz
 
 Thanks
 
 Heinz
 
 # R-Version 2.1.0 Patched (2005-05-30)
 # Windows98
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
 


-- 
Frank E Harrell Jr   Professor and Chair   School of Medicine
  Department of Biostatistics   Vanderbilt University



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



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


[R] factor to numeric in data.frame

2005-04-02 Thread Heinz Tuechler
Dear All,

Assume I have a data.frame that contains also factors and I would like to
get another data.frame containing the factors as numeric vectors, to apply
functions like sapply(..., median) on them.
I read the warning concerning as.numeric or unclass, but in my case this
makes sense, because the factor levels are properly ordered.
I can do it, if I write for each single column unclass(...), but I would
like to use indexing, e.g. unclass(df[1:10]).
Is that possible?

Thanks,
Heinz Tüchler

## Example:
f1 - factor(c(rep('c1-low',2),rep('c2-med',5),rep('c3-high',3)))
f2 - factor(c(rep('c1-low',5),rep('c2-low',3),rep('c3-low',2)))
df.f12 - data.frame(f1,f2) # data.frame containing factors

## this does work
df.f12.num - data.frame(unclass(df.f12[[1]]),unclass(df.f12[[2]]))
df.f12.num
## this does not work
df.f12.num - data.frame(unclass(df.f12[[1:2]]))
df.f12.num
## this does not work
df.f12.num - data.frame(unclass(df.f12[1:2]))
df.f12.num

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


Re: [R] factor to numeric in data.frame

2005-04-02 Thread Heinz Tuechler
At 07:15 02.04.2005 -0500, Gabor Grothendieck wrote:
Try this:

data.matrix(df.f12)

Perfect! This is exactly what I needed.
 
Many thanks,
Heinz Tüchler

On Apr 2, 2005 6:01 AM, Heinz Tuechler [EMAIL PROTECTED] wrote:
 Dear All,
 
 Assume I have a data.frame that contains also factors and I would like to
 get another data.frame containing the factors as numeric vectors, to apply
 functions like sapply(..., median) on them.
 I read the warning concerning as.numeric or unclass, but in my case this
 makes sense, because the factor levels are properly ordered.
 I can do it, if I write for each single column unclass(...), but I would
 like to use indexing, e.g. unclass(df[1:10]).
 Is that possible?
 
 Thanks,
 Heinz Tüchler
 
 ## Example:
 f1 - factor(c(rep('c1-low',2),rep('c2-med',5),rep('c3-high',3)))
 f2 - factor(c(rep('c1-low',5),rep('c2-low',3),rep('c3-low',2)))
 df.f12 - data.frame(f1,f2) # data.frame containing factors
 
 ## this does work
 df.f12.num - data.frame(unclass(df.f12[[1]]),unclass(df.f12[[2]]))
 df.f12.num
 ## this does not work
 df.f12.num - data.frame(unclass(df.f12[[1:2]]))
 df.f12.num
 ## this does not work
 df.f12.num - data.frame(unclass(df.f12[1:2]))
 df.f12.num
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




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


Re: [R] factor to numeric in data.frame

2005-04-02 Thread Heinz Tuechler
At 14:26 02.04.2005 +0100, Prof Brian Ripley wrote:
On Sat, 2 Apr 2005, Heinz Tuechler wrote:

 Dear All,

 Assume I have a data.frame that contains also factors and I would like to
 get another data.frame containing the factors as numeric vectors, to apply
 functions like sapply(..., median) on them.
 I read the warning concerning as.numeric or unclass, but in my case this
 makes sense, because the factor levels are properly ordered.
 I can do it, if I write for each single column unclass(...), but I would
 like to use indexing, e.g. unclass(df[1:10]).
 Is that possible?

Yes: unclass is applied to a column and not the data frame.

newdf - df
newdf[1:10] - lapply(newdf[1:10], unclass)

BTW, please read the posting guide, and do not say `does not work' when it 
patently does work as documented.


Thank you for your answer. I am sorry for the unprecise formulation `does
not work'. I intended `does not solve my problem'.
In the meantime Gabor Grothendieck responded with:
'Try this: data.matrix(df.f12)'
which is exactly, what I was searching for.

Many thanks,
Heinz Tüchler


 Thanks,
 Heinz Tüchler

 ## Example:
 f1 - factor(c(rep('c1-low',2),rep('c2-med',5),rep('c3-high',3)))
 f2 - factor(c(rep('c1-low',5),rep('c2-low',3),rep('c3-low',2)))
 df.f12 - data.frame(f1,f2) # data.frame containing factors

 ## this does work
 df.f12.num - data.frame(unclass(df.f12[[1]]),unclass(df.f12[[2]]))
 df.f12.num
 ## this does not work
 df.f12.num - data.frame(unclass(df.f12[[1:2]]))

Yes, it does work.  What do you think [[1:2]] does?   Please RTFM.

 ## this does not work
 df.f12.num - data.frame(unclass(df.f12[1:2]))
 df.f12.num

That also works: unclassing a data frame gives a list.

-- 
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] From FAQ 7.21 to a command like apply(sapply(list(f1,f2,f3),is.na),2,sum)

2005-03-30 Thread Heinz Tuechler
At 16:13 29.03.2005 -0800, Thomas Lumley wrote:
On Wed, 30 Mar 2005, Heinz Tuechler wrote:

 Dear all,

 Last December there was a thread regarding the famous FAQ 7.21 How can I
 turn a string into a variable? and asking what people want to do with
 these strings.
 My, certainly trivial application would be as follows:
 Assume I have a data.frame containing besides others also the columns f1,
 f2, ..., fn and I want to create a command like:
 apply(sapply(list(f1,f2,f3),is.na),2,sum)
 or
 summary(cbind(f1,f2,f3))

 Can I start from paste('f',1:3,sep='') to arrive at the abovementioned
 command?

No parse,as.name or other complications needed. It's all just indexing. 
Suppose your data frame is called dd

fs-paste('f',1:3,sep='')
apply(sapply(dd[,fs],is.na),2,sum)
summary(dd[,fs])

   -thomas


Thank you, Thomas, for your answer. I was curious if there was a simple way
to do this without referring to the data.frame, so that the resulting
command would correspond in its effect exactly to the abovementioned examples.
It's not urgent, but I will try further.

Many thanks

Heinz

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


Re: [R] From FAQ 7.21 to a command likeapply(sapply(list(f1,f2,f3),is.na),2,sum)

2005-03-30 Thread Heinz Tuechler
At 09:32 30.03.2005 +0200, Heinz Tuechler wrote:
At 16:13 29.03.2005 -0800, Thomas Lumley wrote:
On Wed, 30 Mar 2005, Heinz Tuechler wrote:

 Dear all,

 Last December there was a thread regarding the famous FAQ 7.21 How can I
 turn a string into a variable? and asking what people want to do with
 these strings.
 My, certainly trivial application would be as follows:
 Assume I have a data.frame containing besides others also the columns f1,
 f2, ..., fn and I want to create a command like:
 apply(sapply(list(f1,f2,f3),is.na),2,sum)
 or
 summary(cbind(f1,f2,f3))

 Can I start from paste('f',1:3,sep='') to arrive at the abovementioned
 command?

No parse,as.name or other complications needed. It's all just indexing. 
Suppose your data frame is called dd

fs-paste('f',1:3,sep='')
apply(sapply(dd[,fs],is.na),2,sum)
summary(dd[,fs])

  -thomas


Thank you, Thomas, for your answer. I was curious if there was a simple way
to do this without referring to the data.frame, so that the resulting
command would correspond in its effect exactly to the abovementioned
examples.
It's not urgent, but I will try further.

Many thanks

Heinz

Continuation:
Maybe not an elegant solution, but it seems to work:
apply(sapply(eval(parse(text=paste('list(',paste('f',1:3,sep='',
collapse=','),')'))) ,is.na),2,sum)
What I missed in my earlier attempts was collapse=','.

Heinz

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


[R] From FAQ 7.21 to a command like apply(sapply(list(f1,f2,f3),is.na),2,sum)

2005-03-29 Thread Heinz Tuechler
Dear all,

Last December there was a thread regarding the famous FAQ 7.21 How can I
turn a string into a variable? and asking what people want to do with
these strings.
My, certainly trivial application would be as follows:
Assume I have a data.frame containing besides others also the columns f1,
f2, ..., fn and I want to create a command like:
apply(sapply(list(f1,f2,f3),is.na),2,sum)
or
summary(cbind(f1,f2,f3))

Can I start from paste('f',1:3,sep='') to arrive at the abovementioned
command?
I tried get, parse, as.name, eval in diverse combinations but did not reach
a solution.
More generally my question is, how can I produce a list of variables like
x1 to xn in a convenient way within a command.
I am quite sure that this has been answered several times, but I did not
find one of these answers. So I welcome any hint, where to look.

Heinz Tüchler

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


[R] Again: Variable names in functions

2005-02-17 Thread Heinz Tuechler
Hello,

still I have difficulties with variable names in functions. I know the
famous example form help for deparse/substitute but I will give a simpler
one to explain my problem.
I know from Reid Huntsinger (Tue, 8 Feb 2005 12:39:32 -0500) that:
Semantically, R is pass-by-value, so you don't really have the names, just
the values. In implementation, though, R *does* pass names, in part at least
in order to do lazy evaluation. You can get them via substitute ; see
the help for that. 

The output of several functions does not make much sense, if these names do
not appear (e.g. parameter estimates in Cox-regression, ...)
Only to give a trivial example I show my problem with the table function.

As you know, if I call table as follows, the output is labelled properly.
 charly-c(rep(1,3),rep(2,7));delta-c(rep(1:2,5))
 table(charly, delta)
  delta
charly 1 2
 1 2 1
 2 3 4
If I define a trivial function to call table, the output is less satisfying.
(Of course, I know that this function is useless.)
 mytable1-function(x,y){table(x,y)}
 mytable1(charly, delta)
   y
x   1 2
  1 2 1
  2 3 4
If I define the function in the following way, it does what I wish, namely
it returns output equivalent to the simple call table(charly, delta).
 mytable2-function(x,y){
+   cat(table(,as.symbol((deparse(substitute(x,
+   , ,  as.symbol(deparse(substitute(y))),)\n,
+   file=temp,sep=,append=F)
+   eval(parse(temp,n=-1))
+   }
 mytable2(charly, delta)
  delta
charly 1 2
 1 2 1
 2 3 4
 
I assume that there is a better way to solve this problem and I would be
happy about hints, where to find solutions in the documentation.

Thanks,

Heinz Tüchler

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


Re: [R] Again: Variable names in functions

2005-02-17 Thread Heinz Tuechler
At 11:48 17.02.2005 +0100, Uwe Ligges wrote:

See argument dnn in ?table:


   mytable2 - function(x,y){
 table(x, y, dnn = c(deparse(substitute(x)),
 deparse(substitute(y
   }

Uwe Ligges




Thank you for your hint. This is of course a good solution for the example.
Still I am looking for a more general solution, but it is not urgent.

Heinz Tüchler


Heinz Tuechler wrote:

 Hello,
 
 still I have difficulties with variable names in functions. I know the
 famous example form help for deparse/substitute but I will give a simpler
 one to explain my problem.
 I know from Reid Huntsinger (Tue, 8 Feb 2005 12:39:32 -0500) that:
 Semantically, R is pass-by-value, so you don't really have the names, just
 the values. In implementation, though, R *does* pass names, in part at
least
 in order to do lazy evaluation. You can get them via substitute ; see
 the help for that. 
 
 The output of several functions does not make much sense, if these names do
 not appear (e.g. parameter estimates in Cox-regression, ...)
 Only to give a trivial example I show my problem with the table function.
 
 As you know, if I call table as follows, the output is labelled properly.
 
charly-c(rep(1,3),rep(2,7));delta-c(rep(1:2,5))
table(charly, delta)
 
   delta
 charly 1 2
  1 2 1
  2 3 4
 If I define a trivial function to call table, the output is less
satisfying.
 (Of course, I know that this function is useless.)
 
mytable1-function(x,y){table(x,y)}
mytable1(charly, delta)
 
y
 x   1 2
   1 2 1
   2 3 4
 If I define the function in the following way, it does what I wish, namely
 it returns output equivalent to the simple call table(charly, delta).
 
mytable2-function(x,y){
 
 +   cat(table(,as.symbol((deparse(substitute(x,
 +   , ,  as.symbol(deparse(substitute(y))),)\n,
 +   file=temp,sep=,append=F)
 +   eval(parse(temp,n=-1))
 +   }
 
mytable2(charly, delta)
   delta
 charly 1 2
  1 2 1
  2 3 4
 
 I assume that there is a better way to solve this problem and I would be
 happy about hints, where to find solutions in the documentation.
 
 Thanks,
 
 Heinz Tüchler
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html



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


Re: [R] Again: Variable names in functions

2005-02-17 Thread Heinz Tuechler
At 11:51 17.02.2005 +0100, Peter Dalgaard wrote:
Heinz Tuechler [EMAIL PROTECTED] writes:

  mytable1-function(x,y){table(x,y)}
  mytable1(charly, delta)
y
 x   1 2
   1 2 1
   2 3 4
 If I define the function in the following way, it does what I wish, namely
 it returns output equivalent to the simple call table(charly, delta).
  mytable2-function(x,y){
 +   cat(table(,as.symbol((deparse(substitute(x,
 +   , ,  as.symbol(deparse(substitute(y))),)\n,
 +   file=temp,sep=,append=F)
 +   eval(parse(temp,n=-1))
 +   }
  mytable2(charly, delta)
   delta
 charly 1 2
  1 2 1
  2 3 4
  
 I assume that there is a better way to solve this problem and I would be
 happy about hints, where to find solutions in the documentation.

What did Thomas L. say recently? If the answer involves parse(), you
probably asked the wrong question, I think it was.

The canonical way is

mytable - function(x,y) eval.parent(substitute(table(x,y)))

or, you could of course modify the names(dimnames(...)) and just pass
the names along.


-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907


Thank you, this method works well. One step further I am again using
parse(), but maybe there is a better solution for that situation too.
The example would be a function, where I pass the variable name as string
instead of the name. The motivation for this is that it seems easier to
handle if I want to pass several variables (i.e. a vector of variable
names) to the function (as I learned recently from this help-list). 
In this case I have to use get(). In the case of calling table() the
variable name disappeares.

 alpha-c(rep(1:5,10))
 name.alpha-alpha
 mytable1-function(x){print(table(get(x)))}
 mytable1(name.alpha)

 1  2  3  4  5 
10 10 10 10 10 

If I use eval(parse()) instead, it works as expected. I tried several
combinations of eval() and substitute() but I did not find a solution.
Is there a similar trick?

 mytable2-function(x){
+   string-paste(print(table(,as.symbol(x),)))
+   eval(parse(text=string))}
 mytable2(name.alpha)
alpha
 1  2  3  4  5 
10 10 10 10 10 


Thanks,
Heinz Tüchler

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


RE: [R] Again: Variable names in functions

2005-02-17 Thread Heinz Tuechler
At 08:32 17.02.2005 -0800, Berton Gunter wrote:

I thought Thomas L. was clear, but apparently not...

** Do not pass character string names as arguments to functions. ** Pass the
objects (or expressions) which can consist of lists of vectors, dataframes,
etc. instead. 

If you need the names (e.g. as labels) you can use the deparse(substitute())
construction. I strongly recommend that you study pp. 44-46 and section 3.5
(Computing on the Language) of VR's S PROGRAMMING. The point is that one
can, of course, do things the way you want, but it makes life unnecessarily
difficult and complex because R is set up to pass arguments by value and can
keep better track of proper evaluation environments when this is done (which
means you don't have to).

-- Bert Gunter

Thank you for your advice. I will try to get the book as soon as possible
and meanwhiles study again other publications regarding these questions.
At the moment I am uncertain which way to prefer, since I am making my
first steps in R. Somehow I got the impression that there is a little
ambiguity concerning the use of object (variable) names in functions. My
little experience with R gave me the imression that much output
automatically has a sensible format (title, naming of estimates for
factors, ...) when you pass the object (=variable) name. If you don't do
it, you have more work to arrive at the same result. A title with the
variable's name is usually more informative than one with get(x). So for
a beginner like me it's temting to try to program functions in a way that
they work as similar as possible to the simple call from the R prompt.
Maybe objects like columns of data frames could have something like a name
attribute equal to their (column)name which is passed automatically to
functions.
Again, many thanks,
Heinz Tüchler

 
 
 Thank you, this method works well. One step further I am again using
 parse(), but maybe there is a better solution for that situation too.
 The example would be a function, where I pass the variable 
 name as string
 instead of the name. The motivation for this is that it seems 
 easier to
 handle if I want to pass several variables (i.e. a vector of variable
 names) to the function (as I learned recently from this help-list). 
 In this case I have to use get(). In the case of calling table() the
 variable name disappeares.
 
  alpha-c(rep(1:5,10))
  name.alpha-alpha
  mytable1-function(x){print(table(get(x)))}
  mytable1(name.alpha)
 
  1  2  3  4  5 
 10 10 10 10 10 
 
 If I use eval(parse()) instead, it works as expected. I tried several
 combinations of eval() and substitute() but I did not find a solution.
 Is there a similar trick?
 
  mytable2-function(x){
 +   string-paste(print(table(,as.symbol(x),)))
 +   eval(parse(text=string))}
  mytable2(name.alpha)
 alpha
  1  2  3  4  5 
 10 10 10 10 10 
 
 
 Thanks,
 Heinz Tüchler
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 




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


[R] update.packages - delete downloaded - N

2005-02-15 Thread Heinz Tuechler
Hello,

Using Update Packages from CRAN in R Version 2.0.1 Patched (2005-01-15)
under Windows 98, I found it tricky to save the downloaded files.
Even if I answer N to the question, if the downloaded files should be
deleted, they are deleted after R is quitted. I understood that I have to
copy them to a different location before quitting R. Is this an intended
behavoiur of R or did I miss some instruction?

Heinz Tüchler

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


Re: [R] update.packages - delete downloaded - N

2005-02-15 Thread Heinz Tuechler
Thank you for the hint regarding the destdir parameter of update.packages.

Heinz Tüchler

At 12:15 15.02.2005 +0100, Uwe Ligges wrote:
Heinz Tuechler wrote:

 Hello,
 
 Using Update Packages from CRAN in R Version 2.0.1 Patched (2005-01-15)
 under Windows 98, I found it tricky to save the downloaded files.
 Even if I answer N to the question, if the downloaded files should be
 deleted, they are deleted after R is quitted. I understood that I have to
 copy them to a different location before quitting R. Is this an intended
 behavoiur of R or did I miss some instruction?

Yes, intended, yes, you missed destdir:

It is intended to save in tempdir() by default.
You can specify argument destdir, if you want something different.

Uwe Ligges


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



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


[R] How to get variable names in a function?

2005-02-08 Thread Heinz Tuechler
Hello,

applying a function to a list of variables I face the following problem:
Let's say I want to compute tables for several variables. I could write a
command for every single table, like
bravo-c(1,1,2,3,5,5,5,);charly-c(7,7,4,4,2,1)
table(bravo); table(charly)
 table(bravo); table(charly)
bravo
1 2 3 5 
2 1 1 3 
charly
1 2 4 7 
1 1 2 2 
The results are two tables with the names of the variables above each.
If I want to do the same thing by a function I find no way to get the
variable names above the tables. 
demofn-function(varlist)
{for (i in seq(along=varlist))
   {cat(deparse(varlist[i])) #  - - - - how to change this?
print(table(varlist[i]))}}
 demofn(list(bravo, charly))
list(c(1, 1, 2, 3, 5, 5, 5))
1 2 3 5 
2 1 1 3 
list(c(7, 7, 4, 4, 2, 1))
1 2 4 7 
1 1 2 2 
 

Thanks,
Heinz Tüchler

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


RE: [R] How to get variable names in a function?

2005-02-08 Thread Heinz Tuechler
At 12:51 08.02.2005 -0500, Liaw, Andy wrote:
This might be easier for your purpose:

 lapply(list(bravo=bravo, charly=charly), table)
$bravo

1 2 3 5 
2 1 1 3 

$charly

1 2 4 7 
1 1 2 2 

Andy

Thank you for your answer. In the case of the example it is sufficient, but
I see that I did not choose it well.
What I search a solution for, is in general to use a variable and its name
within a function, e.g. to write a headline like Results for
variablename and to print the table(variablename) and maybe a test for
the same variable below it.
I solved this for one variable, but not too well for a list of variables.
In any case, thanks,
Heinz

 From: Heinz Tuechler
 
 Hello,
 
 applying a function to a list of variables I face the 
 following problem:
 Let's say I want to compute tables for several variables. I 
 could write a
 command for every single table, like
 bravo-c(1,1,2,3,5,5,5,);charly-c(7,7,4,4,2,1)
 table(bravo); table(charly)
  table(bravo); table(charly)
 bravo
 1 2 3 5 
 2 1 1 3 
 charly
 1 2 4 7 
 1 1 2 2 
 The results are two tables with the names of the variables above each.
 If I want to do the same thing by a function I find no way to get the
 variable names above the tables. 
 demofn-function(varlist)
 {for (i in seq(along=varlist))
{cat(deparse(varlist[i])) #  - - - - how to change this?
 print(table(varlist[i]))}}
  demofn(list(bravo, charly))
 list(c(1, 1, 2, 3, 5, 5, 5))
 1 2 3 5 
 2 1 1 3 
 list(c(7, 7, 4, 4, 2, 1))
 1 2 4 7 
 1 1 2 2 
  
 
 Thanks,
 Heinz Tüchler
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 
 


---
---
Notice:  This e-mail message, together with any attachments, contains
information of Merck  Co., Inc. (One Merck Drive, Whitehouse Station, New
Jersey, USA 08889), and/or its affiliates (which may be known outside the
United States as Merck Frosst, Merck Sharp  Dohme or MSD and in Japan, as
Banyu) that may be confidential, proprietary copyrighted and/or legally
privileged. It is intended solely for the use of the individual or entity
named on this message.  If you are not the intended recipient, and have
received this message in error, please notify us immediately by reply
e-mail and then delete it from your system.
---
---



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


RE: [R] How to get variable names in a function?

2005-02-08 Thread Heinz Tuechler
At 10:32 08.02.2005 -0800, Berton Gunter wrote:
If you pass your function a NAMED list, then the following works:

demofn-function(varlist)
{
   nm-names(varlist)
for (i in seq(along=varlist))
   {cat('\n',nm[i]) 
   print(table(varlist[[i]]))
}
}
demofn(list(bravo=bravo, charly=charly))

If you don't pass a named list, then you need to restrict and know the form
of the expression that is the varlist argument in order to substitute() and
deparse it correctly to get the identifiers you want. For example, if you
knew that varlist were an expression of the form:
list(var1,var2,var3,...) 
then you could get the ith identifier vari via:

deparse((as.list(substitute(varlist))[-1])[[i]]) 

HOWEVER, this is probably inefficient and **clearly** clumsy, undesirable,
and almost certain to fail (so don't do this!). 

If the number of tables is small enough that you could simply list them as
arguments (as opposed to constructing the list of vectors to be tabled in
some way), then the function call could be of the form function(...) and the
... arguments could be processed as discussed in section 3.1 of VR's S
PROGRAMMING. That is, your example call would be of the form:
demofn(bravo,charly), and you can forgo lists in the call altogether. This
strategy actually also works for long constructed lists of arguments using
do.call() -- see it's help file and VR again for details.


-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
The business of the statistician is to catalyze the scientific learning
process.  - George E. P. Box
 
Thank you for your detailled answer. I see that it is not as easy as I
expected and I will think about a convenient way to do it.
I tried also the opposit approach i.e. to pass a vector of names to the
function like c(bravo, charly) but until now I did not solve it either.
A third way worked, but seemed to me less generally applicable.
I stored all the names of the variables of a data.frame in a vector, made
the selection of the variables by match() and passed the indices of the
selected variables to the function. By this method I can then access each
variable by its index and also its name via the vector of the stored names.
It seemed to me a crude method of a beginner like me and I still hope to
find a better one.
Your suggestion with the named list may be the best, if I find a practical
way to produce this named list by some function from a simple list without
retyping each name. 

Thanks again,

Heinz
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Heinz Tuechler
 Sent: Tuesday, February 08, 2005 8:45 AM
 To: r-help@stat.math.ethz.ch
 Subject: [R] How to get variable names in a function?
 
 Hello,
 
 applying a function to a list of variables I face the 
 following problem:
 Let's say I want to compute tables for several variables. I 
 could write a
 command for every single table, like
 bravo-c(1,1,2,3,5,5,5,);charly-c(7,7,4,4,2,1)
 table(bravo); table(charly)
  table(bravo); table(charly)
 bravo
 1 2 3 5 
 2 1 1 3 
 charly
 1 2 4 7 
 1 1 2 2 
 The results are two tables with the names of the variables above each.
 If I want to do the same thing by a function I find no way to get the
 variable names above the tables. 
 demofn-function(varlist)
 {for (i in seq(along=varlist))
{cat(deparse(varlist[i])) #  - - - - how to change this?
 print(table(varlist[i]))}}
  demofn(list(bravo, charly))
 list(c(1, 1, 2, 3, 5, 5, 5))
 1 2 3 5 
 2 1 1 3 
 list(c(7, 7, 4, 4, 2, 1))
 1 2 4 7 
 1 1 2 2 
  
 
 Thanks,
 Heinz Tüchler
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 




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


Re: [R] How to access results of survival analysis

2005-02-06 Thread Heinz Tuechler
To sum up:
Starting from the question, how to access the results of survival analysis
Uwe Liggens suggested to ...copy code for calculation of the required
values from those print methods into your own functions...

Since I am new to R I choose the easiest way I knew and changed a few lines
in the print.survfit method. I introduced a parameter ret.res=FALSE set
to false to preserve the normal behaviour of print.
The second last line invisible(x) I changed to:

if (ret.res)
invisible(list(x,x1))
else
invisible(x)

Finally I source the changed function.
Of course this is only a temporary workaround, but it seems to work.

Thanks,
Heinz Tüchler

At 19:09 05.02.2005 +0100, Uwe Ligges wrote:
Heinz Tuechler wrote:

 At 15:19 05.02.2005 +0100, Uwe Ligges wrote:
 
Heinz Tuechler wrote:

Hello,

it seems that the main results of survival analysis with package survival
are shown only as side effects of the print method.

If I compute e.g. a Kaplan-Meier estimate by 


km.survdur-survfit(s.survdur) 

then I can simply print the results by 


km.survdur

Call: survfit(formula = s.survdur)

  n  events  median 0.95LCL 0.95UCL 
  100.058.046.841.079.3 

Is there a simple method to access these results, e.g. if I want to print
only the median with the confidence limits?
 
 
 ...
 
No, the print methods do not return those values.
But you can copy code for calculation of the required values from those 
print methods into your own functions...

Uwe Ligges


 
 Thank you for your answer. I assume, you suggest to use
 capture.output(print(...)). 

No, I suggested to copy the code from survival:::print.survfit and Co. 
that calculates the values you are looking for...

Uwe

  Without your response I would have believed
 that I had missed an important possibility of R.
 
 Regarding the Cox-Model Ales Ziberna gave me a useful hint to use summary()
 which returns a list.
 
 Thanks to both of you,
 
 Heinz Tüchler



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


Re: [R] How to access results of survival analysis

2005-02-05 Thread Heinz Tuechler
Hello Ales,

thank you for your hint regarding names(summary(fit)). Summary(fit) is a
list containig all important results of the Cox-model.
So it helps a lot!
Regarding the results of a Kaplan-Meier estimate summary does not help,
because it does not contain the main results.

Thanks again,
Heinz Tüchler

ps. If I understood it right, you answered only to me and not to the list.
So I assumed that you prefer not to put your answer on the list and
therefore I answer to you off-list.

At 09:24 05.02.2005 +0100, Ales Ziberna wrote:
Hi!

I don't now how to reach the median directly. However I can help you whit 
cox-PH coefficients.

if fit is the resoult of the coxph, then

fit$coefficients should give you the coefficients. To see whatother things 
you can acces in similar way, see
names(fit)
or
names(summary(fit)).

I hope this helps at least a little!

Ales Ziberna


- Original Message - 
From: Heinz Tuechler [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Friday, February 04, 2005 11:17 PM
Subject: [R] How to access results of survival analysis


Hello,

it seems that the main results of survival analysis with package survival
are shown only as side effects of the print method.

If I compute e.g. a Kaplan-Meier estimate by
 km.survdur-survfit(s.survdur)
then I can simply print the results by
 km.survdur
Call: survfit(formula = s.survdur)

  n  events  median 0.95LCL 0.95UCL
  100.058.046.841.079.3

Is there a simple method to access these results, e.g. if I want to print
only the median with the confidence limits?
Regarding the results of a Cox-PH-model I face the same situation. The
printed results are:
 cx.survdur.ipss_mds.sex
Call:
coxph(formula = s.survdur ~ x1 + x2, method = efron)

   coef exp(coef) se(coef) z  p
x1   0.6424  1.900.206 3.123 0.0018
x2.L 0.0616  1.060.263 0.234 0.8100

Likelihood ratio test=9.56  on 2 df, p=0.0084  n=58 (42 observations
deleted due to missing)

Is there a simple method to copy e.g. the coefficients and p-values in a
new object?

I am working with:
R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0
Survival package version: survival_2.16
Operating System: Windows 98SE

Thanks,
Heinz Tüchler

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




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


Re: [R] How to access results of survival analysis

2005-02-05 Thread Heinz Tuechler
At 15:19 05.02.2005 +0100, Uwe Ligges wrote:
Heinz Tuechler wrote:
 Hello,
 
 it seems that the main results of survival analysis with package survival
 are shown only as side effects of the print method.
 
 If I compute e.g. a Kaplan-Meier estimate by 
 
km.survdur-survfit(s.survdur) 
 
 then I can simply print the results by 
 
km.survdur
 
 Call: survfit(formula = s.survdur)
 
   n  events  median 0.95LCL 0.95UCL 
   100.058.046.841.079.3 
 
 Is there a simple method to access these results, e.g. if I want to print
 only the median with the confidence limits?

...

No, the print methods do not return those values.
But you can copy code for calculation of the required values from those 
print methods into your own functions...

Uwe Ligges


Thank you for your answer. I assume, you suggest to use
capture.output(print(...)). Without your response I would have believed
that I had missed an important possibility of R.

Regarding the Cox-Model Ales Ziberna gave me a useful hint to use summary()
which returns a list.

Thanks to both of you,

Heinz Tüchler

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


[R] How to access results of survival analysis

2005-02-04 Thread Heinz Tuechler
Hello,

it seems that the main results of survival analysis with package survival
are shown only as side effects of the print method.

If I compute e.g. a Kaplan-Meier estimate by 
 km.survdur-survfit(s.survdur) 
then I can simply print the results by 
 km.survdur
Call: survfit(formula = s.survdur)

  n  events  median 0.95LCL 0.95UCL 
  100.058.046.841.079.3 

Is there a simple method to access these results, e.g. if I want to print
only the median with the confidence limits?
Regarding the results of a Cox-PH-model I face the same situation. The
printed results are:
 cx.survdur.ipss_mds.sex
Call:
coxph(formula = s.survdur ~ x1 + x2, method = efron)

   coef exp(coef) se(coef) z  p
x1   0.6424  1.900.206 3.123 0.0018
x2.L 0.0616  1.060.263 0.234 0.8100

Likelihood ratio test=9.56  on 2 df, p=0.0084  n=58 (42 observations
deleted due to missing)

Is there a simple method to copy e.g. the coefficients and p-values in a
new object?

I am working with:
R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0
Survival package version: survival_2.16
Operating System: Windows 98SE

Thanks,
Heinz Tüchler

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


Re: [R] Modyfing PATH in Windows Installer for R

2004-12-07 Thread Heinz Tuechler
At 10:30 06.12.2004 -0500, Duncan Murdoch wrote:

But we still have users using Win9x versions, which use a more
DOS-like method of setting the path.  At some point we'll drop support
for them, but I don't want to do it sooner than necessary.

Duncan Murdoch

Thank you for supporting Win9x! I would not be happy to be forced by R to
upgrade to an otherwise unnecessary version of Windows.

Heinz Tüchler

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


Re: [R] How to know if a bug was recognised

2004-12-01 Thread Heinz Tuechler
At 10:43 30.11.2004 -0500, you wrote:
...
If you send a private email, please use a return address that works.
I got messages that [EMAIL PROTECTED] has been disabled when I tried to
respond there.

Duncan Murdoch

...
As I tried to tell you, there seems to be a problem on both sides of our
addresses.

I erroneously sent my response to your posting to you
([EMAIL PROTECTED]) and not to the list. The answer was what you see below.

X-Flags: 
Delivered-To: GMX delivery to [EMAIL PROTECTED]
Date: 30 Nov 2004 15:55:37 -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: failure notice
X-GMX-Antivirus: -1 (not scanned, may not use virus scanner)
X-GMX-Antispam: 0 (Mail was not recognized as spam)

Hi. This is the qmail-send program at mail.gmx.net.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

[EMAIL PROTECTED]:
Connected_to_129.100.45.201_but_sender_was_rejected./Remote_host_said:_550_5
.7.1_[EMAIL PROTECTED]..._Access_denied/

--- Below this line is a copy of the message.

Return-Path: [EMAIL PROTECTED]
Received: (qmail 16050 invoked by uid 65534); 30 Nov 2004 15:55:31 -
Received: from N015P019.adsl.highway.telekom.at (HELO ipc) (213.33.1.211)
  by mail.gmx.net (mp020) with SMTP; 30 Nov 2004 16:55:31 +0100
X-Authenticated: #933343
Message-Id: [EMAIL PROTECTED]
X-Sender: [EMAIL PROTECTED]
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32)
Date: Tue, 30 Nov 2004 16:54:53 +0100
To: Duncan Murdoch [EMAIL PROTECTED]
From: Heinz Tuechler [EMAIL PROTECTED]
Subject: Re: [R] Attn Heinz Tuechler: Re:  problem with sp ecial characters (
 =?iso-8859-1?Q?=E4?=  =?iso-8859-1?Q?,=F6,=FC)?=
In-Reply-To: [EMAIL PROTECTED]
References: [EMAIL PROTECTED]
 [EMAIL PROTECTED]
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Thank you for the information. I did already download the 27-11-2004
version and I have the intention to try it within a day and report on the
result, if this is of interest.

My address ([EMAIL PROTECTED]) should work but I will check that too.

...

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


[R] How to know if a bug was recognised

2004-11-30 Thread Heinz Tuechler
Hello!

A problem with special characters seemed to me to be a bug. I sent a mail
to [EMAIL PROTECTED] concerning the problem (see below).
How can I find out, if this is considered as a bug or an error of myself?
Which part of FAQs or documentation did I miss to find the answer?

thanks in advance

Heinz Tüchler

 copy of abovementioned mail --
to: [EMAIL PROTECTED]
subject: problem with special characters (ä,ö,ü)
Dear Developers!

Using special characters I found a strange behaviour in R 2.0.1 and equally
in 
R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0

Operating System: Windows 98SE

example:
factor1-as.factor(c(weiblich,männlich,österreichisch,frühreif,Gruß
))
factor1
 factor1
[1] weiblich   m\344nnlich\366sterreichisch  fr\374hreif
   
[5] Gru\337   
Levels: frühreif Gruß männlich österreichisch weiblich

with best wishes

Heinz Tüchler

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


Re: [R] Attn Heinz Tuechler: Re: problem with sp ecial characters ( ä,ö,ü)

2004-11-30 Thread Heinz Tuechler
Thank you for the information. I did already download the 27-11-2004
version and I have the intention to try it within a day and report on the
result, if this is of interest.

My address ([EMAIL PROTECTED]) should work but I will check that too.

Heinz Tüchler

At 10:27 30.11.2004 -0500, you wrote:
[I tried to send this message privately, but the return address
bounced.]

I think this has been fixed in R-patched, but I doubt if the fix has
been tested in Win98.  Could you please download a copy from
http://cran.r-project.org/bin/windows/base/rpatched.html and confirm
that it has been fixed?

Duncan Murdoch

On Sat, 27 Nov 2004 23:31:23 +0100, Heinz Tuechler [EMAIL PROTECTED]
wrote :

Dear Developers!

Using special characters I found a strange behaviour in R 2.0.1 and equally
in 
R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0

Operating System: Windows 98SE

example:
factor1-as.factor(c(weiblich,männlich,österreichisch,frühreif,Gruß
))
factor1
 factor1
[1] weiblich   m\344nnlich\366sterreichisch  fr\374hreif
   
[5] Gru\337   
Levels: frühreif Gruß männlich österreichisch weiblich

with best wishes

Heinz Tüchler

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



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


RE: [R] How to know if a bug was recognised

2004-11-30 Thread Heinz Tuechler
Dear Henrik Bengtsson!

Thank you for your kind answer. I am sorry that at the time of writing my
inital message the last version of R was 2004-11-15. As soon as possible I
will try the new version.

with many thanks

Heinz Tüchler


At 14:01 30.11.2004 +0100, you wrote:
 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Heinz Tuechler
 Sent: Tuesday, November 30, 2004 1:25 PM
 To: [EMAIL PROTECTED]
 Subject: [R] How to know if a bug was recognised
 
 
 Hello!
 
 A problem with special characters seemed to me to be a bug. I 
 sent a mail to [EMAIL PROTECTED] concerning the problem 
 (see below). How can I find out, if this is considered as a 
 bug or an error of myself? Which part of FAQs or 
 documentation did I miss to find the answer?

This will not answer your question on what is a bug or not, but if you don't
know, the R team has kindly made a fix for this problem. What I remember
from an earlier thread, this was not really due to R, but to Windows. For
the latest R v2.0.1 patch it now seems to work as before/expected:

R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1 Patched (2004-11-27), ISBN 3-900051-07-0

 å
[1] å
 ä
[1] ä
 ö
[1] ö

Cheers

Henrik Bengtsson


 thanks in advance
 
 Heinz Tüchler
 
  copy of abovementioned mail --
 to: [EMAIL PROTECTED]
 subject: problem with special characters (ä,ö,ü)
 Dear Developers!
 
 Using special characters I found a strange behaviour in R 
 2.0.1 and equally in 
 R : Copyright 2004, The R Foundation for Statistical 
 Computing Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0
 
 Operating System: Windows 98SE
 
 example: 
 factor1-as.factor(c(weiblich,männlich,österreichisch,f
 rühreif,Gruß
 ))
 factor1
  factor1
 [1] weiblich   m\344nnlich\366sterreichisch  
 fr\374hreif

 [5] Gru\337   
 Levels: frühreif Gruß männlich österreichisch weiblich
 
 with best wishes
 
 Heinz Tüchler
 
 __
 [EMAIL PROTECTED] mailing list 
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 
 



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