######################################### # R Function for Taking a PPS Sample # # # # Randomized Systematic PPS Method # # # # Input: x=(x_1,x_2,...,x_N) # # n: sample size # # Output: s, the set of sampled units # # # # Note: Require x_i>0 and x_i/X < 1/n # # where X= sum_1^N x_i # # # # Written by Changbao Wu, July, 2006 # ######################################### syspps=function(x,n){ ## ##Population is first randomized! ## N=length(x) U=sample(N,N) xx=x[U] z=rep(0,N) for(i in 1:N) z[i]=n*sum(xx[1:i])/sum(x) r=runif(1) s=numeric() for(i in 1:N){ if(z[i]>=r){ s=c(s,U[i]) r=r+1 } } return(s[order(s)]) }