五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

R語言邏輯回歸、方差分析 、偽R平方分析

2021-03-02 22:32 作者:拓端tecdat  | 我要投稿

原文鏈接:http://tecdat.cn/?p=9589

?

目錄

怎么做測試

假設(shè)條件

并非所有比例或計(jì)數(shù)都適用于邏輯回歸分析

過度分散

偽R平方

測試p值

Logistic回歸示例

模型擬合

系數(shù)和指數(shù)系數(shù)

方差分析?

偽R平方

模型的整體p值

標(biāo)準(zhǔn)化殘差圖

繪制模型

Logistic回歸示例

模型擬合

系數(shù)和指數(shù)系數(shù)

方差分析

偽R平方

模型的整體p值

標(biāo)準(zhǔn)化殘差圖

繪制模型

Logistic回歸示例

怎么做測試

Logistic回歸可以使用glm??(廣義線性模型)函數(shù)在R中執(zhí)行??。該函數(shù)使用鏈接函數(shù)來確定要使用哪種模型,例如邏輯模型,概率模型或泊松模型。?

假設(shè)條件

廣義線性模型的假設(shè)少于大多數(shù)常見的參數(shù)檢驗(yàn)。觀測值仍然需要獨(dú)立,并且需要指定正確的鏈接函數(shù)。因此,例如應(yīng)該了解何時使用泊松回歸以及何時使用邏輯回歸。但是,不需要數(shù)據(jù)或殘差的正態(tài)分布。

?

并非所有比例或計(jì)數(shù)都適用于邏輯回歸分析

一個不采用邏輯回歸的例子中,飲食研究中人們減肥的體重?zé)o法用初始體重的比例來解釋作為“成功”和“失敗”的計(jì)數(shù)。在這里,只要滿足模型假設(shè),就可以使用常用的參數(shù)方法。

?

過度分散

使用廣義線性模型時要注意的一個潛在問題是過度分散。當(dāng)模型的殘余偏差相對于殘余自由度較高時,就會發(fā)生這種情況。這基本上表明該模型不能很好地擬合數(shù)據(jù)。?

?

但是據(jù)我了解,從技術(shù)上講,過度分散對于簡單的邏輯回歸而言不是問題,即具有二項(xiàng)式因果關(guān)系和單個連續(xù)自變量的問題。

?

偽R平方

對于廣義線性模型(glm),R不產(chǎn)生r平方值。pscl??包中的??pR2? 可以產(chǎn)生偽R平方值。

?

測試p值

檢驗(yàn)邏輯對數(shù)或泊松回歸的p值使用卡方檢驗(yàn)。方差分析??來測試每一個系數(shù)的顯著性。似然比檢驗(yàn)也可以用來檢驗(yàn)整體模型的重要性。

?

Logistic回歸示例

?



  1. Data = read.table(textConnection(Input),header=TRUE)


  2. Data$Total = Data$mpi90 + Data$mpi100


  3. Data$Percent = Data$mpi100 / + Data$Total

模型擬合

?

  1. Trials = cbind(Data$mpi100, Data$mpi90) ? ? ? ? # Sucesses, Failures


  2. model = glm(Trials ~ Latitude,

  3. data = Data,

  4. family = binomial(link="logit"))

系數(shù)和指數(shù)系數(shù)

?


  1. Coefficients:


  2. Estimate Std. Error z value Pr(>|z|)


  3. (Intercept) -7.64686 ? ?0.92487 ?-8.268 ? <2e-16 ***


  4. Latitude ? ? 0.17864 ? ?0.02104 ? 8.490 ? <2e-16 ***







  5. 2.5 % ? ? 97.5 %


  6. (Intercept) -9.5003746 -5.8702453


  7. Latitude ? ? 0.1382141 ?0.2208032





  8. # exponentiated coefficients




  9. (Intercept) ? ? Latitude


  10. 0.0004775391 1.1955899446





  11. # 95% CI for exponentiated coefficients




  12. 2.5 % ? ? ?97.5 %


  13. (Intercept) 7.482379e-05 0.002822181


  14. Latitude ? ?1.148221e+00 1.247077992

方差分析?



  1. Analysis of Deviance Table (Type II tests)




  2. Response: Trials


  3. Df ?Chisq Pr(>Chisq)


  4. Latitude ? 1 72.076 ?< 2.2e-16 ***

