1 Giriş

Sonlandırma kriteriyaları CAT sistemlərinin effektivliyi və ədalətliliyi üçün kritik əhəmiyyət daşıyır. Düzgün sonlandırma kriteriyaları test keyfiyyətini optimum səviyyədə saxlayaraq test uzunluğunu minimuma endirir və test alıcıları üçün ən yaxşı təcrübəni təmin edir.

CAT-da sonlandırma qərarı müxtəlif faktorları nəzərə almalıdır: qiymətləndirmə dəqiqliyi, test uzunluğu, tapşırıq bankının vəziyyəti və praktiki məhdudiyyətlər. Bu bölmədə həm fərdi həm də kombinə edilmiş sonlandırma kriteriyalarını öyrənəcəksiniz.

2 Sonlandırma Kriteriyalarının Növləri

2.1 Əsas Sonlandırma Kriteriləri

# Sonlandırma kriteriyalarının təsnifatı
explain_termination_criteria <- function() {
    cat("=== CAT SONLANDIRMA KRİTERİYALARI ===\n\n")
    
    cat("1. DƏQİQLİK ƏSASLI KRİTERİYALAR:\n")
    cat("   • Standard Error Threshold: SE(θ) ≤ δ\n")
    cat("   • Information Threshold: I(θ) ≥ I_min\n")
    cat("   • Confidence Interval Width: CI_width ≤ w_max\n")
    cat("   • Reliability Threshold: r(θ) ≥ r_min\n\n")
    
    cat("2. TEST UZUNLUĞU KRİTERİYALARI:\n")
    cat("   • Minimum Item Count: n ≥ n_min\n")
    cat("   • Maximum Item Count: n ≤ n_max\n")
    cat("   • Variable Length: n_min ≤ n ≤ n_max\n\n")
    
    cat("3. BANK VƏZİYYƏTİ KRİTERİYALARI:\n")
    cat("   • Available Items: available_items > 0\n")
    cat("   • Exposure Control: max_exposure < threshold\n")
    cat("   • Content Balance: content_requirements met\n\n")
    
    cat("4. KOMBİNƏ KRİTERİYALAR:\n")
    cat("   • SE + Minimum Length: (SE ≤ δ) AND (n ≥ n_min)\n")
    cat("   • Information + Maximum Length: (I ≥ I_min) OR (n ≥ n_max)\n")
    cat("   • Multi-stage: Mərhələli kriterilərin tətbiqi\n\n")
    
    cat("5. ADAPTİV KRİTERİYALAR:\n")
    cat("   • Theta-dependent SE: SE threshold θ-yə görə dəyişir\n")
    cat("   • Progressive tightening: Kriterilərin mərhələli sərtləşməsi\n")
    cat("   • Population-based: Nümunə xarakteristikalarına əsaslı\n")
}

explain_termination_criteria()
## === CAT SONLANDIRMA KRİTERİYALARI ===
## 
## 1. DƏQİQLİK ƏSASLI KRİTERİYALAR:
##    • Standard Error Threshold: SE(θ) ≤ δ
##    • Information Threshold: I(θ) ≥ I_min
##    • Confidence Interval Width: CI_width ≤ w_max
##    • Reliability Threshold: r(θ) ≥ r_min
## 
## 2. TEST UZUNLUĞU KRİTERİYALARI:
##    • Minimum Item Count: n ≥ n_min
##    • Maximum Item Count: n ≤ n_max
##    • Variable Length: n_min ≤ n ≤ n_max
## 
## 3. BANK VƏZİYYƏTİ KRİTERİYALARI:
##    • Available Items: available_items > 0
##    • Exposure Control: max_exposure < threshold
##    • Content Balance: content_requirements met
## 
## 4. KOMBİNƏ KRİTERİYALAR:
##    • SE + Minimum Length: (SE ≤ δ) AND (n ≥ n_min)
##    • Information + Maximum Length: (I ≥ I_min) OR (n ≥ n_max)
##    • Multi-stage: Mərhələli kriterilərin tətbiqi
## 
## 5. ADAPTİV KRİTERİYALAR:
##    • Theta-dependent SE: SE threshold θ-yə görə dəyişir
##    • Progressive tightening: Kriterilərin mərhələli sərtləşməsi
##    • Population-based: Nümunə xarakteristikalarına əsaslı

2.2 Əsas Sonlandırma Yoxlama Funksiyası

# CAT sonlandırma yoxlaması
check_termination <- function(current_step, theta_se, theta_estimate = NULL,
                             min_items = 5, max_items = 30, se_threshold = 0.3,
                             information_threshold = NULL, ci_width_threshold = NULL,
                             available_items = NULL) {
    
    reasons <- character(0)
    terminate <- FALSE
    
    # 1. Minimum tapşırıq sayı yoxlaması
    if (current_step < min_items) {
        return(list(
            terminate = FALSE, 
            reasons = paste("Minimum tapşırıq sayına çatılmayıb (", current_step, "/", min_items, ")"),
            current_step = current_step,
            theta_se = theta_se,
            criterion_met = "none"
        ))
    }
    
    # 2. Maksimum tapşırıq sayı yoxlaması (üstün prioritet)
    if (current_step >= max_items) {
        reasons <- c(reasons, paste("Maksimum tapşırıq sayına çatıldı (", current_step, "/", max_items, ")"))
        terminate <- TRUE
    }
    
    # 3. Standart xəta yoxlaması
    if (!is.null(theta_se) && theta_se <= se_threshold) {
        reasons <- c(reasons, paste("Tələb olunan dəqiqliyə çatıldı (SE =", round(theta_se, 3), "≤", se_threshold, ")"))
        if (!terminate) terminate <- TRUE  # Maksimum uzunluq səbəbindən terminate olmaımışsa
    }
    
    # 4. Information threshold yoxlaması
    if (!is.null(information_threshold)) {
        current_information <- 1 / (theta_se^2)
        if (current_information >= information_threshold) {
            reasons <- c(reasons, paste("Information həddinə çatıldı (I =", round(current_information, 2), "≥", information_threshold, ")"))
            if (!terminate) terminate <- TRUE
        }
    }
    
    # 5. Confidence interval width yoxlaması
    if (!is.null(ci_width_threshold)) {
        ci_width <- 2 * 1.96 * theta_se  # 95% CI width
        if (ci_width <= ci_width_threshold) {
            reasons <- c(reasons, paste("CI width həddinə çatıldı (w =", round(ci_width, 3), "≤", ci_width_threshold, ")"))
            if (!terminate) terminate <- TRUE
        }
    }
    
    # 6. Tapşırıq bankının tükənməsi
    if (!is.null(available_items) && available_items == 0) {
        reasons <- c(reasons, "Mövcud tapşırıq qalmadı")
        terminate <- TRUE
    }
    
    # Əsas terminasiya səbəbini təyin et
    if (terminate) {
        if (current_step >= max_items) {
            criterion_met <- "max_length"
        } else if (theta_se <= se_threshold) {
            criterion_met <- "precision"
        } else if (!is.null(available_items) && available_items == 0) {
            criterion_met <- "no_items"
        } else {
            criterion_met <- "other"
        }
    } else {
        criterion_met <- "none"
    }
    
    return(list(
        terminate = terminate,
        reasons = reasons,
        current_step = current_step,
        theta_se = theta_se,
        criterion_met = criterion_met,
        all_reasons = paste(reasons, collapse = "; ")
    ))
}

# Nümunə yoxlamalar
cat("=== SONLANDIRMA KRİTERİYA NÜMUNƏLƏRİ ===\n\n")
## === SONLANDIRMA KRİTERİYA NÜMUNƏLƏRİ ===
# Test 1: Minimum uzunluğa çatmayıb
test1 <- check_termination(3, 0.25, min_items = 5)
cat("Test 1 - Az tapşırıq:\n")
## Test 1 - Az tapşırıq:
cat("  Sonlandır:", test1$terminate, "\n")
##   Sonlandır: FALSE
cat("  Səbəb:", test1$reasons, "\n\n")
##   Səbəb: Minimum tapşırıq sayına çatılmayıb ( 3 / 5 )
# Test 2: Dəqiqliyə çatıb
test2 <- check_termination(8, 0.25, min_items = 5, se_threshold = 0.3)
cat("Test 2 - Dəqiqliyə çatıb:\n")
## Test 2 - Dəqiqliyə çatıb:
cat("  Sonlandır:", test2$terminate, "\n")
##   Sonlandır: TRUE
cat("  Səbəblər:", test2$all_reasons, "\n\n")
##   Səbəblər: Tələb olunan dəqiqliyə çatıldı (SE = 0.25 ≤ 0.3 )
# Test 3: Maksimum uzunluq
test3 <- check_termination(30, 0.45, min_items = 5, max_items = 30, se_threshold = 0.3)
cat("Test 3 - Maksimum uzunluq:\n")
## Test 3 - Maksimum uzunluq:
cat("  Sonlandır:", test3$terminate, "\n")
##   Sonlandır: TRUE
cat("  Səbəblər:", test3$all_reasons, "\n")
##   Səbəblər: Maksimum tapşırıq sayına çatıldı ( 30 / 30 )

3 Təkmilləşdirilmiş Sonlandırma Strategiyaları

3.1 Theta-Dependent Sonlandırma

# Theta-yə əsaslı adaptiv sonlandırma kriteriləri
theta_dependent_termination <- function(current_step, theta_estimate, theta_se,
                                       min_items = 5, max_items = 30) {
    
    # Theta-yə əsaslı SE threshold-lar
    # Ekstrem theta dəyərlərində daha yüksək SE qəbul edilə bilər
    get_se_threshold <- function(theta) {
        # Base threshold
        base_se <- 0.3
        
        # Ekstrem dəyərlər üçün artırma
        if (abs(theta) > 2.5) {
            adjustment <- 0.1  # SE threshold-ı 0.1 artır
        } else if (abs(theta) > 2.0) {
            adjustment <- 0.05
        } else {
            adjustment <- 0
        }
        
        return(base_se + adjustment)
    }
    
    # Theta-yə əsaslı minimum uzunluq
    get_min_length <- function(theta) {
        # Orta theta dəyərləri üçün daha qısa test
        if (abs(theta) < 0.5) {
            return(max(3, min_items - 2))
        } else if (abs(theta) < 1.5) {
            return(min_items)
        } else {
            return(min_items + 2)  # Ekstrem dəyərlər üçün daha uzun
        }
    }
    
    # Adaptiv kriteriləri hesabla
    adaptive_se_threshold <- get_se_threshold(theta_estimate)
    adaptive_min_length <- get_min_length(theta_estimate)
    
    # Sonlandırma yoxlaması
    termination_result <- check_termination(
        current_step = current_step,
        theta_se = theta_se,
        theta_estimate = theta_estimate,
        min_items = adaptive_min_length,
        max_items = max_items,
        se_threshold = adaptive_se_threshold
    )
    
    # Adaptiv məlumatları əlavə et
    termination_result$adaptive_se_threshold <- adaptive_se_threshold
    termination_result$adaptive_min_length <- adaptive_min_length
    termination_result$theta_estimate <- theta_estimate
    
    return(termination_result)
}

# Müxtəlif theta dəyərləri üçün test
cat("\n=== THETA-DEPENDENT SONLANDIRMA TESTLƏRİ ===\n\n")
## 
## === THETA-DEPENDENT SONLANDIRMA TESTLƏRİ ===
theta_values <- c(-2.5, -1.0, 0.0, 1.0, 2.5)
for(theta in theta_values) {
    result <- theta_dependent_termination(
        current_step = 6,
        theta_estimate = theta,
        theta_se = 0.32,
        min_items = 5,
        max_items = 25
    )
    
    cat("θ =", theta, ":\n")
    cat("  Adaptiv SE threshold:", round(result$adaptive_se_threshold, 3), "\n")
    cat("  Adaptiv min uzunluq:", result$adaptive_min_length, "\n")
    cat("  Sonlandırma:", result$terminate, "\n")
    if(result$terminate) {
        cat("  Səbəb:", result$all_reasons, "\n")
    }
    cat("\n")
}
## θ = -2.5 :
##   Adaptiv SE threshold: 0.35 
##   Adaptiv min uzunluq: 7 
##   Sonlandırma: FALSE 
## 
## θ = -1 :
##   Adaptiv SE threshold: 0.3 
##   Adaptiv min uzunluq: 5 
##   Sonlandırma: FALSE 
## 
## θ = 0 :
##   Adaptiv SE threshold: 0.3 
##   Adaptiv min uzunluq: 3 
##   Sonlandırma: FALSE 
## 
## θ = 1 :
##   Adaptiv SE threshold: 0.3 
##   Adaptiv min uzunluq: 5 
##   Sonlandırma: FALSE 
## 
## θ = 2.5 :
##   Adaptiv SE threshold: 0.35 
##   Adaptiv min uzunluq: 7 
##   Sonlandırma: FALSE

