[R] using list to pass argument to function

TyagiAnupam@aol.com TyagiAnupam at aol.com
Sat Nov 16 23:52:50 CET 2002


Thanks for the clarifications. All the symbols below refer to scalars, unless they are assigned to a non-scalar explicitly.

I am trying to do the following. Would like to avoid using for-loops where possible, so that program can also be used in S efficiently.

1. Create an CxC contingency table (matrix) with certain cell frequencies: Is there are better way of assigning "population" probabilities of cells to contingency table and sampling from it? 
2. Use the contingency table sampling function suggested by Ripley to create a sample ("population sample"), of size n.
3. Compute row and col frequencies and estimates of marginal probabilities: below f1 computes c,d for 2x2 (for a row and a col, the other can be calcualted by 1-c, 1-d inside a fucntion that uses them: f3args).
4. Compute K statistics based on marginal probabilities: f3args does this.
5. use R bootstrap samples of size n based on marginal probabilities to compute standard errors for the statistics estimates.
6. for each population sample use R samples based on *population cell probabilities* and compute same std errs (SD in this case) ("MC-SD"). 
7. Do this for M samples from population k <- below attempts that (sorry for overloading on R, that should be different, say S): that is, repeat steps 2--6, M times (M is the value of S variable).
8. Store the MxK statistics from popoulation samples, their std. errs, and corresponding MC-SD's in a matrix for use,((Mx(3xK)) matrix.

A question: I think the point is to differentiate between a vector of arguments and a list of arguments, because a vector of arguments is treated as value of one argument. Right? Then, how does one pass a list as a value for one argument, without converting it into a vector?

Another Question: what is a good way to update R from disk (not online--can't get the wireless drivers to work on SuSE 7.1. So, have to use windows for internet.)?

---Anupam.

******Brian Ripley wrote*******

> A brief follow up on an earlier posting. Thanks for the earlier suggestion. 
> 
> How does it matter if I pass a list or a vector of 
> arguments to a function that is written to take individual arguments: 


Yes, it does. 


> f3args <- function(a1, a2, a3) { definition} 
> 
> f1 <- function(b1, b2) { 
> calculations 
> n <- samplesize 
> b<- someestimate 
> c<- anotherestimate 
> d <- c(n, b, c) 
> h <- sapply(rep(d, R), f3args) 
> } 
> 
> e <- c(m, n) 
> 
> k <- sapply(rep(e, R), f1) 
> 
> Is there a problem with this. 


It seems to be incomplete, so it's hard to tell what you intended. For 
example, R is undefined. But you are not passing a 
second argument to f1. You do that via an extra argument to sapply. 


> Can one pass a vector of arguments to a 
> fucntion that is written for individual arguments. What would be a good way 
> for doing this? 


?do.call, 


as in do.call("f1", as.list(e)) 



-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/


********************
Pleasures, like flowers, may wither and decay, 
And yet the root perennial may be.
   --H.W.Longfellow, ``Memories"
*******************
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list