?

偽R平方

?


  1. $Models




  2. Model: "glm, Trials ~ Latitude, binomial(link = \"logit\"), Data"


  3. Null: ?"glm, Trials ~ 1, binomial(link = \"logit\"), Data"




  4. $Pseudo.R.squared.for.model.vs.null


  5. Pseudo.R.squared


  6. McFadden ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0.425248


  7. Cox and Snell (ML) ? ? ? ? ? ? ? ? ? 0.999970


  8. Nagelkerke (Cragg and Uhler) ? ? ? ? 0.999970

?

模型的整體p值

?




  1. Analysis of Deviance Table




  2. Model 1: Trials ~ Latitude


  3. Model 2: Trials ~ 1


  4. Resid. Df Resid. Dev Df Deviance ?Pr(>Chi)


  5. 1 ? ? ? ? 6 ? ? 70.333


  6. 2 ? ? ? ? 7 ? ?153.633 -1 ?-83.301 < 2.2e-16 ***





  7. Likelihood ratio test




  8. Model 1: Trials ~ Latitude


  9. Model 2: Trials ~ 1


  10. #Df ?LogLik Df ?Chisq Pr(>Chisq)


  11. 1 ? 2 -56.293


  12. 2 ? 1 -97.944 -1 83.301 ?< 2.2e-16 ***

?

標(biāo)準(zhǔn)化殘差圖

?

?

?

?

標(biāo)準(zhǔn)化殘差與預(yù)測值的關(guān)系圖。殘差應(yīng)無偏且均等。?

?

繪制模型

?

?

?

?

?

?

Logistic回歸示例

?



  1. Data = read.table(textConnection(Input),header=TRUE)



?

模型擬合

?

model

?

系數(shù)和指數(shù)系數(shù)

?



  1. Coefficients:


  2. Estimate Std. Error z value Pr(>|z|)


  3. (Intercept) ?4.41379 ? ?6.66190 ? 0.663 ? ?0.508


  4. Height ? ? ?-0.05016 ? ?0.09577 ?-0.524 ? ?0.600









  5. 2.5 % ? ? 97.5 %


  6. (Intercept) -8.4723648 18.4667731


  7. Height ? ? ?-0.2498133 ?0.1374819




  8. # exponentiated coefficients




  9. (Intercept) ? ? ?Height


  10. 82.5821122 ? 0.9510757





  11. # 95% CI for exponentiated coefficients




  12. 2.5 % ? ? ? 97.5 %


  13. (Intercept) 0.0002091697 1.047171e+08


  14. Height ? ? ?0.7789461738 1.147381e+0



?

方差分析

?



  1. Analysis of Deviance Table (Type II tests)




  2. Response: Insect


  3. Df ?Chisq Pr(>Chisq)


  4. Height ? ? 1 0.2743 ? ? 0.6004


  5. Residuals 23

?

偽R平方

?



  1. $Pseudo.R.squared.for.model.vs.null


  2. Pseudo.R.squared


  3. McFadden ? ? ? ? ? ? ? ? ? ? ? ? ? 0.00936978


  4. Cox and Snell (ML) ? ? ? ? ? ? ? ? 0.01105020


  5. Nagelkerke (Cragg and Uhler) ? ? ? 0.01591030

?

模型的整體p值

?



  1. Analysis of Deviance Table




  2. Model 1: Insect ~ Height


  3. Model 2: Insect ~ 1


  4. Resid. Df Resid. Dev Df Deviance Pr(>Chi)


  5. 1 ? ? ? ?23 ? ? 29.370


  6. 2 ? ? ? ?24 ? ? 29.648 -1 -0.27779 ? 0.5982







  7. Likelihood ratio test




  8. Model 1: Insect ~ Height


  9. Model 2: Insect ~ 1


  10. #Df ?LogLik Df ?Chisq Pr(>Chisq)


  11. 1 ? 2 -14.685


  12. 2 ? 1 -14.824 -1 0.2778 ? ? 0.5982

標(biāo)準(zhǔn)化殘差圖

?

?

?

?

繪制模型

?




  1. Height Insect Insect.num


  2. 1 ? ? ?62 beetle ? ? ? ? ?0


  3. 2 ? ? ?66 ?other ? ? ? ? ?1


  4. 3 ? ? ?61 beetle ? ? ? ? ?0


  5. 23 ? ? 72 ?other ? ? ? ? ?1


  6. 24 ? ? 70 beetle ? ? ? ? ?0


  7. 25 ? ? 74 ?other ? ? ? ? ?1