3.2 Mərhələli Sonlandırma Sistemi

# Mərhələli sonlandırma sistemi
staged_termination_system <- function(current_step, theta_se, theta_estimate,
                                     stage_thresholds = c(5, 10, 20),
                                     stage_se_targets = c(0.5, 0.35, 0.25),
                                     max_items = 30) {
    
    # Cari mərhələni təyin et
    current_stage <- 1
    for(i in 1:length(stage_thresholds)) {
        if(current_step >= stage_thresholds[i]) {
            current_stage <- i + 1
        }
    }
    
    if(current_stage > length(stage_se_targets)) {
        current_stage <- length(stage_se_targets)
    }
    
    # Cari mərhələ üçün SE target
    target_se <- stage_se_targets[current_stage]
    
    # Mərhələ məlumatları
    stage_info <- list(
        current_stage = current_stage,
        stage_name = paste("Mərhələ", current_stage),
        target_se = target_se,
        items_in_stage = current_step
    )
    
    # Mərhələli sonlandırma qərarı
    if(current_step >= max_items) {
        # Maksimum uzunluq
        terminate <- TRUE
        reason <- "Maksimum test uzunluğuna çatıldı"
    } else if(current_stage == 1 && current_step < stage_thresholds[1]) {
        # İlk mərhələdə minimum uzunluğa çatmayıb
        terminate <- FALSE
        reason <- paste("Mərhələ 1: Minimum", stage_thresholds[1], "tapşırıq tələb olunur")
    } else if(theta_se <= target_se) {
        # Cari mərhələ üçün target SE-yə çatıb
        terminate <- TRUE
        reason <- paste("Mərhələ", current_stage, "target SE-yə çatıldı (", 
                       round(theta_se, 3), "≤", target_se, ")")
    } else {
        # Davam et
        terminate <- FALSE
        reason <- paste("Mərhələ", current_stage, ": Target SE =", target_se, 
                       "(cari:", round(theta_se, 3), ")")
    }
    
    return(list(
        terminate = terminate,
        reason = reason,
        stage_info = stage_info,
        current_step = current_step,
        theta_se = theta_se,
        target_se = target_se
    ))
}

# Mərhələli sistem testi
cat("=== MƏRHƏLƏLİ SONLANDIRMA SİSTEMİ TESTİ ===\n\n")
## === MƏRHƏLƏLİ SONLANDIRMA SİSTEMİ TESTİ ===
test_scenarios <- data.frame(
    step = c(3, 7, 12, 25, 35),
    se = c(0.6, 0.4, 0.3, 0.28, 0.24),
    theta = c(-0.5, 0.2, 0.8, 1.2, 1.5)
)

for(i in 1:nrow(test_scenarios)) {
    result <- staged_termination_system(
        current_step = test_scenarios$step[i],
        theta_se = test_scenarios$se[i],
        theta_estimate = test_scenarios$theta[i]
    )
    
    cat("Test", i, "- Addım:", test_scenarios$step[i], ", SE:", test_scenarios$se[i], "\n")
    cat("  ", result$stage_info$stage_name, "(Target SE:", result$target_se, ")\n")
    cat("  Sonlandırma:", result$terminate, "\n")
    cat("  Səbəb:", result$reason, "\n\n")
}
## Test 1 - Addım: 3 , SE: 0.6 
##    Mərhələ 1 (Target SE: 0.5 )
##   Sonlandırma: FALSE 
##   Səbəb: Mərhələ 1: Minimum 5 tapşırıq tələb olunur 
## 
## Test 2 - Addım: 7 , SE: 0.4 
##    Mərhələ 2 (Target SE: 0.35 )
##   Sonlandırma: FALSE 
##   Səbəb: Mərhələ 2 : Target SE = 0.35 (cari: 0.4 ) 
## 
## Test 3 - Addım: 12 , SE: 0.3 
##    Mərhələ 3 (Target SE: 0.25 )
##   Sonlandırma: FALSE 
##   Səbəb: Mərhələ 3 : Target SE = 0.25 (cari: 0.3 ) 
## 
## Test 4 - Addım: 25 , SE: 0.28 
##    Mərhələ 3 (Target SE: 0.25 )
##   Sonlandırma: FALSE 
##   Səbəb: Mərhələ 3 : Target SE = 0.25 (cari: 0.28 ) 
## 
## Test 5 - Addım: 35 , SE: 0.24 
##    Mərhələ 3 (Target SE: 0.25 )
##   Sonlandırma: TRUE 
##   Səbəb: Maksimum test uzunluğuna çatıldı

4 Sonlandırma Effektivliyinin Təhlili

4.1 Sonlandırma Performans Metriklər

# Sonlandırma strategiyalarının performans təhlili
analyze_termination_performance <- function(termination_strategy_func, 
                                           item_bank = NULL,
                                           n_simulations = 100,
                                           true_theta_range = c(-2, 2)) {
    
    if(is.null(item_bank)) {
        # Nümunə item bank yarad
        set.seed(12345)
        item_bank <- data.frame(
            item_id = 1:200,
            a = runif(200, 0.8, 2.5),
            b = rnorm(200, 0, 1.2),
            c = runif(200, 0.1, 0.25)
        )
    }
    
    cat("=== SONLANDIRMA PERFORMANS TƏHLİLİ ===\n")
    cat("Simulyasiya sayı:", n_simulations, "\n")
    cat("Həqiqi θ aralığı:", true_theta_range, "\n\n")
    
    set.seed(456)
    results <- data.frame()
    
    for(sim in 1:n_simulations) {
        # Təsadüfi həqiqi theta
        true_theta <- runif(1, true_theta_range[1], true_theta_range[2])
        
        # CAT simulyasiyası
        administered_items <- c()
        responses <- c()
        current_theta <- 0
        max_possible_items <- 50
        
        for(step in 1:max_possible_items) {
            # Sadə item seçimi (təsadüfi, available items-dən)
            available_items <- setdiff(1:nrow(item_bank), administered_items)
            if(length(available_items) == 0) break
            
            selected_item <- sample(available_items, 1)
            
            # Response simulyasiyası
            a <- item_bank$a[selected_item]
            b <- item_bank$b[selected_item]
            c <- item_bank$c[selected_item]
            
            prob <- c + (1 - c) * plogis(a * (true_theta - b))
            response <- rbinom(1, 1, prob)
            
            administered_items <- c(administered_items, selected_item)
            responses <- c(responses, response)
            
            # Theta qiymətləndirməsi (sadə EAP)
            if(length(responses) >= 2) {
                # Sadə EAP implementasiyası
                theta_points <- seq(-4, 4, 0.2)
                likelihood <- sapply(theta_points, function(theta) {
                    loglik <- 0
                    for(i in 1:length(administered_items)) {
                        item_idx <- administered_items[i]
                        resp <- responses[i]
                        a_i <- item_bank$a[item_idx]
                        b_i <- item_bank$b[item_idx]
                        c_i <- item_bank$c[item_idx]
                        
                        P_i <- c_i + (1 - c_i) * plogis(a_i * (theta - b_i))
                        P_i <- pmax(1e-10, pmin(1 - 1e-10, P_i))
                        
                        if(resp == 1) {
                            loglik <- loglik + log(P_i)
                        } else {
                            loglik <- loglik + log(1 - P_i)
                        }
                    }
                    return(exp(loglik))
                })
                
                # Prior (standard normal)
                prior <- dnorm(theta_points, 0, 1)
                posterior <- likelihood * prior
                posterior <- posterior / sum(posterior)
                
                current_theta <- sum(theta_points * posterior)
                theta_var <- sum((theta_points - current_theta)^2 * posterior)
                current_se <- sqrt(theta_var)
            } else {
                current_se <- 1.0
            }
            
            # Sonlandırma yoxlaması
            termination_result <- termination_strategy_func(
                current_step = step,
                theta_se = current_se,
                theta_estimate = current_theta
            )
            
            if(termination_result$terminate) {
                # Test sonlandırıldı
                final_length <- step
                final_se <- current_se
                final_theta <- current_theta
                final_error <- abs(current_theta - true_theta)
                termination_reason <- termination_result$criterion_met
                break
            }
        }
        
        # Nəticələri saxla
        temp_result <- data.frame(
            Simulation = sim,
            True_Theta = true_theta,
            Final_Length = final_length,
            Final_SE = final_se,
            Final_Theta = final_theta,
            Final_Error = final_error,
            Termination_Reason = termination_reason
        )
        
        results <- rbind(results, temp_result)
        
        if(sim %% 25 == 0) cat("Simulyasiya", sim, "/", n_simulations, "tamamlandı\n")
    }
    
    return(results)
}

# Standard sonlandırma strategiyası
standard_termination <- function(current_step, theta_se, theta_estimate) {
    return(check_termination(
        current_step = current_step,
        theta_se = theta_se,
        min_items = 5,
        max_items = 25,
        se_threshold = 0.3
    ))
}

# Performans təhlili (kiçik nümunə)
cat("Performans təhlili başlayır...\n")
## Performans təhlili başlayır...
performance_results <- analyze_termination_performance(
    standard_termination, 
    n_simulations = 50  # Sürətli test üçün
)
## === SONLANDIRMA PERFORMANS TƏHLİLİ ===
## Simulyasiya sayı: 50 
## Həqiqi θ aralığı: -2 2 
## 
## Simulyasiya 25 / 50 tamamlandı
## Simulyasiya 50 / 50 tamamlandı
# Nəticələrin xülasəsi
cat("\n=== PERFORMANS NƏTİCƏLƏRİ ===\n")
## 
## === PERFORMANS NƏTİCƏLƏRİ ===
cat("Orta test uzunluğu:", round(mean(performance_results$Final_Length), 1), "\n")
## Orta test uzunluğu: 25
cat("Test uzunluğu SD:", round(sd(performance_results$Final_Length), 1), "\n")
## Test uzunluğu SD: 0
cat("Orta final SE:", round(mean(performance_results$Final_SE), 3), "\n")
## Orta final SE: 0.41
cat("Orta final xəta:", round(mean(performance_results$Final_Error), 3), "\n")
## Orta final xəta: 0.289
cat("RMSE:", round(sqrt(mean(performance_results$Final_Error^2)), 3), "\n")
## RMSE: 0.352
# Sonlandırma səbəblərinin paylanması
termination_reasons <- table(performance_results$Termination_Reason)
cat("\nSonlandırma səbəbləri:\n")
## 
## Sonlandırma səbəbləri:
for(i in 1:length(termination_reasons)) {
    cat("  ", names(termination_reasons)[i], ":", termination_reasons[i], 
        "(", round(termination_reasons[i]/sum(termination_reasons)*100, 1), "%)\n")
}
##    max_length : 50 ( 100 %)

5 Sonlandırma Effektivliyinin Vizuallaşdırılması

5.1 Performans Müqayisə Qrafiklər

