[R] random numbers

2007-06-30 Thread Ross Boylan
Although this query was inspired by distributed random number
generation, one of the questions (#2 below) is a single-machine issue.

I call C++ code from R to generate simulated data.  I'm doing this on a
cluster, and use rmpi and rsprng.  While rsprng randomizes R-level
random numbers (e.g., from runif), it has no effect on the C code, which
is completely SPRNG and MPI ignorant.

Currently I generate a seed to pass into the C code, using
as.integer(runif(1, max=.Machine$integer.max)-.Machine$integer.max/2)
It seems to work.

Any comments on this approach?  Here are some issues I see:

1) The much simpler method of using the consecutive integers as seeds
also seemed to work.  This also has the advantage of repeatability.  I
avoided it because I was concerned it wouldn't be random enough.  Would
consecutive integers as in
  parLapply(cluster, seq(nSimulations), function(i) myfunction(seed=i))
be sufficient?

I suppose I could also generate all the random seeds on the master.

2) This got me thinking about how to generate random integers that span
the whole range of 32 bit signed integers.  The method show above only
spans half the range, since .Machine$integer.max = 2^31.  It also makes
some assumptions about the relation between the value in  .Machine
$integer.max and the seed for random numbers.  Interestingly,
integer.max was 2^31 despite running on a 64 bit powerpc, albeit under
the mostly 32 bit OS-X (I think Leopard--not the current one; Darwin
Kernel 7.9.0).

My understanding is that random number generators internally produce 32
bit integers, which then get converted into the desired distribution.
I'm a little surprised there doesn't seem to be a way to get at them.
Or is one supposed to do runif()*2^32-2^31?

3) Vagaries of the underlying C++ random number generator could also
complicate life.

__
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] random numbers

2007-06-30 Thread Ross Boylan
On Sat, 2007-06-30 at 14:50 -0500, Dirk Eddelbuettel wrote:
 On 30 June 2007 at 12:12, Ross Boylan wrote:
 | I call C++ code from R to generate simulated data.  I'm doing this on a
 | cluster, and use rmpi and rsprng.  While rsprng randomizes R-level
 | random numbers (e.g., from runif), it has no effect on the C code, which
 | is completely SPRNG and MPI ignorant.
 | 
 | Currently I generate a seed to pass into the C code, using
 | as.integer(runif(1, max=.Machine$integer.max)-.Machine$integer.max/2)
 | It seems to work.
 | 
 | Any comments on this approach?  Here are some issues I see:
 
 I may be missing something but given that rsprng is running on your cluster,
 you are bound to also have sprng itself -- so why don't you use that from C
 or C++  for this purpose?
 
 Hth, Dirk
Doing so would add considerable complexity, at least as far as I know.

Sometimes I run within an MPI session and sometimes not.  My
understanding is that SPRNG will not work if MPI is absent.  I think
someone on the SPRNG list told me that there wasn't a good way to handle
this at run-time.  Unfortunately, a lot of SPRNG options seem to be
compile-time settings.

Using SPRNG would also complicate my build process, as I'd need autoconf
magic to support it.

Part of the issue is that I want something I can redistribute, not just
something that will work for me on a  one-off basis.

One simple solution would be to build several versions of the library.
A not so simple solution would be to build various random number
generators as separate libraries, and dynamically load the appropriate
one.

__
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] ggplot aspect ratio

2007-06-05 Thread Ross Boylan
Is there a way to control the aspect ratio of plots using ggplot?
Specifically, I'm using the formula=a~b argument to produce a grid of
plots, but the overall width of the result seems to vary for reasons
that are obscure to me.

This affects not only the appearance of the plots but the amount of
space available for the title (which seems to be right justified
relative to the right edge of the grid).

I've tried tweaking some parameters in the past, but they had no effect
that I could tell.

Perhaps related to that, my previous attempts to use abline to produce a
45 degree angle always produced a flat straight line.

There are also a bunch of other tweaks I want to make to get output
presentation ready.  Is it time to try ggplot2?  I found I could get
results very quickly with ggplot, but am not sure how much control it
gives me over the finer details.

Thanks.
-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] making a grid of points

2006-12-07 Thread Ross Boylan
I'd like to evaluate a function at each point on a 2 or 3-D grid.  Is
there some function that already does this, or generates the grid of
points?

My search has led me to the grid and lattice packages, and I found a
reference to the sp package (e.g., SpatialGrid) for this.  There are
things in there that might be relevant, but at first blush many of them
are embedded in other concepts (grobs, shingles, rugs) and don't
obviously solve the problem.

I know this is not a hard thing to program, but I suspect someone has
already done it.  Any pointers?

Thanks.
-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] making a grid of points

2006-12-07 Thread Ross Boylan
On Fri, 2006-12-08 at 08:09 +1300, Peter Alspach wrote:
 Ross
 
 I think you want
 
 ?expand.grid
 
 BTW, help.search('grid') finds this.
 
 Cheers ..
 
 Peter Alspach
 
I can't believe I missed that--my eye just jumped to all the stuff in
the grid package.  Thank you.
 
  -Original Message-
  From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED] On Behalf Of Ross Boylan
  Sent: Friday, 8 December 2006 8:03 a.m.
  To: r-help
  Subject: [R] making a grid of points
 
  I'd like to evaluate a function at each point on a 2 or 3-D
  grid.  Is there some function that already does this, or
  generates the grid of points?
 
  My search has led me to the grid and lattice packages, and I
  found a reference to the sp package (e.g., SpatialGrid) for
  this.  There are things in there that might be relevant, but
  at first blush many of them are embedded in other concepts
  (grobs, shingles, rugs) and don't obviously solve the problem.
 
  I know this is not a hard thing to program, but I suspect
  someone has already done it.  Any pointers?
 
  Thanks.
  --
  Ross Boylan  wk:  (415) 514-8146
  185 Berry St #5700   [EMAIL PROTECTED]
  Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
  University of California, San Francisco
  San Francisco, CA 94107-1739 hm:  (415) 550-1062
 
  __
  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.
 
 
 __
 
 The contents of this e-mail are privileged and/or confidential to the
 named recipient and are not to be used by any other person and/or
 organisation. If you have received this e-mail in error, please notify
 the sender and delete all material pertaining to this e-mail.
 __
-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] Dictionaries with integer indices

2006-02-13 Thread Ross Boylan
Some past threads have pointed out that lists can be used as
dictionaries storing data with an associated key (environments do this
too).

I have the seemingly simpler case with integer values for the
indices--however, the integers are not necessarily contiguous low
numbers.  My concern is that if id is 3000 then
d - list()
d[[id]] - some data

and later retrieval with
d[[id]]
is going to be wasteful (e.g., produce something with 3000 elements).

I could turn id into a string, but that seems pretty indirect.

Is there any problem with the naive scheme outlined above?  If so,
what's a good way around it?
-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] Turning control back over to the terminal

2006-02-13 Thread Ross Boylan
I'm invoking R from withing a shell script like this
R --no-save --no-restore --gui=none  `hostname`  21 BYE
# various commands here
BYE

I would like to regain control from the invoking terminal at some point.
I tried source(stdin()) but got a syntax error, presumably stdin is the
little shell here snippet (the part between BYE
and BYE).

Is there some way to accomplish this?  I am trying to regain control
inside an R session that has been launched inside an MPI environment
(and I'm usually running inside emacs).  This is on a Mac OS X cluster.

I suppose there might be a way to do this with expect, but I'm hoping
for something simpler.  Potentially, I could make the script itself act
differently on the head node (the only one I want to debug right now),
including changing the redirection there.


-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] Customizing the package build process

2005-11-23 Thread Ross Boylan
On Wed, 2005-11-23 at 10:49 +0100, Uwe Ligges wrote:
 Ross Boylan wrote:

  P.S. Previous list postings advised that R CMD install was a better way
  to produce binaries than R CMD build --binary.  The former command
  doesn't seem to have any options for making binaries; has that facility
  been removed?
 
 No, you can use:
 
 R CMD INSTALL --build
 
 
 Uwe Ligges
I was looking at R CMD install --help.  I didn't realize the upper lower
case versions of install differed.  That's a little confusing.

__
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] Customizing the package build process

2005-11-22 Thread Ross Boylan
I've made a package for which R CMD build isn't producing very
satisfactory results.  I'll get to the details in a moment.

I wonder if it would make sense to have my own makefiles (which already
exist and are doing quite a lot) produce the .tar.gz file ordinarily
produced by R CMD build.  As far as I can tell, R CMD build basically
tars up of the project directory after running some checks.  I could run
R CMD check separately.

There are two main problems with the results of R CMD build.  First, it
has lots of files that I don't want included (the input files used to
generate configure, miscellaneous garbage, other stuff not suitable for
distribution).  Second, I have data files as both data.gz and data.
R puts data into the .tar.gz file and sensibly ignores the .gz file.
Unfortunately, my makefiles assume the existence of the data.gz files,
and so may have trouble after the .tar.gz is unpacked and there are no
data.gz files.

My bias would ordinarily be to piggy back on the R build system as much
as possible.  In principle, this could get me extra features (binary
builds, MS Windows builds) and it would track the things R build does
beyond tarring files.  But in this case using the R build system seems
quite ugly.  I could in principle use .Rbuildignore, probably generated
dynamically, to exclude files.  That doesn't solve the 2nd problem
(data.gz becomes data).

So does the alternative of doing the tar'ing myself make sense?

Is there another option that could hook into the R CMD build process
more deeply than the use of .Rbuildignore?

I suppose another option would be to do a clean checkout of the sources
for my package, run a special makefile target that would create the
necessary files and delete all unwanted files, and then do a regular R
CMD build.  This might still have trouble with data.gz.

P.S. Previous list postings advised that R CMD install was a better way
to produce binaries than R CMD build --binary.  The former command
doesn't seem to have any options for making binaries; has that facility
been removed?

Second question: my reading is that .Rbuildignore is only read in the
package root directory, and will have no effect below that.  Is that
correct?  Per directory .Rbuildignore's would be convenient..

-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] Makevars

2005-11-17 Thread Ross Boylan
Is it safe to make any assumptions about how Makevars is used?

In particular, I want to include some conditional material, and wonder
if the GNU make conditional commands would work (at least for those
building with GNU make).  Does Makevars get included in the Makefile?
Does it get treated as a shell script?  Something else?

Is there any kind of assumption I can make portably?

I realize I could generate the file from a configure script, but I'd
like to avoid doing special purpose code that this case would require.

Thanks.
-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] Apparent problem with \eqn

2005-11-15 Thread Ross Boylan
  \eqn{{\bf\beta}_j}{b(j)} in my .Rd file produces this error

! Missing $ inserted.
inserted text 
$
l.7 \eqn{{\bf\beta}_j}{\bf\beta}_
 jnormal-bracket5bracket-normal{b(j)}
--
! Missing $ inserted.
inserted text 
$
l.16 
 
--
! Missing } inserted.
inserted text 
}
l.16 
 
--
! Extra }, or forgotten \endgroup.
\par ...m [EMAIL PROTECTED] {\@@par }\fi \else {\@@par }
  \fi 
l.16 
---
Is this a bug, or am I missing something?  Note that \bf\beta seems to
have been doubled.

Currently on R 2.2.0.final-4 on Debian.  I think I've seen this with
many prior versions too.
 
-- 
Ross Boylan  wk:  (415) 514-8146
185 Berry St #5700   [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739 hm:  (415) 550-1062

__
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] Use of contains in S4 classes

2005-08-19 Thread Ross Boylan
On Thu, 2005-08-18 at 17:30 -0500, Paul Roebuck wrote:
 On Thu, 18 Aug 2005, Ross Boylan wrote:
 
  setClass(B, representation=representation(B, extra=numeric))
  setClass(B, representation=representation(extra=numeric),
  contains=B)
  Are these the same?  If not, how do they differ?
 
  What about
  setClass(B, representation=representation(B, extra=numeric),
  contains=B)
  ?
 
  As far as I can tell, the Green Book doesn't talk about a contains
  argument to setClass.
 
 S4 - Composition and Inheritance by Witold Eryk Wolski
 (a.k.a. Extending.pdf) might be what you're looking for.

