What is the best way to show that when sampling from a normal distribution, the sample mean and sample variance are independent? I know the theory behind this result, I would like to show it using a simulation in R. For now what I did is:
R<-1000
n<-10
mu<-5
sd<-3
mc<-s2<-vector(mode="numeric",length=R)
for(i in 1:R)
{
x<-rnorm(n,mu,sd)
mc[i]<-mean(x)
s2[i]<-var(x)
}
plot(mc,s2)
But i know this is not enough to prove independence. Is there any better way? More in general, i would like to know how to show in R that two random variables are independent. I hope this is not a stupid question, I just started learning R recently.

set.seedto give a replicable analysis. – Ben Feb 24 '24 at 20:59Rcode to do this at https://stats.stackexchange.com/a/106083/919. – whuber Feb 24 '24 at 22:52Hmiscpackagehoeffdfunction. – Frank Harrell Feb 25 '24 at 12:51