# Sonlandırma performansının vizuallaşdırılması
visualize_termination_performance <- function(performance_results) {
    
    # 1. Test uzunluğu paylanması
    p1 <- ggplot(performance_results, aes(x = Final_Length)) +
        geom_histogram(bins = 15, fill = "lightblue", color = "black", alpha = 0.7) +
        geom_vline(xintercept = mean(performance_results$Final_Length), 
                   color = "red", linetype = "dashed", size = 1) +
        labs(title = "Test Uzunluğu Paylanması",
             subtitle = paste("Orta =", round(mean(performance_results$Final_Length), 1)),
             x = "Test Uzunluğu", y = "Tezlik") +
        theme_minimal()
    
    # 2. SE vs Test uzunluğu
    p2 <- ggplot(performance_results, aes(x = Final_Length, y = Final_SE)) +
        geom_point(alpha = 0.6, size = 2, color = "blue") +
        geom_smooth(method = "loess", se = FALSE, color = "red") +
        geom_hline(yintercept = 0.3, linetype = "dashed", color = "green") +
        labs(title = "Test Uzunluğu vs Final SE",
             x = "Test Uzunluğu", y = "Final SE") +
        theme_minimal() +
        annotate("text", x = max(performance_results$Final_Length) * 0.8, y = 0.32,
                 label = "SE threshold = 0.3", color = "green")
    
    # 3. Xəta vs Test uzunluğu
    p3 <- ggplot(performance_results, aes(x = Final_Length, y = Final_Error)) +
        geom_point(alpha = 0.6, size = 2, color = "darkgreen") +
        geom_smooth(method = "loess", se = FALSE, color = "red") +
        labs(title = "Test Uzunluğu vs Qiymətləndirmə Xətası",
             x = "Test Uzunluğu", y = "Mütləq Xəta") +
        theme_minimal()
    
    # 4. Sonlandırma səbəblərinin paylanması
    termination_summary <- performance_results %>%
        count(Termination_Reason) %>%
        mutate(Percentage = round(n / sum(n) * 100, 1))
    
    p4 <- ggplot(termination_summary, aes(x = reorder(Termination_Reason, n), y = n, 
                                          fill = Termination_Reason)) +
        geom_col() +
        geom_text(aes(label = paste0(n, " (", Percentage, "%)")), 
                  hjust = -0.1, size = 3) +
        coord_flip() +
        labs(title = "Sonlandırma Səbəblərinin Paylanması",
             x = "Sonlandırma Səbəbi", y = "Sayı") +
        theme_minimal() +
        theme(legend.position = "none") +
        scale_fill_viridis_d()
    
    # Layout
    grid.arrange(p1, p2, p3, p4, ncol = 2)
    
    return(list(p1 = p1, p2 = p2, p3 = p3, p4 = p4))
}

# Performans vizuallaşdırması
if(exists("performance_results") && nrow(performance_results) > 0) {
    performance_plots <- visualize_termination_performance(performance_results)
}

6 Müxtəlif Sonlandırma Strategiyalarının Müqayisəsi

6.1 Strategiya Müqayisə Təhlili

# Müxtəlif sonlandırma strategiyalarının müqayisəsi
compare_termination_strategies <- function(n_simulations = 30) {
    
    cat("=== SONLANDIRMA STRATEGİYALARI MÜQAYİSƏSİ ===\n\n")
    
    # Müxtəlif strategiyalar
    strategies <- list(
        Conservative = function(current_step, theta_se, theta_estimate) {
            check_termination(current_step, theta_se, min_items = 8, max_items = 35, se_threshold = 0.25)
        },
        Standard = function(current_step, theta_se, theta_estimate) {
            check_termination(current_step, theta_se, min_items = 5, max_items = 25, se_threshold = 0.3)
        },
        Aggressive = function(current_step, theta_se, theta_estimate) {
            check_termination(current_step, theta_se, min_items = 3, max_items = 20, se_threshold = 0.4)
        },
        Adaptive = function(current_step, theta_se, theta_estimate) {
            theta_dependent_termination(current_step, theta_estimate, theta_se, min_items = 4, max_items = 25)
        }
    )
    
    comparison_results <- data.frame()
    
    for(strategy_name in names(strategies)) {
        cat("Strategiya test edilir:", strategy_name, "\n")
        
        # Performans təhlili (kiçik nümunə)
        strategy_results <- analyze_termination_performance(
            strategies[[strategy_name]], 
            n_simulations = n_simulations
        )
        
        # Strategiya adını əlavə et
        strategy_results$Strategy <- strategy_name
        comparison_results <- rbind(comparison_results, strategy_results)
    }
    
    return(comparison_results)
}

# Strategiya müqayisəsi (kiçik nümunə)
strategy_comparison <- compare_termination_strategies(n_simulations = 20)
## === SONLANDIRMA STRATEGİYALARI MÜQAYİSƏSİ ===
## 
## Strategiya test edilir: Conservative 
## === SONLANDIRMA PERFORMANS TƏHLİLİ ===
## Simulyasiya sayı: 20 
## Həqiqi θ aralığı: -2 2 
## 
## Strategiya test edilir: Standard 
## === SONLANDIRMA PERFORMANS TƏHLİLİ ===
## Simulyasiya sayı: 20 
## Həqiqi θ aralığı: -2 2 
## 
## Strategiya test edilir: Aggressive 
## === SONLANDIRMA PERFORMANS TƏHLİLİ ===
## Simulyasiya sayı: 20 
## Həqiqi θ aralığı: -2 2 
## 
## Strategiya test edilir: Adaptive 
## === SONLANDIRMA PERFORMANS TƏHLİLİ ===
## Simulyasiya sayı: 20 
## Həqiqi θ aralığı: -2 2
# Müqayisə nəticələrinin xülasəsi
strategy_summary <- strategy_comparison %>%
    group_by(Strategy) %>%
    summarise(
        Mean_Length = round(mean(Final_Length), 1),
        SD_Length = round(sd(Final_Length), 1),
        Mean_SE = round(mean(Final_SE), 3),
        Mean_Error = round(mean(Final_Error), 3),
        RMSE = round(sqrt(mean(Final_Error^2)), 3),
        Precision_Rate = round(mean(Final_SE <= 0.3) * 100, 1),
        .groups = 'drop'
    )