?

?

?

?




  1. Height Insect Insect.num Insect.log


  2. 1 ? ? ?62 beetle ? ? ? ? ?0 ? ? ?FALSE


  3. 2 ? ? ?66 ?other ? ? ? ? ?1 ? ? ? TRUE


  4. 3 ? ? ?61 beetle ? ? ? ? ?0 ? ? ?FALSE


  5. 23 ? ? 72 ?other ? ? ? ? ?1 ? ? ? TRUE


  6. 24 ? ? 70 beetle ? ? ? ? ?0 ? ? ?FALSE


  7. 25 ? ? 74 ?other ? ? ? ? ?1 ? ? ? TRUE


?

?

Logistic回歸示例

?



  1. Data = read.table(textConnection(Input),header=TRUE)



  2. model


  3. Coefficients:


  4. Estimate Std. Error z value Pr(>|z|)


  5. (Intercept) -66.4981 ? ?32.3787 ?-2.054 ? 0.0400 *


  6. Continuous ? ?0.9027 ? ? 0.4389 ? 2.056 ? 0.0397 *







  7. Analysis of Deviance Table (Type II tests)




  8. Response: Factor


  9. Df Chisq Pr(>Chisq)


  10. Continuous ?1 4.229 ? ?0.03974 *


  11. Residuals ?27






  12. Pseudo.R.squared


  13. McFadden ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0.697579


  14. Cox and Snell (ML) ? ? ? ? ? ? ? ? ? 0.619482


  15. Nagelkerke (Cragg and Uhler) ? ? ? ? 0.826303







  16. Resid. Df Resid. Dev Df Deviance Pr(>Chi)


  17. 1 ? ? ? ?27 ? ? 12.148


  18. 2 ? ? ? ?28 ? ? 40.168 -1 ? -28.02 ?1.2e-07 ***





?

將因子轉(zhuǎn)換為數(shù)字變量,級別為0和1?
?



  1. Continuous Factor Factor.num


  2. 1 ? ? ? ? ?62 ? ? ?A ? ? ? ? ?0


  3. 2 ? ? ? ? ?63 ? ? ?A ? ? ? ? ?0


  4. 3 ? ? ? ? ?64 ? ? ?A ? ? ? ? ?0


  5. 27 ? ? ? ? 84 ? ? ?B ? ? ? ? ?1


  6. 28 ? ? ? ? 85 ? ? ?B ? ? ? ? ?1


  7. 29 ? ? ? ? 86 ? ? ?B ? ? ? ? ?1




?

?

?

將Factor轉(zhuǎn)換為邏輯變量,級別為TRUE和FALSE?
?




  1. Continuous Factor Factor.num Factor.log


  2. 1 ? ? ? ? ?62 ? ? ?A ? ? ? ? ?0 ? ? ?FALSE


  3. 2 ? ? ? ? ?63 ? ? ?A ? ? ? ? ?0 ? ? ?FALSE


  4. 3 ? ? ? ? ?64 ? ? ?A ? ? ? ? ?0 ? ? ?FALSE


  5. 27 ? ? ? ? 84 ? ? ?B ? ? ? ? ?1 ? ? ? TRUE


  6. 28 ? ? ? ? 85 ? ? ?B ? ? ? ? ?1 ? ? ? TRUE


  7. 29 ? ? ? ? 86 ? ? ?B ? ? ? ? ?1 ? ? ? TRUE




R語言邏輯回歸、方差分析 、偽R平方分析的評論 (共 條)

分享到微博請遵守國家法律
河曲县| 吴川市| 沙坪坝区| 汪清县| 恭城| 双桥区| 十堰市| 锦屏县| 河源市| 乌拉特前旗| 西吉县| 长沙县| 昆山市| 德兴市| 方城县| 南宫市| 赣州市| 宜阳县| 达州市| 香格里拉县| 舟山市| 牙克石市| 如东县| 沿河| 漾濞| 古田县| 故城县| 凌源市| 枝江市| 曲阳县| 怀来县| 商都县| 兰坪| 和田市| 嵊州市| 清流县| 吕梁市| 菏泽市| 偃师市| 怀化市| 高碑店市|