Problem in conditional looping

View: New views
2 Messages — Rating Filter:   Alert me  

Problem in conditional looping

by Nadeem Shafique :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Respected All,

I am writing a program in R and facing some problem with applying "if statment".

Program first draw random numbers from bivariate normal distribution
        then compute variable say Pi and Pij from that sample and
then further computation
.....
.....
.....
In some samples Pij is appearing with negitive sign and ultimately
resulted in an negative variance estimator.  Now i want to design the
program like this if the Pij is negative then go back and draw another
sample until we get a sample that produces positive Pij and then move
forward for further processing.

Best Regards,

Nadeem Shafique Butt

______________________________________________
R-devel@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Re: Problem in conditional looping

by Mathieu Ribatet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why don't you consider a "while" loop e.g.

while (Pij < 0)
 ##Then you resample according to your code

Nadeem Shafique a écrit :

> Respected All,
>
> I am writing a program in R and facing some problem with applying "if statment".
>
> Program first draw random numbers from bivariate normal distribution
>         then compute variable say Pi and Pij from that sample and
> then further computation
> .....
> .....
> .....
> In some samples Pij is appearing with negitive sign and ultimately
> resulted in an negative variance estimator.  Now i want to design the
> program like this if the Pij is negative then go back and draw another
> sample until we get a sample that produces positive Pij and then move
> forward for further processing.
>
> Best Regards,
>
> Nadeem Shafique Butt
>
> ______________________________________________
> R-devel@... mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>  

--
Institute of Mathematics
Ecole Polytechnique Fédérale de Lausanne
STAT-IMA-FSB-EPFL, Station 8
CH-1015 Lausanne   Switzerland
http://stat.epfl.ch/
Tel: + 41 (0)21 693 7907

______________________________________________
R-devel@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
LightInTheBox - Buy quality products at wholesale price