0
$\begingroup$

I'm running a Kruskal test with Conover post-hoc test to assess if there is a statistically significant difference between a numerical and a categorical variable with R.
I previously created boxplots and I can see that the boxes mostly overlap each other (some more and some less), but the test returns that there is a significant difference. I suspect that this result is affected by the large number of samples in each category (respectively: 6180, 89694, 24196, 34947) which makes the test very sensible.

For this reason I'd like to try to repeat the same test with a subset of the dataset to conclude that there is in fact a difference, but it is limited and only significant with large sample size. Of course the subset test would not be made on a single subset but on a large number of them to account for the random sampling differences.

Could this workflow make sense and, by your knowledge, has it been already done by someone? If it makes sense, how can I sample a representative subset? Thanks!

$\endgroup$

1 Answer 1

0
$\begingroup$

Try this

dt<- as.data.frame(cbind(category, y))

per<-25  #percntage of sample out of each category
sample<- data.frame(category=character(), y= double())  #Creating empty dataframe for collecting the sample

n<- length(levels(dt$category))
for (i in 1:n) {
  new<- dt[sample(rownames(dt[category==levels(dt$category)[i],]), 
                  ceiling(0.01*per*nrow(dt[category==levels(dt$category)[i],]))),]
  sample<-rbind(sample, new)
}


write.csv(sample, 'sample.csv')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.