cat("\n=== STRATEGİYA PERFORMANS MÜQAYİSƏSİ ===\n")
## 
## === STRATEGİYA PERFORMANS MÜQAYİSƏSİ ===
print(strategy_summary)
## # A tibble: 4 × 7
##   Strategy     Mean_Length SD_Length Mean_SE Mean_Error  RMSE Precision_Rate
##   <chr>              <dbl>     <dbl>   <dbl>      <dbl> <dbl>          <dbl>
## 1 Adaptive            25         0     0.398      0.341 0.417              0
## 2 Aggressive          19.3       1.8   0.44       0.473 0.573              0
## 3 Conservative        35         0     0.348      0.256 0.337             15
## 4 Standard            25         0     0.398      0.341 0.417              0
# Strategiya müqayisə vizuallaşdırması
visualize_strategy_comparison <- function(strategy_comparison) {
    
    # Test uzunluğu müqayisəsi
    p1 <- ggplot(strategy_comparison, aes(x = Strategy, y = Final_Length, fill = Strategy)) +
        geom_boxplot() +
        labs(title = "Strategiyalara Görə Test Uzunluğu",
             x = "Strategiya", y = "Test Uzunluğu") +
        theme_minimal() +
        theme(legend.position = "none") +
        scale_fill_viridis_d()
    
    # SE müqayisəsi
    p2 <- ggplot(strategy_comparison, aes(x = Strategy, y = Final_SE, fill = Strategy)) +
        geom_boxplot() +
        geom_hline(yintercept = 0.3, linetype = "dashed", color = "red") +
        labs(title = "Strategiyalara Görə Final SE",
             x = "Strategiya", y = "Final SE") +
        theme_minimal() +
        theme(legend.position = "none") +
        scale_fill_viridis_d()
    
    # Xəta müqayisəsi
    p3 <- ggplot(strategy_comparison, aes(x = Strategy, y = Final_Error, fill = Strategy)) +
        geom_boxplot() +
        labs(title = "Strategiyalara Görə Qiymətləndirmə Xətası",
             x = "Strategiya", y = "Mütləq Xəta") +
        theme_minimal() +
        theme(legend.position = "none") +
        scale_fill_viridis_d()
    
    # Efficiency scatter plot
    efficiency_data <- strategy_comparison %>%
        group_by(Strategy) %>%
        summarise(
            Mean_Length = mean(Final_Length),
            Mean_Error = mean(Final_Error),
            .groups = 'drop'
        )
    
    p4 <- ggplot(efficiency_data, aes(x = Mean_Length, y = Mean_Error, color = Strategy)) +
        geom_point(size = 4) +
        geom_text(aes(label = Strategy), vjust = -0.5, size = 3) +
        labs(title = "Effektivlik: Test Uzunluğu vs Xəta",
             x = "Orta Test Uzunluğu", y = "Orta Mütləq Xəta") +
        theme_minimal() +
        scale_color_viridis_d()
    
    grid.arrange(p1, p2, p3, p4, ncol = 2)
}

# Strategiya müqayisə vizuallaşdırması
if(exists("strategy_comparison") && nrow(strategy_comparison) > 0) {
    visualize_strategy_comparison(strategy_comparison)
}

7 Real-Time Sonlandırma Monitörinqi

7.1 Adaptive Monitoring Sistemi

# Real-time sonlandırma monitörinqi
adaptive_termination_monitor <- function() {
    
    cat("=== ADAPTİV SONLANDIRMA MONİTÖRİNQİ ===\n\n")
    
    # CAT sessiya simulyasiyası
    set.seed(789)
    
    # Nümunə item bank
    item_bank <- data.frame(
        item_id = 1:100,
        a = runif(100, 0.8, 2.5),
        b = rnorm(100, 0, 1.2),
        c = runif(100, 0.1, 0.25)
    )
    
    # Test alıcısı profili
    true_theta <- 0.7
    administered_items <- c()
    responses <- c()
    
    # Monitoring məlumatları
    monitoring_data <- data.frame()
    
    max_items <- 20
    
    for(step in 1:max_items) {
        
        # Item seçimi (sadə təsadüfi)
        available_items <- setdiff(1:nrow(item_bank), administered_items)
        if(length(available_items) == 0) break
        
        selected_item <- sample(available_items, 1)
        
        # Response simulyasiyası
        a <- item_bank$a[selected_item]
        b <- item_bank$b[selected_item]
        c <- item_bank$c[selected_item]
        
        prob <- c + (1 - c) * plogis(a * (true_theta - b))
        response <- rbinom(1, 1, prob)
        
        administered_items <- c(administered_items, selected_item)
        responses <- c(responses, response)
        
        # Theta qiymətləndirməsi (sadə)
        if(length(responses) >= 2) {
            # Proportion correct əsaslı sadə qiymətləndirmə
            prop_correct <- mean(responses)
            if(prop_correct >= 0.9) {
                current_theta <- 2.0
                current_se <- 0.5
            } else if(prop_correct <= 0.1) {
                current_theta <- -2.0
                current_se <- 0.5
            } else {
                # Logit transform
                current_theta <- log(prop_correct / (1 - prop_correct))
                current_se <- max(0.2, 1 / sqrt(length(responses)))
            }
        } else {
            current_theta <- 0
            current_se <- 1.0
        }
        
        # Sonlandırma yoxlaması
        termination_check <- check_termination(
            current_step = step,
            theta_se = current_se,
            theta_estimate = current_theta,
            min_items = 5,
            max_items = 20,
            se_threshold = 0.35
        )
        
        # Monitoring məlumatını saxla
        temp_monitoring <- data.frame(
            Step = step,
            Item_ID = selected_item,
            Response = response,
            Theta_Est = current_theta,
            SE = current_se,
            Cumulative_Correct = sum(responses),
            Proportion_Correct = mean(responses),
            Terminate_Decision = termination_check$terminate,
            Termination_Reason = ifelse(termination_check$terminate, 
                                       termination_check$criterion_met, "continue"),
            True_Theta = true_theta,
            Absolute_Error = abs(current_theta - true_theta)
        )
        
        monitoring_data <- rbind(monitoring_data, temp_monitoring)
        
        # Real-time məlumat
        cat("Addım", step, ":\n")
        cat("  Item:", selected_item, "| Response:", response, "\n")
        cat("  θ̂:", round(current_theta, 3), "| SE:", round(current_se, 3), "\n")
        cat("  Error:", round(abs(current_theta - true_theta), 3), "\n")
        cat("  Terminate:", termination_check$terminate, "\n")
        
        if(termination_check$terminate) {
            cat("  Səbəb:", termination_check$all_reasons, "\n")
            break
        }
        cat("\n")
    }
    
    return(monitoring_data)
}

