SHARE
TWEET

Untitled

a guest Jun 24th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set.seed(2019)
  2. m = 10^6;  n = 5;  mu = 50;  sg = 7
  3. x = rnorm(m*n, mu, sg)
  4. MAT = matrix(x, nrow=m)      # each row a sample of             n
  5. v1 = apply(MAT, 1, var)      # uses sample mean
  6. v2 = rowSums((MAT - mu)^2)/n # uses population mean
  7. q1 = (n-1)*v1 /sg^2
  8. q2 = n*v2 / sg^2
  9.  
  10. par(mfrow=c(1,2))
  11. hist(q1, prob=T, br=50, col="skyblue2", ylim=c(0,.2))
  12.  curve(dchisq(x, n-1), add=T, lwd=2)
  13.  curve(dchisq(x, n), add=T, col="red", lwd=2, lty="dotted")
  14. hist(q2, prob=T, br=50, col="skyblue2")
  15.   curve(dchisq(x, n), add=T, lwd=2)
  16. par(mfrow=c(1,1))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top