stats4sd / Sampling-Decision-Assistant

GNU General Public License v3.0
0 stars 0 forks source link

Review sampling stage calculator code for cases when single stage #165

Closed chrismclarke closed 6 years ago

chrismclarke commented 6 years ago

How should the sample number be calculated when there is only 1 stage?

I assume this is much simpler, but can it be calculated from existing code?

Also, currently number of stages variable doesn't seem to be used in the code anywhere, should it?

current code (javascript, but v similar to R):

if (input.type == "average value") { SRSn = (input.sd * qnorm(1 - (1 - input.conf) / 2) / input.moe) 2 } if (input.type == "proportion") { p1 = input.prop / 100 moe = input.moe / 100 SRSn = (Math.sqrt(p1 (1 - p1)) qnorm(1 - (1 - input.conf) / 2) / moe) 2 } SRSn_FPC = Math.ceil((SRSn input.Population) / (SRSn + input.Population - 1)) DEFF1 = (1 + (input.nHH - 1) input.rho) FinalstageN = SRSn DEFF1 FinalstageN_FPC = Math.ceil((FinalstageN input.Population) / (FinalstageN + input.Population - 1)) stage2N = Math.ceil(FinalstageN_FPC / input.nHH)

sdumble1 commented 6 years ago

If there's only 1 stage you basically just stop doing calculations half way through - since there is no design effect, or number of clusters to be calculated. Probably worth explicitly pointing that out in the output, so define those values to be NA.

So something like this - assuming you have a variable called something like nstages?

if (input.type == "average value") { SRSn = (input.sd * qnorm(1 - (1 - input.conf) / 2) / input.moe) 2 } if (input.type == "proportion") { p1 = input.prop / 100 moe = input.moe / 100 SRSn = (Math.sqrt(p1 (1 - p1)) qnorm(1 - (1 - input.conf) / 2) / moe) 2 } SRSn_FPC = Math.ceil((SRSn input.Population) / (SRSn + input.Population - 1)) if (nstages==1){ FinalstageN = SRSn FinalstageN_FPC = SRSn_FPC DEFF1 = NA stage2N = NA } if (nstages>1){ DEFF1 = (1 + (input.nHH - 1) input.rho) FinalstageN = SRSn DEFF1 FinalstageN_FPC = Math.ceil((FinalstageN input.Population) / (FinalstageN + input.Population - 1)) stage2N = Math.ceil(FinalstageN_FPC / input.nHH) }

chrismclarke commented 6 years ago

Great, exactly what I was hoping