xeris-s_lair

ch 6 exercise

Nov 11th, 2025
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.47 KB | Source Code | 0 0
  1. ##chapter 6 exercise
  2.     ## part a)
  3. > sample=rpois(1000,1)
  4. > samples=as.data.frame(matrix(rbinom(1000*40,1,0.5),ncol = 40))
  5.  ## part b)
  6.     #mean_n=rowMeans(samples[,1:n]) ##row means for a sample size of n
  7. > mean_5=rowMeans(samples[,1:5])
  8. > mean_15=rowMeans(samples[,1:15])
  9. > mean_40=rowMeans(samples[,1:40])
  10.  ## c) 6 lines; means and sd of each sample size ^
  11.     #mean(mean_n) and sd(mean_n) <- where "mean_n" is a generic vector of 1000 means from b ^
  12. > mean(mean_5)
  13. > sd(mean_5)
  14.  
  15. > mean(mean_15)
  16. > sd(mean_15)*15
  17.  
  18. > mean(mean_40)
  19. > sd(mean_40)*40
  20.  ## d) 4 lines; shapiro test a single column of 'samples' & each set of means ^^
  21.     #shapiro.test(samples[,1])
  22. > shapiro.test(samples[,1])
  23. > shapiro.test(samples[,5])
  24. > shapiro.test(samples[,15])
  25. > shapiro.test(samples[,40])
  26.  ## e) gen 'by groups' boxplot; groups are the single col of 'samples' & each set o means ^^^
  27. > boxplot(cbind(samples[,1],samples[,5],samples[,15],samples[,40]))
  28. > boxplot(cbind(samples[,1]))
  29. ##############################################
  30. #  questions                                 #
  31. # 1. <filled out chart on paper>
  32. # 2. population is skewed high, negative
  33. #   n=5 is skewed high, negative
  34. #   n=15 is skewed low, positive
  35. #   n=40 is skewed high, positive
  36. # 3. As the sample size increases I expect the mean of the sample means to become closer to the population mean.
  37. #   The results from question 1 support this by having the sample mean increase as the sample size increased from 5 to 15 to 40
Advertisement
Add Comment
Please, Sign In to add comment