Thank you.  It speaks directly to this question, and asserts that the
first two forms are equivalent.  contains makes it a bit easier for the
eye to catch that inheritance is happening.

__
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] problem with repeated formal arguments and ...

2005-08-18 Thread Ross Boylan
I want to add an argument if it is not present.  Following the Green
Book, p. 337:
test - function(x, ...){
  dots - list(...)
  if (!hasArg(from))
from - 0
  else
from - dots$from
  curve(x, from=from, ...)
}

 test(sin)
 test(sin, from=4)
Error in curve(x, from = from, ...) : formal argument from matched by
multiple actual arguments

The FAQ says, in the section on differences between R and S,
R disallows repeated formal arguments in function calls.

That seems a perfectly reasonable rule,  but how do I handle this
situation?

-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
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] Use of contains in S4 classes

2005-08-18 Thread Ross Boylan
setClass(B, representation=representation(B, extra=numeric))
setClass(B, representation=representation(extra=numeric),
contains=B)
Are these the same?  If not, how do they differ?

What about
setClass(B, representation=representation(B, extra=numeric),
contains=B)
?

As far as I can tell, the Green Book doesn't talk about a contains
argument to setClass.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
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] Use of contains in S4 classes

2005-08-18 Thread Ross Boylan
Oops, the second class should have been A in the examples.  Corrected
version:

setClass(B, representation=representation(A, extra=numeric))
setClass(B, representation=representation(extra=numeric),
contains=A)
Are these the same?  If not, how do they differ?

What about
setClass(B, representation=representation(A, extra=numeric),
contains=A)
?

As far as I can tell, the Green Book doesn't talk about a contains
argument to setClass.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
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 change the value of a class slot

2005-06-09 Thread Ross Boylan
On Wed, 2005-06-08 at 14:15 +0200, Thomas Petzoldt wrote:
...
 Hello Ross,
 
 I see that your question was related to S4, but I just noticed a
 solution based on the R.oo package so I thought I would add a solution
 based on the proto package too. We had similar problems several times
 ago and (to my surprise) found R to be an extremely flexible language
 even for these things. Our favorite solution is available as
 package(proto). It requires R 2.1, because of several subtle
 improvements regarding environments, which made our implementation more
 streamlined.
 
 Does the following example do what you intended?

Certainly looks like it.  It seems R has an embarrassment of object
systems.  R.oo, which someone else mentioned, also has the semantics I
was thinking of.  There's an interesting paper here
http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Proceedings/Bengtsson.pdf
which contrasts what I was looking for, which it calls
class-object-oriented programming (COOP) with what R does, which it
calls functional-object-oriented programming (FOOP).

The paper also notes that call-by-value vs call-by-reference, which is
the root of the slot update problem, is really orthogonal to the
FOOP/COOP distinction.  It's easy to imagine FOOP with
call-by-reference.  R.oo uses references.

That paper also mentions that Omegahat has on OOP package, which
apparently is similar in spirit to R.oo while taking a more low-level
approach to the implementation.

Ross

 
 ##=
 library(proto)
 
 ## 1) define an object
 CompletePathMaker - proto(
   index = 0,
   bumpIndex = function(., dindex = 1)
 .$index - .$index + as.integer(dindex)
 )
 
 ## 2) create a child object of CompletePathMaker
 cpm - CompletePathMaker$proto()
 
 ## 3) set the index component to 3
 cpm$index - 3
 
 ## 4) iterate the index
 cpm$bumpIndex(2)
 
 ## print the result
 cpm$index
 
 ##=

__
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 change the value of a class slot

2005-06-09 Thread Ross Boylan
On Wed, 2005-06-08 at 09:13 +0200, Uwe Ligges wrote:
[extensive deletions.  Discussion concerned my desire to have a function change 
the value
 of an object in a way that had effects outside of the function, without 
returning the object.]

 You have to think about scoping rules and it 
 will be clear that the approach you are expecting is not a clean one in S.
  
  Could you say a bit more about that?  
 
 I meant the following simple example (not related to any object oriented 
 programming from the S point of view, but maybe well from your point of 
 view?):
 
 Say you want a function foo() that simply incements the argument:
 
 a - 1
 foo(a)
 a # now is 2
 
 But what happens if there is (more than) one a (in different 
 environments), but no a in the environment foo(a) is called from. 
 Which a do you want to change in this case? Seems to be rather dangerous.
 
 Uwe Ligges
 
I believe your example assumes that foo is updating the outer a by
cheating and directly modifying enclosing environments.  (I figure it
also needs to get the name of its actual argument to do this, which
would also involve slightly dirty tricks.) This does seem to be the only
way to do it in standard R.

In contrast, I wanted something like
foo-function(formalArg){ 
  formalArg - new value
  return something  else
}
so that if I call foo(a), a has the new value after the call.
Unfortunately for me, that doesn't work.  Call-by-value semantics imply
that it can't.

__
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 change the value of a class slot

2005-06-07 Thread Ross Boylan
On Mon, 2005-06-06 at 14:15 -0700, Berton Gunter wrote:
 I'm puzzled:
 
  It looks as if instances of class objects are best thought of as
  immutable once created.
  
 
 what then is setReplaceMethod() for? 
assignment operators do the whole object replacement behind the scenes,
at least conceptually, as far as I can tell.  I agree: they are
mutators.  But outside of this special case, it seems mutation of slots
is difficult (i.e., requires the assistance of the caller).

By the way, the documentation on setReplaceMethod does not actually say
what it does.  I found out by looking at the code.

Second, in my experiments I couldn't get setReplacementMethod to work:

bumpIndex- - function(pm, value) {
  [EMAIL PROTECTED] - [EMAIL PROTECTED](value)
  pm
}

# I get an error without the next function definition
bumpIndex - function(pm) [EMAIL PROTECTED]

setReplaceMethod(bumpIndex,
 signature=signature(pm=CompletePathMaker,
   value=numeric), bumpIndex) 

When I try to load this, I get
arguments in definition changed from (spec) to (object)
arguments in definition changed from (self) to (object)
arguments in definition changed from (self) to (object)
Creating a new generic function for 'bumpIndex-' in '.GlobalEnv'
Error in conformMethod(signature, mnames, fnames, f) : 
In method for function bumpIndex-: formal arguments omitted in the
method definition cannot be in the signature (value = numeric)

All the errors are triggered by setReplaceMethod.  Can anyone help me
interpret them?  Or, maybe better, tell me how to debug the
compilation?


 I leave it to language experts to say whether S4 formal classes and
 methods are wise or not in comparison to others. From my fairly ignorant
 perspective, that always seems to be a matter of taste.

There are actually two related issues on that score: first, whether the
complex of expectation set up by talking about objects and classes
are met by what R/S does, and second the wisdom of what R/S does in its
own right.

 
 Cheers,
 Bert
 
 
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
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 change the value of a class slot

2005-06-07 Thread Ross Boylan
On Tue, 2005-06-07 at 08:36 +0200, Uwe Ligges wrote:
 Ross Boylan wrote:
 
  On Sat, Jun 04, 2005 at 07:08:56PM +0200, Martin Maechler wrote:
  
 Ross nextPath - function(pm){ #pm is a CompletePathMaker
 Ross[EMAIL PROTECTED] - [EMAIL PROTECTED](1)
 Ross [etc]
 
 If your nextPath   function has  'pm' as its last statement it
 will return the updated object, and if you call it
 as
 mypm - nextPath(mypm)
 
 you are
 1) updating  mypm
 2) in a proper S way (i.e. no cheating).
 
 Regards,
 Martin
  
  
  Wow.  This is almost the exact inverse of the usual object behavior,
  in which only the class itself can update the slots (aka instance
  variables).  None of the methods of the class can update instances of
  the class persistently without the help of outsiders, and only
  outsiders can change the slot values.
  
  (Yes, I realize that using the idiom you suggest of returning a new
  object one can have only class methods actually fiddling with the
  slots.)
  
  The inability of a class method to change a class object without
  outside help seems unfortunate.
  
  It looks as if instances of class objects are best thought of as
  immutable once created.
 
 Obviously, there are many definition of object oriented programming, 
 and yours seems to be different from the S4 definition.
Yes. And though there are many definitions of object oriented (at
least, many implementations),  I'd say the minimum requirement to be
object oriented is to have objects that encapsulate both state (instance
variables/slots) and behavior (methods).

S4 objects do not fully encapsulate state because they require outside
assistance to alter the state of the object (with the exception of
assignment operators).  The smalltalker in me also gets nervous that
code outside the class can access the slots, but there are many object
systems that act that way.

The way in which names of methods of unrelated classes interfere with
each other seems a break-down of the encapsulation of behavior, though
the problem strictly is not with the behavior but just with the name.
To return to the concrete problem that got me started, if class
Specification defines a method likelihood taking as arguments instances
of class Specification, Path and Parameters, then it is awkward to
define a method likelihood for the class Model when that method has
arguments of class Model, Specification, data.frame, and vector,
particularly if different names for the formal arguments are desired.
(I think technically it could be done, but only in a very ugly
way--i.e., better to use different method names for the two classes).

 
 I was going to answer your first question at first, but you have not 
 given enough details - in particular it was not clear to me why your 
 approach did not work. 
 I assumed that you are assigning the new object 
 again, which is the S way. 
I wasn't, which is why it didn't work.  I wanted the function to return
some other value than the object it was operating on.
 You have to think about scoping rules and it 
 will be clear that the approach you are expecting is not a clean one in S.
Could you say a bit more about that?  I had thought of the issue more in
terms of function calls in S being call by value, preventing updates to
the original arguments.  So the issue isn't so much the scope of the
names of function arguments (that scope being limited to the function
body), but the properties of the thing they refer to (conceptually, a
copy of the argument, not the original).

__
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] fun with S4 method recursion

2005-06-07 Thread Ross Boylan
Apparently using an existing function as the definition for a method is
a no-no (at least as I'm doing it), producing infinite recursion.
setClass(A,
 representation(model=ANY)
 )
fiddle - function(self) {
  1
}

setMethod(fiddle,
  signature(self=A),
  definition = fiddle  ### problem
  )

setClass(B,
 representation(err=ANY),
 contains=A
 )

setMethod(fiddle,
  signature(self=B),
  definition = function(self){
callNextMethod()
2
  })

b - new(B, model=4, err=5)
fiddle(b)

produces
Error: protect(): protection stack overflow

On the other hand, if the line marked ### problem becomes
definition = function(self) 1
everything works OK.

I think the definition of the generic is ending up as the method for A.
This surprised me, because I thought this was the standard way to
approach setting up a method (Any ordinary function can be converted
into a generic by simply setting a method for it; ... the initial,
unique method (the body of the function) becomes the default method pp.
322-323; a generic function is created automatically by specifying a
method for any existing function.  This is by far the more common
situation p 348--all pages in the green book).  It also surprised me
because of the note that setMethod makes a local copy of the function
given as the definition argument (bottom of p. 323).

Does the behavior of R differ from that described in the green book when
the name of a function appears in the definition argument of setMethod?
If not, what have I misunderstood?

Aside: my first real attempt didn't have 
fiddle - function(self) {1}
using just 
setMethod(fiddle, A, function(self) 1)
That produces no existing definition for function 'fiddle'


Given all this, would this be a better model?
fiddle - function(... # definition for A
# do NOT setMethod for class A signature
setMethod(fiddle, B, function(self) #operations for B
So when I do the setMethod my original fiddle becomes the default
generic.

Thanks.
Ross

__
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] Two ways to inherit in S4?

2005-06-07 Thread Ross Boylan
I'm puzzled that it seems possible to specify inheritance via the
representation and contains arguments to setClass.  The examples
that I've seen all seem to use contains only.

Is there some subtle distinction between these two approaches?
Originally I thought one had to repeat the same information in both
places, but that seems not to be the case.

Sorry about all these questions.
Ross

__
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 change the value of a class slot [INFO]

2005-06-07 Thread Ross Boylan
On Tue, 2005-06-07 at 13:49 -0700, Berton Gunter wrote:
  Second, in my experiments I couldn't get setReplacementMethod to work:
  
  bumpIndex- - function(pm, value) {
[EMAIL PROTECTED] - [EMAIL PROTECTED](value)
pm
  }
  
  # I get an error without the next function definition
  bumpIndex - function(pm) [EMAIL PROTECTED]
  
  setReplaceMethod(bumpIndex,
   signature=signature(pm=CompletePathMaker,
 value=numeric), bumpIndex) 
  
...
 
  When I try to load this, I get
  arguments in definition changed from (spec) to (object)
  arguments in definition changed from (self) to (object)
  arguments in definition changed from (self) to (object)
  Creating a new generic function for 'bumpIndex-' in '.GlobalEnv'
  Error in conformMethod(signature, mnames, fnames, f) : 
  In method for function bumpIndex-: formal arguments 
  omitted in the
  method definition cannot be in the signature (value = numeric)
  
With some help from Bert, partly offlist, here's a working version:
setReplaceMethod(bumpIndex,
 signature=signature(pm=CompletePathMaker,
   value=numeric), function(pm, value) {
 [EMAIL PROTECTED] - [EMAIL PROTECTED](value)
 pm
   })
At least 2 problems were caused by my original, final argument of
bumpIndex to setReplaceMethod:
1) This looked for the function bumpIndex, not bumpIndex-.  That's why
I had to define the bumpIndex function.  With the above change, it is no
longer necessary to define bumpIndex.  I needed to point it to
bumpIndex-.  I've been unable to find how to quote that properly.

2) The bumpIndex function doesn't have the right arguments.

By the way, the use of value as the name for the final argument to the
assignment function is mandatory.

The info about value, as well as an extensive discussion of issues with
mutating objects, appear in this 2003 tutorial by Gentleman:
http://www.stat.auckland.ac.nz/S-Workshop/Gentleman/S4Objects.pdf
(thanks to Bert for the pointer).

Ross

__
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 change the value of a class slot

2005-06-06 Thread Ross Boylan
On Sat, Jun 04, 2005 at 07:08:56PM +0200, Martin Maechler wrote:
 Ross nextPath - function(pm){ #pm is a CompletePathMaker
 Ross[EMAIL PROTECTED] - [EMAIL PROTECTED](1)
 Ross [etc]
 
 If your nextPath   function has  'pm' as its last statement it
 will return the updated object, and if you call it
 as
   mypm - nextPath(mypm)
 
 you are
 1) updating  mypm
 2) in a proper S way (i.e. no cheating).
 
 Regards,
 Martin

Wow.  This is almost the exact inverse of the usual object behavior,
in which only the class itself can update the slots (aka instance
variables).  None of the methods of the class can update instances of
the class persistently without the help of outsiders, and only
outsiders can change the slot values.

(Yes, I realize that using the idiom you suggest of returning a new
object one can have only class methods actually fiddling with the
slots.)

The inability of a class method to change a class object without
outside help seems unfortunate.

It looks as if instances of class objects are best thought of as
immutable once created.

Ross

__
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 change the value of a class slot

2005-06-03 Thread Ross Boylan
I defined an S4 class with a slot i.  Then I wrote a regular function
that attempted to increment i.

This didn't work, apparently because of the general rule that a function
can't change the values of its arguments outside the function.  I gather
there are ways around it, but the Green book admonishes cheating on the
S evaluation model is to be avoided (p. 190).

Thinking that class methods needed to an exception to this rule, I then
tried setMethod with the function I had written.  However, when I called
the function I got
 setMethod(nextPath, CompletePathMaker, nextPath)
Creating a new generic function for 'nextPath' in '.GlobalEnv'
[1] nextPath
 nextPath(pm)
Error: protect(): protection stack overflow

I can change the value of the slot interactively, so the problem does
not appear to be that the slots are considered off-limits.

What do I need to do to update slot values?

Here are some possibly relevant code fragments
setClass(CompletePathMaker,
 representation(i=integer,
timeOffset=numeric, # to avoid 0's
truePaths=TruePaths)
 )
nextPath - function(pm){ #pm is a CompletePathMaker
  [EMAIL PROTECTED] - [EMAIL PROTECTED](1)
[etc]

I'm trying to make the class behave like an iterator, with i keeping
track of its location.  I'm sure there are more R'ish ways to go, but
I'm also pretty sure I'm going to want to be able to update slots.

Thanks.
Ross Boylan

__
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] Too generic with S4 methods?

2005-06-02 Thread Ross Boylan
I tried the following (relevant excerpt only)
setMethod(likelihood,
   signature(spec=Specification, covs=vector,
 states=vector),
  function(spec, covs, states) {

setMethod(likelihood,
   signature(model=Model, path=matrix),
   function(model, path) {

This fails with the message
arguments in definition changed from (spec) to (object)
Error in match.call(fun, fcall) : unused argument(s) (model ...)

I'll note in passing that it would be helpful to have a line number for
the error, and  that the error didn't mean much to me.

After study, my guess is that generics are not supposed to work this
way.  All the definitions need to have the same named arguments
(exceptions: some can be missing, and ... is allowed).  So the error
above is a complaint that my second signature uses different names (or
is it different classes?).  And the unused argument is triggered by
the fact that the original signature had 3 args named spec, covs, and
states, and the new signature has none of them.  Is that about right?

It looks as if I might get away by not naming the arguments, so the
first signature could be signature(Specification, vector, vector)
and the 2nd signature(Model, matrix, missing).

Among other problems, the lack of identifiers makes the semantics of the
signature obscure in this case.

Basically, would it be advisable to use different generic names for the
two functions listed above?
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
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] Re: S4 method inheritance

2005-05-24 Thread Ross Boylan
On Tue, May 24, 2005 at 07:07:07AM -0400, Duncan Murdoch wrote:
 Ross Boylan wrote:
 On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:
 
 
 
 Finally, I'm a bit concerned that one article mentioned that S4
 inheritance, in practice, is used mostly for data, not methods (Thomas
 Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
 shouldn't travel?
 
 
 Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
 A), how does B's method foo invoke A's foo?
 
 Your question doesn't make sense in S4.  In S4, classes don't have 
 methods, generics have methods.  There's no such thing as B's method 
 or A's method.
Oops, I keep taking the references to objects too literally.  Thanks.
 
 You might get what you want with foo(as(bObject, A)) if bObject is an 
 instance of class B.
 
 The question assumes that A's foo was defined as an in place function,
 so there's no (obvious) named object for it, i.e,
 setMethod(A, signature(blah=numeric), function(x) something)
There's my confusion: the first argument should be the name of the
generic, not the class.
 
 I don't know what you mean by in place function, but I hope my answer 
 helps anyway.

Just for clarification, in place function was in contrast to a
function defined elsewhere with an explicit name, e.g.,
   fforA-function(x) something
   setMethod(foo, signature(blah=numeric), fforA)
In that case I could just refer to fforA directly. (Trying to avoid
the S3ish f.A).

Is sounds as if the use of as() or callNextMethod() will get me what I
want.  And the docs seem clear that callNextMethod() returns control
(and a value) to the calling function.

Thanks to everyone for their help.

__
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] Re: S4 method inheritance

2005-05-24 Thread Ross Boylan
On Tue, May 24, 2005 at 06:27:56AM -0700, Robert Gentleman wrote:
 
 
 Duncan Murdoch wrote:
 Ross Boylan wrote:
 
 On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:
 
 
 
 Finally, I'm a bit concerned that one article mentioned that S4
 inheritance, in practice, is used mostly for data, not methods (Thomas
 Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
 shouldn't travel?
 
 
 Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
 A), how does B's method foo invoke A's foo?
 
 
 Your question doesn't make sense in S4.  In S4, classes don't have 
 methods, generics have methods.  There's no such thing as B's method 
 or A's method.
 
 You might get what you want with foo(as(bObject, A)) if bObject is an 
 instance of class B.
 
 The question assumes that A's foo was defined as an in place function,
 so there's no (obvious) named object for it, i.e,
 setMethod(A, signature(blah=numeric), function(x) something)
 
 
 In general it may be best to think of a generic function as a 
 dispatching mechanism. For S4 methods are associated with a specific 
 generic function. 
specific generic is a reference to the ability to define generics
 within the context of a particular package?
 A generic knows about all methods that are associated 
 with it, and about no others. 
Presumably setMethod does the association.  Is the where argument
intended to identify which generic method to pick?  The fact that
there is not a package argument to setMethod, as there is to
setGeneric, is a little confusing to me.

 Thus in S4, the little tiff over who owns 
 label goes away - they both do - different packages can define
 generic 
They is two different packages?  Or is this a reference to my
original confusion about class vs generic ownership of a method?

 functions for label, or anything else they care to, and users can write 
 methods for specific generic functions and associate them with a 
 generic.
...
  HTH
Robert

__
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] Documentation of S3 and S4 classes, inheritance

2005-05-23 Thread Ross Boylan
I'd like to have a class A that computes a likelihood, and a subclass B
that computes the same likelihood by sometimes throws in an additional
term (B includes measurement error).

So B's likelihood needs to call A's, and then (sometimes) multiply by an
additional term.

It sounds as if, in the S3 scheme, NextMethod is supposed to do this:

like.A - function(stuff) compute value
like.B - function(stuff) extraFactor*NextMethod()
?

but, after some study of both the Language Manual (2.1) and the online
help of NextMethod I can't tell exactly what it does.  In particular,
I'm not sure if it returns to the calling function, or how it decides
which flavor to call.  The language manual says the method choice
depends on the values of .Generic and .Class, but doesn't say how those
get filled in.  I would expect .Class to be the current class, in which
case the call is recursive.  The online help says 'NextMethod' invokes
the next method (determined by the class) but it doesn't say how it is
determined.  One ambiguity is whether class refers to the class (B) or
the class attribute (B, A).

I think the documentation could be clearer.

Now, probably none of this matters to me, since several sources
(including the online help for S3)indicate that S4 classes are
preferred.

I found the documentation for S4 initially elusive.  As far as I can
tell, it isn't even mentioned in the R Language Definition.  While the
fact that S4 is defined in a package makes clear it is not formally part
of the base language, this is not a very good way to get people to use
S4.

I think by now I've tracked down docs on S4, including the
intro/overview at http://www.omegahat.org/RSMethods/.

Finally, I'm a bit concerned that one article mentioned that S4
inheritance, in practice, is used mostly for data, not methods (Thomas
Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
shouldn't travel?

-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
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: SV: [R] Documentation of S3 and S4 classes, inheritance

2005-05-23 Thread Ross Boylan
On Tue, 2005-05-24 at 00:31 +0200, Søren Højsgaard wrote:
 One of the things that S3 is lacking is clearly multiple inheritance,
I thought if you wanted C to inherit from A and B you could, in S3,
just   
   class(aCObject)- c('C', 'A', 'B')
While the ordering is arbitrary, that's usually the case with multiple
inheritance.

__
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] Re: S4 method inheritance

2005-05-23 Thread Ross Boylan
On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:


 Finally, I'm a bit concerned that one article mentioned that S4
 inheritance, in practice, is used mostly for data, not methods (Thomas
 Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
 shouldn't travel?
 
Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
A), how does B's method foo invoke A's foo?

The question assumes that A's foo was defined as an in place function,
so there's no (obvious) named object for it, i.e,
setMethod(A, signature(blah=numeric), function(x) something)

__
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] Re: main() in libR? only in 1.9

2004-12-19 Thread Ross Boylan
On Wed, 2004-12-15 at 12:05, Ross Boylan wrote:
 libR seems to include a main() function.  Should it?
I think I've tracked this down, and it seems to be specific to R 1.9. 
The 2.0 libR does not include main.

