A Hint for Beginners
It easy to evaluate performance any estimation procedure in simple random sampling by using a bootstrapping approaching, these codes are might be helpful for researchers (Errors or Omissions are expected).
Please write your suggestions in the comment box
#############################
############################
library(sampling)
library(MASS)
##########################
sigma=matrix(c(6,3,3,8),2,2)
mu=c(0,1)
data=mvrnorm(10,mu,sigma);
x=data[,2];y=data[,1]
DF=data.frame(y,x)
N=nrow(DF);mx=mean(x);my=mean(y);sy=var(y);
sx=var(x);cxy=cov(x,y)/(mx*my);rhoxy=cor(y,x)
cx=sd(x)/mx;cy=sd(y)/my;
attach(DF)
####################################
n=50; r=30; N=1000; H=5000
##########################
thetarN=(1/r-1/N);thetarn=(1/r-1/n);
#####################################
beta=cov(y,x)/sx
v1=(1)/(1+cy^2*(thetarN-thetarn*rhoxy^2))
v2=(my*cy*rhoxy)/(mx*cx*(1+cy^2*(thetarN-thetarn*rhoxy^2)))
###############################################
mxn=NULL;mxr=NULL;myn=NULL;myr=NULL;
################################
mxn=c();mxr=c();myn=c();myr=c();z1=c();z2=c();z3=c();
####################################
for(i in 1:H){
S1=DF[sample(1:N, n, replace=T),]
Sr=S1[sample(1:n, r, replace=T),]
mxn[i]=mean(S1$x);mxr[i]=mean(Sr$x);myr[i]=mean(Sr$y);
z1[i]=myr[i]
z2[i]=(myr[i]+beta*(mxn[i]-mxr[i]) )
z3[i]=(v1*myr[i]+v2*(mxn[i]-mxr[i]) )
}
mse1=(sum((z1-my)^(2)))/H
mse2=(sum((z2-my)^(2)))/H
mse3=(sum((z3-my)^(2)))/H
mse1/mse2*100;mse1/mse3*100;
For bootstrapping please visit
Thanks, Your suggestions will be appreciated
Comments
Post a Comment