Re: [R] ignoring objects containing NaN's in a recursive function

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Wed 15 Mar 2006 - 06:31:08 EST


if(any(is.nan(...)))... ##repeat

However,

  1. Have you tried RSiteSearch('permutation test',restr='function') to see what's already there?
  2. I suspect that there are better ways to do this. In particular, generating all random whatevers at once is way more efficient than repeated calls;
  3. It is **not** a permutation test, since there is no guarantee that all the calls to sample() generate different permutations. (depending on the sample size, this may be nitpicking).

Cheers,

"The business of the statistician is to catalyze the scientific learning process." - George E. P. Box    

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Mills, Jason
> Sent: Tuesday, March 14, 2006 11:00 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] ignoring objects containing NaN's in a recursive function
>
> Hi-
>
> General question:
> I have written a function that performs a permutation test. I use the
> function "sample" to randomize my data, then I call on
> another function
> I wrote to analyze the randomized data. This process repeats "n"
> times-- 10, 100 or whatever.
>
> The function applied to the randomized data creates a matrix and
> sometimes the matrix contains NaN's. I would like my
> function to simply
> ignore any matrices that contain NaN's and continue to cycle until it
> has generated "n" matrices without any NaN's. I am aware of the
> function "is.nan", but I'm not sure how to fit it in.
>
>
>
> Specifics:
> Here's the section of code that needs improvement:
>
> for (i in 1:n){
> S[,,]= sample (Y[,,])
> dig=auto(S,H,J,T)
> out[i,]=dig[1,]}
>
>
> n= number of randomizations
> S= array to store randomized data
> Y= original data array
> dig= the matrix returned by the function "auto"
> out= matrix that collects the first row of each "dig" matrix up to "n"
>
> Sometimes "dig" includes NaN's. I want the function to ignore those
> "dig"s but keep working until it has generated "n" matrices
> that contain
> no NaN's.
>
> How could I do this?
>
> Thanks.
>
> Jason Mills
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 15 07:24:03 2006

This archive was generated by hypermail 2.1.8 : Wed 15 Mar 2006 - 09:09:19 EST