美文网首页散文简友广场
R语言验证均匀分布总体参数的的矩估计是相合的consistent

R语言验证均匀分布总体参数的的矩估计是相合的consistent

作者: Cache_wood | 来源:发表于2021-03-27 00:09 被阅读0次

    判断估计的相合性依据的原理是6.2.1,定理6.2.2是扩充。



    即需要证明两点:

    (1)渐进无偏性
    (2)渐进方差等于0

    1.

    第一段代码验证{X1,···,Xn}是总体中值参数θ =µ+ φ^{-1}(0.5)\theta的一致估计量.

    2.

    第二段代码均匀分布的最大统计量假设总体X服从均匀分布U(0, θ),请验证最大统计量X(1) = max{X1,···,Xn}是θ的一致估计量。

    3.

    现在轮到你来验证Unif(a, b)总体参数的矩估计是一致的。

    # === medfun(): Sample median is consistent estimator of population
    # median or not? Here, n: sample size; K: repeating times; mean0 and
    # sd0 are mean and sd of normal distribution
    medfun <- function(n = 100, K = 1000, mean0 = 0, sd0 = 1) {
      meds <- NULL
      # null vector, used to save sample medians
      for (k in 1:K) {
        sams <- rnorm(n, mean = mean0, sd = sd0)
        # samples for normal distribution
        meds <- c(meds, median(sams))
        # compute the sample median
      }
      mbias <- mean(meds) - qnorm(0.5, mean = mean0, sd = sd0)
      # empirical bias
      esd <- sd(meds)
      # empirical standard derviation
      list(n = n, mbias = mbias, esd = esd)
      # result as a list
    }
    
    # N(0,1)
    n100 <- medfun(n = 100)
    n200 <- medfun(n = 200)
    n400 <- medfun(n = 400)
    n800 <- medfun(n = 800)
    n1000 <- medfun(n = 1000)
    re <- rbind(n100, n200, n400, n800, n1000)
    re
    
    # N(1,2)
    n100 <- medfun(n = 100, mean0 = 1, sd0 = 2)
    n200 <- medfun(n = 200, mean0 = 1, sd0 = 2)
    n400 <- medfun(n = 400, mean0 = 1, sd0 = 2)
    n800 <- medfun(n = 800, mean0 = 1, sd0 = 2)
    n1000 <- medfun(n = 1000, mean0 = 1, sd0 = 2)
    re <- rbind(n100, n200, n400, n800, n1000)
    re
    # === consistent if: 1. empirical bias are all close to zero; and 2.
    # empirical sd tends to zero as sample size increases
    # === Uniform(0,theta) ===
    unifun <- function(n = 100, K = 1000, theta = 1) {
      maxval <- NULL
      for (i in 1:K) {
        sams <- runif(n, 0, theta)
        maxval <- c(maxval, max(sams))
      }
      mbias <- mean(maxval) - theta
      esd <- sd(maxval)
      list(n = n, mbias = mbias, esd = esd)
    }
    # U(0,1)
    u1 <- unifun(n = 100)
    u2 <- unifun(n = 200)
    u3 <- unifun(n = 400)
    u4 <- unifun(n = 800)
    rbind(u1, u2, u3, u4)
    
    # U(0,2*sqrt(3))
    u1 <- unifun(n = 100, theta = 2 * sqrt(3))
    u2 <- unifun(n = 200, theta = 2 * sqrt(3))
    u3 <- unifun(n = 400, theta = 2 * sqrt(3))
    u4 <- unifun(n = 800, theta = 2 * sqrt(3))
    rbind(u1, u2, u3, u4)
    
    meanfun <- function(n = 100, K = 1000, a = 0, b = 1) {
      mea <- NULL
      # null vector, used to save sample mean number
      for (k in 1:K) {
        sams <- runif(n, a, b)
        # samples for uniform distribution
        mea <- c(mea, mean(sams))
        # compute the sample mean
      }
      mbias <- mean(mea) - mean(a:b)
      # empirical bias
      esd <- sd(mea)
      # empirical standard derviation
      list(n = n, mbias = mbias, esd = esd)
      # result as a list
    }
    #unif ~ (0,1)
    n100 <- meanfun(n = 100, b = 2)
    n200 <- meanfun(n = 200, b = 2)
    n400 <- meanfun(n = 400, b = 2)
    n800 <- meanfun(n = 800, b = 2)
    n1000 <- meanfun(n = 1000, b = 2)
    rbind(n100, n200, n400, n800, n1000)
    
    # b = 1
       n   mbias        esd        
    u1 100 -0.0352749   0.03513745 
    u2 200 -0.018127    0.01760004 
    u3 400 -0.008798743 0.008986948
    u4 800 -0.004345918 0.004439682
    # b = 2
          n    mbias         esd       
    n100  100  -0.0005611266 0.05589222
    n200  200  -0.000229566  0.04092171
    n400  400  0.0006570319  0.02798479
    n800  800  -0.0002061969 0.02009344
    n1000 1000 -0.0004253045 0.01824597
    

    相关文章

      网友评论

        本文标题:R语言验证均匀分布总体参数的的矩估计是相合的consistent

        本文链接:https://www.haomeiwen.com/subject/ajegcltx.html