I believe main is present in 1.9 because the link line for libR includes
a reference to ../unix/*.lo.  One of those file is the object for
system.c, which includes main.

On reviewing Writing R Extensions for 1.9.1, I note there is no
reference in it to an independent programming calling libR.

I saw this with 1.9.1 on Debian and Mac OS X.

__
[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] main() in libR?

2004-12-15 Thread Ross Boylan
libR seems to include a main() function.  Should it?

I'm hoping this simpler question will get more of a response than my
previous post about R a la carte :)

The evidence that libR includes main() is two-fold.  First, when I use
nm, I see the _main defined.  Second, when I run a program linked to
libR, the main R shell takes over, even though I have my own main (in
another library).

Looking at the sources, it seems the only possible contributor of
main() is src/main/Rmain.c.  I wouldn't expect this in the library,
and the documentation of the library (in R Extensions) says you must
supply your own main.

I have tried to follow through the Makefile's, but the spot the
library is built has not jumped out at me.

I've encountered this with number of generations of R on a number of
platforms (Debian Linux and OS X).

Thanks.

__
[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] Re: Calling R a la carte?

2004-12-09 Thread Ross Boylan
On Thu, 2004-12-09 at 13:15, Ross Boylan wrote:
 I have written an R package, mostly implemented in C++. It works.
 I want to do unit tests of the C++ code, as well as higher level tests
 from R.  I use the boost test framework for this, part of which is a
 library which wants to be the thing that starts everything running
 (i.e., main).
 
 My code has a few invocations of R functions--just error at the moment,
 I think.  The list might grow.  So I linked the test program with the R
 library.
To clarify, the R functions I am calling are C functions, not higher
level ones.

__
[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] Is nesting {} inside \eqn OK?

2004-11-09 Thread Ross Boylan
I'm seeing various things fail when I try to next braces inside \eqn.
This source
  \eqn{{\bf\beta}_j}{b(j)} is the vector
produces this error
--
[4]
! Missing $ inserted.
inserted text 
$
l.258 \eqn{{\bf\beta}_j}{\bf\beta}_
   j{{b(j)} is the vector of
coefficients fo...
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! Missing } inserted.
inserted text 
}
l.258 ...tor of coefficients for outcome \eqn{j}{}
   and
I've inserted something that you may have forgotten.
---

Notice that the argument seems to have been doubled.
I tried using \begingroup and \endgroup, and ran into problem with a
later \eqn with nested braces.

For reference, particularly in case I've missed something earlier, here
is a fuller excerpt from the input file:

  With \eqn{J} possible outcomes and \eqn{p_j}{p(j)} the probability of
  the \eqn{j}'th outcome,
  the formula is \deqn{\newcommand{\B}{{\bf \beta}}\newcommand{\X}{{\bf
X}}
p_j = \frac{e^{\X\B_j}}{\displaystyle\sum_{k=0}^J e^{\X\B_k}}.}{
p(j) = exp[X*b(j)]/sum{exp[X*b(k)], k=0 to J}.}
  \eqn{{\bf\beta}_j}{b(j)} is the vector of coefficients for outcome
\eqn{j} and
  \eqn{{\bf X}}{X} are the covariates.



By the way, the \newcommand is not global, so I can't use \B (for
example) in later \eqn's.

Using R 2.0.0.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
[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] R check passes code and docs that don't match

2004-11-05 Thread Ross Boylan
I have code and documentation that don't match, but R CMD check didn't
flag it.

in mspath.R
mspath - function(formula,   # formula with  observed Markov states  
~  observation times (required)
qmatrix,# matrix of 1s and 0s with indices of
allowed transitions (diagonal is ignored) (required)
misc = FALSE,
ematrix = NULL,# matrix of 1s and 0s with indices of
allowed misclassfications (diagonal is ignored) (required)
inits,  # initial values of optimisation or fixed
values (required)
subject = NULL, # optional, defaults to all the same if
not given
covariates = NULL, # formula specifying covariates on
transition rates.
constraint = NULL, # which intensities have covariates
on them (as in Marshall et al.)
misccovariates = NULL, # formula specifying covariates
on misclassification probs
miscconstraint = NULL, # which misc probs have
covariates on them
qconstraint = NULL, # constraints on equality of
baseline intensities
econstraint = NULL, # constraints on equality of
baseline misc probs
covmatch = previous,   # take the covariate value from
the previous or next observation
initprobs = NULL,  # initial state occupancy
probabilities
data=list(),   # optional data frame in which to
interpret variable names
fromto = FALSE,
fromstate, #
tostate,   #  data required if fromto is TRUE
timelag,   #
death = FALSE,  # 'death' states, ie, entry time known
exactly, but unknown transient state at previous instant
tunit = 1.0, # no longer used
exacttimes = FALSE,
fixedpars = NULL, # specify which parameters to fix
stepnumerator = 1,  # maximum step size in discrete
approximation
stepdenominator = 1,  # rational number; use integers
do.what = 1, # 1 for likelihood, 0 for counts
... # options to optim
)

in mspath.Rd
\usage{
mspath ( formula, qmatrix, misc = FALSE, ematrix, inits, subject,
  covariates = NULL, constraint = NULL, misccovariates = NULL,
  miscconstraint = NULL, qconstraint=NULL, econstraint=NULL,
  covmatch = previous, initprobs = NULL, 
  data = list(), fromto = FALSE, fromstate, tostate, timelag,
  death = FALSE, tunit = 1.0, exacttimes = FALSE,
  fixedpars = NULL, stepsize=1.0... )
}
with corresponding \item's in the \arguments list.

Among the differences (see the end of the argument lists)
In code by not Rd: stepnumerator, stepdenominator, do.what
In Rd but not code: stepsize

Yet R CMD check says
** help
  Building/Updating help pages for package 'mspath'
 Formats: text html latex example 
  mspathtexthtmllatex
 missing link(s):  qmatrix.mspath ematrix.mspath simmulti.mspath
print.mspath plot.mspath summary.mspath qmatrix.mspath pmatrix.mspath
sojourn.mspath
* DONE (mspath)

* checking package directory ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking package dependencies ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for syntax errors ... OK
* checking R files for library.dynam ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking Rd files ... OK
* checking for missing documentation entries ... WARNING
Undocumented code objects:
  MatrixExp absorbing.mspath coef.mspath crudeinits.mspath deltamethod
  ematrix.mspath expit expitsum expsum hazard.mspath lik.mspath logit
  mspath.check.consistency mspath.check.ematrix mspath.check.model
  mspath.check.qmatrix mspath.check.state mspath.check.times
  mspath.form.output mspath.process.covs mspath.results
  observed.mspath odds.mspath plot.mspath pmatrix.mspath
  pmatrix.piecewise.mspath prevalence.mspath print.mspath
  print.summary.mspath qematrix.diagse.formstr qematrix.diagse.mspath
  qematrix.mspath qmatrix.mspath qratio.mspath qratio.se.mspath
  sojourn.mspath statetable.mspath summary.mspath totlos.mspath
  transient.mspath viterbi.mspath
Undocumented data sets:
  e2 gold q2
All user-level objects in a package should have documentation entries.
See chapter 'Writing R documentation files' in manual 'Writing R
Extensions'.
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK

Have I misunderstood how this is suppsed to work?  Have the previous
errors confused or voided the code/documentation test?  Is it a bug?

Using R 2.0.0-3 on Debian.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology

Re: [R] R CMD check testing environment

2004-08-22 Thread Ross Boylan
On Sun, Aug 22, 2004 at 06:58:56PM +0200, Uwe Ligges wrote:
 Ross Boylan wrote:
 I can't tell from the docs  (Writing R Extensions 1.9.1) exactly what
 environment the tests, examples, and vignettes that R CMD check tries to
 run are in.
 
 In particular:
 1) how do I get the package loaded?
 2) how do I access data in the data/ directory?
 3) where is the material in the other directories?  (e.g., has inst/
 material been installed?  where?)
 
 Apparently (section 1.3) stuff in demo/ is not checked, which seems odd.
 
 By inspecting some other packages, it seems the answer to 1) is that the
 package is already loaded, so I don't need to say library(...).  In
 particular, I don't need to figure out what lib.loc is.
 
 I have some C code as part of the package, so that (well the .so file)
 needs to be loaded too.
 
 Yes. You don't need library() in the the help pages' exmaples, but you 
 need it in tests.
 

So what should I use for lib.loc?

 
 2) Others seem to just say data(..), but this doesn't work for me.
 I created the data with
 save(gold, e2, q2, file=mspath/data/inputs, compress=TRUE)
 and later renamed the file to inputs.RData.  (check didn't think the
 file counted without the extension).
 
 Indeed, the manuals tells us that saved images have to be called either
 *.RData (note the capitalization) or *.rda.
 
 
 I have tried to access it in my test script (under tests/) with both
 load and data (e.g., data(inputs), data(inputs.RData),
 data(inputs)).  I get
 
 data(inputs)
 
 Warning message: 
 Data set 'inputs' not found in: data(inputs) 
 
 Works for me as Mytests.R in Mypackage:
 
  library(Mypackage)
  data(MydataInMypackage)
  print(MydataInMypackage)

Is this with MydataInMyPackage in the same directory as Mytests.R, or
in data/.  I'm attempting the latter.

 
 For that matter, my assumed answer to 1) doesn't seem to be working out,
 because when I try to access one of my functions it tells me it can't
 find it.  The function name is the same as the package name.
 
 Perhaps the problem is I have inferred answers from \example{}, and the
 story for tests/ is different.
 
 Right, see above.
 
 
 Although I'm currently focussed on running a script in tests/, I'd like
 to know what the story is for \examples in documentation or vignettes.
 
 You won't need library() in the examples ...

And it's also unnecessary for vignettes?

 
 
 Thanks.
 
 P.S. Is there a typical way to produce the .Rout.save file used in
 tests/?  What I'm doing is a slightly awkward 2-step process.
 
 
 Running R CMD check once, looking whether the Rout looks fine (this 
 should be the step that takes most of the time, and R can't do it for 
 you), rename the file it, finished.
OK, that's what I was doing.
 
 
 Uwe Ligges

Thanks.

__
[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] Error messages and C

2004-08-20 Thread Ross Boylan
I am calling a C (C++ really) function via the .C interface.
Sometimes when things go wrong I want to return an error message.

1.  R provides C functions error and warning which look about right. 
But exactly how does this exit, and in particular what happens with
cleaning up, calling C++ destructors, and unwinding the stack?  Will I
get memory leaks?

2.  Before I discovered those functions, I looked at passing in a
character vector as an argument, char ** p in the C code.  Exactly how
do I use these things?  Am I supposed to allocate a string and stuff the
pointer in the function argument?  Or should I assume *p points to valid
space (how much?) and fill it in?

Thanks.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
[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] Error messages and C

2004-08-20 Thread Ross Boylan
On Fri, 2004-08-20 at 12:04, Thomas Lumley wrote:
 On Fri, 20 Aug 2004, Ross Boylan wrote:
 
  I am calling a C (C++ really) function via the .C interface.
  Sometimes when things go wrong I want to return an error message.
 
  1.  R provides C functions error and warning which look about right.
  But exactly how does this exit, and in particular what happens with
  cleaning up, calling C++ destructors, and unwinding the stack?  Will I
  get memory leaks?
 
 Memory handled by R will be reclaimed properly (ie R_alloc, but not
 Calloc). C++ destructors will not be called -- you have to do that
 yourself either before calling error() 
That's not hard in my case, so that's what I'm doing.
 or in subsequent cleanup code that
 you call from R (perhaps triggered by on.exit()).

That would be tricky, since the location of the objects to be destroyed
is only known inside my original function.  Of course, I could use
global variables...

 
 R does have a finalizer mechanism that you could use. I have never tried
 this but there are some notes at
 http://www.stat.uiowa.edu/~luke/R/references/weakfinex.html
 This allows C or R functions to be called by the garbage collector when an
 object is disposed of.  You can then put an object on the R heap so that
 when R tidies this object up it will call your C++ destructors.
 
The weak references cleaned up are R objects, and my stuff is mostly
non-R objects.  I see two possible ways to get this to work:
1) Create some kind of dummy R object with a finalizer that cleans up my
C++ objects.
2) Hook the C++ object creation facilities (via new) into R.
Either approach is complex, possibly not doable, and probably
inefficient.  Fortunately, I don't need this.
 
  2.  Before I discovered those functions, I looked at passing in a
  character vector as an argument, char ** p in the C code.  Exactly how
  do I use these things?  Am I supposed to allocate a string and stuff the
  pointer in the function argument?  Or should I assume *p points to valid
  space (how much?) and fill it in?
 
 If you think of p as a vector of strings (ie char *p[]) then it
 corresponds to whatever strings you passed in from R.  You can modify
 these in place, possibly making them shorter. So if you need 80 characters
 of error message, pass in a string of length at least 80.

If space permits, is this just an ordinary, C-style null terminated
string?  Or does R have some notion of the string length which is
unaffected by what I stuff in it?

 If you want to allocate more memory you need to do this through R (either
 R_alloc or the Rinternals functions).  Using malloc() and stuffing the
 result in, say, p[1], will cause a memory leak since you won't be able to
 find it and free it.
 
So if I overwrite p[0], for example, the R garbage collector will know
to clean up the old string that was pointed to from that location?

   -thomas

Thanks for the info.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
[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] R CMD check testing environment

2004-08-20 Thread Ross Boylan
I can't tell from the docs  (Writing R Extensions 1.9.1) exactly what
environment the tests, examples, and vignettes that R CMD check tries to
run are in.

In particular:
1) how do I get the package loaded?
2) how do I access data in the data/ directory?
3) where is the material in the other directories?  (e.g., has inst/
material been installed?  where?)

Apparently (section 1.3) stuff in demo/ is not checked, which seems odd.

By inspecting some other packages, it seems the answer to 1) is that the
package is already loaded, so I don't need to say library(...).  In
particular, I don't need to figure out what lib.loc is.

I have some C code as part of the package, so that (well the .so file)
needs to be loaded too.

2) Others seem to just say data(..), but this doesn't work for me.
I created the data with
save(gold, e2, q2, file=mspath/data/inputs, compress=TRUE)
and later renamed the file to inputs.RData.  (check didn't think the
file counted without the extension).

I have tried to access it in my test script (under tests/) with both
load and data (e.g., data(inputs), data(inputs.RData),
data(inputs)).  I get
 data(inputs)
Warning message: 
Data set 'inputs' not found in: data(inputs) 

For that matter, my assumed answer to 1) doesn't seem to be working out,
because when I try to access one of my functions it tells me it can't
find it.  The function name is the same as the package name.

Perhaps the problem is I have inferred answers from \example{}, and the
story for tests/ is different.

Although I'm currently focussed on running a script in tests/, I'd like
to know what the story is for \examples in documentation or vignettes.

Thanks.

P.S. Is there a typical way to produce the .Rout.save file used in
tests/?  What I'm doing is a slightly awkward 2-step process.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

__
[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] snow documentation comments

2004-03-24 Thread Ross Boylan
On Wed, 2004-03-24 at 08:03, Luke Tierney wrote:
 On Tue, 23 Mar 2004, Ross Boylan wrote:
 
  There are a few points I found unclear or unmentioned in the snow
  documentation (mostly I looked at the cluster.html web page).  I thought
  I'd mention them here.
  
  What is the start up environment for the children?
  --
  My best guess at the answer is in parentheses
  Do they inherit shell variables? (no)
  Do they inherit variables set in R or other aspects of the R
  environment? (no)
  What directory does it start in? (the directory you are running in)
  What user are you? (same as original)
  
  I realize some of these answers might depend on the parallelization
  layer you are using, or whether you select the homogenous option.
 
 They do
I've since realized they may also depend on the exact version of the
package used (e.g., newer lams apparently have the ability to export
environment variables) and the way it is invoked.

Personally, I'd even find a single sentence saying explicitly that it
depends clarifying.  It would probably also be good to discuss the
behavior of the socket-based communication, since that it supplied by
the snow package.  Information on the other interfaces would be nice
too, but probably hazardous to provide accurately.

I'll not for the record that my answers above are using Rmpi with
lam/mpi 6.5.8-2 on Debian, running just on my local computer.  And some
of the answers are speculative!
 
  Number of nodes or number of children?
  --
  I thought all the counts of nodes (e.g., in makeCluster(5)) were of the
  total nodes in the cluster, i.e., children + 1.  However, I did a
  makeCluster(2) and I got 2 additional R processes running.  Have I
  misunderstood the semantics, or is it essentially an implementation
  detail that the master node starts a new R process?
 
 makeCluster(2) creates a cluster of two processes that the master
 process uses.  So there are a total of three processes.
So work that is distributed via snow goes to the two processes only?

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


Re: [R] Status of Rmpi--Good with tweaks

2004-03-24 Thread Ross Boylan
I have some more good news and some questions.

On Tue, 2004-03-23 at 20:50, Hao Yu wrote:
 Sorry. I have not been able to update Rmpi since the version
 0.4-4 on R site. 
I don't think any version of Rmpi is on the R site at the moment.

Minor aside: Also, it would be nice if the packages starting with R
were consistent about whether it's R or r.  Rmpi but rpvm is a
little dissonant.  Unfortunately, there seems to be no agreement.

 However, I have been using and testing Rmpi
 internally since 0.4-4. Now it is version 0.4-7. See the
 attached package. It requires R 1.8.1 (no more serialize
 package requirement) and works with the newest MPI-LAM
 versions 7. It will configure automatically if a rpm package
 from www.lam-mpi.org is used. I tested it on both Redhat 9
 and Debian. At least it passed the package check without any
 warning on Redhat 9. Now the problem is that it may have
 some problems with the default lam coming with Debian
 system. This is the reason why I hesitate to release it to
 R. 
I'm happy to report the Rmpi 0.4-7 installs and works without a problem
(or any necessary modification) on my Debian mostly testing system (it
does have some unstable stuff, but in particular it has the older
lam/mpi 6.5.8-2.  version 7 has been held in unstable for 60 days
because of some problems on alpha hardware).

Note this is not quite the lam in the current stable Debian distro,
which is at 6.5.6-6.
 
 I am also working on it to see if #ifdef can be used to work
 MPI 1.2 specs other than LAM-MPI. 
 Hopefully in a couple of months, I am able to submit a
 stable version to R.
Great.  Thanks.  I think it would be well worth making 0.4-7 available
at http://www.stats.uwo.ca/faculty/yu/Rmpi/.  I'll send you, off list,
the hacks I made to get the thing (starting with 0.4-6) to compile with
the MPI 1.2ish mpich.  It didn't run, but at least it did compile and
load at the end.

By the way, I'm in the dark about (r)sprng.  From some of the snow docs,
I thought that was really snow's business.  But your site notes that the
Rmpi packages are withough SPRNG support.  And Tony Rossini's pages (I
think) had a slightly cryptic remark that SPRNG under MPI was a bit
dicey.
 
 Regards,
 
 Hao 
 
 PS: Rmpi should still work without serializing as long as
 native MPI calls are used. The serializing is mainly used to
 help moving an arbitrarily R object around.
I don't completely follow that, since I don't control whether or not
native MPI calls are used, as far as I know.  Do you mean that Rmpi can
be used alone OK, but if you use snow (or, I guess Rmpi calls oriented
toward snow and the transmission of R objects) it will need the
serialize facility (prior to R 1.8)?

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


[R] http://cran.us.r-project.org/ inaccessible

2004-03-24 Thread Ross Boylan
For the last couple of days when I go to http://cran.us.r-project.org/ I
see only the left-hand margin logo and table of contents.  If I click on
one of the links there, I get a timeout.  Other sites (e.g.,
http://cran.stat.ucla.edu/) work fine for me.

Lacking complete confidence this is a bug*, as well as any better notion
of where to report this, I'm reporting it here.

*I have had problems accessing one other site,
http://www.oasis-open.org/, that is generally accessible.  It has been
suggested the problem is that oasis does not cope with congestion
notifications (ECN) properly, so it's not clear whether this is my
problem or the sites.

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


Re: [R] Rmpi and PBS

2004-03-23 Thread Ross Boylan
On Tue, 2003-12-30 at 08:39, Shengqiao Li wrote:
 Hello:
 
 Anybody knows how to run Rmpi through PBS (Portable Batch System) on a
 cluster computer. I'm using a supercomputer which require to submit jobs
 to PBS queue for dispatching. I tried use mpirun in my PBS script. But all
 my Rslaves are spawned to the same node. This is not desired.
 
 Any suggestions are welcome!
 
 Thanks in advance.
This is a late reply, but perhaps still of interest to some.  It looks
as if this problem has been solved, though only integrated into LAM with
release 7: http://www.lam-mpi.org/papers/hpcs2003/tm-implementation.pdf

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


[R] Status of Rmpi

2004-03-23 Thread Ross Boylan
Rmpi is not currently available on CRAN, and I don't think it has been
for a few months.  It is available at
http://www.stats.uwo.ca/faculty/yu/Rmpi/

Does anyone know its current status?

A few months ago I corresponded with the author, who noted some build
problems (specifically on Debian) were the hang up, and seemed to be
working on it.  I wasn't able to get it to work then (on a Debian
GNU/Linux testing system).  After having tried unsuccessfully to get it
working last week on an oddball system, I tried again on my system.

I was able to build the thing, but not actually get it working.  The two
obvious difficulties were that, first, I had to manually load the
serialize library (which now conflicts with the name of something in the
base package) and, second, that whenever I say makeCluster or
makeMPIcluster the thing just hangs up.  I've tried various permutations
of running or not running lamboot first.

I am able to to lamboot and lamexec, and I also tried setting LAMRSH to
use ssh on the master.  My network is just my dual-CPU machine.

Tony Rossini's notes
(http://www.analytics.washington.edu/~rossini/courses/cph-statcomp/cph-4.pdf) refer to 
SNOW and rpvm as being currently maintained (last page), which hints that Rmpi might 
not be.

I'm kind of interested in getting Rmpi to work (I and others here have
been using Rmpi), though I suppose we could switch to rpvm, so I'll
probably keep fiddling with it.  I'm using LAM 6.5.8-2.

Footnote: Does anyone know if the serialize that comes with R 1.8.1 is
compatible with the serialize package?  Should the latter be
unnecessary?
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


Re: [R] Status of Rmpi--Good with tweaks

2004-03-23 Thread Ross Boylan
On Tue, 2004-03-23 at 17:35, Luke Tierney wrote:
 The serialize package should no longer be needed since the
 functionality is now in R itself.  I haven't run snow with a new
 version of Rmpi newer than 0.4-4; with that version things worked on
 my systems the last time I tried.  We need to revize the paper you
 cite; when we get to that we'll hopefully have a chance to give a
 newer version of Rmpi a go.
 
 Best,
 
 luke

I got 0.4-6 to work, with one tweak to eliminate the loading of
serialize and one fix of my own setup.

I changed the .First.Lib code in Rmpi to be
if (!exists(serialize)  !require(serialize))
stop(serialize package cannot be loaded. Exit)

!exists(serialize)  is new.  This is effort to check if the
serialize function exists (R 1.8) and skip loading the library in that
case.  Since there are various ways this might be fooled, perhaps an
explicit check of the R version would be better.

I'm also not sure if the R packaging mechanism makes this easy, or
autogenerates it.  This is a bit of a tricky situation, since serialize
is required for some versions of R but should not be used for the most
recent.

I suspect that without this the cluster would not come up because Rmpi
would not load properly.  I have not tested that.

The other problem was of my own making.  I had Rmpi in a local
directory, loaded with lib.loc.  The children don't know about this, and
automatically try to load Rmpi.  I solved this by setting .Renviron with
the proper R_LIBS path.  (By the way, I wanted to say
R_LIBS=~/lib:${R_LIBS}, but that syntax doesn't work.  This is
consistent with the documentation, just awkward.)

I also ran into a couple of snow things, really documentation issues,
that I'll put in a separate message.

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


[R] snow documentation comments

2004-03-23 Thread Ross Boylan
There are a few points I found unclear or unmentioned in the snow
documentation (mostly I looked at the cluster.html web page).  I thought
I'd mention them here.

What is the start up environment for the children?
--
My best guess at the answer is in parentheses
Do they inherit shell variables? (no)
Do they inherit variables set in R or other aspects of the R
environment? (no)
What directory does it start in? (the directory you are running in)
What user are you? (same as original)

I realize some of these answers might depend on the parallelization
layer you are using, or whether you select the homogenous option.

There are also some entertaining pathological cases; for example,
lam/mpi lets you start some of the children as another user.

Number of nodes or number of children?
--
I thought all the counts of nodes (e.g., in makeCluster(5)) were of the
total nodes in the cluster, i.e., children + 1.  However, I did a
makeCluster(2) and I got 2 additional R processes running.  Have I
misunderstood the semantics, or is it essentially an implementation
detail that the master node starts a new R process?

Options
---
Is the full set of cluster options documented anywhere?

-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


Re: [R] Status of Rmpi--Good with tweaks

2004-03-23 Thread Ross Boylan
On Tue, 2004-03-23 at 18:26, Ross Boylan wrote:
 On Tue, 2004-03-23 at 17:35, Luke Tierney wrote:
  The serialize package should no longer be needed since the
  functionality is now in R itself.  I haven't run snow with a new
  version of Rmpi newer than 0.4-4; with that version things worked on
  my systems the last time I tried.  We need to revize the paper you
  cite; when we get to that we'll hopefully have a chance to give a
  newer version of Rmpi a go.
  
  Best,
  
  luke
 
 I got 0.4-6 to work, with one tweak to eliminate the loading of
 serialize and one fix of my own setup.
 
 I changed the .First.Lib code in Rmpi to be
 if (!exists(serialize)  !require(serialize))
   stop(serialize package cannot be loaded. Exit)
 
 !exists(serialize)  is new.  This is effort to check if the
  ^an   
 serialize function exists (R 1.8) and skip loading the library in that
 case.  Since there are various ways this might be fooled, perhaps an
 explicit check of the R version would be better.
 
 I'm also not sure if the R packaging mechanism makes this easy, or
this refers to the modification to the .First.Lib that I made.
 autogenerates it.  This is a bit of a tricky situation, since serialize
 is required for some versions of R but should not be used for the most
 recent.
 
 I suspect that without this the cluster would not come up because Rmpi
 would not load properly.  I have not tested that.

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


[R] R and package don't know they're built on same system

2004-03-18 Thread Ross Boylan
I just had the interesting experience of building a package and R on
the same system, and having R refuse to load the resultant dynamic
library because it was thought to be for a different system.

The system was non-standard and beta, being a Linux-based 64 bit
Opteron system.  It uses the gnu tool chain.  The dynamic library was
built from C source.

When I tried to load the library R (1.8.1) complained
package Rpmi was built for i686-pc-linux-gnu
Inspection of R.version$platform, which is the thing the i686 is
being compared to, shows that it is x86_64-unknown-linux-gnu.

I worked around this by removing the test causing the error (in
library.R), but, considering I built both R and Rmpi (an unofficial
version 0.4.6 from the author) within minutes of each other, it was
very surprising to find they had different notions of their system.

Any idea what's behind this, or how to fix it?

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


[R] R does in memory analysis only?

2004-02-07 Thread Ross Boylan
I wonder if someone would confirm something I'm 99% sure of from the
docs and discussion on the list, but can't find stated explicitly:
R works only on problems that fit into (real or virtual) memory.

Thus, even if you have a problem (e.g., simple regression) that could be
solved by doing some operation on each row of a dataset at a time, you
can't solve it unless the entire dataset and associated intermediate
results fit in memory.

So if you're in 32 bits, your max problem size is about 2G (regular
Windows and Linux limit your process size to this, though I think some
fancy versions let you go a bit higher).

Is there any thought of relaxing this limitation?  I realize doing so
would be a big job.  I also realize that 64 bits makes it much less
pressing.

Finally, does S-Plus have the same limitation?

Thanks.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] Contributing to the R Extensions documentation

2003-11-05 Thread Ross Boylan
I thought there were some gaps in the R Extensions document; in
particular, I was left wondering how to create a list.  I think a
paragraph on it would be useful.

I would be happy to contribute the paragraph, but I'm not sure if
there's interest or what the procedure is.  Can anyone advise me?

Though I was looking at the 1.7.0 version, I just checked 1.8.0 and the
relevant section seems the same.

My ulterior motive is to discover if my understanding of lists is
actually correct :)
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


Re: [R] Architecting an optimization with external calls

2003-11-04 Thread Ross Boylan
On Tue, 2003-11-04 at 13:12, Prof Brian Ripley wrote:
 Look into external pointers.  That is how we have tackled this, e.g. in 
 the ts package.
I got the following to work.  Any comments?  I indicated some areas of
uncertainty in the comments.  I'm also unsure about the differences, if
any, between the DOUBLE_DATA(x)[0] = val style and SET_ELEMENT(x, i,
val) style.

The R code was the best way I could think of to retain the state while
using a function that worked with optim.  The C code remembers the
argument from the previous call and prints it out when invoked.

The driving R code was
loglika - function(initialparms) {
  opaque - NULL # holds the data returned by the C function
  innerloglik - function(parms){
# If .C can handle externalptr, it would be easier
result - .Call(loglik, as.double(parms), opaque)
opaque - result$opaque
return(result$loglik)
  }
  result - optim(initialparms, innerloglik)
  .Call(cleanup, opaque)
  opaque - NULL
}

And the C:
#include R.h
#include Rdefines.h

SEXP loglik(SEXP params, SEXP data){
  double *pd;
  SEXP returnLik, returnVal, returnNames;

  if (TYPEOF(data) == EXTPTRSXP) {
pd = (double *) EXTPTR_PTR(data);
Rprintf(I've been here with %f\n, *pd);
  } else {
pd = malloc(sizeof(double));
data = R_MakeExternalPtr(pd, R_NilValue, R_NilValue);
/* do I need PROTECT(data)?  if so, argument to
 UNPROTECT is variable */
  }
  
  *pd = DOUBLE_DATA(params)[0];

  /* Real computation would go here */

  PROTECT(returnLik = NEW_NUMERIC(1));
  NUMERIC_POINTER(returnLik)[0] = (*pd)*(*pd); /* our log likelihood */
 /* When I just set it = 5.0 I got a segfault.  Maybe because I
rebuilt the library at the same time */

  /* update opaque data with first input parameter */
  Rprintf(Just recorded input parameter %f\n, *pd);

  /* construct return list object */
  PROTECT(returnVal = NEW_LIST(2));
  PROTECT(returnNames = NEW_CHARACTER(2));
  SET_STRING_ELT(returnNames, 0, mkChar(loglik));
  SET_STRING_ELT(returnNames, 1, mkChar(opaque));
  SET_NAMES(returnVal, returnNames);
  SET_ELEMENT(returnVal, 0, returnLik);
  SET_ELEMENT(returnVal, 1, data);
  UNPROTECT(3);
  return returnVal;
}