# Real-time monitoring simulyasiyası
monitoring_session <- adaptive_termination_monitor()
## === ADAPTİV SONLANDIRMA MONİTÖRİNQİ ===
## 
## Addım 1 :
##   Item: 52 | Response: 1 
##   θ̂: 0 | SE: 1 
##   Error: 0.7 
##   Terminate: FALSE 
## 
## Addım 2 :
##   Item: 4 | Response: 1 
##   θ̂: 2 | SE: 0.5 
##   Error: 1.3 
##   Terminate: FALSE 
## 
## Addım 3 :
##   Item: 19 | Response: 1 
##   θ̂: 2 | SE: 0.5 
##   Error: 1.3 
##   Terminate: FALSE 
## 
## Addım 4 :
##   Item: 79 | Response: 0 
##   θ̂: 1.099 | SE: 0.5 
##   Error: 0.399 
##   Terminate: FALSE 
## 
## Addım 5 :
##   Item: 10 | Response: 1 
##   θ̂: 1.386 | SE: 0.447 
##   Error: 0.686 
##   Terminate: FALSE 
## 
## Addım 6 :
##   Item: 37 | Response: 0 
##   θ̂: 0.693 | SE: 0.408 
##   Error: 0.007 
##   Terminate: FALSE 
## 
## Addım 7 :
##   Item: 53 | Response: 1 
##   θ̂: 0.916 | SE: 0.378 
##   Error: 0.216 
##   Terminate: FALSE 
## 
## Addım 8 :
##   Item: 59 | Response: 1 
##   θ̂: 1.099 | SE: 0.354 
##   Error: 0.399 
##   Terminate: FALSE 
## 
## Addım 9 :
##   Item: 51 | Response: 1 
##   θ̂: 1.253 | SE: 0.333 
##   Error: 0.553 
##   Terminate: TRUE 
##   Səbəb: Tələb olunan dəqiqliyə çatıldı (SE = 0.333 ≤ 0.35 )
# Monitoring vizuallaşdırması
if(exists("monitoring_session") && nrow(monitoring_session) > 0) {
    
    # Theta konvergensiyası
    p1 <- ggplot(monitoring_session, aes(x = Step)) +
        geom_line(aes(y = Theta_Est, color = "Qiymətləndirmə"), size = 1.2) +
        geom_ribbon(aes(ymin = Theta_Est - SE, ymax = Theta_Est + SE), 
                    alpha = 0.3, fill = "lightblue") +
        geom_hline(aes(yintercept = True_Theta, color = "Həqiqi θ"), 
                   linetype = "dashed", size = 1) +
        labs(title = "Real-time Theta Konvergensiyası",
             x = "Test Addımı", y = "Theta Qiymətləndirməsi",
             color = "Tip") +
        theme_minimal() +
        scale_color_manual(values = c("Qiymətləndirmə" = "blue", "Həqiqi θ" = "red"))
    
    # SE azalması
    p2 <- ggplot(monitoring_session, aes(x = Step, y = SE)) +
        geom_line(size = 1.2, color = "red") +
        geom_point(size = 2, color = "red") +
        geom_hline(yintercept = 0.35, linetype = "dashed", color = "green") +
        labs(title = "Standart Xəta Azalması",
             x = "Test Addımı", y = "Standart Xəta") +
        theme_minimal() +
        annotate("text", x = max(monitoring_session$Step) * 0.7, y = 0.38,
                 label = "SE threshold = 0.35", color = "green", size = 3)
    
    grid.arrange(p1, p2, ncol = 1)
}

8 Sonlandırma Optimizasiyası və Tövsiyələr

8.1 Optimizasiya Strategiyaları

# Sonlandırma optimizasiyası tövsiyələri
provide_termination_recommendations <- function() {
    
    cat("=== SONLANDIRMA OPTİMİZASİYA TOVSİYƏLƏRİ ===\n\n")
    
    cat("1. DƏQİQLİK ƏSASLI KRİTERİYALAR:\n")
    cat("   ✓ SE Threshold:\n")
    cat("     • Yüksək riskli qərarlar: SE ≤ 0.20\n")
    cat("     • Orta riskli qərarlar: SE ≤ 0.30\n")
    cat("     • Aşağı riskli qərarlar: SE ≤ 0.40\n\n")
    
    cat("   ✓ Theta-dependent SE:\n")
    cat("     • |θ| < 1.0: Standard SE threshold\n")
    cat("     • 1.0 ≤ |θ| < 2.0: SE + 0.05\n")
    cat("     • |θ| ≥ 2.0: SE + 0.10\n\n")
    
    cat("2. TEST UZUNLUĞU OPTİMİZASİYASI:\n")
    cat("   ✓ Minimum uzunluq:\n")
    cat("     • Psixometrik minimum: 5 tapşırıq\n")
    cat("     • Praktiki minimum: 8-10 tapşırıq\n")
    cat("     • Yüksək stakes: 10-15 tapşırıq\n\n")
    
    cat("   ✓ Maksimum uzunluq:\n")
    cat("     • Yorğunluq faktoru: 25-30 tapşırıq\n")
    cat("     • Vaxt məhdudiyyəti: 20-25 tapşırıq\n")
    cat("     • Bank qorunması: Bank ölçüsü / 4\n\n")
    
    cat("3. ADAPTİV STRATEGİYALAR:\n")
    cat("   ✓ Mərhələli sistem:\n")
    cat("     • Mərhələ 1 (1-5): SE ≤ 0.5\n")
    cat("     • Mərhələ 2 (6-10): SE ≤ 0.35\n")
    cat("     • Mərhələ 3 (11+): SE ≤ 0.25\n\n")
    
    cat("   ✓ Population-based:\n")
    cat("     • Normativ örnekləm əsasında SE adjustment\n")
    cat("     • Demografik qruplara görə kriterilərin uyğunlaşdırılması\n\n")
    
    cat("4. KONTİNGENCY PLANLAR:\n")
    cat("   ✓ Bank tükənməsi:\n")
    cat("     • Exposure rate limiti: 30%\n")
    cat("     • Emergency items pool: Bank ölçüsünün 10%-i\n\n")
    
    cat("   ✓ Aberrant responses:\n")
    cat("     • Pattern detection algorithms\n")
    cat("     • Automatic flagging and review\n\n")
    
    cat("5. PERFORMANS MONİTÖRİNQİ:\n")
    cat("   ✓ Real-time metriklər:\n")
    cat("     • Orta test uzunluğu\n")
    cat("     • SE target achievement rate\n")
    cat("     • Termination reason distribution\n\n")
    
    cat("   ✓ Keyfiyyət göstəriciləri:\n")
    cat("     • Test effektivliyi (accuracy/length)\n")
    cat("     • Measurement precision consistency\n")
    cat("     • Examinee satisfaction metrics\n")
    
    return(invisible(NULL))
}

