r - Sampling package - strange behaviour of strata function -
in function strata declare numer of units drawn each stratum , after executing strange result. numer of units different declared.
here example:
library(sampling) data(swissmunicipalities) st=strata(swissmunicipalities,stratanames=c("reg"),size=c(30,20,45,15,20,11,44),method="srswor") result:
> table(st$reg) 1 2 3 4 5 6 7 20 15 45 30 20 11 44 should be:
30,20,45,15,20,11,44 i grateful anwsers.
if read page of strata function, have :
size: vector of stratum sample sizes (in order in strata given in input data set).
let's check order in numbers in reg variable
require(sampling) data(swissmunicipalities) swiss <- swissmunicipalities unique(swiss$reg) ## [1] 4 1 3 2 5 6 7 as can see not naturally orderered, have 2 options.
first options, write size in same order original data.
size <- c(15, 30, 45, 20, 20, 11, 44) st <- strata(swiss, stratanames = "reg", size = size, method = "srswor") table(st$reg) ## 1 2 3 4 5 6 7 ## 30 20 45 15 20 11 44 second option, order data first , keep size first wrote it
swiss <- swiss[order(swiss$reg), ] st <- strata(swiss, stratanames = "reg", size = c(30, 20, 45, 15, 20, 11, 44), method = "srswor") table(st$reg) ## 1 2 3 4 5 6 7 ## 30 20 45 15 20 11 44
Comments
Post a Comment