Hi all, I have a function rho.f which gives a list of estimators. I have the following problems. rho.f(0.3) gives me the right answer. However, if I use rho.f(corr[4]) give me a different answer, even though corr[4]==0.3. This prevents me from using a for loop. Can someone give me some help? Thank you very much in advance. Hannah> rho.f(0.3)$est.1 [1] 0 0 0 0 0 0 $est.2 [1] 0 0 0 0 0 0 $est.3 [1] 0 0 0 0 0 0 $est.4 [1] 0 0 0 0 0 0 $est.5 [1] 0 0 0 0 0 0> corr <- seq(0,0.9, by=0.1) > corr[4][1] 0.3> rho.f(corr[4])$est.1 [1] 0.0 0.0 2.5 0.0 5.0 0.0 $est.2 [1] 0.00000 0.00000 0.00000 0.00000 3.72678 0.00000 $est.3 [1] 0.000000 0.000000 0.000000 0.000000 2.777778 0.000000 $est.4 [1] 0.00000 0.00000 0.00000 0.00000 13.88889 0.00000 $est.5 [1] 0.00000 0.00000 0.00000 0.00000 13.88889 0.00000>[[alternative HTML version deleted]]
Hi Hannah, No, we can't help because we have no idea what rho.f does - you didn't provide the requested reproducible example. Without more information, the only thing I can think of is that your function might be ridiculously sensive to numeric precision (though that seems unlikely):> corr <- seq(0,0.9, by=0.1) > identical(0.3, corr[4])[1] FALSE> all.equal(0.3, corr[4])[1] TRUE apply() is likely to be more elegant in this case than a for loop. Sarah On Fri, May 28, 2010 at 9:52 AM, li li <hannah.hlx at gmail.com> wrote:> Hi all, > ? I have a function rho.f which gives a list of estimators. I have the > following problems. > rho.f(0.3) gives me the right answer. However, if I use rho.f(corr[4]) give > me a different > answer, even though corr[4]==0.3. > ? This prevents me from using a for loop. Can someone give me some help? > ? ?Thank you very much in advance. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Hannah > >> rho.f(0.3) > $est.1 > [1] 0 0 0 0 0 0 > $est.2 > [1] 0 0 0 0 0 0 > $est.3 > [1] 0 0 0 0 0 0 > $est.4 > [1] 0 0 0 0 0 0 > $est.5 > [1] 0 0 0 0 0 0 > >> corr <- seq(0,0.9, by=0.1) >> corr[4] > [1] 0.3 > >> rho.f(corr[4]) > $est.1 > [1] 0.0 0.0 2.5 0.0 5.0 0.0 > $est.2 > [1] 0.00000 0.00000 0.00000 0.00000 3.72678 0.00000 > $est.3 > [1] 0.000000 0.000000 0.000000 0.000000 2.777778 0.000000 > $est.4 > [1] ?0.00000 ?0.00000 ?0.00000 ?0.00000 13.88889 ?0.00000 > $est.5 > [1] ?0.00000 ?0.00000 ?0.00000 ?0.00000 13.88889 ?0.00000 >> >-- Sarah Goslee http://www.functionaldiversity.org
Hi: The problem is that input arguments such as corr[4] have to be evaluated within the body of your function, and apparently you haven't written it to do so. Unfortunately, I can't help further because my clairvoyance package is still in the concept development stage. In the meantime, it would be advisable if you could post a *minimal* version of the function that works with 0.3 but fails at corr[4] (as per instructions in the posting guide, which is linked at the bottom of this message. The simpler you make it for others to help, the more likely it will be that you'll get a satisfactory answer. HTH, Dennis On Fri, May 28, 2010 at 6:52 AM, li li <hannah.hlx@gmail.com> wrote:> Hi all, > I have a function rho.f which gives a list of estimators. I have the > following problems. > rho.f(0.3) gives me the right answer. However, if I use rho.f(corr[4]) give > me a different > answer, even though corr[4]==0.3. > This prevents me from using a for loop. Can someone give me some help? > Thank you very much in advance. > Hannah > > > rho.f(0.3) > $est.1 > [1] 0 0 0 0 0 0 > $est.2 > [1] 0 0 0 0 0 0 > $est.3 > [1] 0 0 0 0 0 0 > $est.4 > [1] 0 0 0 0 0 0 > $est.5 > [1] 0 0 0 0 0 0 > > > corr <- seq(0,0.9, by=0.1) > > corr[4] > [1] 0.3 > > > rho.f(corr[4]) > $est.1 > [1] 0.0 0.0 2.5 0.0 5.0 0.0 > $est.2 > [1] 0.00000 0.00000 0.00000 0.00000 3.72678 0.00000 > $est.3 > [1] 0.000000 0.000000 0.000000 0.000000 2.777778 0.000000 > $est.4 > [1] 0.00000 0.00000 0.00000 0.00000 13.88889 0.00000 > $est.5 > [1] 0.00000 0.00000 0.00000 0.00000 13.88889 0.00000 > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]