SEXP cleanup(SEXP data){
  if (TYPEOF(data) == EXTPTRSXP) {
free(EXTPTR_PTR(data));
  } else {
error(cleanup called without an External Pointer argument);
  }
  return R_NilValue;
}

I was going on a lot of hunches, even with the docs and code together.

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


Re: [R] Re: packaging a package addon

2003-10-31 Thread Ross Boylan
On Fri, 2003-10-31 at 03:14, Prof Brian Ripley wrote:

 But I would not be doing R CMD check until I had both installed and 
 loaded the package and run a few examples.

That's interesting; I thought R CMD check was supposed to be done before
hand.  So are you saying the proper development sequence is
1.
Do as much as you can with the basic R and C (Fortran, whatever) code to
check it's OK.

2.
R CMD build
test, revise
R CMD build
etc

3. then, when everything looks OK
R CMD check
?

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


Re: [R] Re: packaging a package addon

2003-10-31 Thread Ross Boylan
On Fri, 2003-10-31 at 06:41, A.J. Rossini wrote:
 Ross Boylan [EMAIL PROTECTED] writes:
 
  I also added library(survival) to my .First.lib.  Is library, rather
  than require, the right choice here?  I want it to fail if survival
  doesn't load.
 
 test the results from require, something like: 
 
  if (!require(survival)) stop(can't load survival)
Doesn't using library do about the same thing?  What's the advantage of
this, clearer diagnostics?

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


Re: [R] Re: packaging a package addon

2003-10-31 Thread Ross Boylan
On Fri, 2003-10-31 at 13:29, Prof Brian Ripley wrote:
 I would do 1 3 2  as R CMD check works on a source dir, not a .tar.gz.
 
 Your mileage may vary and all that.
I'm not following something.  1 3 2 was what I was doing.  I thought you
said (below on Fri) that you'd do 2, then 3.  I may be misunderstanding
what the phrase installed and loaded the package means.  I thought
installing and loading it referred to doing an R CMD build to make the
package, and then R CMD INSTALL on the result.

 
 I'd say R CMD check was a final check before distribution via R CMD build.
 
 On Fri, 31 Oct 2003, Ross Boylan wrote:
 
  On Fri, 2003-10-31 at 03:14, Prof Brian Ripley wrote:
  
   But I would not be doing R CMD check until I had both installed and 
   loaded the package and run a few examples.
  
  That's interesting; I thought R CMD check was supposed to be done before
  hand.  So are you saying the proper development sequence is
  1.
  Do as much as you can with the basic R and C (Fortran, whatever) code to
  check it's OK.
  
  2.
  R CMD build
  test, revise
  R CMD build
  etc
  
  3. then, when everything looks OK
  R CMD check
  ?
  
  
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] html glitches with help?

