
# ESTIMATION two-stage sampling {SI,SI}


tableR=read.csv2(".../Data2stCCS.csv")
#or
tableR=read.csv2(file.choose())

ech=tableR[tableR$Dummy_2st==1,]
attach(ech)

library(survey)

n_m=320; n_d=25; N_m=544; N_d=365

######################################## V2d
infoplan <- svydesign ( id=~ID_i+ID_k , fpc=~N_M+N_D, weights =(N_m*N_d) /(n_m*n_d ), data=ech )
( yxratio <- svyratio(~Yik+Zik ,~Xik , infoplan) )
SE(yxratio)^2
confint(yxratio)
#confint(yxratio,level=0.90)

######################################## V2d,a
infoplan <- svydesign ( id=~ID_i , fpc=~N_M, weights =(N_m*N_d) /(n_m*n_d ), data=ech )
( yxratio <- svyratio(~Yik+Zik ,~Xik , infoplan) )
SE(yxratio)^2
confint(yxratio)

