Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x <- vector(length = 100)
- x1 <- vector(length = 100)
- x2 <- vector(length = 100)
- x3 <- vector(length = 100)
- x4 <- vector(length = 100)
- x4 <- vector(length = 100)
- #нормальное
- n_mean <- vector (length = 1000)
- n_mad <- vector (length = 1000)
- n_med <- vector (length = 1000)
- n_sd <- vector(length = 1000)
- n_iqr <- vector(length = 1000)
- n_uq <- vector(length = 1000)
- n_lq <- vector(length = 1000)
- n_count_mean <- 0
- n_count_med <- 0
- n_count_tukey <- 0
- for(i in 1:1000)
- {
- x2<-rnorm(100, mean = 0, sd =1)
- x2<-sort(x2)
- n_mean[i] <- mean(x2)
- n_med[i] <- median(x2)
- n_sd[i] <- sd(x2)
- n_mad[i] <- mad(x2, center = median(x2))
- n_iqr[i] <- IQR(x2)
- n_lq[i] <- x2[25]
- n_uq[i] <- x2[75]
- for (j in 1:100){
- if (((abs(x2[j] - n_mean[i]) / n_sd[i]) > 3)){
- n_count_mean = n_count_mean + 1
- }
- if (((abs(x2[j] - n_med[i]) / n_mad[i]) > 3)){
- n_count_med = n_count_med + 1
- }
- if ((x2[j] > (n_uq[i] + 1.5*n_iqr[i])) | (x2[j] < (n_lq[i] - 1.5*n_iqr[i])) ) {
- n_count_tukey = n_count_tukey + 1
- }
- }
- }
- boxplot(x2, horizontal = TRUE)
- #равномерное
- u_mean <- vector (length = 1000)
- u_mad <- vector (length = 1000)
- u_med <- vector (length = 1000)
- u_sd <- vector(length = 1000)
- u_iqr <- vector(length = 1000)
- u_uq <- vector(length = 1000)
- u_lq <- vector(length = 1000)
- u_count_mean <- 0
- u_count_med <- 0
- u_count_tukey <- 0
- for(i in 1:1000)
- {
- x5<-runif(100, min = -sqrt(3), max = sqrt(3))
- x5<-sort(x)
- u_mean[i] <- mean(x5)
- u_med[i] <- median(x5)
- u_sd[i] <- sd(x5)
- u_mad[i] <- mad(x5, center = median(x5))
- u_iqr[i] <- IQR(x5)
- u_lq[i] <- x5[25]
- u_uq[i] <- x5[75]
- for (j in 1:100){
- if (((abs(x5[j] - u_mean[i]) / u_sd[i]) > 3)){
- u_count_mean = u_count_mean + 1
- }
- if (((abs(x5[j] - u_med[i]) / u_mad[i]) > 3)){
- u_count_med = u_count_med + 1
- }
- if ((x5[j] > (u_uq[i] + 1.5*u_iqr[i])) || (x5[j] < (u_lq[i] - 1.5*u_iqr[i])) ) {
- u_count_tukey = u_count_tukey + 1
- }
- }
- }
- #лаплас
- l_mean <- vector (length = 1000)
- l_mad <- vector (length = 1000)
- l_med <- vector (length = 1000)
- l_sd <- vector(length = 1000)
- l_iqr <- vector(length = 1000)
- l_uq <- vector(length = 1000)
- l_lq <- vector(length = 1000)
- l_count_mean <- 0
- l_count_med <- 0
- l_count_tukey <- 0
- for(i in 1:1000)
- {
- x4<-rlaplace(100,0,1/sqrt(2))
- x4<-sort(x4)
- l_mean[i] <- mean(x4)
- l_med[i] <- median(x4)
- l_sd[i] <- sd(x4)
- l_mad[i] <- mad(x4, center = median(x4))
- l_iqr[i] <- IQR(x4)
- l_lq[i] <- x4[25]
- l_uq[i] <- x4[75]
- for (j in 1:100){
- if (((abs(x4[j] - l_mean[i]) / l_sd[i]) > 3)){
- l_count_mean = l_count_mean + 1
- }
- if (((abs(x4[j] - l_med[i]) / l_mad[i]) > 3)){
- l_count_med = l_count_med + 1
- }
- if ((x4[j] > (l_uq[i] + 1.5*l_iqr[i])) | (x4[j] < (l_lq[i] - 1.5*l_iqr[i])) ) {
- l_count_tukey = l_count_tukey + 1
- }
- }
- }
- #коши
- c_mean <- vector (length = 1000)
- c_mad <- vector (length = 1000)
- c_med <- vector (length = 1000)
- c_sd <- vector(length = 1000)
- c_iqr <- vector(length = 1000)
- c_uq <- vector(length = 1000)
- c_lq <- vector(length = 1000)
- c_count_mean <- 0
- c_count_med <- 0
- c_count_tukey <- 0
- for(i in 1:1000)
- {
- x3<-rcauchy(100, location = 0, scale = 1)
- x3<-sort(x3)
- c_mean[i] <- mean(x3)
- c_med[i] <- median(x3)
- c_sd[i] <- sd(x3)
- c_mad[i] <- mad(x3, center = median(x3))
- c_iqr[i] <- IQR(x3)
- c_lq[i] <- x3[25]
- c_uq[i] <- x3[75]
- for (j in 1:100){
- if (((abs(x3[j] - c_mean[i]) / c_sd[i]) > 3)){
- c_count_mean = c_count_mean + 1
- }
- if (((abs(x3[j] - c_med[i]) / c_mad[i]) > 3)){
- c_count_med = c_count_med + 1
- }
- if ((x3[j] > (c_uq[i] + 1.5*c_iqr[i])) | (x3[j] < (c_lq[i] - 1.5*c_iqr[i])) ) {
- c_count_tukey = c_count_tukey + 1
- }
- }
- }
- #gross error model
- g_mean <- vector (length = 1000)
- g_mad <- vector (length = 1000)
- g_med <- vector (length = 1000)
- g_sd <- vector(length = 1000)
- g_iqr <- vector(length = 1000)
- g_uq <- vector(length = 1000)
- g_lq <- vector(length = 1000)
- g_count_mean <- 0
- g_count_med <- 0
- g_count_tukey <- 0
- for (i in 1:1000) {
- for (j in 1:100) {
- alpha <- runif(1,0,1)
- if (alpha > 0.1) {
- x[j] <- rnorm(1,0,1)
- }
- else {
- x[j] <- rnorm(1,0,10)
- x1[j] <- rnorm(1,0,10)
- }
- }
- x<-sort(x)
- x1<-sort(x1)
- g_mean[i] <- mean(x)
- g_med[i] <- median(x)
- g_sd[i] <- sd(x)
- g_mad[i] <- mad(x, center = median(x))
- g_iqr[i] <- IQR(x)
- g_lq[i] <- x[25]
- g_uq[i] <- x[75]
- for (k in 1:100){
- if (((abs(x1[k] - g_mean[i]) / g_sd[i]) > 3)){
- g_count_mean = g_count_mean + 1
- }
- if (((abs(x1[k] - g_med[i]) / g_mad[i]) > 3)){
- g_count_med = g_count_med + 1
- }
- if ((x1[k] > (g_uq[i] + 1.5*g_iqr[i])) | (x1[k] < (g_lq[i] - 1.5*g_iqr[i])) ) {
- g_count_tukey = g_count_tukey + 1
- }
- }
- }
- boxplot(x, x2, x3, x4, x5, horizontal = TRUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement