[R] Problem in applying conditional looping

From: Nadeem Shafique <nadeemshafique_at_gmail.com>
Date: Thu, 03 Jul 2008 10:25:07 +0100


Respected All,

I hope you are enjoying good health, I am tring to write a program in R but could not be very sucessful. My program draws random sample form bivariate normal distribution and then compute a variable PIJ. For certian samples some entries of variable PIJ is apearing as negative, which result in negative variance estimator. I want to introduce a loop in my program that verify the each value of PIJ and if any value in PIJ is negitive return back and draw another sample until a sample is selected that produces all values of PIJ positive.

library(mvtnorm)
library(combinat)
yg <- function(n,m,s) {

n<-10
m<-c(1,2)
s<- matrix(c(4,.2,.2,3), ncol=2)

x <- rmvnorm(n=n, mean=m, sigma=s)
pi <- x[,2]/sum(x[,2])
P <- pi*((1-2*pi)/(1-pi)+sum(pi/(1-pi))) Pi<-t(combn(pi,2))
y<-t(combn(x[,1],2))
PI<-t(combn(P,2))
yht <- y[,1]/PI[,1]+ y[,2]/PI[,2]

*PIJ <- (Pi[,1]*Pi[,2]*(2-Pi[,1]-Pi[,2]))/((1-Pi[,1])*(1-Pi[,2]))*

Eyht <- sum(yht*PIJ)
E2yht <- sum(yht^2*PIJ)
var1 <- E2yht - Eyht^2
var1
}
I want to impose the condition on PIJ(which is a vector). If any value in the PIJ is negative then go back and take another sample until a sample is selected which produces the PIJ positive(all values in PIJ).

I hope now you can understand.

Best Regards,

Nadeem Shafique Butt

        [[alternative HTML version deleted]]



R-help_at_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. Received on Thu 03 Jul 2008 - 09:41:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jul 2008 - 12:31:52 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive