##################################################### # R codes for solving g_3(lambda)=0 in Wu (2005) # ##################################################### ##################################################### # n=(n_1,...,n_H) # # W=(W_1,...W_H) # # x: sample data matrix of auxiliary variables # # X: population mean vector of auxiliary variables # # ds: design weights # # # # M: solution to g_3(lambda)=0 # # phi: final PEL weights # # # # Written by Changbao Wu, March, 2000 # ##################################################### nst<-sum(n) k<-length(n)-1 ntot<-rep(0,k) ntot[1]<-n[1] for(j in 2:k) ntot[j]<-ntot[j-1]+n[j] ist<-matrix(0,nst,k) ist[1:n[1],1]<-1 for(j in 2:k) ist[(ntot[j-1]+1):ntot[j],j]<-1 uhi<-cbind(ist,x) mu<-c(W[1:k],X) whi<-rep(W[1],n[1]) for(j in 2:(k+1)) whi<-c(whi,rep(W[j],n[j])) dhi<-whi*ds M<-Lag2(uhi,dhi,mu) phi<-as.vector(ds/(1+(uhi-rep(1,nst)%*%t(mu))%*%M))