<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 12.2 皮爾遜卡方檢驗 皮爾遜卡方檢驗為我們提供了一種方法來檢驗觀察到的計數數據是否與定義零假設的某些特定預期值不同: ![](https://img.kancloud.cn/6c/77/6c77c8f959d710ca130457e05eaa9d74_264x49.jpg) 在我們的糖果例子中,無效假設是每種糖果的比例是相等的。我們可以計算我們觀察到的糖果計數的卡方統計,如下所示: ```r # compute chi-squared statistic nullExpectation <- c(1 / 3, 1 / 3, 1 / 3) * sum(candyDf$count) chisqVal <- sum( ((candyDf$count - nullExpectation)**2) / nullExpectation ) ``` 這個分析的卡方統計結果是 0.74,這本身是不可解釋的,因為它取決于加在一起的不同值的數量。然而,我們可以利用這樣一個事實:卡方統計量是根據零假設下的特定分布分布分布的,這就是所謂的 _ 卡方 _ 分布。這種分布被定義為一組標準正態隨機變量的平方和;它有若干自由度,等于被加在一起的變量數。分布的形狀取決于自由度的數量。圖[12.1](#fig:chisqDist)顯示了幾種不同自由度的分布示例。 ![Examples of the chi-squared distribution for various degrees of freedom.](https://img.kancloud.cn/2b/3a/2b3a36b9e9442868b4ea4039730f3c69_384x384.png) 圖 12.1 不同自由度的卡方分布示例。 讓我們通過模擬來驗證卡方分布是否準確地描述了一組標準正態隨機變量的平方和。 ```r # simulate 50,000 sums of 8 standard normal random variables and compare # to theoretical chi-squared distribution # create a matrix with 50k columns of 8 rows of squared normal random variables d <- replicate(50000, rnorm(n = 8, mean = 0, sd = 1)**2) # sum each column of 8 variables dMean <- apply(d, 2, sum) # create a data frame of the theoretical chi-square distribution # with 8 degrees of freedom csDf <- data.frame(x = seq(0.01, 30, 0.01)) %>% mutate(chisq = dchisq(x, 8)) ``` 圖[12.2](#fig:chisqSim)顯示,理論分布與重復將一組隨機正態變量的平方相加的模擬結果非常吻合。 ![Simulation of sum of squared random normal variables. The histogram is based on the sum of squares of 50,000 sets of 8 random normal variables; the blue line shows the values of the theoretical chi-squared distribution with 8 degrees of freedom.](https://img.kancloud.cn/58/f9/58f94ad0d4842f59c1112e8663c8ead3_384x384.png) 圖 12.2 平方隨機正態變量和的模擬。柱狀圖是基于 5 萬組 8 個隨機正態變量的平方和;藍線顯示了 8 個自由度下理論卡方分布的值。 對于糖果的例子,我們可以計算在所有糖果的相同頻率的零假設下,我們觀察到的卡方值為 0.74 的可能性。我們使用自由度等于 k-1(其中 k=類別數)的卡方分布,因為我們在計算平均值以生成預期值時失去了一個自由度。 ```r pval <- pchisq(chisqVal, df = 2, lower.tail = FALSE) #df = degrees of freedom sprintf("p-value = %0.3f", pval) ``` ```r ## [1] "p-value = 0.691" ``` 這表明,觀察到的糖果數量并不是特別令人驚訝的,基于印刷在糖果袋上的比例,我們不會拒絕等比的無效假設。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看