R တွင် glm() မှ regression coefficients ကို မည်သို့ထုတ်ယူရမည်နည်း။
R ရှိ glm() function မှ regression coefficients ကိုထုတ်ယူရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။
နည်းလမ်း 1- regression coefficients အားလုံးကို ထုတ်ယူပါ။
model$coefficients
နည်းလမ်း 2- သတ်မှတ်ထားသော ကိန်းရှင်အတွက် ဆုတ်ယုတ်မှုကိန်းကို ထုတ်ယူပါ။
model$coefficients[' my_variable ']
နည်းလမ်း 3- စံအမှား၊ Z တန်ဖိုးနှင့် P တန်ဖိုးများဖြင့် ဆုတ်ယုတ်မှုကိန်းဂဏန်းများအားလုံးကို ထုတ်ယူပါ။
summary(model)$coefficients
အောက်ဖော်ပြပါ ဥပမာသည် ဤနည်းလမ်းများကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ- R တွင် glm() မှ regression coefficients ကို ထုတ်ယူပါ။
ကျွန်ုပ်တို့သည် ISLR ပက်ကေ့ဂျ်မှ မူရင်း ဒေတာအစုံကို အသုံးပြု၍ ထောက်ပံ့ပို့ဆောင်ရေးဆိုင်ရာ ဆုတ်ယုတ်မှုပုံစံကို အံကိုက်ဆိုပါစို့။
#load dataset data <- ISLR::Default #view first six rows of data head(data) default student balance income 1 No No 729.5265 44361.625 2 No Yes 817.1804 12106.135 3 No No 1073.5492 31767.139 4 No No 529.2506 35704.494 5 No No 785.6559 38463.496 6 No Yes 919.5885 7491.559 #fit logistic regression model model <- glm(default~student+balance+income, family=' binomial ', data=data) #view summary of logistic regression model summary(model) Call: glm(formula = default ~ student + balance + income, family = "binomial", data = data) Deviance Residuals: Min 1Q Median 3Q Max -2.4691 -0.1418 -0.0557 -0.0203 3.7383 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -1.087e+01 4.923e-01 -22.080 < 2e-16 *** studentYes -6.468e-01 2.363e-01 -2.738 0.00619 ** balance 5.737e-03 2.319e-04 24.738 < 2e-16 *** income 3.033e-06 8.203e-06 0.370 0.71152 --- Significant. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 2920.6 on 9999 degrees of freedom Residual deviance: 1571.5 on 9996 degrees of freedom AIC: 1579.5 Number of Fisher Scoring iterations: 8
မော်ဒယ်မှ regression coefficients အားလုံးကို ထုတ်ယူရန် model$coefficients ကို ရိုက်ထည့်နိုင်သည်-
#extract all regression coefficients
model$coefficients
(Intercept) studentYes balance income
-1.086905e+01 -6.467758e-01 5.736505e-03 3.033450e-06
ချိန်ခွင်လျှာ ကိန်းရှင်အတွက်သာ ဆုတ်ယုတ်ကိန်းကိန်းကို ထုတ်ယူရန် model$coefficients[‘balance’] ကိုလည်း ရိုက်ထည့်နိုင်သည်-
#extract coefficient for 'balance'
model$coefficients[' balance ']
balance
0.005736505
၎င်းတို့၏ စံအမှားများ၊ z-တန်ဖိုးများနှင့် p-တန်ဖိုးများ နှင့်အတူ ဆုတ်ယုတ်မှုကိန်းများကို ပြသရန်၊ ကျွန်ုပ်တို့သည် အောက်ပါအတိုင်း အကျဉ်းချုပ်(မော်ဒယ်)$ coefficients ကို အသုံးပြုနိုင်ပါသည်။
#view regression coefficients with standard errors, z values and p-values
summary(model)$coefficients
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.086905e+01 4.922555e-01 -22.080088 4.911280e-108
studentYes -6.467758e-01 2.362525e-01 -2.737646 6.188063e-03
balance 5.736505e-03 2.318945e-04 24.737563 4.219578e-135
income 3.033450e-06 8.202615e-06 0.369815 7.115203e-01
ဤအထွက်တွင် သီးခြားတန်ဖိုးများကို ကျွန်ုပ်တို့လည်း ရယူနိုင်သည်။
ဥပမာအားဖြင့်၊ ကျွန်ုပ်တို့သည် လက်ကျန် ကိန်းရှင်၏ p တန်ဖိုးကို ဝင်ရောက်ရန် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်သည်။
#view p-value for balance variable summary(model)$coefficients[' balance ', ' Pr(>|z|) '] [1] 4.219578e-135
သို့မဟုတ် regression coefficient တစ်ခုစီအတွက် p-value ကိုရယူရန် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်သည်။
#view p-value for all variables summary(model)$coefficients[, ' Pr(>|z|) '] (Intercept) studentYes balance income 4.911280e-108 6.188063e-03 4.219578e-135 7.115203e-01
မော်ဒယ်ရှိ ဆုတ်ယုတ်မှုကိန်းဂဏန်းတစ်ခုစီအတွက် P တန်ဖိုးများကို ဖော်ပြသည်။
အထွက်ရှိ မည်သည့်တန်ဖိုးကိုမဆို ဝင်ရောက်ရန် ဆင်တူသော အထားအသိုကို အသုံးပြုနိုင်သည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
R တွင် ရိုးရှင်းသော linear regression လုပ်နည်း
R တွင် linear regression အများအပြားလုပ်ဆောင်နည်း
R တွင် logistic regression ကို မည်သို့လုပ်ဆောင်ရမည်နည်း
R တွင် quadratic regression ကို မည်သို့လုပ်ဆောင်ရမည်နည်း။