2003-10-31 Thread Ross Boylan
Looking at the html generated help pages for a package I'm working on, I
noticed a couple of things that looked a little funny.  I suspect they
are general features of the html for R (I don't usually look at it).

First is a problem of vertical alignment in tables. The first column
consistently aligned vertically *below* the alignment line of the bottom
line of the second column.  This was a problem even when both columns
were a single line; it was worse when they were multiple lines.

In slightly exagerated form, the output looked like this:

   long discussion of what paramater pp does
   and its wonderful features
pp

Likely at least two separate issues: why is it aligning with the last,
rather than the first, line of the second column, and why is it below
that?

It may be relevant that the first column was in \code{a} and the whole
thing was in an \arguments{\item{foo}{\tabular{ll} section.

Second, the items marked with \code{} appeared fainter than the other
text, and were a little hard to read.  I'd expect them to be bolder.

Perhaps the R.css style sheet could be tweaked for this?
R 1.7.1-1 on Debian GNU/Linux
Viewed with Mozilla 1.4
Konqueror from KDE 3.1.3 looked very similar, except the typeface for
\code was identical to that of the rest.

Sample excerpt from the .Rd file:

\value{returns a list:
  \item{singles}{data frame, one row per simulation, with the following
columns:
\tabular{ll}{
  coefficients \tab one column per variable\cr

  \code{pi1} \tab conditional probability of sampling cases \cr

Similar behavior in \arguments section.  It is the pi1 above, for
example, that is aligned poorly.  Alignment of the outer level \item's
is better (in fact, the opposite problem, their baseline is above the
baseline of the first line of the second column, though their tops are
not much higher).

-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] packaging a package addon

2003-10-29 Thread Ross Boylan
I am trying to package some code that is a tweak to the survival
package.  When I asked earlier, the list consensus was that it would be
best to do this as a separate package, dependent on survival.

This is proving a bit tricky.

I have some run-time and compile time concerns.

Run-time, my R code needs R code from survival, and my C code needs C
functions from survival.  Will this all be properly loaded by, for
example, R CMD check, (assuming the proper dependency in DESCRIPTION) so
that it doesn't blow up?

The reason I haven't just tried it is that the compile-time issues.  My
C code depends on survival C code for headers.  I believe that the
typical target system where the package would be installed won't have
these at all.  Is that true?  If so, what's the best way around this? 
Maybe stick the headers in a subdirectory and mess with the build
options to include them?  And hope they don't get out of sync with the
real ones?
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] Re: packaging a package addon

2003-10-29 Thread Ross Boylan
I have some mixed results to report.  I went ahead and built a package
with the dependency, my changed files, and a few headers.  I left the
headers in the same directory as the C files.

My first attempt passed R CMD check, though there were no examples to
exercise the code.  When I tried to run it, it couldn't find the C
routine.  I had neglected to provide a .First.lib for my new library.

When I corrected that, R cmd check failed with
* checking generic/method consistency ... WARNING
Error in .loadPackageQuietly(package, lib.loc) : 
Error in library(package, lib.loc = lib.loc, character.only = TRUE,
verbose = FALSE) : 
.First.lib failed
Execution halted
* checking for assignment functions with final arg not named 'value' ...
WARNING
Error in .loadPackageQuietly(package, lib.loc) : 
Error in library(package, lib.loc = lib.loc, character.only = TRUE,
verbose = FALSE) : 
.First.lib failed
Execution halted
* checking Rd files ... OK
* checking for undocumented objects ... ERROR
Error in .loadPackageQuietly(package, lib.loc) : 

Hoping this was only a problem for check because it didn't know how to
load dependencies, I tried running the resulting code in a regular R
session.  My first discovery was that dependent libraries need to be
loaded by hand.  After I did that, when I ran my code I got
 library(survival)
 library(survivalrds, lib.loc=/home/ross/src/survivalrds.Rcheck/)
Error in dyn.load(x, as.logical(local), as.logical(now)) : 
unable to load shared library
/home/ross/src/survivalrds.Rcheck/survivalrds/libs/survivalrds.so:
  /home/ross/src/survivalrds.Rcheck/survivalrds/libs/survivalrds.so:
undefined symbol: cholesky2
Error in library(survivalrds, lib.loc =
/home/ross/src/survivalrds.Rcheck/) : 
.First.lib failed

cholesky2 is one of the entry points in survival referenced by
survivalrds.  I tried adding an external to the declaration of
cholesky2 (I think it's redundant) and redoing everything; it didn't
help.

In short, I'm having some dynamic linkage problems.  Any suggestions? 
(I'm on a linux system with the gcc 3.3 toolchain, but obviously it
would be better to solve this portably).
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] Plot can't forget bad parameters

2003-10-02 Thread Ross Boylan
When I give plot some bad paramaters, it keeps giving me error messages
forever after.  I think the last time this happened, I even got the
error messages for completely unrelated, non-graphical functions.

Here's a recent example:
 plot(it[[31]][,c(1, 3)], type=b, usr=c(0, 20, -20, 5))
Warning messages: 
1: parameter usr couldn't be set in high-level plot() function 
2: parameter usr couldn't be set in high-level plot() function 
3: parameter usr couldn't be set in high-level plot() function 
4: parameter usr couldn't be set in high-level plot() function 
5: parameter usr couldn't be set in high-level plot() function 
6: parameter usr couldn't be set in high-level plot() function 
 plot(it[[31]][,c(1, 3)], type=b, ylim=c(-20, 5))
Warning messages: 
1: parameter usr couldn't be set in high-level plot() function 
2: parameter usr couldn't be set in high-level plot() function 
3: parameter usr couldn't be set in high-level plot() function 
4: parameter usr couldn't be set in high-level plot() function 
5: parameter usr couldn't be set in high-level plot() function 
6

Is this a bug, or have I missed something?
R 1.7.1
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


RE: [R] Plot can't forget bad parameters

2003-10-02 Thread Ross Boylan
On Thu, 2003-10-02 at 16:54, [EMAIL PROTECTED] wrote:
 Try 
 
 rm(last.warning)
 
 -Original Message-
 From: Ross Boylan [mailto:[EMAIL PROTECTED] 
 Sent: Friday, 3 October 2003 9:10 AM
 To: r-help
 Subject: [R] Plot can't forget bad parameters
 
 
 When I give plot some bad paramaters, it keeps giving me error messages
 forever after.  I think the last time this happened, I even got the
 error messages for completely unrelated, non-graphical functions.
 
 Here's a recent example:
  plot(it[[31]][,c(1, 3)], type=b, usr=c(0, 20, -20, 5))
 Warning messages: 
 1: parameter usr couldn't be set in high-level plot() function 
 2: parameter usr couldn't be set in high-level plot() function 
 3: parameter usr couldn't be set in high-level plot() function 
 4: parameter usr couldn't be set in high-level plot() function 
 5: parameter usr couldn't be set in high-level plot() function 
 6: parameter usr couldn't be set in high-level plot() function 
  plot(it[[31]][,c(1, 3)], type=b, ylim=c(-20, 5))
 Warning messages: 
 1: parameter usr couldn't be set in high-level plot() function 
 2: parameter usr couldn't be set in high-level plot() function 
 3: parameter usr couldn't be set in high-level plot() function 
 4: parameter usr couldn't be set in high-level plot() function 
 5: parameter usr couldn't be set in high-level plot() function 
 6
 
 Is this a bug, or have I missed something?
 R 1.7.1

Well, that's very odd.  I did the rm(), and it printed out the warnings
again.  Then I repeated the two commands above--only this time, there
were no warnings after the second (i.e., things worked OK).

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


[R] Re: Help needed: plotting with no device

2003-09-30 Thread Ross Boylan
Thanks to everyone for your help.  I decided to see if the session could
be recovered if I connected back from the original, local terminal.

The local screen was locked by the KDE screensaver.  Either my unlocking
it, or the passage of time, seems to have got the process unstuck.  It
happened before I reattached to the screen session from a local
terminal.

Whew!

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


Re: [R] Help needed: plotting with no device

2003-09-30 Thread Ross Boylan
On Mon, 2003-09-29 at 14:25, Luke Tierney wrote:
 Look at ?Signal and see if that would help.  You may need to rename
 the appropriate .RData beforehand to be safer.
 
 luke
For those who follow, note it's actually
?Signals
you want. It talks about USR1 and USR2 (as did some other people in this
thread).

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


[R] Help needed: plotting with no device

2003-09-29 Thread Ross Boylan
I have a hung session I would very much like to recover, since it has
some simulation results I haven't saved (that took about 12 hours to
create).  Yes, I know, I should have saved while I had the chance.

I tried to do a hist() in an environment without a plotting device.
My R session now seems to be hung; ^C doesn't do anything.  I thought
it would timeout, but it has not so far.

The details of this session's environment are a bit baroque.  In case
it matters, here they are:
Running an xterm locally, used the screen program to start a shell.
Ran R.
Then, from a remote computer, used ssh to log in (without X forwarding
enabled).  Grabbed the session by doing screen -d -r.  (screen lets
you trade the controlling tty of a session; that's why I was using
it).

After detaching and reattaching the session a couple of times (still
remote) I did
 hist(tres4$singles[[a]])
tres4$singles is a dataframe.
I can still type on the terminal, but get no response.

R 1.7.1 on Debian.

Is there any way to get the R session back without killing it?

Thanks.

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


Re: [R] Help needed: plotting with no device

2003-09-29 Thread Ross Boylan
On Mon, Sep 29, 2003 at 05:09:49PM -0400, Ben Bolker wrote:
 
   Can you use save.image() to rescue your results?
   I would try save.image(file=salvage.RData) and see if the file 
 appears.  Otherwise I would say you're probably out of luck.
 
The problem is I can't get back to the command prompt, so I can't do
save.image() or anything else.

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


RE: [R] density() integrates to 1?

2003-09-24 Thread Ross Boylan
On Wed, 2003-09-24 at 18:36, Liaw, Andy wrote:
 There was a related thread on R-help, probably last year.  The question was
 getting density() to numerically integrate to 1.  The answer is, yes.  If
 you do fine enough partitions, you will see that it integrates to one.  And
 yes, a kernel density estimate is theoretically a true density (assuming the
 kernel used is a pdf), because it is just a n-component mixture of the
 kernel.
 
 Andy

With this advice, and on reinspection, I think it's possible I was
fooled in my visual integration.  There is an area where the density()
is under the normal.  Vertically, it's actually quite a bit under, even
though the two curves are horizontally very close.  So perhaps that area
is bigger than I thought, enough to account for the discrepancy.

The other possibility is that even though the points on density are OK,
the curve created by plot putting a line through them really is not OK
(in the sense of integrating to 1).  The issue for this is not the
behavior of density when one increases the number of partitions, but the
behavior at a fixed partition (the default 512 in my case).  Or rather,
that behavior plus that of plot's line.

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


[R] subsetting matrix replacement oddities

2003-09-17 Thread Ross Boylan
When assigning a dataframe to a subset of a matrix I got a very odd
result.  Am I missing something, or is this a bug?  Details are below.

Also, if m is defined outside of the current function, is
m[...] - foo
necessary to update it, or does regular replacement
m[] - foo
work (that is, does it update the global rather than creating a
local that conceals it)?  I got conflicting results, which were
tangled up with the oddity below.


Browse[1] covs
epilepsy other.cancer
68000
68100
68200
68301
68400
Browse[1] m - matrix(NA, 5,2)
Browse[1] m[,1:2] - covs
Browse[1] m
[[1]]
[1] 0 0 0 0 0

[[2]]
[1] 0 0 0 1 0

[[3]]
[1] 0 0 0 0 0

[[4]]
[1] 0 0 0 1 0

[[5]]
[1] 0 0 0 0 0

[[6]]
[1] 0 0 0 1 0

[[7]]
[1] 0 0 0 0 0

[[8]]
[1] 0 0 0 1 0

[[9]]
[1] 0 0 0 0 0

[[10]]
[1] 0 0 0 1 0

Browse[1] dim(covs)
[1] 5 2
Browse[1] class(covs)
[1] data.frame
Browse[1] class(m)
[1] list
Browse[1] length(m)
[1] 10

Fortunately, the following seems to work as expected:
Browse[1] m[,1:2] - as.matrix(covs)


Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] (structured) programming style

2003-09-11 Thread Ross Boylan
I find that because R functions are call by value, and because there are
no pointer or reference types (a la C++), I am making fairly heavy use
of lexical scoping to modify variables.  E.g.
outer - function() {
  m - matrix(0, 2, 2)
  inner - function() {
m[2,2] - 3
   ...
   }
}

I am not too pleased with this, as it violates basic rules of structured
programming, namely that it is not obvious what variables inner is
reading or writing.  It's not as totally out of control as the use of
global variables, but it's still bothersome.  In practice, I have many
variables and several levels of nesting that come into play.

A slightly subtler problem is that some of the variables in outer are
just for use by outer, while others are used for communication down the
line.  One can't tell by quick inspection what's what.

I am trying to compensate by commenting the code heavily, but I'd rather
not use a style that makes that necessary.

I recognize that I could pass m as an argument to inner and return a
modified version of it.  Assuming more than one variable was involved
(as would usually be the case) I'd need to put the new m in a list
returned from inner, and then unpack the list in the outer function. 
This is not only rather ugly, but I imagine it also raises some
performance issues.

All of which has me wondering if there are some more natural ways to use
the language to the same general ends.  Can anyone comment?

Thanks.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


Re: [R] (structured) programming style

2003-09-11 Thread Ross Boylan
Thanks for your response.  Is good to know that copying is lazy, but I
don't think that fully solves my problems.  See below.

On Thu, 2003-09-11 at 17:40, Thomas Lumley wrote:
.
 
 you see that unpacking b from a didn't result in a copy, and that b must
 just be a reference to a$m.  When b is modified it must be copied, but
 this is true whether or not it is in a list. What matters is whether there
 is another reference to it somewhere [actually, whether R thinks there
 *might* be another reference: we try to be a bit conservative about this].
 

I'm thinking of a situation like
a - array(0, dim=c(1, 10))
and then I modify a one row at a time.
a[34,] - newrow
So if I write directly to a, I just overwrite the row.
But if I make a copy, even a lazy one, when I change the row I have to
make a copy of the whole array (unless the laziness is really clever,
and your figures suggest that a single write causes the whole thing to
be copied).

Hmm, now that I think of it I suppose I could just return newrow from
the inner function... except I have inner functions that produce several
rows, with inner inner functions that do single rows...

 
 Now, it is certainly possible that you could have a situation where
 assigning with - was really faster than passing back a list, by enough
 to matter.  I think this situation is unusual enough that there may not be
 a firm idea of `good R style', since it assumes that the objects are small
 enough to fit easily in memory but large enough that it's worth going to
 some effort to reduce copying. You might get more useful input from the
 Bioconductor list, where people tend to spend a lot of time doing
 computationally expensive things to medium-sized data sets.

Where and what is the Bioconductor list?

I suppose optimization is one traditional reason to break style
guidelines.

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


[R] Seeking Packaging advice

2003-08-27 Thread Ross Boylan
I have two questions about packaging up code.

1) Weave/tangle advisable?
In the course of extending some C code already in S, I had to work out
the underlying math.  It seems to me useful to keep this information
with the code, using Knuth's tangle/weave type tools.  I know there is
some support for this in R code, but my question is about the wisdow of
doing this with C (or Fortran, or other source) code.

Against the advantage of having the documentation and code nicely
integrated are the drawbacks of added complexity in the build process
and portability concerns.  Some of this is mitigated by the existing
dependence on TeX.

An intermediate approach would be to provide both the web (in the Knuth
sense) source and the C output; the latter could be used directly by
those not wishing to hassle with web.  This isn't ideal, since the
resulting C is likely to be a bit cryptic, and if someone edits the C
without changing the web source confusion will reign.

So do people have any thoughts about whether introducing this is a step
forward or back?

2) Modifications of existing packages.
I modified the survival package (I'm not sure if that's properly called
a base package, but it's close).  I know in this particular case, if
I'm serious, I probably should contact the package maintainer.  But this
kind of operation will probably be pretty common for me; I imagine many
on this list have already done it.  In general, is the best thing to do
a) package the new routines as a small additional package, with a
dependence on the base package if necessary (the particular change I've
made actually produces a few distinct files, slight tweaks of existing
ones, that can stand on their own)
b) package the new things in with the old under the same name as the old
(obviously requires working with package maintainter)
c) package the new things with the old and give it a new name.

I'm also curious about what development strategy is best; I did b), and
it seemed to work OK.  But I kept expecting it to cause disaster (it
probably helped that I usually didn't load the baseline survival
packages; clearly that wouldn't be an option if working with one of the
automatically loaded packages).

Thanks.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] logistic regression without intercept

2003-08-19 Thread Ross Boylan
I want to do a logistic regression without an intercept term.  This
option is absent from glm, though present in some of the inner functions
glm uses.  I gather glm is the standard way to do logistic regression in
R.

Hoping it would be passed in, I said
 r - glm(brain.cancer~epilepsy+other.cancer, c3, 
family=binomial(link=logit), intercept=FALSE)
which produced
Error in glm.control(...) : unused argument(s) (intercept ...)

Is there an easy way to do this?  I suppose I could start hacking away
at glm so it would take the argument and pass it on, but is it absent
for a reason?

Also, I noticed that S-Plus but not R has a glim routine that uses
maximum likelihood.  What would be the equivalent?

Thanks.

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


[R] Error in model.frame

2003-08-15 Thread Ross Boylan
I am getting an error that I don't understand, and wonder if anyone
could explain what's going on.  I call a function defined thus:

clogit.rds-function(formula,data,extra.data,response.prob,
 na.action=getOption(na.action),subset=NULL,
 control=coxph.control()){
method=exact  # only option for now
mf-match.call()
mf[[1]]-as.name(model.frame)
mf$method-mf$control-NULL
mfn-mf

mfn$na.action-I
mfn$subset-NULL
nrows-NROW(eval(mfn,parent.frame()))
etc.
At the eval on the last line, I get

Error in model.frame(formula, rownames, variables, varnames, extras,
extranames,  : 
variable lengths differ

This is puzzling for two reasons.  First, I don't understand where the
arguments given in the error message are coming from.  They are not in
my function definition or call, and they do not seem to be the arguments
to model.frame either.

Second, I don't know why it's not working!  This is modified from clogit
in survival, and that works fine.  I've added two arguments, extra.data
(which is just a column of the data) and response.prob.  The latter has
different dimensions (response.prob = c(1, 1), in fact), but nothing in
the description of model.frame suggests that should be a problem.

model.frame itself is a wrapper on a primitive, so I can't really debug
into it.

Background:

Running R 1.7.1-1 on Debian Gnu/Linux.

In case it matters, the code I'm running was produced by hacking the
survival package, running R CMD check, and then loading the package from
the test directory that created:
library(survival, lib.loc=/home/ross/src/survival.Rcheck)

The clogit command seems to run fine.

One of the variables in the data.frame is name proband, which I notice
gets highlighted by ESS.

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


[R] Re: Error in model.frame

2003-08-15 Thread Ross Boylan
On Fri, 2003-08-15 at 16:03, Ross Boylan wrote:
 I am getting an error that I don't understand, and wonder if anyone
 could explain what's going on.  I call a function defined thus:
 
 clogit.rds-function(formula,data,extra.data,response.prob,
  na.action=getOption(na.action),subset=NULL,
  control=coxph.control()){
 method=exact  # only option for now
 mf-match.call()
 mf[[1]]-as.name(model.frame)
 mf$method-mf$control-NULL
 mfn-mf
 
 mfn$na.action-I
 mfn$subset-NULL
 nrows-NROW(eval(mfn,parent.frame()))
 etc.
 At the eval on the last line, I get
 
 Error in model.frame(formula, rownames, variables, varnames, extras,
 extranames,  : 
   variable lengths differ
 
A clue: if I call this with response.prob set to an element of the
clogit.rds argument data frame, I don't get the error.

I assume that to fix this I must somehow exclude this variable.  But I
will need it back in when I make the next call.  Suggestions?  Insights
into why this is necessary?

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


[R] Re: Error in model.frame SOLVED

2003-08-15 Thread Ross Boylan
On Fri, 2003-08-15 at 16:15, Ross Boylan wrote:
 On Fri, 2003-08-15 at 16:03, Ross Boylan wrote:
  I am getting an error that I don't understand, and wonder if anyone
  could explain what's going on.  I call a function defined thus:
  
  clogit.rds-function(formula,data,extra.data,response.prob,
   na.action=getOption(na.action),subset=NULL,
   control=coxph.control()){
  method=exact  # only option for now
  mf-match.call()
  mf[[1]]-as.name(model.frame)
  mf$method-mf$control-NULL
  mfn-mf
  
  mfn$na.action-I
  mfn$subset-NULL
  nrows-NROW(eval(mfn,parent.frame()))
  etc.
  At the eval on the last line, I get
  
  Error in model.frame(formula, rownames, variables, varnames, extras,
  extranames,  : 
  variable lengths differ
  
 A clue: if I call this with response.prob set to an element of the
 clogit.rds argument data frame, I don't get the error.
 
 I assume that to fix this I must somehow exclude this variable.  But I
 will need it back in when I make the next call.  Suggestions?  Insights
 into why this is necessary?

I need mf$response.prob - NULL to make it work.
Still wonder why model.frame is so picky
--

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


Re: [R] Looking to maximize a conditional likelihood

2003-07-17 Thread Ross Boylan
On Thu, 2003-07-17 at 14:27, Spencer Graves wrote:
 Have you considered optim?
 
 spencer graves
 
Thank you for drawing that to my attention.  I take it that's the best general
purpose optimizer to use?

My hope is to find something that knows a bit more about the structure of the
problem, including particularly the sum of permutations bit.  After looking
at the coxph documentation 
http://stat.ethz.ch/R-alpha/R-patched/library/survival/html/coxph.html
I'm getting more optimistic it's what I need (particularly with 
method=exact, which it says is equivalent to the conditional logistic model, 
which is my case (at least without the c_ij's).

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


Re: [R] Looking to maximize a conditional likelihood

2003-07-17 Thread Ross Boylan
On Thu, 2003-07-17 at 14:37, Peter Dalgaard BSA wrote:
 Ross Boylan [EMAIL PROTECTED] writes:
 
  I want to maximize a conditional likelihood function that is basically
  logistic conditional on the number of successes within strata.  What
  would be a good starting place for this?  A complication is that the
  denominator includes a term that is the sum over all permutations.
  
  Although there is no time dimension to the problem, it's possible a
  degenerate use of the Cox proportional hazards model (in the survival
  package of 1.7) will do what I want.
 
 Did you check out clogit from the same package?
Wow, that looks like it exactly!  Thanks.  I was so sure this was a
time-series package I didn't think to look there.

This leads to a general search question: is there a way I could have
done a search on conditional logit and found this?  I tried various
searches like help.search(condition).  My system doesn't have this
module available, so was that the only problem?  I'm not sure if the
usual searches look through all the available packages.

-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


Re: [R] searching (was Looking to maximize a conditional likelihood)

2003-07-17 Thread Ross Boylan
On Thu, 2003-07-17 at 15:06, Peter Dalgaard BSA wrote:
 Ross Boylan [EMAIL PROTECTED] writes:
 

  This leads to a general search question: is there a way I could have
  done a search on conditional logit and found this? 
 
 In R itself, probably not. The CRAN search engine at
 
 http://finzi.psych.upenn.edu/search.html
 
 will get you there if you search for conditional logistic. 

Hmm... if I limit the search to functions and enter conditional
logistic the clogit function is the 17th of 18 hits.  It's good that it
found it, but sort of weird it ranks it so low.

Among other things the search engine seems not to give points for the
search words being in the page title (I think it's the only one that
meets this requirement) or to their adjacency.
-- 
Ross Boylan  wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840 hm:  (415) 550-1062

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


[R] Question about looking up names

2003-06-04 Thread Ross Boylan
I think I now understand how R looks up names.  Could anyone tell me if
I have this right?

First it looks up the nested environments created by lexical scoping.
Then, if it gets to the top (.GlobalEnv) it also looks through the list
of things that have been attached.

It never looks in the call stack unless you explicitly ask it to, or
mess with the environment frames.

The reason I ask is that it's not entirely clear to me from the R
Language Definition how these 3 search spaces (environments/lexical
scoping; call stack/dynamic scoping; attach/search list) are related. 
For example the discussion of 3.5.3 (the call stack) observes that
dynamic scoping contradicts the default scoping rules in R.  I spent
some time trying to figure out how it could do both, before deciding it
doesn't.  I suppose the implicit corollary of the contradiction referred
to in 3.5.3--so we don't do that and you must intervene to achieve
dynamic scoping--was obvious to the authors.  It just wasn't obvious to
me.  Since I'm still not sure, I thought I'd check.

Thanks.
-- 
Ross Boylan  wk: (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4  [EMAIL PROTECTED]
Dept of Epidemiology and Biostatistics   hm: (415) 550-1062
University of California, San Francisco
San Francisco, CA 94143-0840

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


Re: [R] Question about looking up names

2003-06-04 Thread Ross Boylan
On Tue, 2003-06-03 at 16:34, Robert Gentleman wrote:

 Also, note that you can get the effect of lexical scope by doing
 things like
 
Do you mean you can get the effects of dynamic scope?

  f- function(x) x+y
  e1 - new.env()
  assign(y, 10, env=e1)
  environment(f) - e1
 
 #now like lexical scope; you can futz with f's environment, assigning,
 # modifying as you like
 


P.S. Thanks to everyone who responded.  So fast!

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