# How to do Smart sampling using python/R

I have 1000 samples( i.e 1000 villages name) and I want to select only 100 sample villages for study .

i.e

A1,A2,A3....A600

B1,B2,B3...B300

C1,C2,C3...C100

Where A1,A2.... are high risk villages,

B1,B2,.... are medium risk villages

and C1,C2... are low risk villages.

I want to use smart sampling, for example :

for high risk villages out of 600 ,I want to select 60% samples, ( i. e 60 samples)

for medium risk villages out of 300 , I want to select only 30% samples.

for low risk villages out of 100 , I want to select only 10% samples.

can you guide me how can I select this type of sampling? I am using python/R.

It seems that you want to sample from each dataset proportional to the size of the respective dataset. If you randomly sample from the combined dataset, you will, on average, maintain the proportion.

If you really want to make sure that the sampling procedure obeys the propotions, this is some code that should give an idea how to that:

# some random data
datasetList = list()
datasetList[[1]] = data.frame(id = round(runif(600)*1000), Variable_1 = runif(600))
datasetList[[2]] = data.frame(id = round(runif(300)*1000), Variable_1 = runif(300))
datasetList[[3]] = data.frame(id = round(runif(100)*1000), Variable_1 = runif(100))
# merge to full set
fullSet = rbind(datasetList[[1]],datasetList[[2]])
fullSet = rbind(fullSet,datasetList[[3]])
# compute total number of rows
totalNRow = nrow(datasetList[[1]]) + nrow(datasetList[[2]]) + nrow(datasetList[[3]])
# select your desired sample size
sampleSize = 100
# initialization
samplesPerDataset = vector()
myInd = list()
mySamples = list()
#loop
for (ii in 1:3)
{
# compute sample number for each set
samplesPerDataset[ii] = round(nrow(datasetList[[ii]])/totalNRow * sampleSize)
# randomize sampled indices per set
myInd[[ii]] = sample(nrow(datasetList[[ii]]),samplesPerDataset[ii])
# select rows
mySamples[[ii]] = datasetList[[ii]][myInd[[ii]],]
}
# merge to full set
sampleSet = rbind(mySamples[[1]],mySamples[[2]])
sampleSet = rbind(sampleSet,mySamples[[3]])