provide_termination_recommendations()
## === SONLANDIRMA OPTİMİZASİYA TOVSİYƏLƏRİ ===
## 
## 1. DƏQİQLİK ƏSASLI KRİTERİYALAR:
##    ✓ SE Threshold:
##      • Yüksək riskli qərarlar: SE ≤ 0.20
##      • Orta riskli qərarlar: SE ≤ 0.30
##      • Aşağı riskli qərarlar: SE ≤ 0.40
## 
##    ✓ Theta-dependent SE:
##      • |θ| < 1.0: Standard SE threshold
##      • 1.0 ≤ |θ| < 2.0: SE + 0.05
##      • |θ| ≥ 2.0: SE + 0.10
## 
## 2. TEST UZUNLUĞU OPTİMİZASİYASI:
##    ✓ Minimum uzunluq:
##      • Psixometrik minimum: 5 tapşırıq
##      • Praktiki minimum: 8-10 tapşırıq
##      • Yüksək stakes: 10-15 tapşırıq
## 
##    ✓ Maksimum uzunluq:
##      • Yorğunluq faktoru: 25-30 tapşırıq
##      • Vaxt məhdudiyyəti: 20-25 tapşırıq
##      • Bank qorunması: Bank ölçüsü / 4
## 
## 3. ADAPTİV STRATEGİYALAR:
##    ✓ Mərhələli sistem:
##      • Mərhələ 1 (1-5): SE ≤ 0.5
##      • Mərhələ 2 (6-10): SE ≤ 0.35
##      • Mərhələ 3 (11+): SE ≤ 0.25
## 
##    ✓ Population-based:
##      • Normativ örnekləm əsasında SE adjustment
##      • Demografik qruplara görə kriterilərin uyğunlaşdırılması
## 
## 4. KONTİNGENCY PLANLAR:
##    ✓ Bank tükənməsi:
##      • Exposure rate limiti: 30%
##      • Emergency items pool: Bank ölçüsünün 10%-i
## 
##    ✓ Aberrant responses:
##      • Pattern detection algorithms
##      • Automatic flagging and review
## 
## 5. PERFORMANS MONİTÖRİNQİ:
##    ✓ Real-time metriklər:
##      • Orta test uzunluğu
##      • SE target achievement rate
##      • Termination reason distribution
## 
##    ✓ Keyfiyyət göstəriciləri:
##      • Test effektivliyi (accuracy/length)
##      • Measurement precision consistency
##      • Examinee satisfaction metrics
# Praktiki implementation guidance
cat("\n=== PRATİKİ İMPLEMENTASİYA BƏLƏDÇISI ===\n\n")
## 
## === PRATİKİ İMPLEMENTASİYA BƏLƏDÇISI ===
practical_guidance <- data.frame(
    Sahə = c("Təhsil", "Sertifikasiya", "Klinik", "Tədqiqat", "HR"),
    Min_Items = c("5-8", "8-12", "10-15", "3-5", "5-10"),
    Max_Items = c("20-25", "30-40", "25-35", "15-20", "20-30"),
    SE_Target = c("0.30", "0.25", "0.20", "0.35", "0.35"),
    Xüsusi_Nöqtələr = c(
        "Formativ qiymətləndirmə üçün daha liberal",
        "Yüksək stakes, konservativ yanaşma",
        "Diaqnostik dəqiqlik kritik",
        "Effektivlik vs dəqiqlik balansı",
        "Sürət və cost-effectiveness"
    )
)

print(practical_guidance)
##            Sahə Min_Items Max_Items SE_Target
## 1        Təhsil       5-8     20-25      0.30
## 2 Sertifikasiya      8-12     30-40      0.25
## 3        Klinik     10-15     25-35      0.20
## 4      Tədqiqat       3-5     15-20      0.35
## 5            HR      5-10     20-30      0.35
##                             Xüsusi_Nöqtələr
## 1 Formativ qiymətləndirmə üçün daha liberal
## 2        Yüksək stakes, konservativ yanaşma
## 3                Diaqnostik dəqiqlik kritik
## 4           Effektivlik vs dəqiqlik balansı
## 5               Sürət və cost-effectiveness

9 Nəticə

Bu bölmədə CAT sistemlərində sonlandırma kriteriyalarının dizaynı və optimallaşdırılmasını hərtərəfli öyrəndik. Effektiv sonlandırma strategiyaları test keyfiyyətini saxlayaraq efficiency-ni maksimallaşdırır.

9.1 Əsas Nəticələr

  1. Çoxölçülü kriteriyalar daha robust sonlandırma qərarları verir
  2. Theta-dependent strategies ekstrem qabiliyyət səviyyələrində daha effektivdir
  3. Mərhələli sistemlər progressive precision improvement təmin edir
  4. Real-time monitoring adaptiv optimization imkanı yaradır
  5. Context-specific optimization müxtəlif tətbiq sahələrində vacibdir

9.2 Praktiki Tövsiyələr

9.2.1 Sonlandırma Kriteri Seçimi

  • Conservative: Yüksək stakes testləri (SE ≤ 0.25, min 10 item)
  • Balanced: Ümumi məqsədlər (SE ≤ 0.30, min 5 item)
  • Aggressive: Screening testləri (SE ≤ 0.40, min 3 item)

9.2.2 Implementasiya Strategiyası

  1. Pilot testing məlumat toplamağı
  2. Mərhələli deployment riskləri azaldar
  3. Continuous monitoring performance optimization üçün vacibdir
  4. Stakeholder feedback praktiki uyğunluq üçün lazımdır

9.2.3 Keyfiyyət Nəzarəti

  • Real-time dashboard monitoring

  • Weekly/monthly performance reviews

  • Automated alert systems

  • Continuous improvement protocols

9.3 Növbəti Addımlar

  • Bölmə 12: CAT Exposure Control və Item Pool Management

  • Bölmə 13: CAT Security və Aberrant Response Detection

  • Bölmə 14: Comprehensive CAT System Implementation


Qeyd: Sonlandırma kriteriyaları CAT sisteminin ürəyidir. Düzgün dizayn edilmiş kriteriyalar test keyfiyyəti və efficiency arasında optimal balans yaradır və test alıcıları üçün ədalətli və effektiv təcrübə təmin edir.