I'm trying to take a stratified random sample of a data set that includes indicators with very different hit rates. When I attempt simply stratified random sampling, groups with low hit rates do not make it into the resulting sample. Should I be able to correct this by giving greater weight to the observations in which the "low hit rate" indicator variables have instances?
When I try to include weights in my sampling, I keep receiving errors:
dat <- iris
dat$ind <- ifelse(dat$Petal.Length > 1.5, 1, 0)
dat$ind2 <- ifelse(dat$Sepal.Length > 7, 1, 0)
summary(dat$ind)
summary(dat$ind2) # ind2 occurs significantly less than ind
sample <- dat %>% group_by(Species, ind, ind2) %>% sample_frac(size = 0.05)
How can I include weights that better balance ind and ind2 inclusion in the sample?
Aucun commentaire:
Enregistrer un commentaire