Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. x <- vector(length = 100)
  2. x1 <- vector(length = 100)
  3. x2 <- vector(length = 100)
  4. x3 <- vector(length = 100)
  5. x4 <- vector(length = 100)
  6. x4 <- vector(length = 100)
  7.  
  8. #нормальное
  9. n_mean <- vector (length = 1000)
  10. n_mad <- vector (length = 1000)
  11. n_med <- vector (length = 1000)
  12. n_sd <- vector(length = 1000)
  13. n_iqr <- vector(length = 1000)
  14. n_uq <- vector(length = 1000)
  15. n_lq <- vector(length = 1000)
  16. n_count_mean <- 0
  17. n_count_med <- 0
  18. n_count_tukey <- 0
  19. for(i in 1:1000)
  20. {
  21. x2<-rnorm(100, mean = 0, sd =1)
  22. x2<-sort(x2)
  23. n_mean[i] <- mean(x2)
  24. n_med[i] <- median(x2)
  25. n_sd[i] <- sd(x2)
  26. n_mad[i] <- mad(x2, center = median(x2))
  27. n_iqr[i] <- IQR(x2)
  28. n_lq[i] <- x2[25]
  29. n_uq[i] <- x2[75]
  30. for (j in 1:100){
  31. if (((abs(x2[j] - n_mean[i]) / n_sd[i]) > 3)){
  32. n_count_mean = n_count_mean + 1
  33. }
  34. if (((abs(x2[j] - n_med[i]) / n_mad[i]) > 3)){
  35. n_count_med = n_count_med + 1
  36. }
  37. if ((x2[j] > (n_uq[i] + 1.5*n_iqr[i])) | (x2[j] < (n_lq[i] - 1.5*n_iqr[i])) ) {
  38. n_count_tukey = n_count_tukey + 1
  39. }
  40. }
  41.  
  42. }
  43. boxplot(x2, horizontal = TRUE)
  44.  
  45. #равномерное
  46. u_mean <- vector (length = 1000)
  47. u_mad <- vector (length = 1000)
  48. u_med <- vector (length = 1000)
  49. u_sd <- vector(length = 1000)
  50. u_iqr <- vector(length = 1000)
  51. u_uq <- vector(length = 1000)
  52. u_lq <- vector(length = 1000)
  53. u_count_mean <- 0
  54. u_count_med <- 0
  55. u_count_tukey <- 0
  56. for(i in 1:1000)
  57. {
  58. x5<-runif(100, min = -sqrt(3), max = sqrt(3))
  59. x5<-sort(x)
  60. u_mean[i] <- mean(x5)
  61. u_med[i] <- median(x5)
  62. u_sd[i] <- sd(x5)
  63. u_mad[i] <- mad(x5, center = median(x5))
  64. u_iqr[i] <- IQR(x5)
  65. u_lq[i] <- x5[25]
  66. u_uq[i] <- x5[75]
  67. for (j in 1:100){
  68. if (((abs(x5[j] - u_mean[i]) / u_sd[i]) > 3)){
  69. u_count_mean = u_count_mean + 1
  70. }
  71. if (((abs(x5[j] - u_med[i]) / u_mad[i]) > 3)){
  72. u_count_med = u_count_med + 1
  73. }
  74. if ((x5[j] > (u_uq[i] + 1.5*u_iqr[i])) || (x5[j] < (u_lq[i] - 1.5*u_iqr[i])) ) {
  75. u_count_tukey = u_count_tukey + 1
  76. }
  77. }
  78. }
  79.  
  80. #лаплас
  81. l_mean <- vector (length = 1000)
  82. l_mad <- vector (length = 1000)
  83. l_med <- vector (length = 1000)
  84. l_sd <- vector(length = 1000)
  85. l_iqr <- vector(length = 1000)
  86. l_uq <- vector(length = 1000)
  87. l_lq <- vector(length = 1000)
  88. l_count_mean <- 0
  89. l_count_med <- 0
  90. l_count_tukey <- 0
  91. for(i in 1:1000)
  92. {
  93. x4<-rlaplace(100,0,1/sqrt(2))
  94. x4<-sort(x4)
  95. l_mean[i] <- mean(x4)
  96. l_med[i] <- median(x4)
  97. l_sd[i] <- sd(x4)
  98. l_mad[i] <- mad(x4, center = median(x4))
  99. l_iqr[i] <- IQR(x4)
  100. l_lq[i] <- x4[25]
  101. l_uq[i] <- x4[75]
  102. for (j in 1:100){
  103. if (((abs(x4[j] - l_mean[i]) / l_sd[i]) > 3)){
  104. l_count_mean = l_count_mean + 1
  105. }
  106. if (((abs(x4[j] - l_med[i]) / l_mad[i]) > 3)){
  107. l_count_med = l_count_med + 1
  108. }
  109. if ((x4[j] > (l_uq[i] + 1.5*l_iqr[i])) | (x4[j] < (l_lq[i] - 1.5*l_iqr[i])) ) {
  110. l_count_tukey = l_count_tukey + 1
  111. }
  112. }
  113.  
  114. }
  115.  
  116. #коши
  117. c_mean <- vector (length = 1000)
  118. c_mad <- vector (length = 1000)
  119. c_med <- vector (length = 1000)
  120. c_sd <- vector(length = 1000)
  121. c_iqr <- vector(length = 1000)
  122. c_uq <- vector(length = 1000)
  123. c_lq <- vector(length = 1000)
  124. c_count_mean <- 0
  125. c_count_med <- 0
  126. c_count_tukey <- 0
  127. for(i in 1:1000)
  128. {
  129. x3<-rcauchy(100, location = 0, scale = 1)
  130. x3<-sort(x3)
  131. c_mean[i] <- mean(x3)
  132. c_med[i] <- median(x3)
  133. c_sd[i] <- sd(x3)
  134. c_mad[i] <- mad(x3, center = median(x3))
  135. c_iqr[i] <- IQR(x3)
  136. c_lq[i] <- x3[25]
  137. c_uq[i] <- x3[75]
  138. for (j in 1:100){
  139. if (((abs(x3[j] - c_mean[i]) / c_sd[i]) > 3)){
  140. c_count_mean = c_count_mean + 1
  141. }
  142. if (((abs(x3[j] - c_med[i]) / c_mad[i]) > 3)){
  143. c_count_med = c_count_med + 1
  144. }
  145. if ((x3[j] > (c_uq[i] + 1.5*c_iqr[i])) | (x3[j] < (c_lq[i] - 1.5*c_iqr[i])) ) {
  146. c_count_tukey = c_count_tukey + 1
  147. }
  148. }
  149. }
  150.  
  151. #gross error model
  152. g_mean <- vector (length = 1000)
  153. g_mad <- vector (length = 1000)
  154. g_med <- vector (length = 1000)
  155. g_sd <- vector(length = 1000)
  156. g_iqr <- vector(length = 1000)
  157. g_uq <- vector(length = 1000)
  158. g_lq <- vector(length = 1000)
  159. g_count_mean <- 0
  160. g_count_med <- 0
  161. g_count_tukey <- 0
  162. for (i in 1:1000) {
  163. for (j in 1:100) {
  164. alpha <- runif(1,0,1)
  165. if (alpha > 0.1) {
  166. x[j] <- rnorm(1,0,1)
  167. }
  168. else {
  169. x[j] <- rnorm(1,0,10)
  170. x1[j] <- rnorm(1,0,10)
  171. }
  172. }
  173. x<-sort(x)
  174. x1<-sort(x1)
  175. g_mean[i] <- mean(x)
  176. g_med[i] <- median(x)
  177. g_sd[i] <- sd(x)
  178. g_mad[i] <- mad(x, center = median(x))
  179. g_iqr[i] <- IQR(x)
  180. g_lq[i] <- x[25]
  181. g_uq[i] <- x[75]
  182. for (k in 1:100){
  183. if (((abs(x1[k] - g_mean[i]) / g_sd[i]) > 3)){
  184. g_count_mean = g_count_mean + 1
  185. }
  186. if (((abs(x1[k] - g_med[i]) / g_mad[i]) > 3)){
  187. g_count_med = g_count_med + 1
  188. }
  189. if ((x1[k] > (g_uq[i] + 1.5*g_iqr[i])) | (x1[k] < (g_lq[i] - 1.5*g_iqr[i])) ) {
  190. g_count_tukey = g_count_tukey + 1
  191. }
  192. }
  193. }
  194.  
  195. boxplot(x, x2, x3, x4, x5, horizontal = TRUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement