#MSE landa ML gama ML s(t) h(t) در مدل سوم library(actuar) my_func <- function(){ # تعریف پارامترها و مقداردهی اولیه shape1 <- 2 shape2 <- 1 n <- 50 m <- 20 # تولید داده‌ها از توزیع Burr و مرتب‌سازی آن‌ها y <- sort(rburr(n, shape1, shape2)) # انتخاب داده‌های اولیه x <- y[1:m] # تعریف مقدار T1 و T2 T1 <- 0.5 T2 <- 1 # تنظیم Rs بر اساس مدل سوم Rs <- numeric(n) Rs[1] <- Rs[m] <- (n - m) / 2 # تعریف سایر مقادیر Rs به صفر Rs[-c(1, m)] <- 0 # تعریف سایر متغیرها ds <- 0 Rsd1 <- 0 Rsd2 <- 0 # تنظیم ds بر اساس شرط‌های موردنظر if (x[m] > T1 & x[m] < T2) { ds <- m Rsd1 <- 0 Rsd2 <- 0 } else if (x[m] > T2) { ds <- which.max(x[x < T2]) x <- x[1:ds] Rsd2 <- n - ds } else if (x[m] < T1) { ds <- which.max(y[y < T1]) x <- y[1:ds] Rsd1 <- n - ds } # تنظیم پارامترهای برآورد lambda و gamma gama=array(100) lamda=array(100) gama[1] <- 1 # حلقه محاسبه gamma و lambda for (j in 1:99) { lamda[j] <- ds / (sum(sapply(1:ds, function(i) (Rs[i] + 1) * log(1 + x[i]^gama[j]))) + Rsd1 * log(1 + T1^gama[j]) + Rsd2 * log(1 + T2^gama[j])) denom <- sum(sapply(1:ds, function(i) (lamda[j] * (Rs[i] + 1) + 1) * x[i]^gama[j] * log(x[i]) / (1 + x[i]^gama[j]))) + lamda[j] * (Rsd1 * T1^gama[j] * log(T1^gama[j]) / (1 + T1^gama[j]) + Rsd2 * T2^gama[j] * log(T2^gama[j]) / (1 + T2^gama[j])) - sum(log(x[1:ds])) if (is.nan(denom)) { denom <- rnorm(1) } gama[j + 1] <- ds / denom if (abs(gama[j + 1] - gama[j]) < 0.01) { break } } # برآورد نهایی gamahat و lamdahat gamahat <- gama[length(gama)] lamdahat <- ds / (sum(sapply(1:ds, function(i) (Rs[i] + 1) * log(1 + x[i]^gamahat))) + Rsd1 * log(1 + T1^gamahat) + Rsd2 * log(1 + T2^gamahat)) shat=(1+0.5^gamahat)^(-lamdahat) hhat=lamdahat*gamahat*0.5^(gamahat-1)*(1+0.5^gamahat)^(-1) # برگرداندن مقادیر برآورد شده return(c(gamahat, lamdahat,shat,hhat)) } # انجام شبیه‌سازی و جمع‌آوری نتایج b <- replicate(10000, my_func()) # جداسازی مقادیر gamma و lambda gam <- b[1,] lam <- b[2,] shaat=b[3,] hhaat=b[4,] # فیلتر کردن مقادیر gamma و lambda در محدوده 0 تا 5 gam_filtered <- gam[gam >= 0 & gam <= 5] lam_filtered <- lam[lam >= 0 & lam <= 5] # شمارش تعداد مقادیر فیلتر شده count_gam_filtered <- length(gam_filtered) count_lam_filtered <- length(lam_filtered) # چاپ تعداد مقادیر فیلتر شده print(paste("تعداد عناصر gam_filtered:", count_gam_filtered)) print(paste("تعداد عناصر lam_filtered:", count_lam_filtered)) a<- gam_filtered[-c(1:2000)] a c<- lam_filtered[-c(1:2000)] c actual_gamahat <- 1 actual_lamdahat <- 2 mse_gamahat <- mean((a - actual_gamahat)^2) mse_gamahat mse_lamdahat = mean((c - actual_lamdahat)^2) mse_lamdahat mse_shaat = mean((shaat - actual_lamdahat)^2) mse_shaat mse_hhaat = mean((hhaat - actual_lamdahat)^2) mse_hhaat
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in  on line 0. in /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()
#2 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/ErrorHandler.php(135): yii\web\ErrorHandler->renderException()
#3 [internal function]: yii\base\ErrorHandler->handleException()
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in  on line 0. in /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Application.php(656): yii\web\Response->send()
#2 /var/www/html/prof-homepages/vendor/faravaghi/yii2-filemanager/models/Files.php(696): yii\base\Application->end()
#3 /var/www/html/prof-homepages/vendor/faravaghi/yii2-filemanager/controllers/FilesController.php(484): faravaghi\filemanager\models\Files->getFile()
#4 [internal function]: faravaghi\filemanager\controllers\FilesController->actionGetFile()
#5 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#6 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams()
#7 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction()
#8 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()
#9 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest()
#10 /var/www/html/prof-homepages/frontend/web/index.php(18): yii\base\Application->run()
#11 {main}